@@ -159,7 +159,9 @@ func (t *StateTrie) GetNode(path []byte) ([]byte, int, error) {
159
159
func (t * StateTrie ) MustUpdate (key , value []byte ) {
160
160
hk := crypto .Keccak256 (key )
161
161
t .trie .MustUpdate (hk , value )
162
- t .getSecKeyCache ()[common .Hash (hk )] = common .CopyBytes (key )
162
+ if t .preimages != nil {
163
+ t .getSecKeyCache ()[common .Hash (hk )] = common .CopyBytes (key )
164
+ }
163
165
}
164
166
165
167
// UpdateStorage associates key with value in the trie. Subsequent calls to
@@ -177,7 +179,9 @@ func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
177
179
if err != nil {
178
180
return err
179
181
}
180
- t .getSecKeyCache ()[common .Hash (hk )] = common .CopyBytes (key )
182
+ if t .preimages != nil {
183
+ t .getSecKeyCache ()[common .Hash (hk )] = common .CopyBytes (key )
184
+ }
181
185
return nil
182
186
}
183
187
@@ -191,7 +195,9 @@ func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccoun
191
195
if err := t .trie .Update (hk , data ); err != nil {
192
196
return err
193
197
}
194
- t .getSecKeyCache ()[common .Hash (hk )] = address .Bytes ()
198
+ if t .preimages != nil {
199
+ t .getSecKeyCache ()[common .Hash (hk )] = address .Bytes ()
200
+ }
195
201
return nil
196
202
}
197
203
@@ -203,7 +209,9 @@ func (t *StateTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte
203
209
// will omit any encountered error but just print out an error message.
204
210
func (t * StateTrie ) MustDelete (key []byte ) {
205
211
hk := crypto .Keccak256 (key )
206
- delete (t .getSecKeyCache (), common .Hash (hk ))
212
+ if t .preimages != nil {
213
+ delete (t .getSecKeyCache (), common .Hash (hk ))
214
+ }
207
215
t .trie .MustDelete (hk )
208
216
}
209
217
@@ -212,14 +220,18 @@ func (t *StateTrie) MustDelete(key []byte) {
212
220
// If a node is not found in the database, a MissingNodeError is returned.
213
221
func (t * StateTrie ) DeleteStorage (_ common.Address , key []byte ) error {
214
222
hk := crypto .Keccak256 (key )
215
- delete (t .getSecKeyCache (), common .Hash (hk ))
223
+ if t .preimages != nil {
224
+ delete (t .getSecKeyCache (), common .Hash (hk ))
225
+ }
216
226
return t .trie .Delete (hk )
217
227
}
218
228
219
229
// DeleteAccount abstracts an account deletion from the trie.
220
230
func (t * StateTrie ) DeleteAccount (address common.Address ) error {
221
231
hk := crypto .Keccak256 (address .Bytes ())
222
- delete (t .getSecKeyCache (), common .Hash (hk ))
232
+ if t .preimages != nil {
233
+ delete (t .getSecKeyCache (), common .Hash (hk ))
234
+ }
223
235
return t .trie .Delete (hk )
224
236
}
225
237
0 commit comments