Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/parallel_state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (task *ExecutionTask) Settle() {

coinbaseBalance := task.finalStateDB.GetBalance(task.coinbase)

task.finalStateDB.ApplyMVWriteSet(task.statedb.MVFullWriteList())
task.finalStateDB.ApplyMVWriteSet(task.statedb.MVWriteList())

for _, l := range task.statedb.GetLogs(task.tx.Hash(), task.blockNumber.Uint64(), task.blockHash, task.blockTime) {
task.finalStateDB.AddLog(l)
Expand Down
2 changes: 2 additions & 0 deletions core/state/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"sort"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/blockstm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
)
Expand Down Expand Up @@ -323,6 +324,7 @@ func (ch selfDestructChange) revert(s *StateDB) {
obj := s.getStateObject(ch.account)
if obj != nil {
obj.selfDestructed = false
RevertWrite(s, blockstm.NewSubpathKey(ch.account, SuicidePath))
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (s *StateDB) ApplyMVWriteSet(writes []blockstm.WriteDescriptor) {
s.SetCode(addr, sr.GetCode(addr))
case SuicidePath:
stateObject := s.getStateObject(addr)
if stateObject != nil {
if stateObject != nil && sr.HasSelfDestructed(addr) {
s.SelfDestruct(addr)
}
default:
Expand Down
37 changes: 37 additions & 0 deletions core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2025,3 +2025,40 @@
codeAfterDeletion := s.GetCode(addr)
assert.Equal(t, []byte(nil), codeAfterDeletion, "smart contract should be deleted")
}

// containsKey returns true if the provided write descriptor list contains the given key.
func containsKey(writes []blockstm.WriteDescriptor, key blockstm.Key) bool {
for _, w := range writes {
if w.Path == key {
return true
}
}
return false
}

// Test that selfdestruct writes (suicide and balance) are excluded after revert.
func TestRevertWriteSelfDestruct(t *testing.T) {
t.Parallel()

db := NewDatabase(triedb.NewDatabase(rawdb.NewMemoryDatabase(), triedb.HashDefaults), nil)
mvhm := blockstm.MakeMVHashMap()
s, _ := NewWithMVHashmap(common.Hash{}, db, nil, mvhm)

Check failure on line 2045 in core/state/statedb_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Handle this error explicitly or document why it can be safely ignored.

See more on https://sonarcloud.io/project/issues?id=0xPolygon_bor&issues=AZroaCxrzGElYdflafJB&open=AZroaCxrzGElYdflafJB&pullRequest=1918

addr := common.HexToAddress("0x06")
s.CreateAccount(addr)
s.SetBalance(addr, uint256.NewInt(100), tracing.BalanceChangeTransfer)
// Clear writes so only selfdestruct writes are tracked
s.ClearWriteMap()

snap := s.Snapshot()
s.SelfDestruct(addr)

keySuicide := blockstm.NewSubpathKey(addr, SuicidePath)
assert.True(t, containsKey(s.MVFullWriteList(), keySuicide))
assert.True(t, containsKey(s.MVWriteList(), keySuicide))

s.RevertToSnapshot(snap)
// Full list still contains both, filtered excludes both
assert.True(t, containsKey(s.MVFullWriteList(), keySuicide))
assert.False(t, containsKey(s.MVWriteList(), keySuicide))
}
Loading