Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve tracer/simulation RPC #2071

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@
optimisticProcessingInfo *OptimisticProcessingInfo

// batchVerifier *ante.SR25519BatchVerifier
txDecoder sdk.TxDecoder
txDecoder sdk.TxDecoder
AnteHandler sdk.AnteHandler

versionInfo version.Info

Expand Down Expand Up @@ -922,6 +923,7 @@
if err != nil {
panic(err)
}
app.AnteHandler = anteHandler

app.SetAnteHandler(anteHandler)
app.SetAnteDepGenerator(anteDepGenerator)
Expand Down Expand Up @@ -1842,7 +1844,7 @@
return ctx.WithIsEVM(true)
}
if app.evmRPCConfig.HTTPEnabled {
evmHTTPServer, err := evmrpc.NewEVMHTTPServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, ctxProvider, app.encodingConfig.TxConfig, DefaultNodeHome, nil)
evmHTTPServer, err := evmrpc.NewEVMHTTPServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, app.BaseApp, app.AnteHandler, ctxProvider, app.encodingConfig.TxConfig, DefaultNodeHome, nil)

Check warning on line 1847 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L1847

Added line #L1847 was not covered by tests
if err != nil {
panic(err)
}
Expand All @@ -1852,7 +1854,7 @@
}

if app.evmRPCConfig.WSEnabled {
evmWSServer, err := evmrpc.NewEVMWebSocketServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, ctxProvider, app.encodingConfig.TxConfig, DefaultNodeHome)
evmWSServer, err := evmrpc.NewEVMWebSocketServer(app.Logger(), app.evmRPCConfig, clientCtx.Client, &app.EvmKeeper, app.BaseApp, app.AnteHandler, ctxProvider, app.encodingConfig.TxConfig, DefaultNodeHome)

Check warning on line 1857 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L1857

Added line #L1857 was not covered by tests
if err != nil {
panic(err)
}
Expand Down
6 changes: 4 additions & 2 deletions evmrpc/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"time"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -34,15 +35,16 @@ type SendConfig struct {
slow bool
}

