Merge pull request #39 from vulcanize/roy/upgrade-to-v0.46
Fix Tx extension options & middleware issues
This commit is contained in:
commit
d0fba5b727
21
Makefile
21
Makefile
@ -88,23 +88,22 @@ ifeq (boltdb,$(findstring boltdb,$(COSMOS_BUILD_OPTIONS)))
|
|||||||
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=boltdb
|
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=boltdb
|
||||||
endif
|
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)))
|
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
|
||||||
|
BUILD_FLAGS += -trimpath
|
||||||
ldflags += -w -s
|
ldflags += -w -s
|
||||||
endif
|
endif
|
||||||
ldflags += $(LDFLAGS)
|
ldflags += $(LDFLAGS)
|
||||||
ldflags := $(strip $(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
|
all: tools build lint test
|
||||||
# # The below include contains the tools and runsim targets.
|
# # The below include contains the tools and runsim targets.
|
||||||
# include contrib/devtools/Makefile
|
# include contrib/devtools/Makefile
|
||||||
|
10
app/app.go
10
app/app.go
@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
||||||
"github.com/cosmos/cosmos-sdk/store/streaming"
|
"github.com/cosmos/cosmos-sdk/store/streaming"
|
||||||
|
storetypes "github.com/cosmos/cosmos-sdk/store/v2alpha1"
|
||||||
"github.com/cosmos/cosmos-sdk/store/v2alpha1/multi"
|
"github.com/cosmos/cosmos-sdk/store/v2alpha1/multi"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
@ -88,6 +89,7 @@ import (
|
|||||||
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
|
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
|
||||||
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
|
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
|
||||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
tmos "github.com/tendermint/tendermint/libs/os"
|
tmos "github.com/tendermint/tendermint/libs/os"
|
||||||
@ -113,7 +115,6 @@ import (
|
|||||||
"github.com/tharsis/ethermint/x/evm"
|
"github.com/tharsis/ethermint/x/evm"
|
||||||
|
|
||||||
// evmrest "github.com/tharsis/ethermint/x/evm/client/rest"
|
// 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"
|
evmkeeper "github.com/tharsis/ethermint/x/evm/keeper"
|
||||||
"github.com/tharsis/ethermint/x/feemarket"
|
"github.com/tharsis/ethermint/x/feemarket"
|
||||||
feemarketkeeper "github.com/tharsis/ethermint/x/feemarket/keeper"
|
feemarketkeeper "github.com/tharsis/ethermint/x/feemarket/keeper"
|
||||||
@ -354,6 +355,8 @@ func NewEthermintApp(
|
|||||||
)
|
)
|
||||||
bApp.SetCommitMultiStoreTracer(traceStore)
|
bApp.SetCommitMultiStoreTracer(traceStore)
|
||||||
bApp.SetVersion(version.Version)
|
bApp.SetVersion(version.Version)
|
||||||
|
|
||||||
|
evmtypes.RegisterInterfaces(interfaceRegistry)
|
||||||
bApp.SetInterfaceRegistry(interfaceRegistry)
|
bApp.SetInterfaceRegistry(interfaceRegistry)
|
||||||
|
|
||||||
// configure state listening capabilities using AppOptions
|
// configure state listening capabilities using AppOptions
|
||||||
@ -712,10 +715,7 @@ func (app *EthermintApp) setTxHandler(options middleware.HandlerOptions, txConfi
|
|||||||
|
|
||||||
options.IndexEvents = indexEvents
|
options.IndexEvents = indexEvents
|
||||||
|
|
||||||
txHandler, err := middleware.NewMiddleware(options)
|
txHandler := middleware.NewTxHandler(options)
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
app.SetTxHandler(txHandler)
|
app.SetTxHandler(txHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,20 +17,11 @@ import (
|
|||||||
"github.com/tharsis/ethermint/ethereum/eip712"
|
"github.com/tharsis/ethermint/ethereum/eip712"
|
||||||
ethermint "github.com/tharsis/ethermint/types"
|
ethermint "github.com/tharsis/ethermint/types"
|
||||||
|
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
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,
|
// 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.
|
// the Eip712SigVerificationMiddleware middleware will not get executed on ReCheck.
|
||||||
//
|
//
|
||||||
|
@ -46,7 +46,7 @@ func setGasMeter(ctx sdk.Context, gasLimit uint64, simulate bool) sdk.Context {
|
|||||||
return ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
return ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit))
|
return ctx.WithGasMeter(ethermint.NewInfiniteGasMeterWithLimit(gasLimit))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckTx implements tx.Handler
|
// 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")
|
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
|
// since we will only verify the signature against the hash of the MsgEthereumTx.Data
|
||||||
if wrapperTx, ok := reqTx.(protoTxProvider); ok {
|
if wrapperTx, ok := reqTx.(protoTxProvider); ok {
|
||||||
protoTx := wrapperTx.GetProtoTx()
|
protoTx := wrapperTx.GetProtoTx()
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
"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"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
|
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
|
||||||
)
|
)
|
||||||
@ -16,128 +16,91 @@ const (
|
|||||||
secp256k1VerifyCost uint64 = 21000
|
secp256k1VerifyCost uint64 = 21000
|
||||||
)
|
)
|
||||||
|
|
||||||
type MD struct {
|
type txRouter struct {
|
||||||
ethMiddleware tx.Handler
|
eth, cosmos, eip712 tx.Handler
|
||||||
cosmosMiddleware tx.Handler
|
|
||||||
cosmoseip712 tx.Handler
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ tx.Handler = MD{}
|
var _ tx.Handler = txRouter{}
|
||||||
|
|
||||||
func NewMiddleware(options HandlerOptions) (tx.Handler, error) {
|
func NewTxHandler(options HandlerOptions) tx.Handler {
|
||||||
ethMiddleware, err := newEthAuthMiddleware(options)
|
return authmiddleware.ComposeMiddlewares(
|
||||||
if err != nil {
|
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
|
||||||
return nil, err
|
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
|
// CheckTx implements tx.Handler
|
||||||
func (md MD) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) {
|
func (txh txRouter) route(req tx.Request) (tx.Handler, error) {
|
||||||
var anteHandler tx.Handler
|
txWithExtensions, ok := req.Tx.(authmiddleware.HasExtensionOptionsTx)
|
||||||
reqTx := req.Tx
|
|
||||||
txWithExtensions, ok := reqTx.(authante.HasExtensionOptionsTx)
|
|
||||||
if ok {
|
if ok {
|
||||||
opts := txWithExtensions.GetExtensionOptions()
|
opts := txWithExtensions.GetExtensionOptions()
|
||||||
if len(opts) > 0 {
|
if len(opts) > 0 {
|
||||||
|
var next tx.Handler
|
||||||
switch typeURL := opts[0].GetTypeUrl(); typeURL {
|
switch typeURL := opts[0].GetTypeUrl(); typeURL {
|
||||||
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
|
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
|
||||||
// handle as *evmtypes.MsgEthereumTx
|
// handle as *evmtypes.MsgEthereumTx
|
||||||
anteHandler = md.ethMiddleware
|
next = txh.eth
|
||||||
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
|
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
|
||||||
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
|
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
|
||||||
anteHandler = md.cosmoseip712
|
next = txh.eip712
|
||||||
default:
|
default:
|
||||||
return tx.Response{}, tx.ResponseCheckTx{}, sdkerrors.Wrapf(
|
return nil, sdkerrors.Wrapf(
|
||||||
sdkerrors.ErrUnknownExtensionOptions,
|
sdkerrors.ErrUnknownExtensionOptions,
|
||||||
"rejecting tx with unsupported extension option: %s", typeURL,
|
"rejecting tx with unsupported extension option: %s", typeURL,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
return next, nil
|
||||||
return anteHandler.CheckTx(ctx, req, checkReq)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // handle as totally normal Cosmos SDK tx
|
// // handle as totally normal Cosmos SDK tx
|
||||||
// _, ok = reqTx.(sdk.Tx)
|
// if _, ok = reqTx.(sdk.Tx); !ok {
|
||||||
// if !ok {
|
// return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", reqTx)
|
||||||
// return tx.Response{}, tx.ResponseCheckTx{}, 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
|
// DeliverTx implements tx.Handler
|
||||||
func (md MD) DeliverTx(ctx context.Context, req tx.Request) (tx.Response, error) {
|
func (txh txRouter) DeliverTx(ctx context.Context, req tx.Request) (res tx.Response, err error) {
|
||||||
var anteHandler tx.Handler
|
next, err := txh.route(req)
|
||||||
reqTx := req.Tx
|
if err != nil {
|
||||||
txWithExtensions, ok := reqTx.(authante.HasExtensionOptionsTx)
|
return
|
||||||
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 next.DeliverTx(ctx, req)
|
||||||
return anteHandler.DeliverTx(ctx, req)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return md.cosmosMiddleware.DeliverTx(ctx, req)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SimulateTx implements tx.Handler
|
// SimulateTx implements tx.Handler
|
||||||
func (md MD) SimulateTx(ctx context.Context, req tx.Request) (tx.Response, error) {
|
func (txh txRouter) SimulateTx(ctx context.Context, req tx.Request) (res tx.Response, err error) {
|
||||||
var anteHandler tx.Handler
|
next, err := txh.route(req)
|
||||||
reqTx := req.Tx
|
if err != nil {
|
||||||
txWithExtensions, ok := reqTx.(authante.HasExtensionOptionsTx)
|
return
|
||||||
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 next.SimulateTx(ctx, req)
|
||||||
return anteHandler.SimulateTx(ctx, req)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return md.cosmosMiddleware.SimulateTx(ctx, req)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ authante.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsumer
|
var _ authmiddleware.SignatureVerificationGasConsumer = DefaultSigVerificationGasConsumer
|
||||||
|
|
||||||
// DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas
|
// 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
|
// 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 nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return authante.DefaultSigVerificationGasConsumer(meter, sig, params)
|
return authmiddleware.DefaultSigVerificationGasConsumer(meter, sig, params)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
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.
|
// channel keeper, EVM Keeper and Fee Market Keeper.
|
||||||
type HandlerOptions struct {
|
type HandlerOptions struct {
|
||||||
Debug bool
|
Debug bool
|
||||||
@ -50,41 +50,42 @@ func (options HandlerOptions) Validate() error {
|
|||||||
return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for middlewares")
|
return sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for middlewares")
|
||||||
}
|
}
|
||||||
if options.AccountKeeper == nil {
|
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 {
|
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 {
|
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 {
|
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 {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEthAuthMiddleware(options HandlerOptions) (tx.Handler, error) {
|
func newEthAuthMiddleware(options HandlerOptions) tx.Middleware {
|
||||||
return authmiddleware.ComposeMiddlewares(
|
stack := []tx.Middleware{
|
||||||
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
|
|
||||||
NewEthSetUpContextMiddleware(options.EvmKeeper),
|
NewEthSetUpContextMiddleware(options.EvmKeeper),
|
||||||
NewEthMempoolFeeMiddleware(options.EvmKeeper),
|
NewEthMempoolFeeMiddleware(options.EvmKeeper),
|
||||||
|
authmiddleware.NewIndexEventsTxMiddleware(options.IndexEvents),
|
||||||
NewEthValidateBasicMiddleware(options.EvmKeeper),
|
NewEthValidateBasicMiddleware(options.EvmKeeper),
|
||||||
NewEthSigVerificationMiddleware(options.EvmKeeper),
|
NewEthSigVerificationMiddleware(options.EvmKeeper),
|
||||||
NewEthAccountVerificationMiddleware(options.AccountKeeper, options.BankKeeper, options.EvmKeeper),
|
NewEthAccountVerificationMiddleware(options.AccountKeeper, options.BankKeeper, options.EvmKeeper),
|
||||||
NewEthGasConsumeMiddleware(options.EvmKeeper, options.MaxTxGasWanted),
|
NewEthGasConsumeMiddleware(options.EvmKeeper, options.MaxTxGasWanted),
|
||||||
NewCanTransferMiddleware(options.EvmKeeper),
|
NewCanTransferMiddleware(options.EvmKeeper),
|
||||||
NewEthIncrementSenderSequenceMiddleware(options.AccountKeeper),
|
NewEthIncrementSenderSequenceMiddleware(options.AccountKeeper),
|
||||||
), nil
|
}
|
||||||
|
return func(txh tx.Handler) tx.Handler {
|
||||||
|
return authmiddleware.ComposeMiddlewares(txh, stack...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCosmosAuthMiddleware(options HandlerOptions) (tx.Handler, error) {
|
func newCosmosAuthMiddleware(options HandlerOptions) tx.Middleware {
|
||||||
return authmiddleware.ComposeMiddlewares(
|
stack := []tx.Middleware{
|
||||||
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
|
|
||||||
authmiddleware.NewTxDecoderMiddleware(options.TxDecoder),
|
|
||||||
NewRejectMessagesMiddleware,
|
NewRejectMessagesMiddleware,
|
||||||
// Set a new GasMeter on sdk.Context.
|
// 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.
|
// should be accounted for, should go below this middleware.
|
||||||
authmiddleware.ConsumeBlockGasMiddleware,
|
authmiddleware.ConsumeBlockGasMiddleware,
|
||||||
authmiddleware.NewTipMiddleware(options.BankKeeper),
|
authmiddleware.NewTipMiddleware(options.BankKeeper),
|
||||||
), nil
|
}
|
||||||
|
return func(txh tx.Handler) tx.Handler {
|
||||||
|
return authmiddleware.ComposeMiddlewares(txh, stack...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCosmosAnteHandlerEip712(options HandlerOptions) (tx.Handler, error) {
|
func newCosmosMiddlewareEip712(options HandlerOptions) tx.Middleware {
|
||||||
|
stack := []tx.Middleware{
|
||||||
return authmiddleware.ComposeMiddlewares(
|
|
||||||
authmiddleware.NewRunMsgsTxHandler(options.MsgServiceRouter, options.LegacyRouter),
|
|
||||||
NewRejectMessagesMiddleware,
|
NewRejectMessagesMiddleware,
|
||||||
authmiddleware.NewTxDecoderMiddleware(options.TxDecoder),
|
|
||||||
// Set a new GasMeter on sdk.Context.
|
// Set a new GasMeter on sdk.Context.
|
||||||
//
|
//
|
||||||
// Make sure the Gas middleware is outside of all other middlewares
|
// 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.
|
// should be accounted for, should go below this middleware.
|
||||||
authmiddleware.ConsumeBlockGasMiddleware,
|
authmiddleware.ConsumeBlockGasMiddleware,
|
||||||
authmiddleware.NewTipMiddleware(options.BankKeeper),
|
authmiddleware.NewTipMiddleware(options.BankKeeper),
|
||||||
), nil
|
}
|
||||||
|
return func(txh tx.Handler) tx.Handler {
|
||||||
|
return authmiddleware.ComposeMiddlewares(txh, stack...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
types3 "github.com/cosmos/cosmos-sdk/x/staking/types"
|
types3 "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/spf13/cast"
|
"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/ethereum/eip712"
|
||||||
"github.com/tharsis/ethermint/server/config"
|
"github.com/tharsis/ethermint/server/config"
|
||||||
"github.com/tharsis/ethermint/types"
|
"github.com/tharsis/ethermint/types"
|
||||||
@ -123,7 +123,7 @@ func (suite *MiddlewareTestSuite) SetupTest() {
|
|||||||
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
|
||||||
maxGasWanted := cast.ToUint64(config.DefaultMaxTxGasWanted)
|
maxGasWanted := cast.ToUint64(config.DefaultMaxTxGasWanted)
|
||||||
|
|
||||||
options := ante.HandlerOptions{
|
options := middleware.HandlerOptions{
|
||||||
TxDecoder: suite.clientCtx.TxConfig.TxDecoder(),
|
TxDecoder: suite.clientCtx.TxConfig.TxDecoder(),
|
||||||
AccountKeeper: suite.app.AccountKeeper,
|
AccountKeeper: suite.app.AccountKeeper,
|
||||||
BankKeeper: suite.app.BankKeeper,
|
BankKeeper: suite.app.BankKeeper,
|
||||||
@ -135,14 +135,12 @@ func (suite *MiddlewareTestSuite) SetupTest() {
|
|||||||
MsgServiceRouter: suite.app.MsgSvcRouter,
|
MsgServiceRouter: suite.app.MsgSvcRouter,
|
||||||
FeeMarketKeeper: suite.app.FeeMarketKeeper,
|
FeeMarketKeeper: suite.app.FeeMarketKeeper,
|
||||||
SignModeHandler: suite.clientCtx.TxConfig.SignModeHandler(),
|
SignModeHandler: suite.clientCtx.TxConfig.SignModeHandler(),
|
||||||
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
|
SigGasConsumer: middleware.DefaultSigVerificationGasConsumer,
|
||||||
MaxTxGasWanted: maxGasWanted,
|
MaxTxGasWanted: maxGasWanted,
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.Require().NoError(options.Validate())
|
suite.Require().NoError(options.Validate())
|
||||||
middleware, err := ante.NewMiddleware(options)
|
suite.anteHandler = middleware.NewTxHandler(options)
|
||||||
suite.Require().NoError(err)
|
|
||||||
suite.anteHandler = middleware
|
|
||||||
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
|
suite.ethSigner = ethtypes.LatestSignerForChainID(suite.app.EvmKeeper.ChainID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,22 +5,17 @@ import (
|
|||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
"github.com/cosmos/cosmos-sdk/std"
|
"github.com/cosmos/cosmos-sdk/std"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
|
|
||||||
cryptocodec "github.com/tharsis/ethermint/crypto/codec"
|
cryptocodec "github.com/tharsis/ethermint/crypto/codec"
|
||||||
ethermint "github.com/tharsis/ethermint/types"
|
ethermint "github.com/tharsis/ethermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterLegacyAminoCodec registers Interfaces from types, crypto, and SDK std.
|
// RegisterLegacyAminoCodec registers Interfaces from types, crypto, and SDK std.
|
||||||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||||
sdk.RegisterLegacyAminoCodec(cdc)
|
std.RegisterLegacyAminoCodec(cdc)
|
||||||
cryptocodec.RegisterCrypto(cdc)
|
|
||||||
codec.RegisterEvidences(cdc)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInterfaces registers Interfaces from types, crypto, and SDK std.
|
// RegisterInterfaces registers Interfaces from types, crypto, and SDK std.
|
||||||
func RegisterInterfaces(interfaceRegistry codectypes.InterfaceRegistry) {
|
func RegisterInterfaces(interfaceRegistry codectypes.InterfaceRegistry) {
|
||||||
sdk.RegisterInterfaces(interfaceRegistry)
|
|
||||||
std.RegisterInterfaces(interfaceRegistry)
|
std.RegisterInterfaces(interfaceRegistry)
|
||||||
cryptocodec.RegisterInterfaces(interfaceRegistry)
|
cryptocodec.RegisterInterfaces(interfaceRegistry)
|
||||||
ethermint.RegisterInterfaces(interfaceRegistry)
|
ethermint.RegisterInterfaces(interfaceRegistry)
|
||||||
|
@ -391,7 +391,7 @@ func (api *PublicFilterAPI) Logs(ctx context.Context, crit filters.FilterCriteri
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
|
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -467,7 +467,7 @@ func (api *PublicFilterAPI) NewFilter(criteria filters.FilterCriteria) (rpc.ID,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
|
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
tmjson "github.com/tendermint/tendermint/libs/json"
|
tmjson "github.com/tendermint/tendermint/libs/json"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
"github.com/tendermint/tendermint/libs/log"
|
||||||
|
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
|
||||||
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
|
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
|
||||||
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
@ -27,7 +28,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
txEvents = tmtypes.QueryForEvent(tmtypes.EventTxValue).String()
|
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()
|
headerEvents = tmtypes.QueryForEvent(tmtypes.EventNewBlockHeaderValue).String()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ func (api *pubSubAPI) subscribeLogs(wsConn *wsConn, subID rpc.ID, extra interfac
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
|
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
api.logger.Error("failed to decode tx response", "error", err.Error())
|
api.logger.Error("failed to decode tx response", "error", err.Error())
|
||||||
return
|
return
|
||||||
|
@ -17,10 +17,10 @@ RPC_PORT="854"
|
|||||||
IP_ADDR="0.0.0.0"
|
IP_ADDR="0.0.0.0"
|
||||||
|
|
||||||
KEY="mykey"
|
KEY="mykey"
|
||||||
CHAINID="ethermint_9000-1"
|
CHAINID="chibaclonk_9000-1"
|
||||||
MONIKER="mymoniker"
|
MONIKER="mymoniker"
|
||||||
|
|
||||||
## default port prefixes for ethermintd
|
## default port prefixes for chibaclonkd
|
||||||
NODE_P2P_PORT="2660"
|
NODE_P2P_PORT="2660"
|
||||||
NODE_PORT="2663"
|
NODE_PORT="2663"
|
||||||
NODE_RPC_PORT="2666"
|
NODE_RPC_PORT="2666"
|
||||||
@ -32,6 +32,7 @@ usage() {
|
|||||||
echo "-q <number> -- Quantity of nodes to run. eg: 3"
|
echo "-q <number> -- Quantity of nodes to run. eg: 3"
|
||||||
echo "-z <number> -- Quantity of nodes to run tests against 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 "-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"
|
echo "-r <string> -- Remove test dir after, eg: true, default is false"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -54,6 +55,7 @@ set -euxo pipefail
|
|||||||
|
|
||||||
DATA_DIR=$(mktemp -d -t ethermint-datadir.XXXXX)
|
DATA_DIR=$(mktemp -d -t ethermint-datadir.XXXXX)
|
||||||
|
|
||||||
|
DATA_DIR=$(mktemp -d -t chibaclonk-datadir.XXXXX)
|
||||||
if [[ ! "$DATA_DIR" ]]; then
|
if [[ ! "$DATA_DIR" ]]; then
|
||||||
echo "Could not create $DATA_DIR"
|
echo "Could not create $DATA_DIR"
|
||||||
exit 1
|
exit 1
|
||||||
@ -104,17 +106,21 @@ init_func() {
|
|||||||
|
|
||||||
start_func() {
|
start_func() {
|
||||||
echo "starting chibaclonk node $i in background ..."
|
echo "starting chibaclonk node $i in background ..."
|
||||||
"$PWD"/build/chibaclonkd start --pruning=nothing --rpc.unsafe \
|
"$PWD"/build/chibaclonkd start \
|
||||||
--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" \
|
--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.address=$IP_ADDR:$RPC_PORT"$i" \
|
||||||
--json-rpc.api="eth,txpool,personal,net,debug,web3" \
|
--json-rpc.api="eth,txpool,personal,net,debug,web3" \
|
||||||
--keyring-backend test --mode validator --home "$DATA_DIR$i" \
|
--keyring-backend test --mode validator --home "$DATA_DIR$i" \
|
||||||
|
--log_level debug \
|
||||||
>"$DATA_DIR"/node"$i".log 2>&1 & disown
|
>"$DATA_DIR"/node"$i".log 2>&1 & disown
|
||||||
|
|
||||||
ETHERMINT_PID=$!
|
CHIBACLONK_PID=$!
|
||||||
echo "started chibaclonk node, pid=$ETHERMINT_PID"
|
echo "started chibaclonk node, pid=$CHIBACLONK_PID"
|
||||||
# add PID to array
|
# add PID to array
|
||||||
arr+=("$ETHERMINT_PID")
|
arr+=("$CHIBACLONK_PID")
|
||||||
|
|
||||||
if [[ $MODE == "pending" ]]; then
|
if [[ $MODE == "pending" ]]; then
|
||||||
echo "waiting for the first block..."
|
echo "waiting for the first block..."
|
||||||
@ -163,16 +169,15 @@ if [[ -z $TEST || $TEST == "rpc" || $TEST == "pending" ]]; then
|
|||||||
|
|
||||||
TEST_FAIL=$?
|
TEST_FAIL=$?
|
||||||
done
|
done
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
stop_func() {
|
stop_func() {
|
||||||
ETHERMINT_PID=$i
|
CHIBACLONK_PID=$i
|
||||||
echo "shutting down node, pid=$ETHERMINT_PID ..."
|
echo "shutting down node, pid=$CHIBACLONK_PID ..."
|
||||||
|
|
||||||
# Shutdown ethermint node
|
# Shutdown chibaclonk node
|
||||||
kill -9 "$ETHERMINT_PID"
|
kill -9 "$CHIBACLONK_PID"
|
||||||
wait "$ETHERMINT_PID"
|
wait "$CHIBACLONK_PID"
|
||||||
|
|
||||||
if [ $REMOVE_DATA_DIR == "true" ]
|
if [ $REMOVE_DATA_DIR == "true" ]
|
||||||
then
|
then
|
||||||
|
@ -301,17 +301,6 @@ func deployTestContract(t *testing.T) (hexutil.Bytes, map[string]interface{}) {
|
|||||||
return hash, receipt
|
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{} {
|
func waitForReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
|
||||||
timeout := time.After(12 * time.Second)
|
timeout := time.After(12 * time.Second)
|
||||||
ticker := time.Tick(500 * time.Millisecond)
|
ticker := time.Tick(500 * time.Millisecond)
|
||||||
@ -321,7 +310,7 @@ func waitForReceipt(t *testing.T, hash hexutil.Bytes) map[string]interface{} {
|
|||||||
case <-timeout:
|
case <-timeout:
|
||||||
return nil
|
return nil
|
||||||
case <-ticker:
|
case <-ticker:
|
||||||
receipt := getTransactionReceipt(t, hash)
|
receipt := GetTransactionReceipt(t, hash)
|
||||||
if receipt != nil {
|
if receipt != nil {
|
||||||
return receipt
|
return receipt
|
||||||
}
|
}
|
||||||
|
@ -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
|
// RefundGas will deduct the given amount from the gas consumed. If the amount is greater than the
|
||||||
// gas consumed, the function will panic.
|
// 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.
|
// EVM-compatible chains can fully support the go-ethereum StateDb interface.
|
||||||
// See https://github.com/cosmos/cosmos-sdk/pull/9403 for reference.
|
// See https://github.com/cosmos/cosmos-sdk/pull/9403 for reference.
|
||||||
func (g *infiniteGasMeterWithLimit) RefundGas(amount sdk.Gas, descriptor string) {
|
func (g *infiniteGasMeterWithLimit) RefundGas(amount sdk.Gas, descriptor string) {
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
func TestIntegrationTestSuite(t *testing.T) {
|
func TestIntegrationTestSuite(t *testing.T) {
|
||||||
cfg := network.DefaultConfig()
|
cfg := network.DefaultConfig()
|
||||||
cfg.NumValidators = 2
|
cfg.NumValidators = 1
|
||||||
|
|
||||||
suite.Run(t, NewIntegrationTestSuite(cfg))
|
suite.Run(t, NewIntegrationTestSuite(cfg))
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,6 @@ import (
|
|||||||
|
|
||||||
func TestIntegrationTestSuite(t *testing.T) {
|
func TestIntegrationTestSuite(t *testing.T) {
|
||||||
cfg := network.DefaultConfig()
|
cfg := network.DefaultConfig()
|
||||||
cfg.NumValidators = 2
|
cfg.NumValidators = 1
|
||||||
suite.Run(t, NewIntegrationTestSuite(cfg))
|
suite.Run(t, NewIntegrationTestSuite(cfg))
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ var _ types.MsgServer = &Keeper{}
|
|||||||
|
|
||||||
// EthereumTx implements the gRPC MsgServer interface. It receives a transaction which is then
|
// 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
|
// 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
|
// so that it can call the StateDB methods without receiving it as a function parameter.
|
||||||
// parameter.
|
|
||||||
func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
|
func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(goCtx)
|
ctx := sdk.UnwrapSDKContext(goCtx)
|
||||||
|
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
"github.com/cosmos/cosmos-sdk/types/msgservice"
|
||||||
|
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
proto "github.com/gogo/protobuf/proto"
|
proto "github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
TxResponse interface{}
|
||||||
ExtensionOptionsEthereumTxI interface{}
|
ExtensionOptionsEthereumTxI interface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,9 +20,8 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|||||||
(*sdk.Msg)(nil),
|
(*sdk.Msg)(nil),
|
||||||
&MsgEthereumTx{},
|
&MsgEthereumTx{},
|
||||||
)
|
)
|
||||||
registry.RegisterInterface(
|
registry.RegisterImplementations(
|
||||||
"ethermint.evm.v1.ExtensionOptionsEthereumTx",
|
(*tx.TxExtensionOptionI)(nil),
|
||||||
(*ExtensionOptionsEthereumTxI)(nil),
|
|
||||||
&ExtensionOptionsEthereumTx{},
|
&ExtensionOptionsEthereumTx{},
|
||||||
)
|
)
|
||||||
registry.RegisterInterface(
|
registry.RegisterInterface(
|
||||||
@ -33,6 +31,16 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
|
|||||||
&AccessListTx{},
|
&AccessListTx{},
|
||||||
&LegacyTx{},
|
&LegacyTx{},
|
||||||
)
|
)
|
||||||
|
registry.RegisterInterface(
|
||||||
|
"ethermint.evm.v1.MsgEthereumTxResponse",
|
||||||
|
(*TxResponse)(nil),
|
||||||
|
&MsgEthereumTxResponse{},
|
||||||
|
)
|
||||||
|
registry.RegisterInterface(
|
||||||
|
"ethermint.evm.v1.ExtensionOptionsEthereumTx",
|
||||||
|
(*ExtensionOptionsEthereumTxI)(nil),
|
||||||
|
&ExtensionOptionsEthereumTx{},
|
||||||
|
)
|
||||||
|
|
||||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
@ -18,25 +18,27 @@ const maxBitLen = 256
|
|||||||
var EmptyCodeHash = crypto.Keccak256(nil)
|
var EmptyCodeHash = crypto.Keccak256(nil)
|
||||||
|
|
||||||
// DecodeTxResponse decodes an protobuf-encoded byte slice into TxResponse
|
// 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
|
var txMsgData sdk.TxMsgData
|
||||||
if err := proto.Unmarshal(in, &txMsgData); err != nil {
|
if err := txMsgData.Unmarshal(in); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := txMsgData.GetData()
|
responses := txMsgData.GetMsgResponses()
|
||||||
if len(data) == 0 {
|
if len(responses) == 0 {
|
||||||
return &MsgEthereumTxResponse{}, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var res MsgEthereumTxResponse
|
if err := cdc.UnpackAny(responses[0], new(TxResponse)); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to unmarshal tx response message: %w", err)
|
||||||
err := proto.Unmarshal(data[0].GetData(), &res)
|
|
||||||
if err != nil {
|
|
||||||
return nil, sdkerrors.Wrap(err, "failed to unmarshal tx response message data")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
// EncodeTransactionLogs encodes TransactionLogs slice into a protobuf-encoded byte slice.
|
||||||
@ -44,16 +46,6 @@ func EncodeTransactionLogs(res *TransactionLogs) ([]byte, error) {
|
|||||||
return proto.Marshal(res)
|
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
|
// UnwrapEthereumMsg extract MsgEthereumTx from wrapping sdk.Tx
|
||||||
func UnwrapEthereumMsg(tx *sdk.Tx, ethHash common.Hash) (*MsgEthereumTx, error) {
|
func UnwrapEthereumMsg(tx *sdk.Tx, ethHash common.Hash) (*MsgEthereumTx, error) {
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
|
@ -5,23 +5,33 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"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"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||||
proto "github.com/gogo/protobuf/proto"
|
|
||||||
"github.com/tharsis/ethermint/app"
|
"github.com/tharsis/ethermint/app"
|
||||||
"github.com/tharsis/ethermint/encoding"
|
"github.com/tharsis/ethermint/encoding"
|
||||||
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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) {
|
func TestEvmDataEncoding(t *testing.T) {
|
||||||
ret := []byte{0x5, 0x8}
|
ret := []byte{0x5, 0x8}
|
||||||
|
|
||||||
data := &evmtypes.MsgEthereumTxResponse{
|
resp := &evmtypes.MsgEthereumTxResponse{
|
||||||
Hash: common.BytesToHash([]byte("hash")).String(),
|
Hash: common.BytesToHash([]byte("hash")).String(),
|
||||||
Logs: []*evmtypes.Log{{
|
Logs: []*evmtypes.Log{{
|
||||||
Data: []byte{1, 2, 3, 4},
|
Data: []byte{1, 2, 3, 4},
|
||||||
@ -30,21 +40,20 @@ func TestEvmDataEncoding(t *testing.T) {
|
|||||||
Ret: ret,
|
Ret: ret,
|
||||||
}
|
}
|
||||||
|
|
||||||
enc, err := proto.Marshal(data)
|
any, err := codectypes.NewAnyWithValue(resp)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
txData := &sdk.TxMsgData{
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
res, err := evmtypes.DecodeTxResponse(txDataBz)
|
decoded, err := evmtypes.DecodeTxResponse(txDataBz, testCodec)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, decoded)
|
||||||
require.Equal(t, data.Logs, res.Logs)
|
require.Equal(t, resp.Logs, decoded.Logs)
|
||||||
require.Equal(t, ret, res.Ret)
|
require.Equal(t, ret, decoded.Ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnwrapEthererumMsg(t *testing.T) {
|
func TestUnwrapEthererumMsg(t *testing.T) {
|
||||||
|
@ -9,6 +9,6 @@ import (
|
|||||||
|
|
||||||
func TestIntegrationTestSuite(t *testing.T) {
|
func TestIntegrationTestSuite(t *testing.T) {
|
||||||
cfg := network.DefaultConfig()
|
cfg := network.DefaultConfig()
|
||||||
cfg.NumValidators = 2
|
cfg.NumValidators = 1
|
||||||
suite.Run(t, NewIntegrationTestSuite(cfg))
|
suite.Run(t, NewIntegrationTestSuite(cfg))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user