mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 14:16:44 +00:00
state: track code dirtyness and only write if changed
This commit is contained in:
parent
8fbdde5491
commit
3c26ba4d30
2 changed files with 8 additions and 5 deletions
|
|
@ -82,9 +82,10 @@ type StateObject struct {
|
||||||
// Cache flags.
|
// Cache flags.
|
||||||
// When an object is marked for deletion it will be delete from the trie
|
// When an object is marked for deletion it will be delete from the trie
|
||||||
// during the "update" phase of the state transition
|
// during the "update" phase of the state transition
|
||||||
dirty bool // true if anything has changed
|
dirty bool // true if anything has changed
|
||||||
remove bool
|
dirtyCode bool // true if the code was updated
|
||||||
deleted bool
|
remove bool
|
||||||
|
deleted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Account is the Ethereum consensus representation of accounts.
|
// Account is the Ethereum consensus representation of accounts.
|
||||||
|
|
@ -238,6 +239,7 @@ func (self *StateObject) Copy(db trie.Database) *StateObject {
|
||||||
stateObject.storage = self.storage.Copy()
|
stateObject.storage = self.storage.Copy()
|
||||||
stateObject.remove = self.remove
|
stateObject.remove = self.remove
|
||||||
stateObject.dirty = self.dirty
|
stateObject.dirty = self.dirty
|
||||||
|
stateObject.dirtyCode = self.dirtyCode
|
||||||
stateObject.deleted = self.deleted
|
stateObject.deleted = self.deleted
|
||||||
return stateObject
|
return stateObject
|
||||||
}
|
}
|
||||||
|
|
@ -270,7 +272,7 @@ func (self *StateObject) Code(db trie.Database) []byte {
|
||||||
func (self *StateObject) SetCode(code []byte) {
|
func (self *StateObject) SetCode(code []byte) {
|
||||||
self.code = code
|
self.code = code
|
||||||
self.data.CodeHash = crypto.Keccak256(code)
|
self.data.CodeHash = crypto.Keccak256(code)
|
||||||
self.dirty = true
|
self.dirty, self.dirtyCode = true, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateObject) SetNonce(nonce uint64) {
|
func (self *StateObject) SetNonce(nonce uint64) {
|
||||||
|
|
|
||||||
|
|
@ -447,10 +447,11 @@ func (s *StateDB) commit(dbw trie.DatabaseWriter) (root common.Hash, err error)
|
||||||
delete(s.all, addr)
|
delete(s.all, addr)
|
||||||
} else if stateObject.dirty {
|
} else if stateObject.dirty {
|
||||||
// Write any contract code associated with the state object
|
// Write any contract code associated with the state object
|
||||||
if stateObject.code != nil {
|
if stateObject.code != nil && stateObject.dirtyCode {
|
||||||
if err := dbw.Put(stateObject.CodeHash(), stateObject.code); err != nil {
|
if err := dbw.Put(stateObject.CodeHash(), stateObject.code); err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
stateObject.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 := stateObject.CommitTrie(s.db, dbw); err != nil {
|
if err := stateObject.CommitTrie(s.db, dbw); err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue