From 934b97d30ef9fab939203bcfd9b58f127065a4ae Mon Sep 17 00:00:00 2001 From: 0xaatif Date: Thu, 12 Sep 2024 14:39:54 +0100 Subject: [PATCH] demo: design --- trace_decoder/src/core.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/trace_decoder/src/core.rs b/trace_decoder/src/core.rs index 3b9ddb181..4814d78e4 100644 --- a/trace_decoder/src/core.rs +++ b/trace_decoder/src/core.rs @@ -66,6 +66,7 @@ pub fn entrypoint( b_meta.block_timestamp, b_meta.parent_beacon_block_root, withdrawals, + |_ignore| {}, )?; let mut running_gas_used = 0; @@ -266,6 +267,7 @@ struct IntraBlockTries { pub receipt: ReceiptTrie, } +#[allow(clippy::too_many_arguments)] /// Does the main work mentioned in the [module documentation](super). fn middle( // state at the beginning of the block @@ -280,6 +282,8 @@ fn middle( parent_beacon_block_root: H256, // added to final batch mut withdrawals: Vec<(Address, U256)>, + // called with the untrimmed tries after each batch + mut observer: impl FnMut(&IntraBlockTries), ) -> anyhow::Result>> { // Initialise the storage tries. for (haddr, acct) in state_trie.iter() { @@ -503,6 +507,7 @@ fn middle( false => vec![], }, before: { + observer(&before); before.state.mask(state_mask)?; before.receipt.mask(batch_first_txn_ix..txn_ix)?; before.transaction.mask(batch_first_txn_ix..txn_ix)?; @@ -642,3 +647,23 @@ impl FromIterator> for Hash2Code { this } } + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn discuss() { + let _ignore_result = middle( + StateMpt::default(), + BTreeMap::new(), + vec![], + &mut Hash2Code::new(), + U256::zero(), + H256::zero(), + vec![], + |IntraBlockTries { state, .. }| { + let _serialized_state = serde_json::to_string(state.as_hashed_partial_trie()); + }, + ); + } +}