Skip to content

Commit

Permalink
optimism: use op-alloy TxDeposit (#10667)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
tcoratger and mattsse authored Sep 5, 2024
1 parent c267c1c commit b0fddef
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 251 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,10 @@ alloy-transport-ipc = { version = "0.3.1", default-features = false }
alloy-transport-ws = { version = "0.3.1", default-features = false }

# op
op-alloy-rpc-types = "0.2.5"
op-alloy-rpc-types-engine = "0.2"
op-alloy-network = "0.2"
op-alloy-rpc-types = "0.2.8"
op-alloy-rpc-types-engine = "0.2.8"
op-alloy-network = "0.2.8"
op-alloy-consensus = "0.2.8"

# misc
aquamarine = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ mod tests {
to: TxKind::Create,
mint: None,
value: U256::ZERO,
gas_limit: 0u64,
gas_limit: 0,
is_system_transaction: false,
input: Default::default(),
});
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ alloy-eips = { workspace = true, features = ["serde"] }

# optimism
op-alloy-rpc-types = { workspace = true, optional = true }
op-alloy-consensus = { workspace = true, features = ["arbitrary"], optional = true }

# crypto
secp256k1 = { workspace = true, features = [
Expand Down Expand Up @@ -105,7 +106,9 @@ optimism = [
"reth-chainspec/optimism",
"reth-ethereum-forks/optimism",
"revm-primitives/optimism",
"reth-codecs?/optimism",
"dep:reth-optimism-chainspec",
"dep:op-alloy-consensus",
]
alloy-compat = ["reth-primitives-traits/alloy-compat", "dep:alloy-rpc-types", "dep:alloy-serde", "dep:op-alloy-rpc-types"]
test-utils = ["reth-primitives-traits/test-utils"]
Expand Down
5 changes: 1 addition & 4 deletions crates/primitives/src/alloy_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,7 @@ impl TryFrom<WithOtherFields<alloy_rpc_types::Transaction>> for Transaction {
to: TxKind::from(tx.to),
mint: fields.mint.filter(|n| *n != 0),
value: tx.value,
gas_limit: tx
.gas
.try_into()
.map_err(|_| ConversionError::Eip2718Error(RlpError::Overflow.into()))?,
gas_limit: tx.gas,
is_system_transaction: fields.is_system_tx.unwrap_or(false),
input: tx.input,
}))
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/transaction/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl FillTxEnv for TransactionSigned {
#[cfg(feature = "optimism")]
Transaction::Deposit(tx) => {
tx_env.access_list.clear();
tx_env.gas_limit = tx.gas_limit;
tx_env.gas_limit = tx.gas_limit as u64;
tx_env.gas_price = U256::ZERO;
tx_env.gas_priority_fee = None;
tx_env.transact_to = tx.to;
Expand Down
24 changes: 14 additions & 10 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ impl<'a> arbitrary::Arbitrary<'a> for Transaction {
Self::Eip7702(tx)
}
#[cfg(feature = "optimism")]
TxType::Deposit => Self::Deposit(TxDeposit::arbitrary(u)?),
TxType::Deposit => {
let mut tx = TxDeposit::arbitrary(u)?;
tx.gas_limit = (tx.gas_limit as u64).into();
Self::Deposit(tx)
}
})
}
}
Expand Down Expand Up @@ -250,7 +254,7 @@ impl Transaction {
Self::Eip4844(_) => TxType::Eip4844,
Self::Eip7702(_) => TxType::Eip7702,
#[cfg(feature = "optimism")]
Self::Deposit(deposit_tx) => deposit_tx.tx_type(),
Self::Deposit(_) => TxType::Deposit,
}
}

Expand Down Expand Up @@ -315,7 +319,7 @@ impl Transaction {
Self::Eip7702(TxEip7702 { gas_limit, .. }) |
Self::Eip2930(TxEip2930 { gas_limit, .. }) => *gas_limit as u64,
#[cfg(feature = "optimism")]
Self::Deposit(TxDeposit { gas_limit, .. }) => *gas_limit,
Self::Deposit(TxDeposit { gas_limit, .. }) => *gas_limit as u64,
}
}

Expand Down Expand Up @@ -556,7 +560,7 @@ impl Transaction {
with_header,
),
#[cfg(feature = "optimism")]
Self::Deposit(deposit_tx) => deposit_tx.encode(out, with_header),
Self::Deposit(deposit_tx) => deposit_tx.encode_inner(out, with_header),
}
}

Expand All @@ -569,7 +573,7 @@ impl Transaction {
Self::Eip4844(tx) => tx.gas_limit = gas_limit.into(),
Self::Eip7702(tx) => tx.gas_limit = gas_limit.into(),
#[cfg(feature = "optimism")]
Self::Deposit(tx) => tx.gas_limit = gas_limit,
Self::Deposit(tx) => tx.gas_limit = gas_limit.into(),
}
}

Expand Down Expand Up @@ -839,7 +843,7 @@ impl Encodable for Transaction {
}
#[cfg(feature = "optimism")]
Self::Deposit(deposit_tx) => {
deposit_tx.encode(out, true);
deposit_tx.encode_inner(out, true);
}
}
}
Expand All @@ -852,7 +856,7 @@ impl Encodable for Transaction {
Self::Eip4844(blob_tx) => blob_tx.payload_len_for_signature(),
Self::Eip7702(set_code_tx) => set_code_tx.payload_len_for_signature(),
#[cfg(feature = "optimism")]
Self::Deposit(deposit_tx) => deposit_tx.payload_len(),
Self::Deposit(deposit_tx) => deposit_tx.encoded_len(true),
}
}
}
Expand Down Expand Up @@ -1243,7 +1247,7 @@ impl TransactionSigned {
true,
),
#[cfg(feature = "optimism")]
Transaction::Deposit(deposit_tx) => deposit_tx.payload_len(),
Transaction::Deposit(deposit_tx) => deposit_tx.encoded_len(true),
}
}

Expand Down Expand Up @@ -1370,7 +1374,7 @@ impl TransactionSigned {
TxType::Eip4844 => Transaction::Eip4844(TxEip4844::decode_fields(data)?),
TxType::Eip7702 => Transaction::Eip7702(TxEip7702::decode_fields(data)?),
#[cfg(feature = "optimism")]
TxType::Deposit => Transaction::Deposit(TxDeposit::decode_inner(data)?),
TxType::Deposit => Transaction::Deposit(TxDeposit::decode_fields(data)?),
TxType::Legacy => return Err(RlpError::Custom("unexpected legacy tx type")),
};

Expand Down Expand Up @@ -1455,7 +1459,7 @@ impl TransactionSigned {
false,
),
#[cfg(feature = "optimism")]
Transaction::Deposit(deposit_tx) => deposit_tx.payload_len_without_header(),
Transaction::Deposit(deposit_tx) => deposit_tx.encoded_len(false),
}
}
}
Expand Down
Loading

0 comments on commit b0fddef

Please sign in to comment.