mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
Fix incorrect balance when CreateContract is used in block-stm (#1382)
* Fix incorrect balance when CreateContract is used in block-stm * address CR comments
This commit is contained in:
parent
d227610781
commit
67b12b50df
2 changed files with 30 additions and 6 deletions
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue