@@ -96,7 +96,12 @@ impl Trie {
9696 Ok ( match self . root {
9797 NodeRef :: Node ( ref node, _) => node. get ( self . db . as_ref ( ) , Nibbles :: from_bytes ( path) ) ?,
9898 NodeRef :: Hash ( hash) if hash. is_valid ( ) => {
99- let rlp = self . db . get ( hash) ?. ok_or ( TrieError :: InconsistentTree ) ?;
99+ let rlp = self
100+ . db
101+ . get ( hash) ?
102+ . ok_or ( TrieError :: InconsistentTree ( format ! (
103+ "Node hash {hash:?} not found in db"
104+ ) ) ) ?;
100105 let node = Node :: decode ( & rlp) . map_err ( TrieError :: RLPDecode ) ?;
101106 node. get ( self . db . as_ref ( ) , Nibbles :: from_bytes ( path) ) ?
102107 }
@@ -112,7 +117,10 @@ impl Trie {
112117 // If the trie is not empty, call the root node's insertion logic.
113118 self . root
114119 . get_node ( self . db . as_ref ( ) ) ?
115- . ok_or ( TrieError :: InconsistentTree ) ?
120+ . ok_or ( TrieError :: InconsistentTree ( format ! (
121+ "Root node with hash {:?} not found in db" ,
122+ self . root. compute_hash( )
123+ ) ) ) ?
116124 . insert ( self . db . as_ref ( ) , path, value) ?
117125 . into ( )
118126 } else {
@@ -134,7 +142,10 @@ impl Trie {
134142 let ( node, value) = self
135143 . root
136144 . get_node ( self . db . as_ref ( ) ) ?
137- . ok_or ( TrieError :: InconsistentTree ) ?
145+ . ok_or ( TrieError :: InconsistentTree ( format ! (
146+ "Root node with hash {:?} not found in db" ,
147+ self . root. compute_hash( )
148+ ) ) ) ?
138149 . remove ( self . db . as_ref ( ) , Nibbles :: from_bytes ( path) ) ?;
139150 self . root = node. map ( Into :: into) . unwrap_or_default ( ) ;
140151
@@ -234,7 +245,10 @@ impl Trie {
234245 let encoded_root = self
235246 . root
236247 . get_node ( self . db . as_ref ( ) ) ?
237- . ok_or ( TrieError :: InconsistentTree ) ?
248+ . ok_or ( TrieError :: InconsistentTree ( format ! (
249+ "Root node with hash {:?} not found in db" ,
250+ self . root. compute_hash( )
251+ ) ) ) ?
238252 . encode_raw ( ) ;
239253
240254 let mut node_path = HashSet :: new ( ) ;
@@ -263,7 +277,9 @@ impl Trie {
263277 ) -> Result < NodeRef , TrieError > {
264278 let root_rlp = all_nodes
265279 . get ( & root_hash)
266- . ok_or ( TrieError :: InconsistentTree ) ?;
280+ . ok_or ( TrieError :: InconsistentTree ( format ! (
281+ "Root node {root_hash:?} not found in db"
282+ ) ) ) ?;
267283
268284 fn get_embedded_node (
269285 all_nodes : & BTreeMap < H256 , Vec < u8 > > ,
@@ -385,8 +401,12 @@ impl Trie {
385401 Some ( idx) => {
386402 let child_ref = & branch_node. choices [ idx] ;
387403 if child_ref. is_valid ( ) {
388- let child_node =
389- child_ref. get_node ( db) ?. ok_or ( TrieError :: InconsistentTree ) ?;
404+ let child_node = child_ref. get_node ( db) ?. ok_or (
405+ TrieError :: InconsistentTree ( format ! (
406+ "Node with hash {:?} not found in db" ,
407+ child_ref. compute_hash( )
408+ ) ) ,
409+ ) ?;
390410 get_node_inner ( db, child_node, partial_path)
391411 } else {
392412 Ok ( vec ! [ ] )
@@ -398,10 +418,12 @@ impl Trie {
398418 if partial_path. skip_prefix ( & extension_node. prefix )
399419 && extension_node. child . is_valid ( )
400420 {
401- let child_node = extension_node
402- . child
403- . get_node ( db) ?
404- . ok_or ( TrieError :: InconsistentTree ) ?;
421+ let child_node = extension_node. child . get_node ( db) ?. ok_or (
422+ TrieError :: InconsistentTree ( format ! (
423+ "Extension Node child with hash {:?} with not found in db" ,
424+ extension_node. child. compute_hash( )
425+ ) ) ,
426+ ) ?;
405427 get_node_inner ( db, child_node, partial_path)
406428 } else {
407429 Ok ( vec ! [ ] )
@@ -417,7 +439,10 @@ impl Trie {
417439 self . db . as_ref ( ) ,
418440 self . root
419441 . get_node ( self . db . as_ref ( ) ) ?
420- . ok_or ( TrieError :: InconsistentTree ) ?,
442+ . ok_or ( TrieError :: InconsistentTree ( format ! (
443+ "Root node with hash {:?} not found in db" ,
444+ self . root. compute_hash( )
445+ ) ) ) ?,
421446 partial_path,
422447 )
423448 } else {
@@ -468,7 +493,10 @@ impl ProofTrie {
468493 self . 0
469494 . root
470495 . get_node ( self . 0 . db . as_ref ( ) ) ?
471- . ok_or ( TrieError :: InconsistentTree ) ?
496+ . ok_or ( TrieError :: InconsistentTree ( format ! (
497+ "Root node with hash {:?} not found in db" ,
498+ self . 0 . root. compute_hash( )
499+ ) ) ) ?
472500 . insert ( self . 0 . db . as_ref ( ) , partial_path, external_ref) ?
473501 . into ( )
474502 } else {
0 commit comments