Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ func New(
}
app.EvmKeeper = *evmkeeper.NewKeeper(keys[evmtypes.StoreKey],
tkeys[evmtypes.TransientStoreKey], app.GetSubspace(evmtypes.ModuleName), app.receiptStore, app.BankKeeper,
&app.AccountKeeper, &app.StakingKeeper, app.TransferKeeper,
&app.AccountKeeper, &app.StakingKeeper,
wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper), &app.WasmKeeper, &app.UpgradeKeeper)
app.BankKeeper.RegisterRecipientChecker(app.EvmKeeper.CanAddressReceive)

Expand Down Expand Up @@ -797,7 +797,7 @@ func New(

app.GigaEvmKeeper = *gigaevmkeeper.NewKeeper(keys[evmtypes.StoreKey],
tkeys[evmtypes.TransientStoreKey], app.GetSubspace(evmtypes.ModuleName), app.receiptStore, app.GigaBankKeeper,
&app.AccountKeeper, &app.StakingKeeper, app.TransferKeeper,
&app.AccountKeeper, &app.StakingKeeper,
wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper), &app.WasmKeeper, &app.UpgradeKeeper)
app.GigaEvmKeeper.UseRegularStore = true
app.GigaBankKeeper.UseRegularStore = true
Expand Down
12 changes: 0 additions & 12 deletions app/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ type PrecompileKeepers struct {
putils.SlashingMsgServer
putils.SlashingQuerier
putils.UpgradeQuerier
putils.TransferKeeper
putils.ClientKeeper
putils.ConnectionKeeper
putils.ChannelKeeper
txConf client.TxConfig
cdc codec.Codec
}
Expand Down Expand Up @@ -73,10 +69,6 @@ func NewPrecompileKeepers(a *App) *PrecompileKeepers {
SlashingMsgServer: slashingkeeper.NewMsgServerImpl(a.SlashingKeeper),
SlashingQuerier: a.SlashingKeeper,
UpgradeQuerier: a.UpgradeKeeper,
TransferKeeper: a.TransferKeeper,
ClientKeeper: a.IBCKeeper.ClientKeeper,
ConnectionKeeper: a.IBCKeeper.ConnectionKeeper,
ChannelKeeper: a.IBCKeeper.ChannelKeeper,
txConf: a.GetTxConfig(),
cdc: a.appCodec,
}
Expand Down Expand Up @@ -109,9 +101,5 @@ func (pk *PrecompileKeepers) ParamsQ() putils.ParamsQuerier { return pk.P
func (pk *PrecompileKeepers) SlashingMS() putils.SlashingMsgServer { return pk.SlashingMsgServer }
func (pk *PrecompileKeepers) SlashingQ() putils.SlashingQuerier { return pk.SlashingQuerier }
func (pk *PrecompileKeepers) UpgradeQ() putils.UpgradeQuerier { return pk.UpgradeQuerier }
func (pk *PrecompileKeepers) TransferK() putils.TransferKeeper { return pk.TransferKeeper }
func (pk *PrecompileKeepers) ClientK() putils.ClientKeeper { return pk.ClientKeeper }
func (pk *PrecompileKeepers) ConnectionK() putils.ConnectionKeeper { return pk.ConnectionKeeper }
func (pk *PrecompileKeepers) ChannelK() putils.ChannelKeeper { return pk.ChannelKeeper }
func (pk *PrecompileKeepers) TxConfig() client.TxConfig { return pk.txConf }
func (pk *PrecompileKeepers) Codec() codec.Codec { return pk.cdc }
57 changes: 57 additions & 0 deletions evmrpc/historical_trace_error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package evmrpc

import (
"context"
"sync"

pcommon "github.com/sei-protocol/sei-chain/precompiles/common"
sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types"
)

type historicalTraceErrorCollector struct {
mu sync.Mutex
err error
}

func (c *historicalTraceErrorCollector) RecordHistoricalTraceError(err error) {
c.mu.Lock()
defer c.mu.Unlock()
if c.err == nil {
c.err = err
}
}

func (c *historicalTraceErrorCollector) Err() error {
c.mu.Lock()
defer c.mu.Unlock()
return c.err
}

type historicalTraceErrorCollectorKey struct{}

func withHistoricalTraceErrorCollector(ctx context.Context) (context.Context, *historicalTraceErrorCollector) {
collector := &historicalTraceErrorCollector{}
return context.WithValue(ctx, historicalTraceErrorCollectorKey{}, collector), collector
}

func historicalTraceErrorCollectorFromContext(ctx context.Context) *historicalTraceErrorCollector {
collector, _ := ctx.Value(historicalTraceErrorCollectorKey{}).(*historicalTraceErrorCollector)
return collector
}

// attachHistoricalTraceErrorCollector bridges the RPC request context into the
// SDK context used by precompiles during replay.
func attachHistoricalTraceErrorCollector(sdkCtx sdk.Context, requestCtx context.Context) sdk.Context {
collector := historicalTraceErrorCollectorFromContext(requestCtx)
if collector == nil {
return sdkCtx
}
return pcommon.WithHistoricalTraceErrorRecorder(sdkCtx, collector)
}

func rejectUnavailableHistoricalTrace(result interface{}, traceErr error, collector *historicalTraceErrorCollector) (interface{}, error) {
if err := collector.Err(); err != nil {
return nil, err
}
return result, traceErr
}
43 changes: 43 additions & 0 deletions evmrpc/historical_trace_error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package evmrpc

import (
"context"
"errors"
"testing"

"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require"
)

func TestRejectUnavailableHistoricalTrace(t *testing.T) {
ctx, collector := withHistoricalTraceErrorCollector(context.Background())
require.NotNil(t, historicalTraceErrorCollectorFromContext(ctx))

historicalErr := errors.New("historical execution unavailable")
collector.RecordHistoricalTraceError(historicalErr)

result, err := rejectUnavailableHistoricalTrace("plausible but wrong", nil, collector)
require.Nil(t, result)
require.ErrorIs(t, err, historicalErr)
}

type recordingHistoricalTraceBlockTracer struct {
err error
}

func (t recordingHistoricalTraceBlockTracer) TraceBlockByNumber(ctx context.Context, _ rpc.BlockNumber, _ *tracers.TraceConfig) ([]*tracers.TxTraceResult, error) {
historicalTraceErrorCollectorFromContext(ctx).RecordHistoricalTraceError(t.err)
return []*tracers.TxTraceResult{{}}, nil
}

func TestHistoricalTraceGuardedBlockTracer(t *testing.T) {
historicalErr := errors.New("historical execution unavailable")
tracer := historicalTraceGuardedBlockTracer{
delegate: recordingHistoricalTraceBlockTracer{err: historicalErr},
}

result, err := tracer.TraceBlockByNumber(context.Background(), 1, nil)
require.Nil(t, result)
require.ErrorIs(t, err, historicalErr)
}
6 changes: 5 additions & 1 deletion evmrpc/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ func (b *Backend) initializeBlock(ctx context.Context, block *ethtypes.Block, ct
reqBeginBlock := tmBlock.Block.ToReqBeginBlock(res.Validators)
reqBeginBlock.Simulate = true
baseCtx, baseRelease := ctxProvider(prevBlockHeight)
baseCtx = attachHistoricalTraceErrorCollector(baseCtx, ctx)
sdkCtx := baseCtx.WithBlockHeight(blockNumber).WithBlockTime(tmBlock.Block.Time)
legacyabci.BeginBlock(sdkCtx, blockNumber, reqBeginBlock.LastCommitInfo.Votes, tmBlock.Block.Evidence.ToABCI(), b.beginBlockKeepers)
nextCtx, nextRelease := ctxProvider(sdkCtx.BlockHeight())
Expand All @@ -714,7 +715,10 @@ func (b *Backend) initializeBlock(ctx context.Context, block *ethtypes.Block, ct
}, nil
}

func (b *Backend) GetEVM(_ context.Context, msg *core.Message, stateDB vm.StateDB, h *ethtypes.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM {
func (b *Backend) GetEVM(ctx context.Context, msg *core.Message, stateDB vm.StateDB, h *ethtypes.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM {
if db := state.GetDBImpl(stateDB); db != nil {
db.WithCtx(attachHistoricalTraceErrorCollector(db.Ctx(), ctx))
}
txContext := core.NewEVMTxContext(msg)
if blockCtx == nil {
blockCtx, _ = b.keeper.GetVMBlockContext(b.ctxProvider(LatestCtxHeight).WithIsEVM(true).WithEVMEntryViaWasmdPrecompile(wasmd.IsWasmdCall(msg.To)), b.keeper.GetGasPool())
Expand Down
17 changes: 15 additions & 2 deletions evmrpc/trace_baker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ type blockTracer interface {
TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, config *gethtracers.TraceConfig) ([]*gethtracers.TxTraceResult, error)
}

type historicalTraceGuardedBlockTracer struct {
delegate blockTracer
}

func (t historicalTraceGuardedBlockTracer) TraceBlockByNumber(ctx context.Context, number rpc.BlockNumber, config *gethtracers.TraceConfig) ([]*gethtracers.TxTraceResult, error) {
ctx, collector := withHistoricalTraceErrorCollector(ctx)
result, err := t.delegate.TraceBlockByNumber(ctx, number, config)
if historicalErr := collector.Err(); historicalErr != nil {
return nil, historicalErr
}
return result, err
}

// TraceBaker re-runs committed blocks through the tracer in background workers
// and writes the JSON to a TraceDB. Enqueue is non-blocking; misses fall
// through to live re-execution.
Expand Down Expand Up @@ -64,13 +77,13 @@ func StartTraceBakerForDebugAPI(api *DebugAPI, cfg TraceBakerConfig) *TraceBaker
if cache == nil {
return nil
}
b := NewTraceBaker(api.tracersAPI, cache, cfg)
b := NewTraceBaker(historicalTraceGuardedBlockTracer{delegate: api.tracersAPI}, cache, cfg)
cache.SetTraceEnqueuer(b)
b.Start()
return b
}

func NewTraceBaker(api *gethtracers.API, cache *keeper.TraceDB, cfg TraceBakerConfig) *TraceBaker {
func NewTraceBaker(api blockTracer, cache *keeper.TraceDB, cfg TraceBakerConfig) *TraceBaker {
if cfg.Workers <= 0 {
cfg.Workers = 1
}
Expand Down
7 changes: 7 additions & 0 deletions evmrpc/trace_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (api *DebugAPI) TraceTransactionProfile(ctx context.Context, hash common.Ha
return nil, returnErr
}

ctx, collector := withHistoricalTraceErrorCollector(ctx)
ctx, done, err := api.prepareTraceContext(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -94,6 +95,9 @@ func (api *DebugAPI) TraceTransactionProfile(ctx context.Context, hash common.Ha
if err != nil {
return nil, err
}
if err := collector.Err(); err != nil {
return nil, err
}

blockContextStart := time.Now()
blockCtx, err := tracingBackend.GetBlockContext(ctx, block, statedb, tracingBackend)
Expand All @@ -119,6 +123,9 @@ func (api *DebugAPI) TraceTransactionProfile(ctx context.Context, hash common.Ha
if err != nil {
return nil, err
}
if err := collector.Err(); err != nil {
return nil, err
}

storeDump := dumpStoreTrace(statedb)
historicalLookupNanos := historicalLookupNanos(storeDump)
Expand Down
17 changes: 13 additions & 4 deletions evmrpc/tracers.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func (api *DebugAPI) TraceTransaction(ctx context.Context, hash common.Hash, con
return cached, nil
}

ctx, collector := withHistoricalTraceErrorCollector(ctx)
ctx, done, err := api.prepareTraceContext(ctx)
if err != nil {
return nil, err
Expand All @@ -349,7 +350,8 @@ func (api *DebugAPI) TraceTransaction(ctx context.Context, hash common.Hash, con
config = &tracers.TraceConfig{}
}
api.clampDefaultStructLogLimit(config)
return api.tracersAPI.TraceTransaction(ctx, hash, config)
result, returnErr = api.tracersAPI.TraceTransaction(ctx, hash, config)
return rejectUnavailableHistoricalTrace(result, returnErr, collector)
}

func (api *DebugAPI) tryTraceCache(hash common.Hash, config *tracers.TraceConfig) (interface{}, bool) {
Expand Down Expand Up @@ -558,6 +560,7 @@ func (api *DebugAPI) TraceBlockByNumber(ctx context.Context, number rpc.BlockNum
return cached, nil
}

ctx, collector := withHistoricalTraceErrorCollector(ctx)
if config == nil {
config = &tracers.TraceConfig{}
}
Expand All @@ -567,7 +570,7 @@ func (api *DebugAPI) TraceBlockByNumber(ctx context.Context, number rpc.BlockNum
} else {
result, returnErr = api.tracersAPI.TraceBlockByNumber(ctx, number, config)
}
return
return rejectUnavailableHistoricalTrace(result, returnErr, collector)
}

func (api *DebugAPI) TraceBlockByHash(ctx context.Context, hash common.Hash, config *tracers.TraceConfig) (result interface{}, returnErr error) {
Expand All @@ -594,6 +597,7 @@ func (api *DebugAPI) TraceBlockByHash(ctx context.Context, hash common.Hash, con
return cached, nil
}

ctx, collector := withHistoricalTraceErrorCollector(ctx)
if config == nil {
config = &tracers.TraceConfig{}
}
Expand All @@ -603,7 +607,7 @@ func (api *DebugAPI) TraceBlockByHash(ctx context.Context, hash common.Hash, con
} else {
result, returnErr = api.tracersAPI.TraceBlockByHash(ctx, hash, config)
}
return
return rejectUnavailableHistoricalTrace(result, returnErr, collector)
}

func (api *DebugAPI) TraceCall(ctx context.Context, args export.TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, config *tracers.TraceCallConfig) (result interface{}, returnErr error) {
Expand Down Expand Up @@ -633,8 +637,9 @@ func (api *DebugAPI) TraceCall(ctx context.Context, args export.TransactionArgs,
return nil, returnErr
}
api.clampDefaultStructLogLimit(&config.TraceConfig)
ctx, collector := withHistoricalTraceErrorCollector(ctx)
result, returnErr = api.tracersAPI.TraceCall(ctx, args, blockNrOrHash, config)
return
return rejectUnavailableHistoricalTrace(result, returnErr, collector)
}

func (api *DebugAPI) GetRawHeader(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (_ hexutil.Bytes, returnErr error) {
Expand Down Expand Up @@ -687,6 +692,7 @@ func (api *DebugAPI) TraceStateAccess(ctx context.Context, hash common.Hash) (re
return nil, returnErr
}

ctx, collector := withHistoricalTraceErrorCollector(ctx)
ctx, done, err := api.prepareTraceContext(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -721,6 +727,9 @@ func (api *DebugAPI) TraceStateAccess(ctx context.Context, hash common.Hash) (re
if err != nil {
return nil, err
}
if err := collector.Err(); err != nil {
return nil, err
}
// Bail before the potentially expensive prestate/trace serialization if the
// trace deadline has already elapsed during replay.
if err := ctx.Err(); err != nil {
Expand Down
5 changes: 1 addition & 4 deletions giga/deps/xevm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
stakingkeeper "github.com/sei-protocol/sei-chain/sei-cosmos/x/staking/keeper"
upgradekeeper "github.com/sei-protocol/sei-chain/sei-cosmos/x/upgrade/keeper"
"github.com/sei-protocol/sei-chain/sei-db/ledger_db/receipt"
ibctransferkeeper "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/apps/transfer/keeper"
abci "github.com/sei-protocol/sei-chain/sei-tendermint/abci/types"
tmtypes "github.com/sei-protocol/sei-chain/sei-tendermint/types"
wasmkeeper "github.com/sei-protocol/sei-chain/sei-wasmd/x/wasm/keeper"
Expand All @@ -55,7 +54,6 @@ type Keeper struct {
bankKeeper bankkeeper.Keeper
accountKeeper *authkeeper.AccountKeeper
stakingKeeper *stakingkeeper.Keeper
transferKeeper ibctransferkeeper.Keeper
wasmKeeper *wasmkeeper.PermissionedKeeper
wasmViewKeeper *wasmkeeper.Keeper
upgradeKeeper *upgradekeeper.Keeper
Expand Down Expand Up @@ -128,7 +126,7 @@ func (ctx *ReplayChainContext) Config() *params.ChainConfig {
func NewKeeper(
storeKey sdk.StoreKey, transientStoreKey sdk.StoreKey, paramstore paramtypes.Subspace, receiptStateStore receipt.ReceiptStore,
bankKeeper bankkeeper.Keeper, accountKeeper *authkeeper.AccountKeeper, stakingKeeper *stakingkeeper.Keeper,
transferKeeper ibctransferkeeper.Keeper, wasmKeeper *wasmkeeper.PermissionedKeeper, wasmViewKeeper *wasmkeeper.Keeper, upgradeKeeper *upgradekeeper.Keeper) *Keeper {
wasmKeeper *wasmkeeper.PermissionedKeeper, wasmViewKeeper *wasmkeeper.Keeper, upgradeKeeper *upgradekeeper.Keeper) *Keeper {

if !paramstore.HasKeyTable() {
paramstore = paramstore.WithKeyTable(types.ParamKeyTable())
Expand All @@ -140,7 +138,6 @@ func NewKeeper(
bankKeeper: bankKeeper,
accountKeeper: accountKeeper,
stakingKeeper: stakingKeeper,
transferKeeper: transferKeeper,
wasmKeeper: wasmKeeper,
wasmViewKeeper: wasmViewKeeper,
upgradeKeeper: upgradeKeeper,
Expand Down
22 changes: 0 additions & 22 deletions precompiles/common/legacy/v605/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"context"
"math/big"

connectiontypes "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/03-connection/types"
"github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/04-channel/types"
"github.com/sei-protocol/sei-chain/sei-ibc-go/modules/core/exported"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
sdk "github.com/sei-protocol/sei-chain/sei-cosmos/types"
Expand All @@ -16,7 +12,6 @@ import (
distrtypes "github.com/sei-protocol/sei-chain/sei-cosmos/x/distribution/types"
govtypes "github.com/sei-protocol/sei-chain/sei-cosmos/x/gov/types"
stakingtypes "github.com/sei-protocol/sei-chain/sei-cosmos/x/staking/types"
ibctypes "github.com/sei-protocol/sei-chain/sei-ibc-go/modules/apps/transfer/types"
"github.com/sei-protocol/sei-chain/utils"
oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types"
)
Expand Down Expand Up @@ -117,20 +112,3 @@ type DistributionKeeper interface {
WithdrawDelegationRewards(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdk.Coins, error)
DelegationTotalRewards(c context.Context, req *distrtypes.QueryDelegationTotalRewardsRequest) (*distrtypes.QueryDelegationTotalRewardsResponse, error)
}

type TransferKeeper interface {
Transfer(goCtx context.Context, msg *ibctypes.MsgTransfer) (*ibctypes.MsgTransferResponse, error)
}

type ClientKeeper interface {
GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool)
GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool)
}

type ConnectionKeeper interface {
GetConnection(ctx sdk.Context, connectionID string) (connectiontypes.ConnectionEnd, bool)
}

type ChannelKeeper interface {
GetChannel(ctx sdk.Context, portID, channelID string) (types.Channel, bool)
}
Loading
Loading