1use crate::{
2 hash_builder::HashBuilder,
3 trie_cursor::CursorSubNode,
4 updates::{StorageTrieUpdates, TrieUpdates},
5};
6use alloy_primitives::B256;
7use reth_primitives_traits::Account;
8use reth_stages_types::MerkleCheckpoint;
9
10#[derive(Debug)]
12pub enum StateRootProgress {
13 Complete(B256, usize, TrieUpdates),
16 Progress(Box<IntermediateStateRootState>, usize, TrieUpdates),
21}
22
23#[derive(Debug)]
25pub struct IntermediateStateRootState {
26 pub account_root_state: IntermediateRootState,
28 pub storage_root_state: Option<IntermediateStorageRootState>,
30}
31
32#[derive(Debug)]
34pub struct IntermediateStorageRootState {
35 pub state: IntermediateRootState,
37 pub account: Account,
39}
40
41impl From<MerkleCheckpoint> for IntermediateStateRootState {
42 fn from(value: MerkleCheckpoint) -> Self {
43 Self {
44 account_root_state: IntermediateRootState {
45 hash_builder: HashBuilder::from(value.state),
46 walker_stack: value.walker_stack.into_iter().map(CursorSubNode::from).collect(),
47 last_hashed_key: value.last_account_key,
48 },
49 storage_root_state: value.storage_root_checkpoint.map(|checkpoint| {
50 IntermediateStorageRootState {
51 state: IntermediateRootState {
52 hash_builder: HashBuilder::from(checkpoint.state),
53 walker_stack: checkpoint
54 .walker_stack
55 .into_iter()
56 .map(CursorSubNode::from)
57 .collect(),
58 last_hashed_key: checkpoint.last_storage_key,
59 },
60 account: Account {
61 nonce: checkpoint.account_nonce,
62 balance: checkpoint.account_balance,
63 bytecode_hash: Some(checkpoint.account_bytecode_hash),
64 },
65 }
66 }),
67 }
68 }
69}
70
71#[derive(Debug)]
73pub struct IntermediateRootState {
74 pub hash_builder: HashBuilder,
76 pub walker_stack: Vec<CursorSubNode>,
78 pub last_hashed_key: B256,
80}
81
82#[derive(Debug)]
84pub enum StorageRootProgress {
85 Complete(B256, usize, StorageTrieUpdates),
87 Progress(Box<IntermediateRootState>, usize, StorageTrieUpdates),
90}