Skip to content

Commit

Permalink
Update that brings go-ethereum with live tracer support
Browse files Browse the repository at this point in the history
This only brings the dependency (will need to wait for a merge + tag of the branch before merging this PR) and the required changes to adapt `DBImpl` to support the new interface.

Relates to:
- sei-protocol/go-ethereum#15
- sei-protocol#1344
  • Loading branch information
maoueh committed Mar 19, 2024
1 parent d63321d commit bab14be
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 48 deletions.
4 changes: 2 additions & 2 deletions evmrpc/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (b *Backend) HeaderByNumber(ctx context.Context, bn rpc.BlockNumber) (*etht
return b.getHeader(big.NewInt(height)), nil
}

func (b *Backend) StateAtTransaction(ctx context.Context, block *ethtypes.Block, txIndex int, reexec uint64) (*core.Message, vm.BlockContext, vm.StateDB, tracers.StateReleaseFunc, error) {
func (b *Backend) StateAtTransaction(ctx context.Context, block *ethtypes.Block, txIndex int, reexec uint64) (*ethtypes.Transaction, vm.BlockContext, vm.StateDB, tracers.StateReleaseFunc, error) {
emptyRelease := func() {}
// Short circuit if it's genesis block.
if block.Number().Int64() == 0 {
Expand All @@ -285,7 +285,7 @@ func (b *Backend) StateAtTransaction(ctx context.Context, block *ethtypes.Block,
return nil, vm.BlockContext{}, nil, nil, err
}
if idx == txIndex {
return msg, *blockContext, statedb, emptyRelease, nil
return tx, *blockContext, statedb, emptyRelease, nil
}
// Not yet the searched for transaction, execute on top of the current state
vmenv := vm.NewEVM(*blockContext, txContext, statedb, b.ChainConfig(), vm.Config{})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ replace (
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.77-seiv2
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.9
github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.0
github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-11
github.com/ethereum/go-ethereum => github.com/streamingfast/go-ethereum v1.13.6-0.20240315215018-7aaf4d2c5d8c
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.33
// Latest goleveldb is broken, we have to stick to this version
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1347,8 +1347,6 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod
github.com/securego/gosec/v2 v2.11.0 h1:+PDkpzR41OI2jrw1q6AdXZCbsNGNGT7pQjal0H0cArI=
github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/go-ethereum v1.13.5-sei-11 h1:SdJaJYZCwYadW/G73rJl8nMNKdktPWRQNBpiMxQwLX4=
github.com/sei-protocol/go-ethereum v1.13.5-sei-11/go.mod h1:kcRZmuzRn1lVejiFNTz4l4W7imnpq1bDAnuKS/RyhbQ=
github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQpIbXDA=
github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8=
github.com/sei-protocol/sei-cosmos v0.2.77-seiv2 h1:w3Ihbr6lRK4PpaivP7eYioMWEG/ySov7V1wfIUoV2Qg=
Expand Down Expand Up @@ -1434,6 +1432,8 @@ github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8L
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
github.com/streamingfast/go-ethereum v1.13.6-0.20240315215018-7aaf4d2c5d8c h1:A0lf1fpxpTJbLMsWEXO6MfDl9YVFAUA/j7V4jMxk+aY=
github.com/streamingfast/go-ethereum v1.13.6-0.20240315215018-7aaf4d2c5d8c/go.mod h1:kcRZmuzRn1lVejiFNTz4l4W7imnpq1bDAnuKS/RyhbQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
15 changes: 8 additions & 7 deletions x/evm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
ethtypes "github.com/ethereum/go-ethereum/core/types"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm"
Expand All @@ -28,19 +29,19 @@ func TestABCI(t *testing.T) {
m.BeginBlock(ctx, abci.RequestBeginBlock{})
// 1st tx
s := state.NewDBImpl(ctx.WithTxIndex(1), k, false)
s.SubBalance(evmAddr1, big.NewInt(10000000000000))
s.AddBalance(evmAddr2, big.NewInt(8000000000000))
s.SubBalance(evmAddr1, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified)
s.AddBalance(evmAddr2, big.NewInt(8000000000000), tracing.BalanceChangeUnspecified)
feeCollectorAddr, err := k.GetFeeCollectorAddress(ctx)
require.Nil(t, err)
s.AddBalance(feeCollectorAddr, big.NewInt(2000000000000))
s.AddBalance(feeCollectorAddr, big.NewInt(2000000000000), tracing.BalanceChangeUnspecified)
surplus, err := s.Finalize()
require.Nil(t, err)
require.Equal(t, sdk.ZeroInt(), surplus)
k.AppendToEvmTxDeferredInfo(ctx.WithTxIndex(1), ethtypes.Bloom{}, common.Hash{}, surplus)
// 3rd tx
s = state.NewDBImpl(ctx.WithTxIndex(3), k, false)
s.SubBalance(evmAddr2, big.NewInt(5000000000000))
s.AddBalance(evmAddr1, big.NewInt(5000000000000))
s.SubBalance(evmAddr2, big.NewInt(5000000000000), tracing.BalanceChangeUnspecified)
s.AddBalance(evmAddr1, big.NewInt(5000000000000), tracing.BalanceChangeUnspecified)
surplus, err = s.Finalize()
require.Nil(t, err)
require.Equal(t, sdk.ZeroInt(), surplus)
Expand All @@ -54,8 +55,8 @@ func TestABCI(t *testing.T) {
m.BeginBlock(ctx, abci.RequestBeginBlock{})
// 2nd tx
s = state.NewDBImpl(ctx.WithTxIndex(2), k, false)
s.SubBalance(evmAddr2, big.NewInt(3000000000000))
s.AddBalance(evmAddr1, big.NewInt(2000000000000))
s.SubBalance(evmAddr2, big.NewInt(3000000000000), tracing.BalanceChangeUnspecified)
s.AddBalance(evmAddr1, big.NewInt(2000000000000), tracing.BalanceChangeUnspecified)
surplus, err = s.Finalize()
require.Nil(t, err)
require.Equal(t, sdk.NewInt(1000000000000), surplus)
Expand Down
11 changes: 6 additions & 5 deletions x/evm/state/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/sei-protocol/sei-chain/x/evm/types"
)

func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int) {
func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int, reason tracing.BalanceChangeReason) {
s.k.PrepareReplayedAddr(s.ctx, evmAddr)
if amt.Sign() == 0 {
return
}
if amt.Sign() < 0 {
s.AddBalance(evmAddr, new(big.Int).Neg(amt))
s.AddBalance(evmAddr, new(big.Int).Neg(amt), reason)
return
}

Expand All @@ -31,13 +32,13 @@ func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int) {
s.tempStateCurrent.surplus = s.tempStateCurrent.surplus.Add(sdk.NewIntFromBigInt(amt))
}

func (s *DBImpl) AddBalance(evmAddr common.Address, amt *big.Int) {
func (s *DBImpl) AddBalance(evmAddr common.Address, amt *big.Int, reason tracing.BalanceChangeReason) {
s.k.PrepareReplayedAddr(s.ctx, evmAddr)
if amt.Sign() == 0 {
return
}
if amt.Sign() < 0 {
s.SubBalance(evmAddr, new(big.Int).Neg(amt))
s.SubBalance(evmAddr, new(big.Int).Neg(amt), reason)
return
}

Expand All @@ -62,7 +63,7 @@ func (s *DBImpl) GetBalance(evmAddr common.Address) *big.Int {
}

// should only be called during simulation
func (s *DBImpl) SetBalance(evmAddr common.Address, amt *big.Int) {
func (s *DBImpl) SetBalance(evmAddr common.Address, amt *big.Int, reason tracing.BalanceChangeReason) {
if !s.simulation {
panic("should never call SetBalance in a non-simulation setting")
}
Expand Down
53 changes: 27 additions & 26 deletions x/evm/state/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/core/tracing"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/state"
"github.com/sei-protocol/sei-chain/x/evm/types"
Expand All @@ -16,17 +17,17 @@ func TestAddBalance(t *testing.T) {
db := state.NewDBImpl(ctx, k, false)
seiAddr, evmAddr := testkeeper.MockAddressPair()
require.Equal(t, big.NewInt(0), db.GetBalance(evmAddr))
db.AddBalance(evmAddr, big.NewInt(0))
db.AddBalance(evmAddr, big.NewInt(0), tracing.BalanceChangeUnspecified)

// set association
k.SetAddressMapping(db.Ctx(), seiAddr, evmAddr)
require.Equal(t, big.NewInt(0), db.GetBalance(evmAddr))
db.AddBalance(evmAddr, big.NewInt(10000000000000))
db.AddBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified)
require.Nil(t, db.Err())
require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000))

_, evmAddr2 := testkeeper.MockAddressPair()
db.SubBalance(evmAddr2, big.NewInt(-5000000000000)) // should redirect to AddBalance
db.SubBalance(evmAddr2, big.NewInt(-5000000000000), tracing.BalanceChangeUnspecified) // should redirect to AddBalance
require.Nil(t, db.Err())
require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000))
require.Equal(t, db.GetBalance(evmAddr2), big.NewInt(5000000000000))
Expand All @@ -37,42 +38,42 @@ func TestSubBalance(t *testing.T) {
db := state.NewDBImpl(ctx, k, false)
seiAddr, evmAddr := testkeeper.MockAddressPair()
require.Equal(t, big.NewInt(0), db.GetBalance(evmAddr))
db.SubBalance(evmAddr, big.NewInt(0))
db.SubBalance(evmAddr, big.NewInt(0), tracing.BalanceChangeUnspecified)

// set association
k.SetAddressMapping(db.Ctx(), seiAddr, evmAddr)
require.Equal(t, big.NewInt(0), db.GetBalance(evmAddr))
amt := sdk.NewCoins(sdk.NewCoin(k.GetBaseDenom(ctx), sdk.NewInt(20)))
k.BankKeeper().MintCoins(db.Ctx(), types.ModuleName, amt)
k.BankKeeper().SendCoinsFromModuleToAccount(db.Ctx(), types.ModuleName, seiAddr, amt)
db.SubBalance(evmAddr, big.NewInt(10000000000000))
db.SubBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified)
require.Nil(t, db.Err())
require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000))

_, evmAddr2 := testkeeper.MockAddressPair()
amt = sdk.NewCoins(sdk.NewCoin(k.GetBaseDenom(ctx), sdk.NewInt(10)))
k.BankKeeper().MintCoins(db.Ctx(), types.ModuleName, amt)
k.BankKeeper().SendCoinsFromModuleToAccount(db.Ctx(), types.ModuleName, sdk.AccAddress(evmAddr2[:]), amt)
db.AddBalance(evmAddr2, big.NewInt(-5000000000000)) // should redirect to SubBalance
db.AddBalance(evmAddr2, big.NewInt(-5000000000000), tracing.BalanceChangeUnspecified) // should redirect to SubBalance
require.Nil(t, db.Err())
require.Equal(t, db.GetBalance(evmAddr), big.NewInt(10000000000000))
require.Equal(t, db.GetBalance(evmAddr2), big.NewInt(5000000000000))

// insufficient balance
db.SubBalance(evmAddr2, big.NewInt(10000000000000))
db.SubBalance(evmAddr2, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified)
require.NotNil(t, db.Err())
}

func TestSetBalance(t *testing.T) {
k, ctx := testkeeper.MockEVMKeeper()
db := state.NewDBImpl(ctx, k, true)
_, evmAddr := testkeeper.MockAddressPair()
db.SetBalance(evmAddr, big.NewInt(10000000000000))
db.SetBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified)
require.Equal(t, big.NewInt(10000000000000), db.GetBalance(evmAddr))

seiAddr2, evmAddr2 := testkeeper.MockAddressPair()
k.SetAddressMapping(db.Ctx(), seiAddr2, evmAddr2)
db.SetBalance(evmAddr2, big.NewInt(10000000000000))
db.SetBalance(evmAddr2, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified)
require.Equal(t, big.NewInt(10000000000000), db.GetBalance(evmAddr2))
}

