Skip to content

Commit

Permalink
Revert "Add method to statedb to move an account (#146)"
Browse files Browse the repository at this point in the history
This reverts commit 0ec50cc.
  • Loading branch information
palango committed Sep 11, 2024
1 parent 394cf78 commit 4fc3c7c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 51 deletions.
13 changes: 0 additions & 13 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1484,16 +1484,3 @@ func (s *StateDB) PointCache() *utils.PointCache {
func (s *StateDB) Witness() *stateless.Witness {
return s.witness
}

func (s *StateDB) MoveAccount(from, to common.Address) error {
fromObj := s.getStateObject(from)
if fromObj == nil {
return fmt.Errorf("account %s not found", from.Hex())
}

fromObj.address = to
fromObj.addrHash = crypto.Keccak256Hash(to[:])

s.setStateObject(fromObj)
return nil
}
38 changes: 0 additions & 38 deletions core/state/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"github.com/ethereum/go-ethereum/triedb/hashdb"
"github.com/ethereum/go-ethereum/triedb/pathdb"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"
)

// Tests that updating a state trie does not leak any database writes prior to
Expand Down Expand Up @@ -1374,40 +1373,3 @@ func TestStorageDirtiness(t *testing.T) {
state.RevertToSnapshot(snap)
checkDirty(common.Hash{0x1}, common.Hash{0x1}, true)
}

func TestMoveStorage(t *testing.T) {
var (
disk = rawdb.NewMemoryDatabase()
tdb = triedb.NewDatabase(disk, nil)
db = NewDatabaseWithNodeDB(disk, tdb)
snaps, _ = snapshot.New(snapshot.Config{CacheSize: 10}, disk, tdb, types.EmptyRootHash)
state, _ = New(types.EmptyRootHash, db, snaps)
from = common.HexToAddress("0x1")
to = common.HexToAddress("0x2")
slotA = common.HexToHash("0x11")
valueA = common.HexToHash("0x111")
slotB = common.HexToHash("0x22")
valueB = common.HexToHash("0x222")
balance = uint256.NewInt(123)
)

var dummyReason tracing.BalanceChangeReason = 250
state.SetBalance(from, balance, dummyReason)
state.SetState(from, slotA, valueA)
state.SetState(from, slotB, valueB)

root, _ := state.Commit(0, true)

require.True(t, state.Empty(to))

err := state.MoveAccount(from, to)
require.NoError(t, err)

require.False(t, state.Empty(to))
require.Equal(t, balance, state.GetBalance(to))
require.Equal(t, valueA, state.GetState(to, slotA))
require.Equal(t, valueB, state.GetState(to, slotB))

root2, _ := state.Commit(1, true)
require.NotEqual(t, root, root2)
}

0 comments on commit 4fc3c7c

Please sign in to comment.