Skip to content

Commit

Permalink
Add a corner case where a state read is not recorded correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
cffls committed Aug 20, 2024
1 parent a50e685 commit 644a2bf
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions core/state/intra_block_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type IntraBlockState struct {
stateObjects map[libcommon.Address]*stateObject
stateObjectsDirty map[libcommon.Address]struct{}

seenStateObjects map[libcommon.Address]*stateObject // State objects that have been seen at least once
seenStateObjects map[libcommon.Address]struct{} // State objects that have been seen at least once

nilAccounts map[libcommon.Address]struct{} // Remember non-existent account to avoid reading them again

Expand Down Expand Up @@ -99,7 +99,7 @@ func New(stateReader StateReader) *IntraBlockState {
return &IntraBlockState{
stateReader: stateReader,
stateObjects: map[libcommon.Address]*stateObject{},
seenStateObjects: map[libcommon.Address]*stateObject{},
seenStateObjects: map[libcommon.Address]struct{}{},
stateObjectsDirty: map[libcommon.Address]struct{}{},
nilAccounts: map[libcommon.Address]struct{}{},
logs: map[libcommon.Hash][]*types.Log{},
Expand Down Expand Up @@ -422,10 +422,8 @@ func (sdb *IntraBlockState) HasLiveAccount(addr libcommon.Address) bool {
}

func (sdb *IntraBlockState) SeenAccount(addr libcommon.Address) bool {
if stateObject := sdb.seenStateObjects[addr]; stateObject != nil {
return true
}
return false
_, ok := sdb.seenStateObjects[addr]
return ok
}

func (sdb *IntraBlockState) HasLiveState(addr libcommon.Address, key *libcommon.Hash) bool {
Expand Down Expand Up @@ -517,6 +515,7 @@ func (sdb *IntraBlockState) getStateObject(addr libcommon.Address) (stateObject
return nil
}
account, err := sdb.stateReader.ReadAccountData(addr)
sdb.seenStateObjects[addr] = struct{}{}
if err != nil {
sdb.setErrorUnsafe(err)
return nil
Expand All @@ -542,7 +541,7 @@ func (sdb *IntraBlockState) setStateObject(addr libcommon.Address, object *state
sdb.journal.append(balanceIncreaseTransfer{bi: bi})
}
sdb.stateObjects[addr] = object
sdb.seenStateObjects[addr] = object
sdb.seenStateObjects[addr] = struct{}{}
}

// Retrieve a state object or create a new state object if nil.
Expand Down

0 comments on commit 644a2bf

Please sign in to comment.