Skip to content

Commit

Permalink
demo: design
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaatif authored and atanmarko committed Sep 12, 2024
1 parent a37f1b3 commit 934b97d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions trace_decoder/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -266,6 +267,7 @@ struct IntraBlockTries<StateTrieT> {
pub receipt: ReceiptTrie,
}

#[allow(clippy::too_many_arguments)]
/// Does the main work mentioned in the [module documentation](super).
fn middle<StateTrieT: StateTrie + Clone>(
// state at the beginning of the block
Expand All @@ -280,6 +282,8 @@ fn middle<StateTrieT: StateTrie + Clone>(
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<StateTrieT>),
) -> anyhow::Result<Vec<Batch<StateTrieT>>> {
// Initialise the storage tries.
for (haddr, acct) in state_trie.iter() {
Expand Down Expand Up @@ -503,6 +507,7 @@ fn middle<StateTrieT: StateTrie + Clone>(
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)?;
Expand Down Expand Up @@ -642,3 +647,23 @@ impl FromIterator<Vec<u8>> 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());
},
);
}
}

0 comments on commit 934b97d

Please sign in to comment.