Skip to content

Commit 959f00d

Browse files
committed
trie: no need to store preimage if not enabled
Signed-off-by: jsvisa <[email protected]>
1 parent 9e0611b commit 959f00d

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

trie/secure_trie.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ func (t *StateTrie) GetNode(path []byte) ([]byte, int, error) {
159159
func (t *StateTrie) MustUpdate(key, value []byte) {
160160
hk := crypto.Keccak256(key)
161161
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+
}
163165
}
164166

165167
// 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 {
177179
if err != nil {
178180
return err
179181
}
180-
t.getSecKeyCache()[common.Hash(hk)] = common.CopyBytes(key)
182+
if t.preimages != nil {
183+
t.getSecKeyCache()[common.Hash(hk)] = common.CopyBytes(key)
184+
}
181185
return nil
182186
}
183187

@@ -191,7 +195,9 @@ func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccoun
191195
if err := t.trie.Update(hk, data); err != nil {
192196
return err
193197
}
194-
t.getSecKeyCache()[common.Hash(hk)] = address.Bytes()
198+
if t.preimages != nil {
199+
t.getSecKeyCache()[common.Hash(hk)] = address.Bytes()
200+
}
195201
return nil
196202
}
197203

@@ -203,7 +209,9 @@ func (t *StateTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte
203209
// will omit any encountered error but just print out an error message.
204210
func (t *StateTrie) MustDelete(key []byte) {
205211
hk := crypto.Keccak256(key)
206-
delete(t.getSecKeyCache(), common.Hash(hk))
212+
if t.preimages != nil {
213+
delete(t.getSecKeyCache(), common.Hash(hk))
214+
}
207215
t.trie.MustDelete(hk)
208216
}
209217

@@ -212,14 +220,18 @@ func (t *StateTrie) MustDelete(key []byte) {
212220
// If a node is not found in the database, a MissingNodeError is returned.
213221
func (t *StateTrie) DeleteStorage(_ common.Address, key []byte) error {
214222
hk := crypto.Keccak256(key)
215-
delete(t.getSecKeyCache(), common.Hash(hk))
223+
if t.preimages != nil {
224+
delete(t.getSecKeyCache(), common.Hash(hk))
225+
}
216226
return t.trie.Delete(hk)
217227
}
218228

219229
// DeleteAccount abstracts an account deletion from the trie.
220230
func (t *StateTrie) DeleteAccount(address common.Address) error {
221231
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+
}
223235
return t.trie.Delete(hk)
224236
}
225237

0 commit comments

Comments
 (0)