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 let account = checkpoint.account();
51 IntermediateStorageRootState {
52 state: IntermediateRootState {
53 hash_builder: HashBuilder::from(checkpoint.state),
54 walker_stack: checkpoint
55 .walker_stack
56 .into_iter()
57 .map(CursorSubNode::from)
58 .collect(),
59 last_hashed_key: checkpoint.last_storage_key,
60 },
61 account,
62 }
63 }),
64 }
65 }
66}
67
68#[derive(Debug)]
70pub struct IntermediateRootState {
71 pub hash_builder: HashBuilder,
73 pub walker_stack: Vec<CursorSubNode>,
75 pub last_hashed_key: B256,
77}
78
79#[derive(Debug)]
81pub enum StorageRootProgress {
82 Complete(B256, usize, StorageTrieUpdates),
84 Progress(Box<IntermediateRootState>, usize, StorageTrieUpdates),
87}