mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core/state: improve journal
This commit is contained in:
parent
4f2b554b35
commit
916666c3db
1 changed files with 2 additions and 10 deletions
|
|
@ -106,7 +106,8 @@ func (self *StateDB) Reset(root common.Hash) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// openTrie creates a trie. If a trie is available from the journal.
|
// openTrie creates a trie. It uses an existing trie if one is available
|
||||||
|
// from the journal if available.
|
||||||
func (self *StateDB) openTrie(root common.Hash) (*trie.SecureTrie, error) {
|
func (self *StateDB) openTrie(root common.Hash) (*trie.SecureTrie, error) {
|
||||||
if self.trie != nil && self.trie.Hash() == root {
|
if self.trie != nil && self.trie.Hash() == root {
|
||||||
return self.trie, nil
|
return self.trie, nil
|
||||||
|
|
@ -121,15 +122,6 @@ func (self *StateDB) openTrie(root common.Hash) (*trie.SecureTrie, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) pushTrie(t *trie.SecureTrie) {
|
func (self *StateDB) pushTrie(t *trie.SecureTrie) {
|
||||||
// Remove t's equivalent if it's already in the journal.
|
|
||||||
root := t.Hash()
|
|
||||||
for i := len(self.pastTries) - 1; i >= 0; i-- {
|
|
||||||
if self.pastTries[i].Hash() == root {
|
|
||||||
self.pastTries = append(self.pastTries[i:i], self.pastTries[i+1:]...)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Insert.
|
|
||||||
if len(self.pastTries) >= maxJournalLength {
|
if len(self.pastTries) >= maxJournalLength {
|
||||||
copy(self.pastTries, self.pastTries[1:])
|
copy(self.pastTries, self.pastTries[1:])
|
||||||
self.pastTries[len(self.pastTries)-1] = t
|
self.pastTries[len(self.pastTries)-1] = t
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue