From 6f84f67a1561b33ae8001d957a2b8e2c54366e64 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Fri, 11 Jul 2025 10:48:10 +0800 Subject: [PATCH] core: rename CommitTrie to commitTrie #25896 (#1214) --- core/blockchain.go | 4 ++-- core/state/state_object.go | 8 ++++---- core/state/statedb.go | 8 +++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 2b66d6a963..675278d05a 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -127,7 +127,7 @@ const ( blocksHashCacheLimit = 900 ) -// CacheConfig contains the configuration values for the trie caching/pruning +// CacheConfig contains the configuration values for the trie database // that's resident in a blockchain. type CacheConfig struct { TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory @@ -1193,7 +1193,7 @@ func (bc *BlockChain) Rollback(chain []common.Hash) { hash := chain[i] // Degrade the chain markers if they are explicitly reverted. - // In theory we should update all in-memory markers in the + // In theory, we should update all in-memory markers in the // last step, however the direction of rollback is from high // to low, so it's safe the update in-memory markers directly. currentHeader := bc.hc.CurrentHeader() diff --git a/core/state/state_object.go b/core/state/state_object.go index 1fcda94546..e0a02fba17 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -59,7 +59,7 @@ func (s Storage) Copy() Storage { // The usage pattern is as follows: // First you need to obtain a state object. // Account values can be accessed and modified through the object. -// Finally, call CommitTrie to write the modified storage trie into a database. +// Finally, call commitTrie to write the modified storage trie into a database. type stateObject struct { db *StateDB address common.Address // address of ethereum account @@ -320,9 +320,9 @@ func (s *stateObject) updateRoot(db Database) { s.data.Root = s.trie.Hash() } -// CommitTrie the storage trie of the object to db. -// This updates the trie root. -func (s *stateObject) CommitTrie(db Database) error { +// commitTrie submits the storage changes into the storage trie and re-computes +// the root. Besides, all trie changes will be collected in a nodeset and returned. +func (s *stateObject) commitTrie(db Database) error { // If nothing changed, don't bother with hashing anything if s.updateTrie(db) == nil { return nil diff --git a/core/state/statedb.go b/core/state/statedb.go index b710c99278..9012f336cf 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -808,10 +808,16 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) { obj.dirtyCode = false } // Write any storage changes in the state object to its storage trie. - if err := obj.CommitTrie(s.db); err != nil { + if err := obj.commitTrie(s.db); err != nil { return common.Hash{}, err } } + // If the contract is destructed, the storage is still left in the + // database as dangling data. Theoretically it's should be wiped from + // database as well, but in hash-based-scheme it's extremely hard to + // determine that if the trie nodes are also referenced by other storage, + // and in path-based-scheme some technical challenges are still unsolved. + // Although it won't affect the correctness but please fix it TODO(rjl493456442). } if len(s.stateObjectsDirty) > 0 { s.stateObjectsDirty = make(map[common.Address]struct{})