diff --git a/core/state/statedb.go b/core/state/statedb.go index e51fcd2cfe..abf0a02a87 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -577,7 +577,8 @@ func (s *StateDB) updateStateObject(obj *stateObject) { } } -// updateStateObject writes the given object to the trie. +// updateStateObject writes the given object to the trie. The actual value is +// only resolved from the provided function when it is needed during trie hashing. func (s *StateDB) updateStateObjectAsync(addr common.Address, resolver func() *types.StateAccount) { if err := s.trie.UpdateAccountAsync(addr, resolver); err != nil { s.setError(fmt.Errorf("updateStateObject (%x) error: %v", addr, err)) diff --git a/tests/testdata b/tests/testdata index 81862e4848..c67e485ff8 160000 --- a/tests/testdata +++ b/tests/testdata @@ -1 +1 @@ -Subproject commit 81862e4848585a438d64f911a19b3825f0f4cd95 +Subproject commit c67e485ff8b5be9abc8ad15345ec21aa22e290d9 diff --git a/trie/secure_trie.go b/trie/secure_trie.go index b48d28199b..4c8a181acf 100644 --- a/trie/secure_trie.go +++ b/trie/secure_trie.go @@ -226,6 +226,9 @@ func (t *StateTrie) UpdateAccount(address common.Address, acc *types.StateAccoun return nil } +// UpdateAccountAsync will abstract the write of an account to the secure trie. +// The actual value of the account is not resolved from the passed function until +// it is needed when hashing the trie. func (t *StateTrie) UpdateAccountAsync(address common.Address, accountResolve func() *types.StateAccount) error { hk := crypto.Keccak256(address.Bytes()) resolve := func() []byte { diff --git a/trie/trie.go b/trie/trie.go index ec84a038da..eb64d1f7c9 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -382,6 +382,8 @@ func (t *Trie) Update(key, value []byte) error { return t.update(key, value) } +// UpdateAsync associates a key with value in the trie. The actual value is +// not resolved until needed (by calling Get, or Hash). func (t *Trie) UpdateAsync(key []byte, valueResolver func() []byte) error { t.unhashed++ t.uncommitted++