mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 10:20:44 +00:00
parent
34a245fbc8
commit
6f84f67a15
3 changed files with 13 additions and 7 deletions
|
|
@ -127,7 +127,7 @@ const (
|
||||||
blocksHashCacheLimit = 900
|
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.
|
// that's resident in a blockchain.
|
||||||
type CacheConfig struct {
|
type CacheConfig struct {
|
||||||
TrieCleanLimit int // Memory allowance (MB) to use for caching trie nodes in memory
|
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]
|
hash := chain[i]
|
||||||
|
|
||||||
// Degrade the chain markers if they are explicitly reverted.
|
// 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
|
// last step, however the direction of rollback is from high
|
||||||
// to low, so it's safe the update in-memory markers directly.
|
// to low, so it's safe the update in-memory markers directly.
|
||||||
currentHeader := bc.hc.CurrentHeader()
|
currentHeader := bc.hc.CurrentHeader()
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ func (s Storage) Copy() Storage {
|
||||||
// The usage pattern is as follows:
|
// The usage pattern is as follows:
|
||||||
// First you need to obtain a state object.
|
// First you need to obtain a state object.
|
||||||
// Account values can be accessed and modified through the 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 {
|
type stateObject struct {
|
||||||
db *StateDB
|
db *StateDB
|
||||||
address common.Address // address of ethereum account
|
address common.Address // address of ethereum account
|
||||||
|
|
@ -320,9 +320,9 @@ func (s *stateObject) updateRoot(db Database) {
|
||||||
s.data.Root = s.trie.Hash()
|
s.data.Root = s.trie.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommitTrie the storage trie of the object to db.
|
// commitTrie submits the storage changes into the storage trie and re-computes
|
||||||
// This updates the trie root.
|
// the root. Besides, all trie changes will be collected in a nodeset and returned.
|
||||||
func (s *stateObject) CommitTrie(db Database) error {
|
func (s *stateObject) commitTrie(db Database) error {
|
||||||
// If nothing changed, don't bother with hashing anything
|
// If nothing changed, don't bother with hashing anything
|
||||||
if s.updateTrie(db) == nil {
|
if s.updateTrie(db) == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -808,10 +808,16 @@ func (s *StateDB) Commit(deleteEmptyObjects bool) (common.Hash, error) {
|
||||||
obj.dirtyCode = false
|
obj.dirtyCode = false
|
||||||
}
|
}
|
||||||
// Write any storage changes in the state object to its storage trie.
|
// 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
|
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 {
|
if len(s.stateObjectsDirty) > 0 {
|
||||||
s.stateObjectsDirty = make(map[common.Address]struct{})
|
s.stateObjectsDirty = make(map[common.Address]struct{})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue