diff --git a/Cargo.lock b/Cargo.lock index e84660832..d3939eb34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,6 +70,7 @@ dependencies = [ "auto_impl", "c-kzg", "derive_more 1.0.0", + "k256", "serde", ] @@ -249,9 +250,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.8.19" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d039d267aa5cbb7732fa6ce1fd9b5e9e29368f580f80ba9d7a8450c794de4b2" +checksum = "d9d64f851d95619233f74b310f12bcf16e0cbc27ee3762b6115c14a84809280a" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -263,9 +264,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.8.19" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "620ae5eee30ee7216a38027dec34e0585c55099f827f92f50d11e3d2d3a4a954" +checksum = "6bf7ed1574b699f48bf17caab4e6e54c6d12bc3c006ab33d58b1e227c1c3559f" dependencies = [ "alloy-sol-macro-input", "const-hex", @@ -281,9 +282,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro-input" -version = "0.8.19" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad9f7d057e00f8c5994e4ff4492b76532c51ead39353aa2ed63f8c50c0f4d52e" +checksum = "8c02997ccef5f34f9c099277d4145f183b422938ed5322dc57a089fe9b9ad9ee" dependencies = [ "const-hex", "dunce", @@ -5333,6 +5334,7 @@ name = "stratus" version = "0.20.1" dependencies = [ "alloy-consensus", + "alloy-eips", "alloy-primitives", "alloy-rpc-types-eth", "alloy-rpc-types-trace", diff --git a/Cargo.toml b/Cargo.toml index fb1b160ae..bc5cd4c25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,8 +82,9 @@ triehash = "=0.8.4" revm-inspectors = "=0.14.1" alloy-rpc-types-trace = "=0.9.2" alloy-rpc-types-eth = "=0.9.2" -alloy-consensus = "=0.9.2" +alloy-consensus = { version = "=0.9.2", features = ["k256"] } alloy-primitives = "=0.8.15" +alloy-eips = "=0.9.2" # network jsonrpsee = { version = "=0.24.7", features = ["server", "client"] } diff --git a/src/alias.rs b/src/alias.rs index 3045619d1..8df7f28f6 100644 --- a/src/alias.rs +++ b/src/alias.rs @@ -33,9 +33,7 @@ pub type AlloyUint256 = alloy_primitives::Uint<256, 4>; // ----------------------------------------------------------------------------- // Ethers // ----------------------------------------------------------------------------- -pub type AlloyBlockEthersTransaction = alloy_rpc_types_eth::Block; pub type EthersBytes = ethers_core::types::Bytes; -pub type EthersTransaction = ethers_core::types::Transaction; // ----------------------------------------------------------------------------- // REVM diff --git a/src/bin/importer_offline.rs b/src/bin/importer_offline.rs index def71e271..453917373 100644 --- a/src/bin/importer_offline.rs +++ b/src/bin/importer_offline.rs @@ -26,7 +26,6 @@ use stratus::eth::miner::MinerMode; use stratus::eth::primitives::Block; use stratus::eth::primitives::BlockNumber; use stratus::eth::primitives::ExternalReceipts; -use stratus::eth::primitives::ExternalTransaction; use stratus::ext::spawn_named; use stratus::ext::spawn_thread; use stratus::log_and_err; @@ -235,17 +234,11 @@ fn run_external_block_executor( for blocks in Itertools::chunks(blocks.into_iter(), SAVER_BATCH_SIZE).into_iter() { let mut executed_batch = Vec::with_capacity(SAVER_BATCH_SIZE); - for (mut block, receipts) in blocks { + for (block, receipts) in blocks { if GlobalState::is_shutdown_warn(TASK_NAME) { return Ok(()); } - // fill missing transaction_type with `v` - let BlockTransactions::Full(txs) = &mut block.transactions else { - return log_and_err!(GlobalState::shutdown_from(TASK_NAME, "expected full transactions, got hashes or uncle")); - }; - txs.iter_mut().for_each(ExternalTransaction::fill_missing_transaction_type); - // TODO: remove clone executor.execute_external_block(block.clone(), ExternalReceipts::from(receipts))?; let mined_block = miner.mine_external(block)?; @@ -318,8 +311,8 @@ async fn fetch_blocks_and_receipts(rpc_storage: Arc, block_ // perform additional checks on the transaction index for window in transactions.windows(2) { - let tx_index = window[0].transaction_index.ok_or(anyhow!("missing transaction index"))?.as_u32(); - let next_tx_index = window[1].transaction_index.ok_or(anyhow!("missing transaction index"))?.as_u32(); + let tx_index = window[0].transaction_index.ok_or(anyhow!("missing transaction index"))? as u32; + let next_tx_index = window[1].transaction_index.ok_or(anyhow!("missing transaction index"))? as u32; assert!( tx_index + 1 == next_tx_index, "two consecutive transactions must have consecutive indices: {} and {}", diff --git a/src/eth/executor/evm_input.rs b/src/eth/executor/evm_input.rs index 915f0cdeb..713e15d5d 100644 --- a/src/eth/executor/evm_input.rs +++ b/src/eth/executor/evm_input.rs @@ -1,3 +1,4 @@ +use alloy_consensus::Transaction; use alloy_rpc_types_trace::geth::GethDebugTracingOptions; use display_json::DebugAsJson; @@ -139,20 +140,17 @@ impl EvmInput { /// Successful external transactions executes with max gas and zero gas price to ensure we will have the same execution result. pub fn from_external(tx: &ExternalTransaction, receipt: &ExternalReceipt, block_number: BlockNumber, block_timestamp: UnixTime) -> anyhow::Result { Ok(Self { - from: tx.0.from.into(), - to: tx.0.to.map_into(), - value: tx.0.value.into(), - data: tx.0.input.clone().into(), - nonce: Some(tx.0.nonce.try_into()?), - gas_limit: if_else!(receipt.is_success(), Gas::MAX, tx.0.gas.try_into()?), - gas_price: if_else!(receipt.is_success(), Wei::ZERO, tx.0.gas_price.map_into().unwrap_or(Wei::ZERO)), + from: tx.from.into(), + to: tx.inner.to().map_into(), + value: tx.inner.value().into(), + data: tx.inner.input().clone().into(), + nonce: Some(tx.inner.nonce().into()), + gas_limit: if_else!(receipt.is_success(), Gas::MAX, tx.inner.gas_limit().into()), + gas_price: if_else!(receipt.is_success(), Wei::ZERO, tx.inner.gas_price().map_into().unwrap_or(Wei::ZERO)), point_in_time: PointInTime::Pending, block_number, block_timestamp, - chain_id: match tx.0.chain_id { - Some(chain_id) => Some(chain_id.try_into()?), - None => None, - }, + chain_id: tx.inner.chain_id().map(Into::into), }) } diff --git a/src/eth/executor/executor.rs b/src/eth/executor/executor.rs index f9368c9dc..ee02984e9 100644 --- a/src/eth/executor/executor.rs +++ b/src/eth/executor/executor.rs @@ -3,6 +3,7 @@ use std::mem; use std::str::FromStr; use std::sync::Arc; +use alloy_consensus::Transaction; use alloy_rpc_types_trace::geth::GethDebugTracingOptions; use alloy_rpc_types_trace::geth::GethTrace; use anyhow::anyhow; @@ -358,10 +359,14 @@ impl Executor { ) -> anyhow::Result<()> { // track #[cfg(feature = "metrics")] - let (start, tx_function, tx_contract) = (metrics::now(), codegen::function_sig(&tx.0.input), codegen::contract_name(&tx.0.to.map_into())); + let (start, tx_function, tx_contract) = ( + metrics::now(), + codegen::function_sig(tx.inner.input()), + codegen::contract_name(&tx.0.to().map_into()), + ); #[cfg(feature = "tracing")] - let _span = info_span!("executor::external_transaction", tx_hash = %tx.hash).entered(); + let _span = info_span!("executor::external_transaction", tx_hash = %tx.hash()).entered(); tracing::info!(%block_number, tx_hash = %tx.hash(), "reexecuting external transaction"); // when transaction externally failed, create fake transaction instead of reexecuting diff --git a/src/eth/follower/importer/importer.rs b/src/eth/follower/importer/importer.rs index 5f6ccdded..73bea4c3a 100644 --- a/src/eth/follower/importer/importer.rs +++ b/src/eth/follower/importer/importer.rs @@ -455,8 +455,8 @@ impl Importer { // perform additional checks on the transaction index for window in transactions.windows(2) { - let tx_index = window[0].transaction_index.ok_or(anyhow!("missing transaction index"))?.as_u32(); - let next_tx_index = window[1].transaction_index.ok_or(anyhow!("missing transaction index"))?.as_u32(); + let tx_index = window[0].transaction_index.ok_or(anyhow!("missing transaction index"))? as u32; + let next_tx_index = window[1].transaction_index.ok_or(anyhow!("missing transaction index"))? as u32; if tx_index + 1 != next_tx_index { tracing::error!(tx_index, next_tx_index, "two consecutive transactions must have consecutive indices"); } diff --git a/src/eth/primitives/block.rs b/src/eth/primitives/block.rs index 257785195..85fc3f5f6 100644 --- a/src/eth/primitives/block.rs +++ b/src/eth/primitives/block.rs @@ -5,9 +5,9 @@ use alloy_rpc_types_eth::BlockTransactions; use display_json::DebugAsJson; use itertools::Itertools; -use crate::alias::AlloyBlockEthersTransaction; +use crate::alias::AlloyBlockAlloyTransaction; use crate::alias::AlloyBlockH256; -use crate::alias::EthersTransaction; +use crate::alias::AlloyTransaction; use crate::alias::JsonValue; use crate::eth::primitives::Address; use crate::eth::primitives::BlockHeader; @@ -70,7 +70,7 @@ impl Block { /// Serializes itself to JSON-RPC block format with full transactions included. pub fn to_json_rpc_with_full_transactions(self) -> JsonValue { - let alloy_block: AlloyBlockEthersTransaction = self.into(); + let alloy_block: AlloyBlockAlloyTransaction = self.into(); to_json_value(alloy_block) } @@ -127,10 +127,10 @@ impl Block { // ----------------------------------------------------------------------------- // Conversions: Self -> Other // ----------------------------------------------------------------------------- -impl From for AlloyBlockEthersTransaction { +impl From for AlloyBlockAlloyTransaction { fn from(block: Block) -> Self { - let alloy_block: AlloyBlockEthersTransaction = block.header.into(); - let transactions: Vec = block.transactions.into_iter().map_into().collect(); + let alloy_block: AlloyBlockAlloyTransaction = block.header.into(); + let transactions: Vec = block.transactions.into_iter().map_into().collect(); Self { transactions: BlockTransactions::Full(transactions), diff --git a/src/eth/primitives/execution_result.rs b/src/eth/primitives/execution_result.rs index c46ee64f2..2fe38db6a 100644 --- a/src/eth/primitives/execution_result.rs +++ b/src/eth/primitives/execution_result.rs @@ -53,7 +53,7 @@ impl std::fmt::Display for RevertReason { #[cfg(test)] mod tests { - use ethers_core::utils::hex; + use alloy_primitives::hex; use super::*; diff --git a/src/eth/primitives/external_transaction.rs b/src/eth/primitives/external_transaction.rs index 4c26a37a0..39249d444 100644 --- a/src/eth/primitives/external_transaction.rs +++ b/src/eth/primitives/external_transaction.rs @@ -1,13 +1,12 @@ use anyhow::Context; use anyhow::Result; -use crate::alias::EthersTransaction; +use crate::alias::AlloyTransaction; use crate::eth::primitives::BlockNumber; use crate::eth::primitives::Hash; - -#[derive(Debug, Clone, Default, derive_more::Deref, serde::Deserialize, serde::Serialize)] +#[derive(Debug, Clone, derive_more::Deref, serde::Deserialize, serde::Serialize)] #[serde(transparent)] -pub struct ExternalTransaction(#[deref] pub EthersTransaction); +pub struct ExternalTransaction(#[deref] pub AlloyTransaction); impl ExternalTransaction { /// Returns the block number where the transaction was mined. @@ -17,28 +16,15 @@ impl ExternalTransaction { /// Returns the transaction hash. pub fn hash(&self) -> Hash { - self.0.hash.into() - } - - /// Fills the field transaction_type based on `v` - pub fn fill_missing_transaction_type(&mut self) { - // Don't try overriding if it's already set - if self.0.transaction_type.is_some() { - return; - } - - let v = self.0.v.as_u64(); - if [0, 1].contains(&v) { - self.0.transaction_type = Some(2.into()); - } + Hash::from(*self.0.inner.tx_hash()) } } // ----------------------------------------------------------------------------- // Conversions: Other -> Self // ----------------------------------------------------------------------------- -impl From for ExternalTransaction { - fn from(value: EthersTransaction) -> Self { +impl From for ExternalTransaction { + fn from(value: AlloyTransaction) -> Self { ExternalTransaction(value) } } diff --git a/src/eth/primitives/mod.rs b/src/eth/primitives/mod.rs index 36d431a4b..56c20efb7 100644 --- a/src/eth/primitives/mod.rs +++ b/src/eth/primitives/mod.rs @@ -35,6 +35,7 @@ mod nonce; mod pending_block; mod pending_block_header; mod point_in_time; +mod signature_component; mod size; mod slot; mod slot_index; @@ -89,6 +90,7 @@ pub use nonce::Nonce; pub use pending_block::PendingBlock; pub use pending_block_header::PendingBlockHeader; pub use point_in_time::PointInTime; +pub use signature_component::SignatureComponent; pub use size::Size; pub use slot::Slot; pub use slot_index::SlotIndex; @@ -168,6 +170,7 @@ mod tests { gen_test_serde!(LogTopic); gen_test_serde!(MinerNonce); gen_test_serde!(Nonce); + gen_test_serde!(SignatureComponent); gen_test_serde!(Size); gen_test_serde!(Slot); gen_test_serde!(SlotIndex); diff --git a/src/eth/primitives/signature_component.rs b/src/eth/primitives/signature_component.rs new file mode 100644 index 000000000..50015ef80 --- /dev/null +++ b/src/eth/primitives/signature_component.rs @@ -0,0 +1,45 @@ +use alloy_primitives::Uint; +use display_json::DebugAsJson; +use ethereum_types::U256; +use fake::Dummy; +use fake::Faker; +use rand::Rng; + +use crate::alias::AlloyUint256; +use crate::gen_newtype_from; + +/// A signature component (r or s value) +#[derive(DebugAsJson, Clone, Copy, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct SignatureComponent(pub U256); + +impl Dummy for SignatureComponent { + fn dummy_with_rng(_: &Faker, rng: &mut R) -> Self { + Self(U256::from(rng.gen::())) + } +} + +// ----------------------------------------------------------------------------- +// Conversions: Other -> Self +// ----------------------------------------------------------------------------- +gen_newtype_from!(self = SignatureComponent, other = U256); + +impl From> for SignatureComponent { + fn from(value: Uint<256, 4>) -> Self { + Self(U256::from(value.to_be_bytes::<32>())) + } +} + +// ----------------------------------------------------------------------------- +// Conversions: Self -> Other +// ----------------------------------------------------------------------------- +impl From for AlloyUint256 { + fn from(value: SignatureComponent) -> Self { + Self::from_limbs(value.0 .0) + } +} + +impl From for U256 { + fn from(value: SignatureComponent) -> Self { + value.0 + } +} diff --git a/src/eth/primitives/transaction_input.rs b/src/eth/primitives/transaction_input.rs index 40c2c9c1c..2f18a3040 100644 --- a/src/eth/primitives/transaction_input.rs +++ b/src/eth/primitives/transaction_input.rs @@ -1,3 +1,10 @@ +use alloy_consensus::Signed; +use alloy_consensus::Transaction; +use alloy_consensus::TxEnvelope; +use alloy_consensus::TxLegacy; +use alloy_eips::eip2718::Decodable2718; +use alloy_primitives::PrimitiveSignature; +use alloy_primitives::TxKind; use anyhow::anyhow; use display_json::DebugAsJson; use ethereum_types::U256; @@ -7,7 +14,8 @@ use fake::Fake; use fake::Faker; use rlp::Decodable; -use crate::alias::EthersTransaction; +use crate::alias::AlloyTransaction; +use crate::eth::primitives::signature_component::SignatureComponent; use crate::eth::primitives::Address; use crate::eth::primitives::Bytes; use crate::eth::primitives::ChainId; @@ -16,7 +24,6 @@ use crate::eth::primitives::Gas; use crate::eth::primitives::Hash; use crate::eth::primitives::Nonce; use crate::eth::primitives::Wei; -use crate::ext::OptionExt; #[derive(DebugAsJson, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct TransactionInput { @@ -67,12 +74,40 @@ impl Dummy for TransactionInput { // ----------------------------------------------------------------------------- // Serialization / Deserialization // ----------------------------------------------------------------------------- + impl Decodable for TransactionInput { fn decode(rlp: &rlp::Rlp) -> Result { - let ethers_transaction = EthersTransaction::decode(rlp)?; - match Self::try_from(ethers_transaction) { - Ok(transaction) => Ok(transaction), - Err(_) => Err(rlp::DecoderError::Custom("decoding error")), + fn convert_tx(envelope: TxEnvelope) -> Result { + TransactionInput::try_from(alloy_rpc_types_eth::Transaction { + inner: envelope, + block_hash: None, + block_number: None, + transaction_index: None, + from: Address::default().into(), + effective_gas_price: None, + }) + .map_err(|_| rlp::DecoderError::Custom("failed to convert transaction")) + } + + let raw_bytes = rlp.as_raw(); + + if raw_bytes.is_empty() { + return Err(rlp::DecoderError::Custom("empty transaction bytes")); + } + + if rlp.is_list() { + // Legacy transaction + let mut bytes = raw_bytes; + TxEnvelope::fallback_decode(&mut bytes) + .map_err(|_| rlp::DecoderError::Custom("failed to decode legacy transaction")) + .and_then(convert_tx) + } else { + // Typed transaction (EIP-2718) + let first_byte = raw_bytes[0]; + let mut remaining_bytes = &raw_bytes[1..]; + TxEnvelope::typed_decode(first_byte, &mut remaining_bytes) + .map_err(|_| rlp::DecoderError::Custom("failed to decode transaction envelope")) + .and_then(convert_tx) } } } @@ -84,49 +119,55 @@ impl TryFrom for TransactionInput { type Error = anyhow::Error; fn try_from(value: ExternalTransaction) -> anyhow::Result { - try_from_ethers_transaction(value.0, false) + try_from_alloy_transaction(value.0, false) } } -impl TryFrom for TransactionInput { +impl TryFrom for TransactionInput { type Error = anyhow::Error; - fn try_from(value: EthersTransaction) -> anyhow::Result { - try_from_ethers_transaction(value, true) + fn try_from(value: AlloyTransaction) -> anyhow::Result { + try_from_alloy_transaction(value, true) } } -fn try_from_ethers_transaction(value: EthersTransaction, compute_signer: bool) -> anyhow::Result { +fn try_from_alloy_transaction(value: alloy_rpc_types_eth::Transaction, compute_signer: bool) -> anyhow::Result { // extract signer let signer: Address = match compute_signer { - true => match value.recover_from() { - Ok(signer) => signer.into(), + true => match value.inner.recover_signer() { + Ok(signer) => Address::from(signer), Err(e) => { tracing::warn!(reason = ?e, "failed to recover transaction signer"); return Err(anyhow!("Transaction signer cannot be recovered. Check the transaction signature is valid.")); } }, - false => value.from.into(), + false => Address::from(value.from), }; + // Get signature components from the envelope + let signature = value.inner.signature(); + let r = U256::from(signature.r().to_be_bytes::<32>()); + let s = U256::from(signature.s().to_be_bytes::<32>()); + let v = if signature.v() { U64::from(1) } else { U64::from(0) }; + Ok(TransactionInput { - tx_type: value.transaction_type, - chain_id: match value.chain_id { - Some(chain_id) => Some(chain_id.try_into()?), - None => None, - }, - hash: value.hash.into(), - nonce: value.nonce.try_into()?, + tx_type: Some(U64::from(value.inner.tx_type() as u8)), + chain_id: value.inner.chain_id().map(Into::into), + hash: Hash::from(*value.inner.tx_hash()), + nonce: Nonce::from(value.inner.nonce()), signer, - from: Address::new(value.from.into()), - to: value.to.map_into(), - value: value.value.into(), - input: value.input.clone().into(), - gas_limit: value.gas.try_into()?, - gas_price: value.gas_price.unwrap_or_default().into(), - v: value.v, - r: value.r, - s: value.s, + from: Address::from(value.from), + to: match value.inner.kind() { + TxKind::Call(addr) => Some(Address::from(addr)), + TxKind::Create => None, + }, + value: Wei::from(value.inner.value()), + input: Bytes::from(value.inner.input().clone()), + gas_limit: Gas::from(value.inner.gas_limit()), + gas_price: Wei::from(value.inner.gas_price().or(value.effective_gas_price).unwrap_or_default()), + v, + r, + s, }) } @@ -134,23 +175,32 @@ fn try_from_ethers_transaction(value: EthersTransaction, compute_signer: bool) - // Conversions: Self -> Other // ----------------------------------------------------------------------------- -impl From for EthersTransaction { +impl From for AlloyTransaction { fn from(value: TransactionInput) -> Self { + let inner = TxEnvelope::Legacy(Signed::new_unchecked( + TxLegacy { + chain_id: value.chain_id.map(Into::into), + nonce: value.nonce.into(), + gas_price: value.gas_price.into(), + gas_limit: value.gas_limit.into(), + to: match value.to { + Some(addr) => TxKind::Call(addr.into()), + None => TxKind::Create, + }, + value: value.value.into(), + input: value.input.clone().into(), + }, + PrimitiveSignature::new(SignatureComponent(value.r).into(), SignatureComponent(value.s).into(), value.v.as_u64() == 1), + value.hash.into(), + )); + Self { - chain_id: value.chain_id.map_into(), - hash: value.hash.into(), - nonce: value.nonce.into(), + inner, + block_hash: None, + block_number: None, + transaction_index: None, from: value.signer.into(), - to: value.to.map_into(), - value: value.value.into(), - input: value.input.clone().into(), - gas: value.gas_limit.into(), - gas_price: Some(value.gas_price.into()), - v: value.v, - r: value.r, - s: value.s, - transaction_type: value.tx_type, - ..Default::default() + effective_gas_price: Some(value.gas_price.into()), } } } diff --git a/src/eth/primitives/transaction_mined.rs b/src/eth/primitives/transaction_mined.rs index 283514061..1500f3a69 100644 --- a/src/eth/primitives/transaction_mined.rs +++ b/src/eth/primitives/transaction_mined.rs @@ -7,7 +7,7 @@ use display_json::DebugAsJson; use itertools::Itertools; use crate::alias::AlloyReceipt; -use crate::alias::EthersTransaction; +use crate::alias::AlloyTransaction; use crate::eth::primitives::logs_bloom::LogsBloom; use crate::eth::primitives::BlockNumber; use crate::eth::primitives::EvmExecution; @@ -96,27 +96,20 @@ impl TransactionMined { // ----------------------------------------------------------------------------- // Conversions: Self -> Other // ----------------------------------------------------------------------------- -impl From for EthersTransaction { + +impl From for AlloyTransaction { fn from(value: TransactionMined) -> Self { - let input = value.input; + let signer = value.input.signer; + let gas_price = value.input.gas_price; + let tx: AlloyTransaction = value.input.into(); + Self { - chain_id: input.chain_id.map_into(), - hash: input.hash.into(), - nonce: input.nonce.into(), + inner: tx.inner, block_hash: Some(value.block_hash.into()), - block_number: Some(value.block_number.into()), + block_number: Some(value.block_number.as_u64()), transaction_index: Some(value.transaction_index.into()), - from: input.signer.into(), - to: input.to.map_into(), - value: input.value.into(), - gas_price: Some(input.gas_price.into()), - gas: input.gas_limit.into(), - input: input.input.into(), - v: input.v, - r: input.r, - s: input.s, - transaction_type: input.tx_type, - ..Default::default() + from: signer.into(), + effective_gas_price: Some(gas_price.into()), } } } diff --git a/src/eth/primitives/transaction_stage.rs b/src/eth/primitives/transaction_stage.rs index 83a7530b4..77b171c09 100644 --- a/src/eth/primitives/transaction_stage.rs +++ b/src/eth/primitives/transaction_stage.rs @@ -3,7 +3,7 @@ use super::BlockNumber; use super::ExecutionResult; use super::Index; use crate::alias::AlloyReceipt; -use crate::alias::EthersTransaction; +use crate::alias::AlloyTransaction; use crate::alias::JsonValue; use crate::eth::primitives::TransactionExecution; use crate::eth::primitives::TransactionMined; @@ -26,18 +26,18 @@ impl TransactionStage { pub fn to_json_rpc_transaction(self) -> JsonValue { match self { TransactionStage::Executed(TransactionExecution::Local(tx)) => { - let json_rpc_payload: EthersTransaction = tx.input.into(); + let json_rpc_payload: AlloyTransaction = tx.input.into(); to_json_value(json_rpc_payload) } TransactionStage::Executed(TransactionExecution::External(tx)) => { // remove block information because we don't know to which local block the transaction will be added to. - let mut ethers_tx = tx.tx.0; - ethers_tx.block_number = None; - ethers_tx.block_hash = None; - to_json_value(ethers_tx) + let mut alloy_tx = tx.tx.0; + alloy_tx.block_number = None; + alloy_tx.block_hash = None; + to_json_value(alloy_tx) } TransactionStage::Mined(tx) => { - let json_rpc_payload: EthersTransaction = tx.into(); + let json_rpc_payload: AlloyTransaction = tx.into(); to_json_value(json_rpc_payload) } } diff --git a/src/eth/primitives/wei.rs b/src/eth/primitives/wei.rs index 5189a96ce..81eeed1e0 100644 --- a/src/eth/primitives/wei.rs +++ b/src/eth/primitives/wei.rs @@ -59,6 +59,12 @@ impl TryFrom for Wei { // Conversions: Self -> Other // ----------------------------------------------------------------------------- +impl From for u128 { + fn from(value: Wei) -> Self { + value.as_u128() + } +} + impl From for RevmU256 { fn from(value: Wei) -> Self { RevmU256::from_limbs(value.0 .0) diff --git a/src/infra/blockchain_client/blockchain_client.rs b/src/infra/blockchain_client/blockchain_client.rs index 63c96a052..d14afaf25 100644 --- a/src/infra/blockchain_client/blockchain_client.rs +++ b/src/infra/blockchain_client/blockchain_client.rs @@ -12,8 +12,8 @@ use jsonrpsee::ws_client::WsClientBuilder; use tokio::sync::RwLock; use tokio::sync::RwLockReadGuard; +use crate::alias::AlloyTransaction; use crate::alias::EthersBytes; -use crate::alias::EthersTransaction; use crate::alias::JsonValue; use crate::eth::primitives::Address; use crate::eth::primitives::BlockNumber; @@ -170,12 +170,12 @@ impl BlockchainClient { } /// Fetches a transaction by hash. - pub async fn fetch_transaction(&self, tx_hash: Hash) -> anyhow::Result> { + pub async fn fetch_transaction(&self, tx_hash: Hash) -> anyhow::Result> { tracing::debug!(%tx_hash, "fetching transaction"); let hash = to_json_value(tx_hash); - let result = self.http.request::, _>("eth_getTransactionByHash", [hash]).await; + let result = self.http.request::, _>("eth_getTransactionByHash", [hash]).await; match result { Ok(tx) => Ok(tx),