b1cd16e5bf
* Problem: feemarket's query cli has redundant height parameter Soluton: - remove the positional height parameter, since there's a flag already. Update CHANGELOG.md * Apply feemarket to native cosmos tx - add tx extension option for user to input tip price - apply feemarket's base fee to native tx comments and cleanup fallback to default sdk logic when london hardfork not enabled integration test cleanup feemarket query cli commands Update CHANGELOG.md update unit tests disable feemarket in simulation tests for now fix lint Update app/simulation_test.go fix python lint fix lint Update x/evm/types/extension_option.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> address review suggestions * fix unit tests * fix integration test * improve unit test coverage * fix go lint * refactor * fix integration test * fix simulation tests * fix go linter Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
111 lines
3.3 KiB
Go
111 lines
3.3 KiB
Go
package ante
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime/debug"
|
|
|
|
tmlog "github.com/tendermint/tendermint/libs/log"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
|
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
|
|
"github.com/evmos/ethermint/crypto/ethsecp256k1"
|
|
)
|
|
|
|
const (
|
|
secp256k1VerifyCost uint64 = 21000
|
|
)
|
|
|
|
// NewAnteHandler returns an ante handler responsible for attempting to route an
|
|
// Ethereum or SDK transaction to an internal ante handler for performing
|
|
// transaction-level processing (e.g. fee payment, signature verification) before
|
|
// being passed onto it's respective handler.
|
|
func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
|
|
if err := options.validate(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return func(
|
|
ctx sdk.Context, tx sdk.Tx, sim bool,
|
|
) (newCtx sdk.Context, err error) {
|
|
var anteHandler sdk.AnteHandler
|
|
|
|
defer Recover(ctx.Logger(), &err)
|
|
|
|
txWithExtensions, ok := tx.(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 = newEthAnteHandler(options)
|
|
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
|
|
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
|
|
anteHandler = newCosmosAnteHandlerEip712(options)
|
|
case "/ethermint.types.v1.ExtensionOptionDynamicFeeTx":
|
|
// cosmos-sdk tx with dynamic fee extension
|
|
anteHandler = newCosmosAnteHandler(options)
|
|
default:
|
|
return ctx, sdkerrors.Wrapf(
|
|
sdkerrors.ErrUnknownExtensionOptions,
|
|
"rejecting tx with unsupported extension option: %s", typeURL,
|
|
)
|
|
}
|
|
|
|
return anteHandler(ctx, tx, sim)
|
|
}
|
|
}
|
|
|
|
// handle as totally normal Cosmos SDK tx
|
|
switch tx.(type) {
|
|
case sdk.Tx:
|
|
anteHandler = newCosmosAnteHandler(options)
|
|
default:
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type: %T", tx)
|
|
}
|
|
|
|
return anteHandler(ctx, tx, sim)
|
|
}, nil
|
|
}
|
|
|
|
func Recover(logger tmlog.Logger, err *error) {
|
|
if r := recover(); r != nil {
|
|
*err = sdkerrors.Wrapf(sdkerrors.ErrPanic, "%v", r)
|
|
|
|
if e, ok := r.(error); ok {
|
|
logger.Error(
|
|
"ante handler panicked",
|
|
"error", e,
|
|
"stack trace", string(debug.Stack()),
|
|
)
|
|
} else {
|
|
logger.Error(
|
|
"ante handler panicked",
|
|
"recover", fmt.Sprintf("%v", r),
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
var _ authante.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
|
|
// by the concrete type.
|
|
func DefaultSigVerificationGasConsumer(
|
|
meter sdk.GasMeter, sig signing.SignatureV2, params authtypes.Params,
|
|
) error {
|
|
// support for ethereum ECDSA secp256k1 keys
|
|
_, ok := sig.PubKey.(*ethsecp256k1.PubKey)
|
|
if ok {
|
|
meter.ConsumeGas(secp256k1VerifyCost, "ante verify: eth_secp256k1")
|
|
return nil
|
|
}
|
|
|
|
return authante.DefaultSigVerificationGasConsumer(meter, sig, params)
|
|
}
|