core/state: modify touch undo function

in `touch` operation, only `touched` filed has been changed. Therefore
in the related undo function, only `touched` field should be reverted.
In addition, whether remove this obj from dirty map should depend on
prevDirty flag.
This commit is contained in:
rjl493456442 2017-03-24 16:37:17 +08:00
parent 8771c3061f
commit 5079dbea6e
2 changed files with 8 additions and 4 deletions

View file

@ -73,6 +73,7 @@ type (
touchChange struct { touchChange struct {
account *common.Address account *common.Address
prev bool prev bool
prevDirty bool
} }
) )
@ -97,8 +98,10 @@ var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")
func (ch touchChange) undo(s *StateDB) { func (ch touchChange) undo(s *StateDB) {
if !ch.prev && *ch.account != ripemd { if !ch.prev && *ch.account != ripemd {
delete(s.stateObjects, *ch.account) s.getStateObject(*ch.account).touched = ch.prev
delete(s.stateObjectsDirty, *ch.account) if !ch.prevDirty {
delete(s.stateObjectsDirty, *ch.account)
}
} }
} }

View file

@ -137,8 +137,9 @@ func (self *stateObject) markSuicided() {
func (c *stateObject) touch() { func (c *stateObject) touch() {
c.db.journal = append(c.db.journal, touchChange{ c.db.journal = append(c.db.journal, touchChange{
account: &c.address, account: &c.address,
prev: c.touched, prev: c.touched,
prevDirty: c.onDirty == nil,
}) })
if c.onDirty != nil { if c.onDirty != nil {
c.onDirty(c.Address()) c.onDirty(c.Address())