@@ -42,7 +42,7 @@ impl<'a, CF: TrieCursorFactory> TrieCursorFactory for InMemoryTrieCursorFactory<
42
42
pub struct InMemoryAccountTrieCursor < ' a , C > {
43
43
cursor : C ,
44
44
trie_updates : & ' a TrieUpdatesSorted ,
45
- last_key : Option < TrieKey > ,
45
+ last_key : Option < Nibbles > ,
46
46
}
47
47
48
48
impl < ' a , C > InMemoryAccountTrieCursor < ' a , C > {
@@ -56,12 +56,12 @@ impl<'a, C: TrieCursor> TrieCursor for InMemoryAccountTrieCursor<'a, C> {
56
56
& mut self ,
57
57
key : Nibbles ,
58
58
) -> Result < Option < ( Nibbles , BranchNodeCompact ) > , DatabaseError > {
59
- if let Some ( ( trie_key , trie_op) ) = self . trie_updates . find_account_node ( & key) {
60
- self . last_key = Some ( trie_key ) ;
59
+ if let Some ( ( nibbles , trie_op) ) = self . trie_updates . find_account_node ( & key) {
60
+ self . last_key = Some ( nibbles ) ;
61
61
Ok ( trie_op. into_update ( ) . map ( |node| ( key, node) ) )
62
62
} else {
63
63
let result = self . cursor . seek_exact ( key) ?;
64
- self . last_key = result. as_ref ( ) . map ( |( k , _) | TrieKey :: AccountNode ( k . clone ( ) ) ) ;
64
+ self . last_key = result. as_ref ( ) . map ( |( key , _) | key . clone ( ) ) ;
65
65
Ok ( result)
66
66
}
67
67
}
@@ -78,20 +78,22 @@ impl<'a, C: TrieCursor> TrieCursor for InMemoryAccountTrieCursor<'a, C> {
78
78
. cloned ( ) ;
79
79
80
80
if let Some ( ( trie_key, trie_op) ) = trie_update_entry {
81
- let nibbles = match & trie_key {
82
- TrieKey :: AccountNode ( nibbles) => nibbles. clone ( ) ,
81
+ let nibbles = match trie_key {
82
+ TrieKey :: AccountNode ( nibbles) => {
83
+ self . last_key = Some ( nibbles. clone ( ) ) ;
84
+ nibbles
85
+ }
83
86
_ => panic ! ( "Invalid trie key" ) ,
84
87
} ;
85
- self . last_key = Some ( trie_key) ;
86
88
return Ok ( trie_op. into_update ( ) . map ( |node| ( nibbles, node) ) )
87
89
}
88
90
89
91
let result = self . cursor . seek ( key) ?;
90
- self . last_key = result. as_ref ( ) . map ( |( k , _) | TrieKey :: AccountNode ( k . clone ( ) ) ) ;
92
+ self . last_key = result. as_ref ( ) . map ( |( key , _) | key . clone ( ) ) ;
91
93
Ok ( result)
92
94
}
93
95
94
- fn current ( & mut self ) -> Result < Option < TrieKey > , DatabaseError > {
96
+ fn current ( & mut self ) -> Result < Option < Nibbles > , DatabaseError > {
95
97
if self . last_key . is_some ( ) {
96
98
Ok ( self . last_key . clone ( ) )
97
99
} else {
@@ -108,7 +110,7 @@ pub struct InMemoryStorageTrieCursor<'a, C> {
108
110
trie_update_index : usize ,
109
111
trie_updates : & ' a TrieUpdatesSorted ,
110
112
hashed_address : B256 ,
111
- last_key : Option < TrieKey > ,
113
+ last_key : Option < Nibbles > ,
112
114
}
113
115
114
116
impl < ' a , C > InMemoryStorageTrieCursor < ' a , C > {
@@ -129,8 +131,7 @@ impl<'a, C: TrieCursor> TrieCursor for InMemoryStorageTrieCursor<'a, C> {
129
131
Ok ( trie_op. into_update ( ) . map ( |node| ( key, node) ) )
130
132
} else {
131
133
let result = self . cursor . seek_exact ( key) ?;
132
- self . last_key =
133
- result. as_ref ( ) . map ( |( k, _) | TrieKey :: StorageNode ( self . hashed_address , k. clone ( ) ) ) ;
134
+ self . last_key = result. as_ref ( ) . map ( |( key, _) | key. clone ( ) ) ;
134
135
Ok ( result)
135
136
}
136
137
}
@@ -151,20 +152,21 @@ impl<'a, C: TrieCursor> TrieCursor for InMemoryStorageTrieCursor<'a, C> {
151
152
trie_update_entry. filter ( |( k, _) | matches ! ( k, TrieKey :: StorageNode ( _, _) ) )
152
153
{
153
154
let nibbles = match trie_key {
154
- TrieKey :: StorageNode ( _, nibbles) => nibbles. clone ( ) ,
155
+ TrieKey :: StorageNode ( _, nibbles) => {
156
+ self . last_key = Some ( nibbles. clone ( ) ) ;
157
+ nibbles. clone ( )
158
+ }
155
159
_ => panic ! ( "this should not happen!" ) ,
156
160
} ;
157
- self . last_key = Some ( trie_key. clone ( ) ) ;
158
161
return Ok ( trie_op. as_update ( ) . map ( |node| ( nibbles, node. clone ( ) ) ) )
159
162
}
160
163
161
164
let result = self . cursor . seek ( key) ?;
162
- self . last_key =
163
- result. as_ref ( ) . map ( |( k, _) | TrieKey :: StorageNode ( self . hashed_address , k. clone ( ) ) ) ;
165
+ self . last_key = result. as_ref ( ) . map ( |( key, _) | key. clone ( ) ) ;
164
166
Ok ( result)
165
167
}
166
168
167
- fn current ( & mut self ) -> Result < Option < TrieKey > , DatabaseError > {
169
+ fn current ( & mut self ) -> Result < Option < Nibbles > , DatabaseError > {
168
170
if self . last_key . is_some ( ) {
169
171
Ok ( self . last_key . clone ( ) )
170
172
} else {
0 commit comments