Expand All @@ -82,55 +83,55 @@ func TestSurplus(t *testing.T) {

// test negative usei surplus negative wei surplus
db := state.NewDBImpl(ctx, k, false)
db.AddBalance(evmAddr, big.NewInt(1_000_000_000_001))
db.AddBalance(evmAddr, big.NewInt(1_000_000_000_001), tracing.BalanceChangeUnspecified)
_, err := db.Finalize()
require.NotNil(t, err)
require.Contains(t, err.Error(), "negative surplus value")

// test negative usei surplus positive wei surplus (negative total)
db = state.NewDBImpl(ctx, k, false)
db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000))
db.SubBalance(evmAddr, big.NewInt(1))
db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified)
db.SubBalance(evmAddr, big.NewInt(1), tracing.BalanceChangeUnspecified)
_, err = db.Finalize()
require.NotNil(t, err)
require.Contains(t, err.Error(), "negative surplus value")

// test negative usei surplus positive wei surplus (positive total)
db = state.NewDBImpl(ctx, k, false)
db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000))
db.SubBalance(evmAddr, big.NewInt(2))
db.SubBalance(evmAddr, big.NewInt(999_999_999_999))
db.AddBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified)
db.SubBalance(evmAddr, big.NewInt(2), tracing.BalanceChangeUnspecified)
db.SubBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified)
surplus, err := db.Finalize()
require.Nil(t, err)
require.Equal(t, sdk.OneInt(), surplus)

// test positive usei surplus negative wei surplus (negative total)
db = state.NewDBImpl(ctx, k, false)
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000))
db.AddBalance(evmAddr, big.NewInt(2))
db.AddBalance(evmAddr, big.NewInt(999_999_999_999))
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified)
db.AddBalance(evmAddr, big.NewInt(2), tracing.BalanceChangeUnspecified)
db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified)
_, err = db.Finalize()
require.NotNil(t, err)
require.Contains(t, err.Error(), "negative surplus value")

// test positive usei surplus negative wei surplus (positive total)
db = state.NewDBImpl(ctx, k, false)
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000))
db.AddBalance(evmAddr, big.NewInt(999_999_999_999))
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified)
db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified)
surplus, err = db.Finalize()
require.Nil(t, err)
require.Equal(t, sdk.OneInt(), surplus)

// test snapshots
db = state.NewDBImpl(ctx, k, false)
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000))
db.AddBalance(evmAddr, big.NewInt(999_999_999_999))
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified)
db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified)
db.Snapshot()
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000))
db.AddBalance(evmAddr, big.NewInt(999_999_999_999))
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified)
db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified)
db.Snapshot()
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000))
db.AddBalance(evmAddr, big.NewInt(999_999_999_999))
db.SubBalance(evmAddr, big.NewInt(1_000_000_000_000), tracing.BalanceChangeUnspecified)
db.AddBalance(evmAddr, big.NewInt(999_999_999_999), tracing.BalanceChangeUnspecified)
surplus, err = db.Finalize()
require.Nil(t, err)
require.Equal(t, sdk.NewInt(3), surplus)
Expand Down
5 changes: 3 additions & 2 deletions x/evm/state/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/core/tracing"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/state"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -35,11 +36,11 @@ func TestEmpty(t *testing.T) {
require.True(t, statedb.Empty(addr))

// has balance
statedb.AddBalance(addr, big.NewInt(1000000000000))
statedb.AddBalance(addr, big.NewInt(1000000000000), tracing.BalanceChangeUnspecified)
require.False(t, statedb.Empty(addr))

// has non-zero nonce
statedb.SubBalance(addr, big.NewInt(1000000000000))
statedb.SubBalance(addr, big.NewInt(1000000000000), tracing.BalanceChangeUnspecified)
statedb.SetNonce(addr, 1)
require.False(t, statedb.Empty(addr))

Expand Down
4 changes: 4 additions & 0 deletions x/evm/state/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type Logs struct {
func (s *DBImpl) AddLog(l *ethtypes.Log) {
l.Index = uint(len(s.GetAllLogs()))
s.tempStateCurrent.logs = append(s.tempStateCurrent.logs, l)

if s.logger != nil && s.logger.OnLog != nil {
s.logger.OnLog(l)
}
}

func (s *DBImpl) GetAllLogs() []*ethtypes.Log {
Expand Down
3 changes: 2 additions & 1 deletion x/evm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/sei-protocol/sei-chain/x/evm/types"
)

Expand Down Expand Up @@ -62,7 +63,7 @@ func (s *DBImpl) SelfDestruct(acc common.Address) {
s.k.DeleteAddressMapping(s.ctx, seiAddr, acc)
}

s.SubBalance(acc, s.GetBalance(acc))
s.SubBalance(acc, s.GetBalance(acc), tracing.BalanceDecreaseSelfdestruct)

// clear account state
s.clearAccountState(acc)
Expand Down
5 changes: 3 additions & 2 deletions x/evm/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/x/evm/state"
"github.com/sei-protocol/sei-chain/x/evm/types"
Expand All @@ -19,7 +20,7 @@ func TestState(t *testing.T) {
statedb.CreateAccount(evmAddr)
require.True(t, statedb.Created(evmAddr))
require.False(t, statedb.HasSelfDestructed(evmAddr))
statedb.AddBalance(evmAddr, big.NewInt(10))
statedb.AddBalance(evmAddr, big.NewInt(10), tracing.BalanceChangeUnspecified)
k.BankKeeper().MintCoins(statedb.Ctx(), types.ModuleName, sdk.NewCoins(sdk.NewCoin(k.GetBaseDenom(ctx), sdk.NewInt(10))))
key := common.BytesToHash([]byte("abc"))
val := common.BytesToHash([]byte("def"))
Expand Down Expand Up @@ -60,7 +61,7 @@ func TestCreate(t *testing.T) {
tval := common.BytesToHash([]byte("mno"))
statedb.SetState(evmAddr, key, val)
statedb.SetTransientState(evmAddr, tkey, tval)
statedb.AddBalance(evmAddr, big.NewInt(10000000000000))
statedb.AddBalance(evmAddr, big.NewInt(10000000000000), tracing.BalanceChangeUnspecified)
// recreate an account should clear its state, but keep its balance and transient state
statedb.CreateAccount(evmAddr)
require.Equal(t, tval, statedb.GetTransientState(evmAddr, tkey))
Expand Down
8 changes: 8 additions & 0 deletions x/evm/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/sei-protocol/sei-chain/utils"
Expand All @@ -29,6 +30,8 @@ type DBImpl struct {

k EVMKeeper
simulation bool

logger *tracing.Hooks
}

func NewDBImpl(ctx sdk.Context, k EVMKeeper, simulation bool) *DBImpl {
Expand All @@ -44,6 +47,10 @@ func NewDBImpl(ctx sdk.Context, k EVMKeeper, simulation bool) *DBImpl {
return s
}

func (s *DBImpl) SetLogger(logger *tracing.Hooks) {
s.logger = logger
}

func (s *DBImpl) SetEVM(evm *vm.EVM) {
s.ctx = types.SetCtxEVM(s.ctx, evm)
s.snapshottedCtxs = utils.Map(s.snapshottedCtxs, func(ctx sdk.Context) sdk.Context { return types.SetCtxEVM(ctx, evm) })
Expand Down Expand Up @@ -105,6 +112,7 @@ func (s *DBImpl) Copy() vm.StateDB {
coinbaseAddress: s.coinbaseAddress,
simulation: s.simulation,
err: s.err,
logger: s.logger,
}
}

Expand Down

0 comments on commit bab14be

Please sign in to comment.