Skip to content

Commit

Permalink
tweak: infer transaction type from tx signature (#1585)
Browse files Browse the repository at this point in the history
* chore: update config/importer-offline.env.local
  • Loading branch information
marcospb19-cw authored Aug 2, 2024
1 parent 9461253 commit 637eff8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion config/importer-offline.env.local
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
6 changes: 5 additions & 1 deletion src/bin/importer_offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/eth/primitives/external_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions src/eth/primitives/external_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 637eff8

Please sign in to comment.