Skip to content

Commit

Permalink
Rename TxType variants to UpperCamelCase (paradigmxyz#7012)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnerZheng authored Mar 6, 2024
1 parent dd6742e commit 6f8d1a8
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 116 deletions.
2 changes: 1 addition & 1 deletion crates/net/eth-wire/src/types/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tests {
fn roundtrip_eip1559() {
let receipts = Receipts(vec![vec![ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::EIP1559,
tx_type: TxType::Eip1559,
success: false,
cumulative_gas_used: 0,
logs: vec![],
Expand Down
8 changes: 4 additions & 4 deletions crates/net/network/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,17 @@ impl TxTypesCounter {
TxType::Legacy => {
self.legacy += 1;
}
TxType::EIP2930 => {
TxType::Eip2930 => {
self.eip2930 += 1;
}
TxType::EIP1559 => {
TxType::Eip1559 => {
self.eip1559 += 1;
}
TxType::EIP4844 => {
TxType::Eip4844 => {
self.eip4844 += 1;
}
#[cfg(feature = "optimism")]
TxType::DEPOSIT => {}
TxType::Deposit => {}
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions crates/net/network/src/transactions/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ impl ValidateTx68 for EthMessageFilter {
// the biggest transaction so far is a blob transaction, which is currently max 2^17,
// encoded length, nonetheless, the blob tx may become bigger in the future.
match ty {
TxType::Legacy | TxType::EIP2930 | TxType::EIP1559 => Some(MAX_MESSAGE_SIZE),
TxType::EIP4844 => None,
TxType::Legacy | TxType::Eip2930 | TxType::Eip1559 => Some(MAX_MESSAGE_SIZE),
TxType::Eip4844 => None,
#[cfg(feature = "optimism")]
TxType::DEPOSIT => None,
TxType::Deposit => None,
}
}

Expand Down Expand Up @@ -393,7 +393,7 @@ mod test {
#[test]
fn eth68_announcement_too_small_tx() {
let types =
vec![TxType::MAX_RESERVED_EIP as u8, TxType::Legacy as u8, TxType::EIP2930 as u8];
vec![TxType::MAX_RESERVED_EIP as u8, TxType::Legacy as u8, TxType::Eip2930 as u8];
let sizes = vec![
0, // the first length isn't valid
0, // neither is the second
Expand Down Expand Up @@ -433,10 +433,10 @@ mod test {
#[test]
fn eth68_announcement_duplicate_tx_hash() {
let types = vec![
TxType::EIP1559 as u8,
TxType::EIP4844 as u8,
TxType::EIP1559 as u8,
TxType::EIP4844 as u8,
TxType::Eip1559 as u8,
TxType::Eip4844 as u8,
TxType::Eip1559 as u8,
TxType::Eip4844 as u8,
];
let sizes = vec![1, 1, 1, MAX_MESSAGE_SIZE];
// first three or the same
Expand Down
4 changes: 2 additions & 2 deletions crates/payload/optimism/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ mod builder {
}

// A sequencer's block should never contain blob transactions.
if matches!(sequencer_tx.tx_type(), TxType::EIP4844) {
if matches!(sequencer_tx.tx_type(), TxType::Eip4844) {
return Err(PayloadBuilderError::other(
OptimismPayloadBuilderError::BlobTransactionRejected,
))
Expand Down Expand Up @@ -426,7 +426,7 @@ mod builder {
}

// A sequencer's block should never contain blob transactions.
if pool_tx.tx_type() == TxType::EIP4844 as u8 {
if pool_tx.tx_type() == TxType::Eip4844 as u8 {
return Err(PayloadBuilderError::other(
OptimismPayloadBuilderError::BlobTransactionRejected,
))
Expand Down
14 changes: 7 additions & 7 deletions crates/primitives/src/proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ mod tests {
// 0xb0d6ee650637911394396d81172bd1c637d568ed1fbddab0daddfca399c58b53
ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::DEPOSIT,
tx_type: TxType::Deposit,
success: true,
cumulative_gas_used: 46913,
logs: vec![],
Expand All @@ -332,7 +332,7 @@ mod tests {
// 0x2f433586bae30573c393adfa02bc81d2a1888a3d6c9869f473fb57245166bd9a
ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::EIP1559,
tx_type: TxType::Eip1559,
success: true,
cumulative_gas_used: 118083,
logs: vec![
Expand Down Expand Up @@ -376,7 +376,7 @@ mod tests {
// 0x6c33676e8f6077f46a62eabab70bc6d1b1b18a624b0739086d77093a1ecf8266
ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::EIP1559,
tx_type: TxType::Eip1559,
success: true,
cumulative_gas_used: 189253,
logs: vec![
Expand Down Expand Up @@ -420,7 +420,7 @@ mod tests {
// 0x4d3ecbef04ba7ce7f5ab55be0c61978ca97c117d7da448ed9771d4ff0c720a3f
ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::EIP1559,
tx_type: TxType::Eip1559,
success: true,
cumulative_gas_used: 346969,
logs: vec![
Expand Down Expand Up @@ -494,7 +494,7 @@ mod tests {
// 0xf738af5eb00ba23dbc1be2dbce41dbc0180f0085b7fb46646e90bf737af90351
ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::EIP1559,
tx_type: TxType::Eip1559,
success: true,
cumulative_gas_used: 623249,
logs: vec![
Expand Down Expand Up @@ -548,7 +548,7 @@ mod tests {
let bloom = bloom!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001");
let receipt = ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::EIP2930,
tx_type: TxType::Eip2930,
success: true,
cumulative_gas_used: 102068,
logs,
Expand All @@ -569,7 +569,7 @@ mod tests {
let bloom = bloom!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001");
let receipt = ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::EIP2930,
tx_type: TxType::Eip2930,
success: true,
cumulative_gas_used: 102068,
logs,
Expand Down
30 changes: 15 additions & 15 deletions crates/primitives/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl proptest::arbitrary::Arbitrary for Receipt {
{
// Only receipts for deposit transactions may contain a deposit nonce
#[cfg(feature = "optimism")]
let (deposit_nonce, deposit_receipt_version) = if tx_type == TxType::DEPOSIT {
let (deposit_nonce, deposit_receipt_version) = if tx_type == TxType::Deposit {
// The deposit receipt version is only present if the deposit nonce is present
let deposit_receipt_version = _deposit_nonce.and(_deposit_receipt_version);
(_deposit_nonce, deposit_receipt_version)
Expand Down Expand Up @@ -251,7 +251,7 @@ impl<'a> arbitrary::Arbitrary<'a> for Receipt {

// Only receipts for deposit transactions may contain a deposit nonce
#[cfg(feature = "optimism")]
let (deposit_nonce, deposit_receipt_version) = if tx_type == TxType::DEPOSIT {
let (deposit_nonce, deposit_receipt_version) = if tx_type == TxType::Deposit {
let deposit_nonce = Option::<u64>::arbitrary(u)?;
let deposit_nonce_version =
deposit_nonce.map(|_| Option::<u64>::arbitrary(u)).transpose()?.flatten();
Expand Down Expand Up @@ -295,7 +295,7 @@ impl ReceiptWithBloom {

let receipt = match tx_type {
#[cfg(feature = "optimism")]
TxType::DEPOSIT => {
TxType::Deposit => {
let remaining = |b: &[u8]| rlp_head.payload_length - (started_len - b.len()) > 0;
let deposit_nonce =
remaining(b).then(|| alloy_rlp::Decodable::decode(b)).transpose()?;
Expand Down Expand Up @@ -364,20 +364,20 @@ impl Decodable for ReceiptWithBloom {
match receipt_type {
0x01 => {
buf.advance(1);
Self::decode_receipt(buf, TxType::EIP2930)
Self::decode_receipt(buf, TxType::Eip2930)
}
0x02 => {
buf.advance(1);
Self::decode_receipt(buf, TxType::EIP1559)
Self::decode_receipt(buf, TxType::Eip1559)
}
0x03 => {
buf.advance(1);
Self::decode_receipt(buf, TxType::EIP4844)
Self::decode_receipt(buf, TxType::Eip4844)
}
#[cfg(feature = "optimism")]
0x7E => {
buf.advance(1);
Self::decode_receipt(buf, TxType::DEPOSIT)
Self::decode_receipt(buf, TxType::Deposit)
}
_ => Err(alloy_rlp::Error::Custom("invalid receipt type")),
}
Expand Down Expand Up @@ -448,7 +448,7 @@ impl<'a> ReceiptWithBloomEncoder<'a> {
rlp_head.payload_length += self.receipt.logs.length();

#[cfg(feature = "optimism")]
if self.receipt.tx_type == TxType::DEPOSIT {
if self.receipt.tx_type == TxType::Deposit {
if let Some(deposit_nonce) = self.receipt.deposit_nonce {
rlp_head.payload_length += deposit_nonce.length();
}
Expand All @@ -468,7 +468,7 @@ impl<'a> ReceiptWithBloomEncoder<'a> {
self.bloom.encode(out);
self.receipt.logs.encode(out);
#[cfg(feature = "optimism")]
if self.receipt.tx_type == TxType::DEPOSIT {
if self.receipt.tx_type == TxType::Deposit {
if let Some(deposit_nonce) = self.receipt.deposit_nonce {
deposit_nonce.encode(out)
}
Expand Down Expand Up @@ -497,17 +497,17 @@ impl<'a> ReceiptWithBloomEncoder<'a> {
match self.receipt.tx_type {
TxType::Legacy => unreachable!("legacy already handled"),

TxType::EIP2930 => {
TxType::Eip2930 => {
out.put_u8(0x01);
}
TxType::EIP1559 => {
TxType::Eip1559 => {
out.put_u8(0x02);
}
TxType::EIP4844 => {
TxType::Eip4844 => {
out.put_u8(0x03);
}
#[cfg(feature = "optimism")]
TxType::DEPOSIT => {
TxType::Deposit => {
out.put_u8(0x7E);
}
}
Expand Down Expand Up @@ -617,7 +617,7 @@ mod tests {
// Deposit Receipt (post-regolith)
let expected = ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::DEPOSIT,
tx_type: TxType::Deposit,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
Expand All @@ -643,7 +643,7 @@ mod tests {
// Deposit Receipt (post-regolith)
let expected = ReceiptWithBloom {
receipt: Receipt {
tx_type: TxType::DEPOSIT,
tx_type: TxType::Deposit,
cumulative_gas_used: 46913,
logs: vec![],
success: true,
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl TxEip1559 {

/// Get transaction type
pub(crate) fn tx_type(&self) -> TxType {
TxType::EIP1559
TxType::Eip1559
}

/// Calculates a heuristic for the in-memory size of the [TxEip1559] transaction.
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl TxEip2930 {

/// Get transaction type
pub(crate) fn tx_type(&self) -> TxType {
TxType::EIP2930
TxType::Eip2930
}

/// Encodes the legacy transaction in RLP for signing.
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl TxEip4844 {

/// Get transaction type
pub(crate) fn tx_type(&self) -> TxType {
TxType::EIP4844
TxType::Eip4844
}

/// Encodes the legacy transaction in RLP for signing.
Expand Down
12 changes: 6 additions & 6 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,19 +1266,19 @@ impl TransactionSigned {
return Err(RlpError::Custom("unsupported typed transaction type"))
};
let transaction = match tx_type {
TxType::EIP2930 => Transaction::Eip2930(TxEip2930::decode_inner(data)?),
TxType::EIP1559 => Transaction::Eip1559(TxEip1559::decode_inner(data)?),
TxType::EIP4844 => Transaction::Eip4844(TxEip4844::decode_inner(data)?),
TxType::Eip2930 => Transaction::Eip2930(TxEip2930::decode_inner(data)?),
TxType::Eip1559 => Transaction::Eip1559(TxEip1559::decode_inner(data)?),
TxType::Eip4844 => Transaction::Eip4844(TxEip4844::decode_inner(data)?),
#[cfg(feature = "optimism")]
TxType::DEPOSIT => Transaction::Deposit(TxDeposit::decode_inner(data)?),
TxType::Deposit => Transaction::Deposit(TxDeposit::decode_inner(data)?),
TxType::Legacy => unreachable!("path for legacy tx has diverged before this method"),
};

#[cfg(not(feature = "optimism"))]
let signature = Signature::decode(data)?;

#[cfg(feature = "optimism")]
let signature = if let TxType::DEPOSIT = tx_type {
let signature = if let TxType::Deposit = tx_type {
Signature::optimism_deposit_tx_signature()
} else {
Signature::decode(data)?
Expand Down Expand Up @@ -1664,7 +1664,7 @@ mod tests {
// https://sepolia.etherscan.io/getRawTx?tx=0x9a22ccb0029bc8b0ddd073be1a1d923b7ae2b2ea52100bae0db4424f9107e9c0
let raw_tx = alloy_primitives::hex::decode("0x03f9011d83aa36a7820fa28477359400852e90edd0008252089411e9ca82a3a762b4b5bd264d4173a242e7a770648080c08504a817c800f8a5a0012ec3d6f66766bedb002a190126b3549fce0047de0d4c25cffce0dc1c57921aa00152d8e24762ff22b1cfd9f8c0683786a7ca63ba49973818b3d1e9512cd2cec4a0013b98c6c83e066d5b14af2b85199e3d4fc7d1e778dd53130d180f5077e2d1c7a001148b495d6e859114e670ca54fb6e2657f0cbae5b08063605093a4b3dc9f8f1a0011ac212f13c5dff2b2c6b600a79635103d6f580a4221079951181b25c7e654901a0c8de4cced43169f9aa3d36506363b2d2c44f6c49fc1fd91ea114c86f3757077ea01e11fdd0d1934eda0492606ee0bb80a7bf8f35cc5f86ec60fe5031ba48bfd544").unwrap();
let decoded = TransactionSigned::decode_enveloped(&mut raw_tx.as_slice()).unwrap();
assert_eq!(decoded.tx_type(), TxType::EIP4844);
assert_eq!(decoded.tx_type(), TxType::Eip4844);

let from = decoded.recover_signer();
assert_eq!(from, Some(address!("A83C816D4f9b2783761a22BA6FADB0eB0606D7B2")));
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/optimism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl TxDeposit {

/// Get the transaction type
pub(crate) fn tx_type(&self) -> TxType {
TxType::DEPOSIT
TxType::Deposit
}
}

Expand Down
Loading

0 comments on commit 6f8d1a8

Please sign in to comment.