core, core/state: fixed consensus issue added touch revert

Implemented proper touch revert journal entries and copied a Parity
consensus bug in order to remain in sync with the current longest chain.
This commit is contained in:
Jeffrey Wilcke
2016-11-24 16:24:04 +01:00
parent c04c8f10f0
commit 12d654a6fc
8 changed files with 172 additions and 31 deletions

View File

@ -87,6 +87,7 @@ type StateObject struct {
// during the "update" phase of the state transition.
dirtyCode bool // true if the code was updated
suicided bool
touched bool
deleted bool
onDirty func(addr common.Address) // Callback method to mark a state object newly dirty
}
@ -139,6 +140,18 @@ func (self *StateObject) markSuicided() {
}
}
func (c *StateObject) touch() {
c.db.journal = append(c.db.journal, touchChange{
account: &c.address,
prev: c.touched,
})
if c.onDirty != nil {
c.onDirty(c.Address())
c.onDirty = nil
}
c.touched = true
}
func (c *StateObject) getTrie(db trie.Database) *trie.SecureTrie {
if c.trie == nil {
var err error
@ -231,7 +244,11 @@ func (self *StateObject) CommitTrie(db trie.Database, dbw trie.DatabaseWriter) e
func (c *StateObject) AddBalance(amount *big.Int) {
// EIP158: We must check emptiness for the objects such that the account
// clearing (0,0,0 objects) can take effect.
if amount.Cmp(common.Big0) == 0 && !c.empty() {
if amount.Cmp(common.Big0) == 0 {
if c.empty() {
c.touch()
}
return
}
c.SetBalance(new(big.Int).Add(c.Balance(), amount))