Merge pull request #39 from vulcanize/roy/upgrade-to-v0.46

Fix Tx extension options & middleware issues
This commit is contained in:
Sai Kumar 2022-05-17 08:20:21 +05:30 committed by GitHub
commit d0fba5b727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 180 additions and 227 deletions

View File

@ -88,23 +88,22 @@ ifeq (boltdb,$(findstring boltdb,$(COSMOS_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=boltdb
endif
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# Check for debug option
ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags 'all=-N -l'
COSMOS_BUILD_OPTIONS += nostrip
endif
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
# Check for debug option
ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif
all: tools build lint test
# # The below include contains the tools and runsim targets.
# include contrib/devtools/Makefile

View File

@ -29,6 +29,7 @@ import (
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/store/streaming"
storetypes "github.com/cosmos/cosmos-sdk/store/v2alpha1"
"github.com/cosmos/cosmos-sdk/store/v2alpha1/multi"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
@ -88,6 +89,7 @@ import (
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
@ -113,7 +115,6 @@ import (
"github.com/tharsis/ethermint/x/evm"
// evmrest "github.com/tharsis/ethermint/x/evm/client/rest"
storetypes "github.com/cosmos/cosmos-sdk/store/v2alpha1"
evmkeeper "github.com/tharsis/ethermint/x/evm/keeper"
"github.com/tharsis/ethermint/x/feemarket"
feemarketkeeper "github.com/tharsis/ethermint/x/feemarket/keeper"
@ -354,6 +355,8 @@ func NewEthermintApp(
)
bApp.SetCommitMultiStoreTracer(traceStore)
bApp.SetVersion(version.Version)
evmtypes.RegisterInterfaces(interfaceRegistry)
bApp.SetInterfaceRegistry(interfaceRegistry)
// configure state listening capabilities using AppOptions
@ -712,10 +715,7 @@ func (app *EthermintApp) setTxHandler(options middleware.HandlerOptions, txConfi
options.IndexEvents = indexEvents
txHandler, err := middleware.NewMiddleware(options)
if err != nil {
panic(err)
}
txHandler := middleware.NewTxHandler(options)
app.SetTxHandler(txHandler)
}

View File

@ -17,20 +17,11 @@ import (
"github.com/tharsis/ethermint/ethereum/eip712"
ethermint "github.com/tharsis/ethermint/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)
var ethermintCodec codec.ProtoCodecMarshaler
func init() {
registry := codectypes.NewInterfaceRegistry()
ethermint.RegisterInterfaces(registry)
ethermintCodec = codec.NewProtoCodec(registry)
}
// Eip712SigVerificationMiddleware Verify all signatures for a tx and return an error if any are invalid. Note,
// the Eip712SigVerificationMiddleware middleware will not get executed on ReCheck.
//

View File

@ -46,7 +46,7 @@ func setGasMeter(ctx sdk.Context, gasLimit uint64, simulate bool) sdk.Context {
return ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
}
return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit))
return ctx.WithGasMeter(ethermint.NewInfiniteGasMeterWithLimit(gasLimit))
}
// CheckTx implements tx.Handler
@ -180,7 +180,7 @@ func (vbd EthValidateBasicMiddleware) CheckTx(cx context.Context, req tx.Request
return tx.Response{}, tx.ResponseCheckTx{}, sdkerrors.Wrap(err, "tx basic validation failed")
}
// For eth type cosmos tx, some fields should be veified as zero values,
// For eth type cosmos tx, some fields should be verified as zero values,
// since we will only verify the signature against the hash of the MsgEthereumTx.Data
if wrapperTx, ok := reqTx.(protoTxProvider); ok {
protoTx := wrapperTx.GetProtoTx()

View File

@ -7,7 +7,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authante "github.com/cosmos/cosmos-sdk/x/auth/middleware"
authmiddleware "github.com/cosmos/cosmos-sdk/x/auth/middleware"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
)
@ -16,128 +16,91 @@ const (
secp256k1VerifyCost uint64 = 21000
)
type MD struct {
ethMiddleware tx.Handler
cosmosMiddleware tx.Handler
cosmoseip712 tx.Handler
type txRouter struct {
eth, cosmos, eip712 tx.Handler
}
var _ tx.Handler = MD{}
var _ tx.Handler = txRouter{}
func NewMiddleware(options HandlerOptions) (tx.Handler, error) {
ethMiddleware, err := newEthAuthMiddleware(options)
if err != nil {
return nil, err
func NewTxHandler(options HandlerOptions) tx.Handler {
return authmiddleware.ComposeMiddlewares(
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
authmiddleware.NewTxDecoderMiddleware(options.TxDecoder),
NewTxRouterMiddleware(options),
)
}
func NewTxRouterMiddleware(options HandlerOptions) tx.Middleware {
ethMiddleware := newEthAuthMiddleware(options)
cosmoseip712 := newCosmosMiddlewareEip712(options)
cosmosMiddleware := newCosmosAuthMiddleware(options)
return func(txh tx.Handler) tx.Handler {
return txRouter{
eth: ethMiddleware(txh),
cosmos: cosmosMiddleware(txh),
eip712: cosmoseip712(txh),
}
}
cosmoseip712, err := newCosmosAnteHandlerEip712(options)
if err != nil {
return nil, err
}
cosmosMiddleware, err := newCosmosAuthMiddleware(options)
if err != nil {
return nil, err
}
return MD{
ethMiddleware: ethMiddleware,
cosmosMiddleware: cosmosMiddleware,
cosmoseip712: cosmoseip712,
}, nil
}
// CheckTx implements tx.Handler
func (md MD) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) {
var anteHandler tx.Handler
reqTx := req.Tx
txWithExtensions, ok := reqTx.(authante.HasExtensionOptionsTx)
func (txh txRouter) route(req tx.Request) (tx.Handler, error) {
txWithExtensions, ok := req.Tx.(authmiddleware.HasExtensionOptionsTx)
if ok {
opts := txWithExtensions.GetExtensionOptions()
if len(opts) > 0 {
var next tx.Handler
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = md.ethMiddleware
next = txh.eth
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = md.cosmoseip712
next = txh.eip712
default:
return tx.Response{}, tx.ResponseCheckTx{}, sdkerrors.Wrapf(
return nil, sdkerrors.Wrapf(
sdkerrors.ErrUnknownExtensionOptions,
"rejecting tx with unsupported extension option: %s", typeURL,
)
}
return anteHandler.CheckTx(ctx, req, checkReq)
return next, nil
}
}
// // handle as totally normal Cosmos SDK tx
// _, ok = reqTx.(sdk.Tx)
// if !ok {
// return tx.Response{}, tx.ResponseCheckTx{}, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", reqTx)
// if _, ok = reqTx.(sdk.Tx); !ok {
// return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", reqTx)
// }
return txh.cosmos, nil
}
return md.cosmosMiddleware.CheckTx(ctx, req, checkReq)
// CheckTx implements tx.Handler
func (txh txRouter) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (res tx.Response, rct tx.ResponseCheckTx, err error) {
next, err := txh.route(req)
if err != nil {
return
}
return next.CheckTx(ctx, req, checkReq)
}
// DeliverTx implements tx.Handler
func (md MD) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) {
var anteHandler tx.Handler
reqTx := req.Tx
txWithExtensions, ok := reqTx.(authante.HasExtensionOptionsTx)
if ok {
opts := txWithExtensions.GetExtensionOptions()
if len(opts) > 0 {
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = md.ethMiddleware
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = md.cosmoseip712
default:
return tx.Response{}, sdkerrors.Wrapf(
sdkerrors.ErrUnknownExtensionOptions,
"rejecting tx with unsupported extension option: %s", typeURL,
)
}
return anteHandler.DeliverTx(ctx, req)
}
func (txh txRouter) DeliverTx(ctx context.Context, req tx.Request) (res tx.Response, err error) {
next, err := txh.route(req)
if err != nil {
return
}
return md.cosmosMiddleware.DeliverTx(ctx, req)
return next.DeliverTx(ctx, req)
}
// SimulateTx implements tx.Handler
func (md MD) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) {
var anteHandler tx.Handler
reqTx := req.Tx
txWithExtensions, ok := reqTx.(authante.HasExtensionOptionsTx)
if ok {
opts := txWithExtensions.GetExtensionOptions()
if len(opts) > 0 {
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = md.ethMiddleware
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = md.cosmoseip712
default:
return tx.Response{}, sdkerrors.Wrapf(
sdkerrors.ErrUnknownExtensionOptions,
"rejecting tx with unsupported extension option: %s", typeURL,
)
}
return anteHandler.SimulateTx(ctx, req)
}
func (txh txRouter) SimulateTx(ctx context.Context, req tx.Request) (res tx.Response, err error) {
next, err := txh.route(req)
if err != nil {
return
}
return md.cosmosMiddleware.SimulateTx(ctx, req)
return next.SimulateTx(ctx, req)
}
var _ authante.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsumer
var _ authmiddleware.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsumer
// DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched
@ -152,5 +115,5 @@ func DefaultSigVerificationGasConsumer(
return nil
}
return authante.DefaultSigVerificationGasConsumer(meter, sig, params)
return authmiddleware.DefaultSigVerificationGasConsumer(meter, sig, params)
}

View File

@ -13,7 +13,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// HandlerOptions extend the SDK's TxHandler options by requiring the IBC
// channel keeper, EVM Keeper and Fee Market Keeper.
type HandlerOptions struct {
Debug bool
@ -50,41 +50,42 @@ func (options HandlerOptions) Validate() error {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for middlewares")
}
if options.AccountKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler")
return sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for middlewares")
}
if options.BankKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler")
return sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for middlewares")
}
if options.SignModeHandler == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for middlewares")
}
if options.FeeMarketKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "fee market keeper is required for AnteHandler")
return sdkerrors.Wrap(sdkerrors.ErrLogic, "fee market keeper is required for middlewares")
}
if options.EvmKeeper == nil {
return sdkerrors.Wrap(sdkerrors.ErrLogic, "evm keeper is required for AnteHandler")
return sdkerrors.Wrap(sdkerrors.ErrLogic, "evm keeper is required for middlewares")
}
return nil
}
func newEthAuthMiddleware(options HandlerOptions) (tx.Handler, error) {
return authmiddleware.ComposeMiddlewares(
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
func newEthAuthMiddleware(options HandlerOptions) tx.Middleware {
stack := []tx.Middleware{
NewEthSetUpContextMiddleware(options.EvmKeeper),
NewEthMempoolFeeMiddleware(options.EvmKeeper),
authmiddleware.NewIndexEventsTxMiddleware(options.IndexEvents),
NewEthValidateBasicMiddleware(options.EvmKeeper),
NewEthSigVerificationMiddleware(options.EvmKeeper),
NewEthAccountVerificationMiddleware(options.AccountKeeper, options.BankKeeper, options.EvmKeeper),
NewEthGasConsumeMiddleware(options.EvmKeeper, options.MaxTxGasWanted),
NewCanTransferMiddleware(options.EvmKeeper),
NewEthIncrementSenderSequenceMiddleware(options.AccountKeeper),
), nil
}
return func(txh tx.Handler) tx.Handler {
return authmiddleware.ComposeMiddlewares(txh, stack...)
}
}
func newCosmosAuthMiddleware(options HandlerOptions) (tx.Handler, error) {
return authmiddleware.ComposeMiddlewares(
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
authmiddleware.NewTxDecoderMiddleware(options.TxDecoder),
func newCosmosAuthMiddleware(options HandlerOptions) tx.Middleware {
stack := []tx.Middleware{
NewRejectMessagesMiddleware,
// Set a new GasMeter on sdk.Context.
//
@ -123,15 +124,15 @@ func newCosmosAuthMiddleware(options HandlerOptions) (tx.Handler, error) {
// should be accounted for, should go below this middleware.
authmiddleware.ConsumeBlockGasMiddleware,
authmiddleware.NewTipMiddleware(options.BankKeeper),
), nil
}
return func(txh tx.Handler) tx.Handler {
return authmiddleware.ComposeMiddlewares(txh, stack...)
}
}
func newCosmosAnteHandlerEip712(options HandlerOptions) (tx.Handler, error) {
return authmiddleware.ComposeMiddlewares(
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
func newCosmosMiddlewareEip712(options HandlerOptions) tx.Middleware {
stack := []tx.Middleware{
NewRejectMessagesMiddleware,
authmiddleware.NewTxDecoderMiddleware(options.TxDecoder),
// Set a new GasMeter on sdk.Context.
//
// Make sure the Gas middleware is outside of all other middlewares
@ -170,5 +171,8 @@ func newCosmosAnteHandlerEip712(options HandlerOptions) (tx.Handler, error) {
// should be accounted for, should go below this middleware.
authmiddleware.ConsumeBlockGasMiddleware,
authmiddleware.NewTipMiddleware(options.BankKeeper),
), nil
}
return func(txh tx.Handler) tx.Handler {
return authmiddleware.ComposeMiddlewares(txh, stack...)
}
}

View File

@ -13,7 +13,7 @@ import (
types3 "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/spf13/cast"
ante "github.com/tharsis/ethermint/app/middleware"
"github.com/tharsis/ethermint/app/middleware"
"github.com/tharsis/ethermint/ethereum/eip712"
"github.com/tharsis/ethermint/server/config"
"github.com/tharsis/ethermint/types"
@ -123,7 +123,7 @@ func (suite *MiddlewareTestSuite) SetupTest() {
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
maxGasWanted := cast.ToUint64(config.DefaultMaxTxGasWanted)
options := ante.HandlerOptions{
options := middleware.HandlerOptions{
TxDecoder: suite.clientCtx.TxConfig.TxDecoder(),
AccountKeeper: suite.app.AccountKeeper,
BankKeeper: suite.app.BankKeeper,
@ -135,14 +135,12 @@ func (suite *MiddlewareTestSuite) SetupTest() {
MsgServiceRouter: suite.app.MsgSvcRouter,
FeeMarketKeeper: suite.app.FeeMarketKeeper,
SignModeHandler: suite.clientCtx.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
SigGasConsumer: middleware.DefaultSigVerificationGasConsumer,
MaxTxGasWanted: maxGasWanted,
}
suite.Require().NoError(options.Validate())
middleware, err := ante.NewMiddleware(options)
suite.Require().NoError(err)
suite.anteHandler = middleware
suite.anteHandler = middleware.NewTxHandler(options)
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
}

View File

@ -5,22 +5,17 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
cryptocodec "github.com/tharsis/ethermint/crypto/codec"
ethermint "github.com/tharsis/ethermint/types"
)
// RegisterLegacyAminoCodec registers Interfaces from types, crypto, and SDK std.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
sdk.RegisterLegacyAminoCodec(cdc)
cryptocodec.RegisterCrypto(cdc)
codec.RegisterEvidences(cdc)
std.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers Interfaces from types, crypto, and SDK std.
func RegisterInterfaces(interfaceRegistry codectypes.InterfaceRegistry) {
sdk.RegisterInterfaces(interfaceRegistry)
std.RegisterInterfaces(interfaceRegistry)
cryptocodec.RegisterInterfaces(interfaceRegistry)
ethermint.RegisterInterfaces(interfaceRegistry)

View File

@ -391,7 +391,7 @@ func (api *PublicFilterAPI) Logs(ctx context.Context, crit filters.FilterCriteri
continue
}
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
if err != nil {
return
}
@ -467,7 +467,7 @@ func (api *PublicFilterAPI) NewFilter(criteria filters.FilterCriteria) (rpc.ID,
continue
}
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
if err != nil {
return
}

View File

@ -10,6 +10,7 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
tmtypes "github.com/tendermint/tendermint/types"
@ -27,7 +28,7 @@ import (
var (
txEvents = tmtypes.QueryForEvent(tmtypes.EventTxValue).String()
evmEvents = fmt.Sprintf("%s='%s' AND %s.%s='%s'", tmtypes.EventTypeKey, tmtypes.EventTx, sdk.EventTypeMessage, sdk.AttributeKeyModule, evmtypes.ModuleName)
evmEvents = tmquery.MustCompile(fmt.Sprintf("%s='%s' AND %s.%s='%s'", tmtypes.EventTypeKey, tmtypes.EventTxValue, sdk.EventTypeMessage, sdk.AttributeKeyModule, evmtypes.ModuleName)).String()
headerEvents = tmtypes.QueryForEvent(tmtypes.EventNewBlockHeaderValue).String()
)

View File

@ -536,7 +536,7 @@ func (api *pubSubAPI) subscribeLogs(wsConn *wsConn, subID rpc.ID, extra interfac
continue
}
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
if err != nil {
api.logger.Error("failed to decode tx response", "error", err.Error())
return

View File

@ -17,10 +17,10 @@ RPC_PORT="854"
IP_ADDR="0.0.0.0"
KEY="mykey"
CHAINID="ethermint_9000-1"
CHAINID="chibaclonk_9000-1"
MONIKER="mymoniker"
## default port prefixes for ethermintd
## default port prefixes for chibaclonkd
NODE_P2P_PORT="2660"
NODE_PORT="2663"
NODE_RPC_PORT="2666"
@ -32,6 +32,7 @@ usage() {
echo "-q <number> -- Quantity of nodes to run. eg: 3"
echo "-z <number> -- Quantity of nodes to run tests against eg: 3"
echo "-s <number> -- Sleep between operations in secs. eg: 5"
echo "-m <string> -- Mode for testing. eg: rpc"
echo "-r <string> -- Remove test dir after, eg: true, default is false"
exit 1
}
@ -54,6 +55,7 @@ set -euxo pipefail
DATA_DIR=$(mktemp -d -t ethermint-datadir.XXXXX)
DATA_DIR=$(mktemp -d -t chibaclonk-datadir.XXXXX)
if [[ ! "$DATA_DIR" ]]; then
echo "Could not create $DATA_DIR"
exit 1
@ -104,17 +106,21 @@ init_func() {
start_func() {
echo "starting chibaclonk node $i in background ..."
"$PWD"/build/chibaclonkd start --pruning=nothing --rpc.unsafe \
--p2p.laddr tcp://$IP_ADDR:$NODE_P2P_PORT"$i" --address tcp://$IP_ADDR:$NODE_PORT"$i" --rpc.laddr tcp://$IP_ADDR:$NODE_RPC_PORT"$i" \
--json-rpc.address=$IP_ADDR:$RPC_PORT"$i" \
--json-rpc.api="eth,txpool,personal,net,debug,web3" \
--keyring-backend test --mode validator --home "$DATA_DIR$i" \
"$PWD"/build/chibaclonkd start \
--pruning=nothing --rpc.unsafe \
--p2p.laddr tcp://$IP_ADDR:$NODE_P2P_PORT"$i" \
--address tcp://$IP_ADDR:$NODE_PORT"$i" \
--rpc.laddr tcp://$IP_ADDR:$NODE_RPC_PORT"$i" \
--json-rpc.address=$IP_ADDR:$RPC_PORT"$i" \
--json-rpc.api="eth,txpool,personal,net,debug,web3" \
--keyring-backend test --mode validator --home "$DATA_DIR$i" \
--log_level debug \
>"$DATA_DIR"/node"$i".log 2>&1 & disown
ETHERMINT_PID=$!
echo "started chibaclonk node, pid=$ETHERMINT_PID"
CHIBACLONK_PID=$!
echo "started chibaclonk node, pid=$CHIBACLONK_PID"
# add PID to array
arr+=("$ETHERMINT_PID")
arr+=("$CHIBACLONK_PID")
if [[ $MODE == "pending" ]]; then
echo "waiting for the first block..."
@ -163,16 +169,15 @@ if [[ -z $TEST || $TEST == "rpc" || $TEST == "pending" ]]; then
TEST_FAIL=$?
done
fi
stop_func() {
ETHERMINT_PID=$i
echo "shutting down node, pid=$ETHERMINT_PID ..."
CHIBACLONK_PID=$i
echo "shutting down node, pid=$CHIBACLONK_PID ..."
# Shutdown ethermint node
kill -9 "$ETHERMINT_PID"
wait "$ETHERMINT_PID"
# Shutdown chibaclonk node
kill -9 "$CHIBACLONK_PID"
wait "$CHIBACLONK_PID"
if [ $REMOVE_DATA_DIR == "true" ]
then

View File

@ -301,17 +301,6 @@ func deployTestContract(t *testing.T) (hexutil.Bytes, map[string]interface{}) {
return hash, receipt
}
func getTransactionReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
param := []string{hash.String()}
rpcRes := call(t, "eth_getTransactionReceipt", param)
receipt := make(map[string]interface{})
err := json.Unmarshal(rpcRes.Result, &receipt)
require.NoError(t, err)
return receipt
}
func waitForReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
timeout := time.After(12 * time.Second)
ticker := time.Tick(500 * time.Millisecond)
@ -321,7 +310,7 @@ func waitForReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
case <-timeout:
return nil
case <-ticker:
receipt := getTransactionReceipt(t, hash)
receipt := GetTransactionReceipt(t, hash)
if receipt != nil {
return receipt
}

View File

@ -75,7 +75,7 @@ func (g *infiniteGasMeterWithLimit) ConsumeGas(amount sdk.Gas, descriptor string
// RefundGas will deduct the given amount from the gas consumed. If the amount is greater than the
// gas consumed, the function will panic.
//
// Use case: This functionality enables refunding gas to the trasaction or block gas pools so that
// Use case: This functionality enables refunding gas to the transaction or block gas pools so that
// EVM-compatible chains can fully support the go-ethereum StateDb interface.
// See https://github.com/cosmos/cosmos-sdk/pull/9403 for reference.
func (g *infiniteGasMeterWithLimit) RefundGas(amount sdk.Gas, descriptor string) {

View File

@ -10,7 +10,7 @@ import (
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 2
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}

View File

@ -9,6 +9,6 @@ import (
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 2
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}

View File

@ -19,8 +19,7 @@ var _ types.MsgServer = &Keeper{}
// EthereumTx implements the gRPC MsgServer interface. It receives a transaction which is then
// executed (i.e applied) against the go-ethereum EVM. The provided SDK Context is set to the Keeper
// so that it can implements and call the StateDB methods without receiving it as a function
// parameter.
// so that it can call the StateDB methods without receiving it as a function parameter.
func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

View File

@ -1,17 +1,16 @@
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/msgservice"
"github.com/cosmos/cosmos-sdk/types/tx"
proto "github.com/gogo/protobuf/proto"
)
var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
type (
TxResponse interface{}
ExtensionOptionsEthereumTxI interface{}
)
@ -21,9 +20,8 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*sdk.Msg)(nil),
&MsgEthereumTx{},
)
registry.RegisterInterface(
"ethermint.evm.v1.ExtensionOptionsEthereumTx",
(*ExtensionOptionsEthereumTxI)(nil),
registry.RegisterImplementations(
(*tx.TxExtensionOptionI)(nil),
&ExtensionOptionsEthereumTx{},
)
registry.RegisterInterface(
@ -33,6 +31,16 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&AccessListTx{},
&LegacyTx{},
)
registry.RegisterInterface(
"ethermint.evm.v1.MsgEthereumTxResponse",
(*TxResponse)(nil),
&MsgEthereumTxResponse{},
)
registry.RegisterInterface(
"ethermint.evm.v1.ExtensionOptionsEthereumTx",
(*ExtensionOptionsEthereumTxI)(nil),
&ExtensionOptionsEthereumTx{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

View File

@ -6,8 +6,8 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
@ -18,25 +18,27 @@ const maxBitLen = 256
var EmptyCodeHash = crypto.Keccak256(nil)
// DecodeTxResponse decodes an protobuf-encoded byte slice into TxResponse
func DecodeTxResponse(in []byte) (*MsgEthereumTxResponse, error) {
func DecodeTxResponse(in []byte, cdc codec.Codec) (*MsgEthereumTxResponse, error) {
var txMsgData sdk.TxMsgData
if err := proto.Unmarshal(in, &txMsgData); err != nil {
if err := txMsgData.Unmarshal(in); err != nil {
return nil, err
}
data := txMsgData.GetData()
if len(data) == 0 {
return &MsgEthereumTxResponse{}, nil
responses := txMsgData.GetMsgResponses()
if len(responses) == 0 {
return nil, nil
}
var res MsgEthereumTxResponse
err := proto.Unmarshal(data[0].GetData(), &res)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to unmarshal tx response message data")
if err := cdc.UnpackAny(responses[0], new(TxResponse)); err != nil {
return nil, fmt.Errorf("failed to unmarshal tx response message: %w", err)
}
return &res, nil
msgval := responses[0].GetCachedValue()
res, ok := msgval.(*MsgEthereumTxResponse)
if !ok {
return nil, fmt.Errorf("tx response message has invalid type: %T", msgval)
}
return res, nil
}
// EncodeTransactionLogs encodes TransactionLogs slice into a protobuf-encoded byte slice.
@ -44,16 +46,6 @@ func EncodeTransactionLogs(res *TransactionLogs) ([]byte, error) {
return proto.Marshal(res)
}
// DecodeTxResponse decodes an protobuf-encoded byte slice into TransactionLogs
func DecodeTransactionLogs(data []byte) (TransactionLogs, error) {
var logs TransactionLogs
err := proto.Unmarshal(data, &logs)
if err != nil {
return TransactionLogs{}, err
}
return logs, nil
}
// UnwrapEthereumMsg extract MsgEthereumTx from wrapping sdk.Tx
func UnwrapEthereumMsg(tx *sdk.Tx, ethHash common.Hash) (*MsgEthereumTx, error) {
if tx == nil {

View File

@ -5,23 +5,33 @@ import (
"math/big"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
proto "github.com/gogo/protobuf/proto"
"github.com/tharsis/ethermint/app"
"github.com/tharsis/ethermint/encoding"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
)
var testCodec codec.Codec
func init() {
registry := codectypes.NewInterfaceRegistry()
evmtypes.RegisterInterfaces(registry)
testCodec = codec.NewProtoCodec(registry)
}
func TestEvmDataEncoding(t *testing.T) {
ret := []byte{0x5, 0x8}
data := &evmtypes.MsgEthereumTxResponse{
resp := &evmtypes.MsgEthereumTxResponse{
Hash: common.BytesToHash([]byte("hash")).String(),
Logs: []*evmtypes.Log{{
Data: []byte{1, 2, 3, 4},
@ -30,21 +40,20 @@ func TestEvmDataEncoding(t *testing.T) {
Ret: ret,
}
enc, err := proto.Marshal(data)
any, err := codectypes.NewAnyWithValue(resp)
require.NoError(t, err)
txData := &sdk.TxMsgData{
Data: []*sdk.MsgData{{MsgType: evmtypes.TypeMsgEthereumTx, Data: enc}},
MsgResponses: []*codectypes.Any{any},
}
txDataBz, err := proto.Marshal(txData)
txDataBz, err := txData.Marshal()
require.NoError(t, err)
res, err := evmtypes.DecodeTxResponse(txDataBz)
decoded, err := evmtypes.DecodeTxResponse(txDataBz, testCodec)
require.NoError(t, err)
require.NotNil(t, res)
require.Equal(t, data.Logs, res.Logs)
require.Equal(t, ret, res.Ret)
require.NotNil(t, decoded)
require.Equal(t, resp.Logs, decoded.Logs)
require.Equal(t, ret, decoded.Ret)
}
func TestUnwrapEthererumMsg(t *testing.T) {

View File

@ -9,6 +9,6 @@ import (
func TestIntegrationTestSuite(t *testing.T) {
cfg := network.DefaultConfig()
cfg.NumValidators = 2
cfg.NumValidators = 1
suite.Run(t, NewIntegrationTestSuite(cfg))
}