func NewSendAPI(tmClient rpcclient.Client, txConfig client.TxConfig, sendConfig *SendConfig, k *keeper.Keeper, ctxProvider func(int64) sdk.Context, homeDir string, simulateConfig *SimulateConfig, connectionType ConnectionType) *SendAPI {
func NewSendAPI(tmClient rpcclient.Client, txConfig client.TxConfig, sendConfig *SendConfig, k *keeper.Keeper, ctxProvider func(int64) sdk.Context, homeDir string, simulateConfig *SimulateConfig, app *baseapp.BaseApp,
antehandler sdk.AnteHandler, connectionType ConnectionType) *SendAPI {
return &SendAPI{
tmClient: tmClient,
txConfig: txConfig,
sendConfig: sendConfig,
keeper: k,
ctxProvider: ctxProvider,
homeDir: homeDir,
backend: NewBackend(ctxProvider, k, txConfig.TxDecoder(), tmClient, simulateConfig),
backend: NewBackend(ctxProvider, k, txConfig.TxDecoder(), tmClient, simulateConfig, app, antehandler),
connectionType: connectionType,
}
}
Expand Down
17 changes: 11 additions & 6 deletions evmrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"strings"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
Expand All @@ -30,6 +31,8 @@ func NewEVMHTTPServer(
config Config,
tmClient rpcclient.Client,
k *keeper.Keeper,
app *baseapp.BaseApp,
antehandler sdk.AnteHandler,
ctxProvider func(int64) sdk.Context,
txConfig client.TxConfig,
homeDir string,
Expand All @@ -45,18 +48,18 @@ func NewEVMHTTPServer(
return nil, err
}
simulateConfig := &SimulateConfig{GasCap: config.SimulationGasLimit, EVMTimeout: config.SimulationEVMTimeout}
sendAPI := NewSendAPI(tmClient, txConfig, &SendConfig{slow: config.Slow}, k, ctxProvider, homeDir, simulateConfig, ConnectionTypeHTTP)
sendAPI := NewSendAPI(tmClient, txConfig, &SendConfig{slow: config.Slow}, k, ctxProvider, homeDir, simulateConfig, app, antehandler, ConnectionTypeHTTP)
ctx := ctxProvider(LatestCtxHeight)

txAPI := NewTransactionAPI(tmClient, k, ctxProvider, txConfig, homeDir, ConnectionTypeHTTP)
debugAPI := NewDebugAPI(tmClient, k, ctxProvider, txConfig.TxDecoder(), simulateConfig, ConnectionTypeHTTP)
debugAPI := NewDebugAPI(tmClient, k, ctxProvider, txConfig.TxDecoder(), simulateConfig, app, antehandler, ConnectionTypeHTTP)
if isPanicOrSyntheticTxFunc == nil {
isPanicOrSyntheticTxFunc = func(ctx context.Context, hash common.Hash) (bool, error) {
return debugAPI.isPanicOrSyntheticTx(ctx, hash)
}
}
seiTxAPI := NewSeiTransactionAPI(tmClient, k, ctxProvider, txConfig, homeDir, ConnectionTypeHTTP, isPanicOrSyntheticTxFunc)
seiDebugAPI := NewSeiDebugAPI(tmClient, k, ctxProvider, txConfig.TxDecoder(), simulateConfig, ConnectionTypeHTTP)
seiDebugAPI := NewSeiDebugAPI(tmClient, k, ctxProvider, txConfig.TxDecoder(), simulateConfig, app, antehandler, ConnectionTypeHTTP)

apis := []rpc.API{
{
Expand Down Expand Up @@ -97,7 +100,7 @@ func NewEVMHTTPServer(
},
{
Namespace: "eth",
Service: NewSimulationAPI(ctxProvider, k, txConfig.TxDecoder(), tmClient, simulateConfig, ConnectionTypeHTTP),
Service: NewSimulationAPI(ctxProvider, k, txConfig.TxDecoder(), tmClient, simulateConfig, app, antehandler, ConnectionTypeHTTP),
},
{
Namespace: "net",
Expand Down Expand Up @@ -157,6 +160,8 @@ func NewEVMWebSocketServer(
config Config,
tmClient rpcclient.Client,
k *keeper.Keeper,
app *baseapp.BaseApp,
antehandler sdk.AnteHandler,
ctxProvider func(int64) sdk.Context,
txConfig client.TxConfig,
homeDir string,
Expand Down Expand Up @@ -194,11 +199,11 @@ func NewEVMWebSocketServer(
},
{
Namespace: "eth",
Service: NewSendAPI(tmClient, txConfig, &SendConfig{slow: config.Slow}, k, ctxProvider, homeDir, simulateConfig, ConnectionTypeWS),
Service: NewSendAPI(tmClient, txConfig, &SendConfig{slow: config.Slow}, k, ctxProvider, homeDir, simulateConfig, app, antehandler, ConnectionTypeWS),
},
{
Namespace: "eth",
Service: NewSimulationAPI(ctxProvider, k, txConfig.TxDecoder(), tmClient, simulateConfig, ConnectionTypeWS),
Service: NewSimulationAPI(ctxProvider, k, txConfig.TxDecoder(), tmClient, simulateConfig, app, antehandler, ConnectionTypeWS),
},
{
Namespace: "net",
Expand Down
17 changes: 12 additions & 5 deletions evmrpc/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/gorilla/websocket"
"github.com/sei-protocol/sei-chain/app"
"github.com/sei-protocol/sei-chain/evmrpc"
testkeeper "github.com/sei-protocol/sei-chain/testutil/keeper"
"github.com/sei-protocol/sei-chain/utils"
"github.com/sei-protocol/sei-chain/x/evm/config"
"github.com/sei-protocol/sei-chain/x/evm/keeper"
Expand Down Expand Up @@ -436,6 +437,10 @@ func (c *MockClient) Events(_ context.Context, req *coretypes.RequestEvents) (*c
}
}

func (c *MockClient) Validators(ctx context.Context, height *int64, page, perPage *int) (*coretypes.ResultValidators, error) {
return &coretypes.ResultValidators{}, nil
}

func buildSingleResultEvent(data interface{}, more bool, cursor string, event string) *coretypes.ResultEvents {
eventData, err := json.Marshal(data)
if err != nil {
Expand Down Expand Up @@ -545,7 +550,7 @@ func init() {
if err != nil {
panic(err)
}
HttpServer, err := evmrpc.NewEVMHTTPServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, ctxProvider, TxConfig, "", isPanicTxFunc)
HttpServer, err := evmrpc.NewEVMHTTPServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, testApp.BaseApp, testApp.AnteHandler, ctxProvider, TxConfig, "", isPanicTxFunc)
if err != nil {
panic(err)
}
Expand All @@ -557,7 +562,7 @@ func init() {
badConfig := evmrpc.DefaultConfig
badConfig.HTTPPort = TestBadPort
badConfig.FilterTimeout = 500 * time.Millisecond
badHTTPServer, err := evmrpc.NewEVMHTTPServer(infoLog, badConfig, &MockBadClient{}, EVMKeeper, ctxProvider, TxConfig, "", nil)
badHTTPServer, err := evmrpc.NewEVMHTTPServer(infoLog, badConfig, &MockBadClient{}, EVMKeeper, testApp.BaseApp, testApp.AnteHandler, ctxProvider, TxConfig, "", nil)
if err != nil {
panic(err)
}
Expand All @@ -566,7 +571,7 @@ func init() {
}

// Start ws server
wsServer, err := evmrpc.NewEVMWebSocketServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, ctxProvider, TxConfig, "")
wsServer, err := evmrpc.NewEVMWebSocketServer(infoLog, goodConfig, &MockClient{}, EVMKeeper, testApp.BaseApp, testApp.AnteHandler, ctxProvider, TxConfig, "")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -643,8 +648,8 @@ func generateTxData() {
})
debugTraceTxBuilder, _ := buildTx(ethtypes.DynamicFeeTx{
Nonce: 0,
GasFeeCap: big.NewInt(10),
Gas: 22000,
GasFeeCap: big.NewInt(1000000000),
Gas: 200000,
To: &to,
Value: big.NewInt(1000),
Data: []byte("abc"),
Expand Down Expand Up @@ -763,6 +768,8 @@ func buildTx(txData ethtypes.DynamicFeeTx) (client.TxBuilder, *ethtypes.Transact
derivedPriv, _ := hd.Secp256k1.Derive()(mnemonic, "", "")
privKey := hd.Secp256k1.Generate()(derivedPriv)
testPrivHex := hex.EncodeToString(privKey.Bytes())
_, evmAddr := testkeeper.PrivateKeyToAddresses(privKey)
EVMKeeper.BankKeeper().AddCoins(Ctx, sdk.AccAddress(evmAddr[:]), sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(10000000))), false)
key, _ := crypto.HexToECDSA(testPrivHex)
ethCfg := types.DefaultChainConfig().EthereumConfig(chainId)
signer := ethtypes.MakeSigner(ethCfg, big.NewInt(Ctx.BlockHeight()), uint64(Ctx.BlockTime().Unix()))
Expand Down
Loading
Loading