Skip to content

Commit

Permalink
Adjusted patch for new go-ethereum version
Browse files Browse the repository at this point in the history
  • Loading branch information
maoueh committed Mar 15, 2024
1 parent 0614782 commit 5e81591
Show file tree
Hide file tree
Showing 18 changed files with 689 additions and 303 deletions.
3 changes: 2 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import (
evmante "github.com/sei-protocol/sei-chain/x/evm/ante"
evmkeeper "github.com/sei-protocol/sei-chain/x/evm/keeper"
evmtracers "github.com/sei-protocol/sei-chain/x/evm/tracers"
"github.com/sei-protocol/sei-chain/x/evm/tracing"
evmtypes "github.com/sei-protocol/sei-chain/x/evm/types"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
Expand Down Expand Up @@ -372,7 +373,7 @@ type App struct {

encodingConfig appparams.EncodingConfig
evmRPCConfig evmrpc.Config
evmTracer evmtracers.BlockchainLogger
evmTracer *tracing.Hooks
}

// New returns a reference to an initialized blockchain app
Expand Down
4 changes: 2 additions & 2 deletions evmrpc/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,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 @@ -282,7 +282,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
3 changes: 2 additions & 1 deletion precompiles/addr/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"embed"
"fmt"
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -84,7 +85,7 @@ func (p Precompile) Address() common.Address {
return p.address
}

func (p Precompile) Run(evm *vm.EVM, _ common.Address, input []byte) (bz []byte, err error) {
func (p Precompile) Run(evm *vm.EVM, _ common.Address, input []byte, value *big.Int) (bz []byte, err error) {
ctx, method, args, err := p.Prepare(evm, input)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion precompiles/bank/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (p Precompile) Address() common.Address {
return p.address
}

func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte) (bz []byte, err error) {
func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte, value *big.Int) (bz []byte, err error) {
ctx, method, args, err := p.Prepare(evm, input)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion precompiles/distribution/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"embed"
"errors"
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
Expand Down Expand Up @@ -89,7 +90,7 @@ func (p Precompile) Address() common.Address {
return p.address
}

func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte) (bz []byte, err error) {
func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte, value *big.Int) (bz []byte, err error) {
ctx, method, args, err := p.Prepare(evm, input)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion precompiles/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (p Precompile) Address() common.Address {
return p.address
}

func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte) (bz []byte, err error) {
func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte, value *big.Int) (bz []byte, err error) {
ctx, method, args, err := p.Prepare(evm, input)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion precompiles/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (p Precompile) Address() common.Address {
return p.address
}

func (p Precompile) Run(evm *vm.EVM, _ common.Address, input []byte) (bz []byte, err error) {
func (p Precompile) Run(evm *vm.EVM, _ common.Address, input []byte, value *big.Int) (bz []byte, err error) {
ctx, method, args, err := p.Prepare(evm, input)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion precompiles/staking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (p Precompile) Address() common.Address {
return p.address
}

func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte) (bz []byte, err error) {
func (p Precompile) Run(evm *vm.EVM, caller common.Address, input []byte, value *big.Int) (bz []byte, err error) {
ctx, method, args, err := p.Prepare(evm, input)
if err != nil {
return nil, err
Expand Down
9 changes: 7 additions & 2 deletions precompiles/wasmd/wasmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/ethereum/go-ethereum/core/vm"
pcommon "github.com/sei-protocol/sei-chain/precompiles/common"
)
Expand Down Expand Up @@ -105,7 +106,7 @@ func (p Precompile) Address() common.Address {
return p.address
}

func (p Precompile) RunAndCalculateGas(evm *vm.EVM, caller common.Address, callingContract common.Address, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) {
func (p Precompile) RunAndCalculateGas(evm *vm.EVM, caller common.Address, callingContract common.Address, input []byte, suppliedGas uint64, logger *tracing.Hooks) (ret []byte, remainingGas uint64, err error) {
ctx, method, args, err := p.Prepare(evm, input)
if err != nil {
return nil, 0, err
Expand All @@ -120,6 +121,10 @@ func (p Precompile) RunAndCalculateGas(evm *vm.EVM, caller common.Address, calli
}
ctx = ctx.WithGasMeter(sdk.NewGasMeter(gasLimitBigInt.Uint64()))

if logger != nil && logger.OnGasChange != nil {
defer func() { logger.OnGasChange(suppliedGas, remainingGas, tracing.GasChangeCallPrecompiledContract) }()
}

switch method.Name {
case InstantiateMethod:
return p.instantiate(ctx, method, caller, args)
Expand All @@ -131,7 +136,7 @@ func (p Precompile) RunAndCalculateGas(evm *vm.EVM, caller common.Address, calli
return
}

func (p Precompile) Run(*vm.EVM, common.Address, []byte) ([]byte, error) {
func (p Precompile) Run(*vm.EVM, common.Address, []byte, *big.Int) ([]byte, error) {
panic("static gas Run is not implemented for dynamic gas precompile")
}

Expand Down
12 changes: 6 additions & 6 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT
}

logger := evmtracers.GetCtxBlockchainLogger(ctx)
if logger != nil {
logger.CaptureTxStart(evmInstance, tx, emsg.From)
if logger != nil && logger.OnTxStart != nil {
logger.OnTxStart(evmInstance.GetVMContext(), tx, emsg.From)
}

var transitionRes *core.ExecutionResult
Expand All @@ -73,7 +73,7 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT
panic(pe)
}

if logger != nil {
if logger != nil && logger.OnTxEnd != nil {
var receipt *ethtypes.Receipt
if err == nil {
receipt = server.getEthReceipt(ctx, tx, emsg, serverRes, stateDB)
Expand All @@ -84,7 +84,7 @@ func (server msgServer) EVMTransaction(goCtx context.Context, msg *types.MsgEVMT
txErr = transitionRes.Err
}

logger.CaptureTxEnd(receipt, txErr)
logger.OnTxEnd(receipt, txErr)
}

if err != nil {
Expand Down Expand Up @@ -161,10 +161,10 @@ func (server msgServer) getEVM(ctx sdk.Context, msg *core.Message, stateDB *stat

logger := evmtracers.GetCtxBlockchainLogger(ctx)
evmInstance := vm.NewEVM(*blockCtx, txCtx, stateDB, cfg, vm.Config{
Tracer: logger,
Tracer: logger.Hooks,
})
stateDB.SetEVM(evmInstance)
stateDB.SetLogger(logger)
stateDB.SetLogger(logger.Hooks)

return evmInstance, nil
}
Expand Down
8 changes: 4 additions & 4 deletions x/evm/state/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"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, reason state.BalanceChangeReason) {
func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int, reason tracing.BalanceChangeReason) {
if amt.Sign() == 0 {
return
}
Expand All @@ -31,7 +31,7 @@ func (s *DBImpl) SubBalance(evmAddr common.Address, amt *big.Int, reason state.B
s.tempStateCurrent.surplus = s.tempStateCurrent.surplus.Add(sdk.NewIntFromBigInt(amt))
}

func (s *DBImpl) AddBalance(evmAddr common.Address, amt *big.Int, reason state.BalanceChangeReason) {
func (s *DBImpl) AddBalance(evmAddr common.Address, amt *big.Int, reason tracing.BalanceChangeReason) {
if amt.Sign() == 0 {
return
}
Expand Down Expand Up @@ -60,7 +60,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, reason state.BalanceChangeReason) {
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
2 changes: 1 addition & 1 deletion x/evm/state/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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 {
if s.logger != nil && s.logger.OnLog != nil {
s.logger.OnLog(l)
}
}
Expand Down
4 changes: 2 additions & 2 deletions x/evm/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +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/state"
"github.com/ethereum/go-ethereum/core/tracing"
"github.com/sei-protocol/sei-chain/x/evm/types"
)

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

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

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

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"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 @@ -31,7 +31,7 @@ type DBImpl struct {
k EVMKeeper
simulation bool

logger state.StateLogger
logger *tracing.Hooks
}

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

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

Expand Down
Loading

0 comments on commit 5e81591

Please sign in to comment.