Skip to content

Commit e805c39

Browse files
committed
fix verkle
1 parent 2fc29f6 commit e805c39

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

core/state/database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ type Trie interface {
102102
// UpdateAccountAsync will abstract the write of an account to the secure trie.
103103
// The actual value of the account is not resolved from the passed function until
104104
// it is needed when hashing the trie.
105-
UpdateAccountAsync(address common.Address, accountResolver func() *types.StateAccount) error
105+
UpdateAccountAsync(address common.Address, accountResolver func() (*types.StateAccount, int)) error
106106

107107
// UpdateStorage associates key with value in the trie. If value has length zero,
108108
// any existing value is deleted from the trie. The value bytes must not be modified

core/state/statedb.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ func (s *StateDB) updateStateObject(obj *stateObject) {
579579

580580
// updateStateObject writes the given object to the trie. The actual value is
581581
// only resolved from the provided function when it is needed during trie hashing.
582-
func (s *StateDB) updateStateObjectAsync(addr common.Address, resolver func() *types.StateAccount) {
582+
func (s *StateDB) updateStateObjectAsync(addr common.Address, resolver func() (*types.StateAccount, int)) {
583583
if err := s.trie.UpdateAccountAsync(addr, resolver); err != nil {
584584
s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr, err))
585585
}
@@ -838,13 +838,17 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
838838
workers.SetLimit(1)
839839
}
840840

841-
stateObjectsResolve := make(map[common.Address]func() *types.StateAccount)
841+
type stateAccountWithCodeLen struct {
842+
*types.StateAccount
843+
codeLen int
844+
}
845+
stateObjectsResolve := make(map[common.Address]func() (*types.StateAccount, int))
842846
for addr, op := range s.mutations {
843847
if op.applied || op.isDelete() {
844848
continue
845849
}
846850
obj := s.stateObjects[addr] // closure for the task runner below
847-
complete := make(chan *types.StateAccount)
851+
complete := make(chan stateAccountWithCodeLen)
848852
workers.Go(func() error {
849853
if s.db.TrieDB().IsVerkle() {
850854
obj.updateTrie()
@@ -857,12 +861,13 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
857861
s.witness.AddState(obj.trie.Witness())
858862
}
859863
}
860-
complete <- &obj.data
864+
complete <- stateAccountWithCodeLen{&obj.data, 0}
861865
return nil
862866
})
863867

864-
stateObjectsResolve[addr] = func() *types.StateAccount {
865-
return <-complete
868+
stateObjectsResolve[addr] = func() (*types.StateAccount, int) {
869+
res := <-complete
870+
return res.StateAccount, res.codeLen
866871
}
867872
}
868873
// If witness building is enabled, gather all the read-only accesses.
@@ -914,6 +919,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
914919
}
915920
}
916921
}
922+
917923
s.StorageUpdates += time.Since(start)
918924

919925
// Now we're about to start to write changes to the trie. The trie is so far
@@ -954,11 +960,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
954960
if op.isDelete() {
955961
deletedAddrs = append(deletedAddrs, addr)
956962
} else {
957-
if s.db.TrieDB().IsVerkle() {
958-
s.updateStateObject(s.stateObjects[addr])
959-
} else {
960-
s.updateStateObjectAsync(addr, stateObjectsResolve[addr])
961-
}
963+
s.updateStateObjectAsync(addr, stateObjectsResolve[addr])
962964
s.AccountUpdated += 1
963965
}
964966
usedAddrs = append(usedAddrs, addr) // Copy needed for closure

trie/secure_trie.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccoun
229229
// UpdateAccountAsync will abstract the write of an account to the secure trie.
230230
// The actual value of the account is not resolved from the passed function until
231231
// it is needed when hashing the trie.
232-
func (t *StateTrie) UpdateAccountAsync(address common.Address, accountResolve func() *types.StateAccount) error {
232+
func (t *StateTrie) UpdateAccountAsync(address common.Address, accountResolve func() (*types.StateAccount, int)) error {
233233
hk := crypto.Keccak256(address.Bytes())
234234
resolve := func() []byte {
235-
acc := accountResolve()
235+
acc, _ := accountResolve()
236236
data, err := rlp.EncodeToBytes(acc)
237237
if err != nil {
238238
panic(err) // TODO: what do do here?

trie/transition.go

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

1919
import (
20-
"errors"
2120
"fmt"
2221

2322
"github.com/ethereum/go-ethereum/common"
@@ -139,8 +138,9 @@ func (t *TransitionTrie) UpdateAccount(addr common.Address, account *types.State
139138
// only needs to know what the account trie does now.
140139
return t.overlay.UpdateAccount(addr, account, codeLen)
141140
}
142-
func (t *TransitionTrie) UpdateAccountAsync(address common.Address, accountResolver func() *types.StateAccount) error {
143-
return errors.New("not implemented")
141+
func (t *TransitionTrie) UpdateAccountAsync(address common.Address, accountResolver func() (*types.StateAccount, int)) error {
142+
acct, codeLen := accountResolver()
143+
return t.overlay.UpdateAccount(address, acct, codeLen)
144144
}
145145

146146
// DeleteStorage removes any existing value for key from the trie. If a node was not

trie/verkle.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,9 @@ 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")
180+
func (t *VerkleTrie) UpdateAccountAsync(address common.Address, accountResolver func() (*types.StateAccount, int)) error {
181+
acct, codeSize := accountResolver()
182+
return t.UpdateAccount(address, acct, codeSize)
182183
}
183184

184185
// UpdateStorage implements state.Trie, writing the provided storage slot into

0 commit comments

Comments
 (0)