@@ -13,6 +13,7 @@ use katana_provider_api::ProviderError;
1313use katana_trie:: {
1414 compute_contract_state_hash, ClassesTrie , ContractLeaf , ContractsTrie , StoragesTrie ,
1515} ;
16+ use starknet:: providers:: Provider ;
1617
1718use crate :: providers:: db:: DbProvider ;
1819use crate :: ProviderResult ;
@@ -85,8 +86,11 @@ impl<Db: Database> TrieWriter for DbProvider<Db> {
8586 let storage_root = storage_trie. root ( ) ;
8687 leaf. storage_root = Some ( storage_root) ;
8788
88- let latest_state = self . latest ( ) ?;
89- let leaf_hash = contract_state_leaf_hash ( latest_state, & address, & leaf) ;
89+ let state = self
90+ . historical ( block_number. into ( ) ) ?
91+ . expect ( "historical state should exist" ) ;
92+ let leaf_hash =
93+ contract_state_leaf_hash ( state, & address, & leaf, block_number) ;
9094
9195 Ok ( ( address, leaf_hash) )
9296 } )
@@ -108,6 +112,7 @@ fn contract_state_leaf_hash(
108112 provider : impl StateProvider ,
109113 address : & ContractAddress ,
110114 contract_leaf : & ContractLeaf ,
115+ block_number : BlockNumber ,
111116) -> Felt {
112117 let nonce =
113118 contract_leaf. nonce . unwrap_or ( provider. nonce ( * address) . unwrap ( ) . unwrap_or_default ( ) ) ;
@@ -118,5 +123,18 @@ fn contract_state_leaf_hash(
118123
119124 let storage_root = contract_leaf. storage_root . expect ( "root need to set" ) ;
120125
121- compute_contract_state_hash ( & class_hash, & storage_root, & nonce)
126+ let root = compute_contract_state_hash ( & class_hash, & storage_root, & nonce) ;
127+
128+ if block_number >= 6481 {
129+ println ! ( "----------------------------------------" ) ;
130+ println ! ( "block {block_number}" ) ;
131+ println ! ( "address: {address}" ) ;
132+ println ! ( "class hash : {class_hash:#x}" ) ;
133+ println ! ( "nonce : {nonce:#x}" ) ;
134+ println ! ( "storage root : {storage_root:#x}" ) ;
135+ println ! ( "Contract state hash: {root}" ) ;
136+ println ! ( "----------------------------------------" ) ;
137+ }
138+
139+ root
122140}
0 commit comments