diff --git a/core/state/statedb.go b/core/state/statedb.go index e477651906..2ea0662ce0 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -418,7 +418,6 @@ func (s *StateDB) ApplyMVWriteSet(writes []blockstm.WriteDescriptor) { switch path.GetSubpath() { case BalancePath: - // todo: @anshalshukla || @cffls - check balance change reason s.SetBalance(addr, sr.GetBalance(addr), tracing.BalanceChangeUnspecified) case NoncePath: s.SetNonce(addr, sr.GetNonce(addr)) @@ -1095,9 +1094,6 @@ func (s *StateDB) createObject(addr common.Address) *stateObject { // consensus bug eventually. func (s *StateDB) CreateAccount(addr common.Address) { s.createObject(addr) - // todo: @anshalshukla || @cffls - // Check the below MV Write, balance path change have been removed - MVWrite(s, blockstm.NewAddressKey(addr)) } // CreateContract is used whenever a contract is created. This may be preceded @@ -1107,13 +1103,14 @@ func (s *StateDB) CreateAccount(addr common.Address) { // correctly handle EIP-6780 'delete-in-same-transaction' logic. func (s *StateDB) CreateContract(addr common.Address) { obj := s.getStateObject(addr) + if obj != nil { + obj = s.mvRecordWritten(obj) + } if !obj.newContract { obj.newContract = true s.journal.append(createContractChange{account: addr}) } - // todo: @anshalshukla || @cffls - // Check the below MV Write, balance path change have been removed MVWrite(s, blockstm.NewAddressKey(addr)) } diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index a514f7c9f4..9fe1cd9995 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -813,6 +813,33 @@ func TestMVHashMapReadWriteDelete(t *testing.T) { assert.Equal(t, uint256.NewInt(0), b) } +func TestMVHashMapCreateContract(t *testing.T) { + t.Parallel() + + db := NewDatabase(rawdb.NewMemoryDatabase()) + mvhm := blockstm.MakeMVHashMap() + s, _ := NewWithMVHashmap(common.Hash{}, db, nil, mvhm) + + states := []*StateDB{s} + + // Create copies of the original state for each transition + for i := 1; i <= 4; i++ { + sCopy := s.Copy() + sCopy.txIndex = i + states = append(states, sCopy) + } + + addr := common.HexToAddress("0x01") + states[0].SetBalance(addr, uint256.NewInt(100), tracing.BalanceChangeTransfer) + states[0].FlushMVWriteSet() + + states[1].CreateContract(addr) + states[1].FlushMVWriteSet() + + b := states[1].GetBalance(addr) + assert.Equal(t, uint256.NewInt(100), b) +} + func TestMVHashMapRevert(t *testing.T) { t.Parallel()