From 637eff802bdd9a1e7cb07540967d6ac73c96d02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= <164224824+marcospb19-cw@users.noreply.github.com> Date: Thu, 1 Aug 2024 22:59:34 -0300 Subject: [PATCH] tweak: infer transaction type from tx signature (#1585) * chore: update config/importer-offline.env.local --- config/importer-offline.env.local | 4 +++- src/bin/importer_offline.rs | 6 +++++- src/eth/primitives/external_block.rs | 2 +- src/eth/primitives/external_transaction.rs | 13 +++++++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/config/importer-offline.env.local b/config/importer-offline.env.local index d1e07879c..c1d66b071 100644 --- a/config/importer-offline.env.local +++ b/config/importer-offline.env.local @@ -1,4 +1,4 @@ -RUST_LOG=info,stratus::eth::miner=warn,stratus::eth::executor=warn,importer_offline::rx=off +RUST_LOG=info,stratus::eth::miner::miner=warn,stratus::eth::executor=warn CHAIN_ID=2008 EVMS=8 @@ -9,3 +9,5 @@ TEMP_STORAGE=inmemory EXTERNAL_RPC_STORAGE=postgres://postgres:123@localhost:5432/stratus EXTERNAL_RPC_STORAGE_CONNECTIONS=3 EXTERNAL_RPC_STORAGE_TIMEOUT=20000 + +EXECUTOR_REJECT_NOT_CONTRACT=false diff --git a/src/bin/importer_offline.rs b/src/bin/importer_offline.rs index e5e99d3c6..0f2e1fb85 100644 --- a/src/bin/importer_offline.rs +++ b/src/bin/importer_offline.rs @@ -24,6 +24,7 @@ use stratus::eth::primitives::BlockNumber; use stratus::eth::primitives::ExternalBlock; use stratus::eth::primitives::ExternalReceipt; use stratus::eth::primitives::ExternalReceipts; +use stratus::eth::primitives::ExternalTransaction; use stratus::eth::storage::ExternalRpcStorage; use stratus::eth::storage::InMemoryPermanentStorage; use stratus::ext::spawn_named; @@ -148,11 +149,14 @@ fn execute_block_importer( let mut transaction_count = 0; let instant_before_execution = Instant::now(); - for block in blocks.into_iter() { + for mut block in blocks.into_iter() { if GlobalState::is_shutdown_warn(TASK_NAME) { return Ok(()); } + // fill missing transaction_type with `v` + block.transactions.iter_mut().for_each(ExternalTransaction::fill_missing_transaction_type); + // re-execute (and import) block executor.execute_external_block(&block, &receipts)?; transaction_count += block.transactions.len(); diff --git a/src/eth/primitives/external_block.rs b/src/eth/primitives/external_block.rs index 995fc76a3..fbc26a961 100644 --- a/src/eth/primitives/external_block.rs +++ b/src/eth/primitives/external_block.rs @@ -12,7 +12,7 @@ use crate::eth::primitives::Hash; use crate::eth::primitives::UnixTime; use crate::log_and_err; -#[derive(Debug, Clone, derive_more:: Deref, serde::Deserialize, serde::Serialize)] +#[derive(Debug, Clone, derive_more::Deref, derive_more::DerefMut, serde::Deserialize, serde::Serialize)] #[serde(transparent)] pub struct ExternalBlock(#[deref] pub EthersBlockExternalTransaction); diff --git a/src/eth/primitives/external_transaction.rs b/src/eth/primitives/external_transaction.rs index 1cd85a20f..5c56a564d 100644 --- a/src/eth/primitives/external_transaction.rs +++ b/src/eth/primitives/external_transaction.rs @@ -16,6 +16,19 @@ impl ExternalTransaction { 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()); + } + } } // -----------------------------------------------------------------------------