Skip to content

Commit 896d91a

Browse files
committed
add UpdateAsync operation to trie
1 parent cb3e450 commit 896d91a

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

core/state/database.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ type Trie interface {
9999
// in the trie with provided address.
100100
UpdateAccount(address common.Address, account *types.StateAccount, codeLen int) error
101101

102+
UpdateAccountAsync(address common.Address, accountResolver func() *types.StateAccount) error
103+
102104
// UpdateStorage associates key with value in the trie. If value has length zero,
103105
// any existing value is deleted from the trie. The value bytes must not be modified
104106
// by the caller while they are stored in the trie. If a node was not found in the

trie/secure_trie.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,25 @@ func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccoun
226226
return nil
227227
}
228228

229+
func (t *StateTrie) UpdateAccountAsync(address common.Address, accountResolve func() *types.StateAccount) error {
230+
hk := crypto.Keccak256(address.Bytes())
231+
resolve := func() []byte {
232+
acc := accountResolve()
233+
data, err := rlp.EncodeToBytes(acc)
234+
if err != nil {
235+
panic(err) // TODO: what do do here?
236+
}
237+
return data
238+
}
239+
if err := t.trie.UpdateAsync(hk, resolve); err != nil {
240+
return err
241+
}
242+
if t.preimages != nil {
243+
t.secKeyCache[common.Hash(hk)] = address.Bytes()
244+
}
245+
return nil
246+
}
247+
229248
func (t *StateTrie) UpdateContractCode(_ common.Address, _ common.Hash, _ []byte) error {
230249
return nil
231250
}

trie/transition.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package trie
1818

1919
import (
20+
"errors"
2021
"fmt"
2122

2223
"github.com/ethereum/go-ethereum/common"
@@ -138,6 +139,9 @@ func (t *TransitionTrie) UpdateAccount(addr common.Address, account *types.State
138139
// only needs to know what the account trie does now.
139140
return t.overlay.UpdateAccount(addr, account, codeLen)
140141
}
142+
func (t *TransitionTrie) UpdateAccountAsync(address common.Address, accountResolver func() *types.StateAccount) error {
143+
return errors.New("not implemented")
144+
}
141145

142146
// DeleteStorage removes any existing value for key from the trie. If a node was not
143147
// found in the database, a trie.MissingNodeError is returned.

trie/verkle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount,
177177
return nil
178178
}
179179

180+
func (t *VerkleTrie) UpdateAccountAsync(address common.Address, accountResolver func() *types.StateAccount) error {
181+
return errors.New("not implemented")
182+
}
183+
180184
// UpdateStorage implements state.Trie, writing the provided storage slot into
181185
// the tree. If the tree is corrupted, an error will be returned.
182186
func (t *VerkleTrie) UpdateStorage(address common.Address, key, value []byte) error {

0 commit comments

Comments
 (0)