Skip to content

Commit

Permalink
core/state: make TestSnapshotRandom work again (#3816)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rjl493456442 authored and fjl committed Apr 4, 2017
1 parent b319f02 commit 49437a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type (
touchChange struct {
account *common.Address
prev bool
prevDirty bool
}
)

Expand All @@ -97,8 +98,10 @@ var ripemd = common.HexToAddress("0000000000000000000000000000000000000003")

func (ch touchChange) undo(s *StateDB) {
if !ch.prev && *ch.account != ripemd {
delete(s.stateObjects, *ch.account)
delete(s.stateObjectsDirty, *ch.account)
s.getStateObject(*ch.account).touched = ch.prev
if !ch.prevDirty {
delete(s.stateObjectsDirty, *ch.account)
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ func (self *stateObject) markSuicided() {

func (c *stateObject) touch() {
c.db.journal = append(c.db.journal, touchChange{
account: &c.address,
prev: c.touched,
account: &c.address,
prev: c.touched,
prevDirty: c.onDirty == nil,
})
if c.onDirty != nil {
c.onDirty(c.Address())
Expand Down
1 change: 0 additions & 1 deletion core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ func TestIntermediateLeaks(t *testing.T) {
}

func TestSnapshotRandom(t *testing.T) {
t.Skip("@fjl fix me please")
config := &quick.Config{MaxCount: 1000}
err := quick.Check((*snapshotTest).run, config)
if cerr, ok := err.(*quick.CheckError); ok {
Expand Down

0 comments on commit 49437a0

Please sign in to comment.