2020-04-17 22:32:01 +00:00
|
|
|
|
package ante
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
|
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
|
|
|
|
|
|
|
|
|
|
evmtypes "github.com/cosmos/ethermint/x/evm/types"
|
|
|
|
|
|
2020-06-22 16:07:35 +00:00
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2021-05-10 16:34:00 +00:00
|
|
|
|
"github.com/ethereum/go-ethereum/core"
|
|
|
|
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
2020-04-17 22:32:01 +00:00
|
|
|
|
)
|
|
|
|
|
|
2020-09-02 19:41:05 +00:00
|
|
|
|
// EVMKeeper defines the expected keeper interface used on the Eth AnteHandler
|
|
|
|
|
type EVMKeeper interface {
|
2021-05-31 09:05:32 +00:00
|
|
|
|
ChainID() *big.Int
|
2020-09-02 19:41:05 +00:00
|
|
|
|
GetParams(ctx sdk.Context) evmtypes.Params
|
2021-05-10 16:34:00 +00:00
|
|
|
|
GetChainConfig(ctx sdk.Context) (evmtypes.ChainConfig, bool)
|
2021-05-25 12:56:36 +00:00
|
|
|
|
WithContext(ctx sdk.Context)
|
|
|
|
|
ResetRefundTransient(ctx sdk.Context)
|
2020-09-02 19:41:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-17 22:32:01 +00:00
|
|
|
|
// EthSigVerificationDecorator validates an ethereum signature
|
2021-04-18 16:39:15 +00:00
|
|
|
|
type EthSigVerificationDecorator struct {
|
2021-05-10 16:34:00 +00:00
|
|
|
|
evmKeeper EVMKeeper
|
2021-04-18 16:39:15 +00:00
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
|
|
|
|
// NewEthSigVerificationDecorator creates a new EthSigVerificationDecorator
|
2021-05-10 16:34:00 +00:00
|
|
|
|
func NewEthSigVerificationDecorator(ek EVMKeeper) EthSigVerificationDecorator {
|
|
|
|
|
return EthSigVerificationDecorator{
|
|
|
|
|
evmKeeper: ek,
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// AnteHandle validates checks that the registered chain id is the same as the one on the message, and
|
|
|
|
|
// that the signer address matches the one defined on the message.
|
2020-04-17 22:32:01 +00:00
|
|
|
|
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// no need to verify signatures on recheck tx
|
|
|
|
|
if ctx.IsReCheckTx() {
|
2021-04-18 16:39:15 +00:00
|
|
|
|
return next(ctx, tx, simulate)
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// get and set account must be called with an infinite gas meter in order to prevent
|
|
|
|
|
// additional gas from being deducted.
|
|
|
|
|
infCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
chainID := esvd.evmKeeper.ChainID()
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
config, found := esvd.evmKeeper.GetChainConfig(infCtx)
|
2021-05-10 16:34:00 +00:00
|
|
|
|
if !found {
|
|
|
|
|
return ctx, evmtypes.ErrChainConfigNotFound
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
ethCfg := config.EthereumConfig(chainID)
|
2021-05-10 16:34:00 +00:00
|
|
|
|
blockNum := big.NewInt(ctx.BlockHeight())
|
|
|
|
|
signer := ethtypes.MakeSigner(ethCfg, blockNum)
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
for _, msg := range tx.GetMsgs() {
|
|
|
|
|
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
|
|
|
|
|
if !ok {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type %T, expected %T", tx, &evmtypes.MsgEthereumTx{})
|
|
|
|
|
}
|
2021-05-10 16:34:00 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
if _, err := signer.Sender(msgEthTx.AsTransaction()); err != nil {
|
|
|
|
|
return ctx, sdkerrors.Wrap(sdkerrors.ErrorInvalidSigner, err.Error())
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
|
return next(ctx, tx, simulate)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EthAccountVerificationDecorator validates an account balance checks
|
|
|
|
|
type EthAccountVerificationDecorator struct {
|
2021-04-17 10:00:07 +00:00
|
|
|
|
ak AccountKeeper
|
|
|
|
|
bankKeeper BankKeeper
|
|
|
|
|
evmKeeper EVMKeeper
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
|
// NewEthAccountVerificationDecorator creates a new EthAccountVerificationDecorator
|
|
|
|
|
func NewEthAccountVerificationDecorator(ak AccountKeeper, bankKeeper BankKeeper, ek EVMKeeper) EthAccountVerificationDecorator {
|
|
|
|
|
return EthAccountVerificationDecorator{
|
2021-04-17 10:00:07 +00:00
|
|
|
|
ak: ak,
|
|
|
|
|
bankKeeper: bankKeeper,
|
|
|
|
|
evmKeeper: ek,
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AnteHandle validates the signature and returns sender address
|
2021-04-18 16:39:15 +00:00
|
|
|
|
func (avd EthAccountVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
2020-04-17 22:32:01 +00:00
|
|
|
|
if !ctx.IsCheckTx() {
|
|
|
|
|
return next(ctx, tx, simulate)
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// get and set account must be called with an infinite gas meter in order to prevent
|
|
|
|
|
// additional gas from being deducted.
|
|
|
|
|
infCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
evmDenom := avd.evmKeeper.GetParams(infCtx).EvmDenom
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
for _, msg := range tx.GetMsgs() {
|
|
|
|
|
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
|
|
|
|
|
if !ok {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type %T, expected %T", tx, &evmtypes.MsgEthereumTx{})
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// sender address should be in the tx cache from the previous AnteHandle call
|
|
|
|
|
from := msgEthTx.GetFrom()
|
|
|
|
|
if from.Empty() {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "from address cannot be empty")
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
acc := avd.ak.GetAccount(infCtx, from)
|
|
|
|
|
if acc == nil {
|
|
|
|
|
_ = avd.ak.NewAccountWithAddress(infCtx, from)
|
|
|
|
|
}
|
2020-09-02 19:41:05 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// validate sender has enough funds to pay for gas cost
|
|
|
|
|
balance := avd.bankKeeper.GetBalance(infCtx, from, evmDenom)
|
|
|
|
|
if balance.Amount.BigInt().Cmp(msgEthTx.Cost()) < 0 {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(
|
|
|
|
|
sdkerrors.ErrInsufficientFunds,
|
|
|
|
|
"sender balance < tx gas cost (%s < %s%s)", balance.String(), msgEthTx.Cost().String(), evmDenom,
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return next(ctx, tx, simulate)
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
|
// EthNonceVerificationDecorator checks that the account nonce from the transaction matches
|
2020-05-04 22:41:17 +00:00
|
|
|
|
// the sender account sequence.
|
2021-04-18 16:39:15 +00:00
|
|
|
|
type EthNonceVerificationDecorator struct {
|
2021-04-17 10:00:07 +00:00
|
|
|
|
ak AccountKeeper
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
|
// NewEthNonceVerificationDecorator creates a new EthNonceVerificationDecorator
|
|
|
|
|
func NewEthNonceVerificationDecorator(ak AccountKeeper) EthNonceVerificationDecorator {
|
|
|
|
|
return EthNonceVerificationDecorator{
|
2020-04-17 22:32:01 +00:00
|
|
|
|
ak: ak,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AnteHandle validates that the transaction nonce is valid (equivalent to the sender account’s
|
|
|
|
|
// current nonce).
|
2021-04-18 16:39:15 +00:00
|
|
|
|
func (nvd EthNonceVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// no need to check the nonce on ReCheckTx
|
|
|
|
|
if ctx.IsReCheckTx() {
|
|
|
|
|
return next(ctx, tx, simulate)
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// get and set account must be called with an infinite gas meter in order to prevent
|
|
|
|
|
// additional gas from being deducted.
|
|
|
|
|
infCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
for _, msg := range tx.GetMsgs() {
|
|
|
|
|
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
|
|
|
|
|
if !ok {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type %T, expected %T", tx, &evmtypes.MsgEthereumTx{})
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// sender address should be in the tx cache from the previous AnteHandle call
|
|
|
|
|
seq, err := nvd.ak.GetSequence(infCtx, msgEthTx.GetFrom())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ctx, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if multiple transactions are submitted in succession with increasing nonces,
|
|
|
|
|
// all will be rejected except the first, since the first needs to be included in a block
|
|
|
|
|
// before the sequence increments
|
|
|
|
|
if msgEthTx.Data.Nonce != seq {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(
|
|
|
|
|
sdkerrors.ErrInvalidSequence,
|
|
|
|
|
"invalid nonce; got %d, expected %d", msgEthTx.Data.Nonce, seq,
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return next(ctx, tx, simulate)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EthGasConsumeDecorator validates enough intrinsic gas for the transaction and
|
|
|
|
|
// gas consumption.
|
|
|
|
|
type EthGasConsumeDecorator struct {
|
2021-04-17 10:00:07 +00:00
|
|
|
|
ak AccountKeeper
|
|
|
|
|
bankKeeper BankKeeper
|
|
|
|
|
evmKeeper EVMKeeper
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewEthGasConsumeDecorator creates a new EthGasConsumeDecorator
|
2021-04-17 10:00:07 +00:00
|
|
|
|
func NewEthGasConsumeDecorator(ak AccountKeeper, bankKeeper BankKeeper, ek EVMKeeper) EthGasConsumeDecorator {
|
2020-04-17 22:32:01 +00:00
|
|
|
|
return EthGasConsumeDecorator{
|
2021-04-17 10:00:07 +00:00
|
|
|
|
ak: ak,
|
|
|
|
|
bankKeeper: bankKeeper,
|
|
|
|
|
evmKeeper: ek,
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AnteHandle validates that the Ethereum tx message has enough to cover intrinsic gas
|
|
|
|
|
// (during CheckTx only) and that the sender has enough balance to pay for the gas cost.
|
|
|
|
|
//
|
|
|
|
|
// Intrinsic gas for a transaction is the amount of gas
|
|
|
|
|
// that the transaction uses before the transaction is executed. The gas is a
|
|
|
|
|
// constant value of 21000 plus any cost inccured by additional bytes of data
|
|
|
|
|
// supplied with the transaction.
|
|
|
|
|
func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// get and set account must be called with an infinite gas meter in order to prevent
|
|
|
|
|
// additional gas from being deducted.
|
|
|
|
|
infCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
if len(tx.GetMsgs()) != 1 {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "only 1 ethereum msg supported per tx, got %d", len(tx.GetMsgs()))
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// reset the refund gas value for the current transaction
|
|
|
|
|
egcd.evmKeeper.ResetRefundTransient(infCtx)
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
config, found := egcd.evmKeeper.GetChainConfig(infCtx)
|
|
|
|
|
if !found {
|
|
|
|
|
return ctx, evmtypes.ErrChainConfigNotFound
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
ethCfg := config.EthereumConfig(egcd.evmKeeper.ChainID())
|
2021-05-10 16:34:00 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
blockHeight := big.NewInt(ctx.BlockHeight())
|
|
|
|
|
homestead := ethCfg.IsHomestead(blockHeight)
|
|
|
|
|
istanbul := ethCfg.IsIstanbul(blockHeight)
|
2021-05-10 16:34:00 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
for _, msg := range tx.GetMsgs() {
|
|
|
|
|
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
|
|
|
|
|
if !ok {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "invalid transaction type %T, expected %T", tx, &evmtypes.MsgEthereumTx{})
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
isContractCreation := msgEthTx.To() == nil
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// fetch sender account from signature
|
|
|
|
|
signerAcc, err := authante.GetSignerAcc(infCtx, egcd.ak, msgEthTx.GetFrom())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return ctx, err
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
gasLimit := msgEthTx.GetGas()
|
2020-09-02 19:41:05 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
var accessList ethtypes.AccessList
|
|
|
|
|
if msgEthTx.Data.Accesses != nil {
|
|
|
|
|
accessList = *msgEthTx.Data.Accesses.ToEthAccessList()
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
intrinsicGas, err := core.IntrinsicGas(msgEthTx.Data.Input, accessList, isContractCreation, homestead, istanbul)
|
2020-04-17 22:32:01 +00:00
|
|
|
|
if err != nil {
|
2021-05-31 09:05:32 +00:00
|
|
|
|
return ctx, sdkerrors.Wrap(err, "failed to compute intrinsic gas cost")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// intrinsic gas verification during CheckTx
|
|
|
|
|
if ctx.IsCheckTx() && gasLimit < intrinsicGas {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(sdkerrors.ErrOutOfGas, "gas limit too low: %d (gas limit) < %d (intrinsic gas)", gasLimit, intrinsicGas)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cost calculates the fees paid to validators based on gas limit and price
|
|
|
|
|
cost := msgEthTx.Fee() // fee = gas limit * gas price
|
|
|
|
|
|
|
|
|
|
evmDenom := egcd.evmKeeper.GetParams(infCtx).EvmDenom
|
|
|
|
|
feeAmt := sdk.Coins{sdk.NewCoin(evmDenom, sdk.NewIntFromBigInt(cost))}
|
|
|
|
|
|
|
|
|
|
// deduct the full gas cost from the user balance
|
|
|
|
|
if err := authante.DeductFees(egcd.bankKeeper, infCtx, signerAcc, feeAmt); err != nil {
|
2020-04-17 22:32:01 +00:00
|
|
|
|
return ctx, err
|
|
|
|
|
}
|
2021-05-31 09:05:32 +00:00
|
|
|
|
|
|
|
|
|
// consume intrinsic gas for the current transaction. After runTx is executed on Baseapp, the
|
|
|
|
|
// application will consume gas from the block gas pool.
|
|
|
|
|
ctx.GasMeter().ConsumeGas(intrinsicGas, "intrinsic gas")
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// generate a copy of the gas pool (i.e block gas meter) to see if we've run out of gas for this block
|
|
|
|
|
// if current gas consumed is greater than the limit, this funcion panics and the error is recovered on the Baseapp
|
|
|
|
|
gasPool := sdk.NewGasMeter(ctx.BlockGasMeter().Limit())
|
|
|
|
|
gasPool.ConsumeGas(ctx.GasMeter().GasConsumedToLimit(), "gas pool check")
|
2021-05-25 12:56:36 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
// we know that we have enough gas on the pool to cover the intrinsic gas
|
|
|
|
|
// set up the updated context to the evm Keeper
|
|
|
|
|
egcd.evmKeeper.WithContext(ctx)
|
|
|
|
|
return next(ctx, tx, simulate)
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
|
// EthIncrementSenderSequenceDecorator increments the sequence of the signers. The
|
2020-04-17 22:32:01 +00:00
|
|
|
|
// main difference with the SDK's IncrementSequenceDecorator is that the MsgEthereumTx
|
|
|
|
|
// doesn't implement the SigVerifiableTx interface.
|
|
|
|
|
//
|
|
|
|
|
// CONTRACT: must be called after msg.VerifySig in order to cache the sender address.
|
2021-04-18 16:39:15 +00:00
|
|
|
|
type EthIncrementSenderSequenceDecorator struct {
|
2021-04-17 10:00:07 +00:00
|
|
|
|
ak AccountKeeper
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-18 16:39:15 +00:00
|
|
|
|
// NewEthIncrementSenderSequenceDecorator creates a new EthIncrementSenderSequenceDecorator.
|
|
|
|
|
func NewEthIncrementSenderSequenceDecorator(ak AccountKeeper) EthIncrementSenderSequenceDecorator {
|
|
|
|
|
return EthIncrementSenderSequenceDecorator{
|
2020-04-17 22:32:01 +00:00
|
|
|
|
ak: ak,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AnteHandle handles incrementing the sequence of the sender.
|
2021-04-18 16:39:15 +00:00
|
|
|
|
func (issd EthIncrementSenderSequenceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
|
2020-05-04 22:41:17 +00:00
|
|
|
|
// get and set account must be called with an infinite gas meter in order to prevent
|
|
|
|
|
// additional gas from being deducted.
|
2021-05-31 09:05:32 +00:00
|
|
|
|
infCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter())
|
|
|
|
|
|
|
|
|
|
for _, msg := range tx.GetMsgs() {
|
|
|
|
|
// increment sequence of all signers
|
|
|
|
|
for _, addr := range msg.GetSigners() {
|
|
|
|
|
acc := issd.ak.GetAccount(infCtx, addr)
|
|
|
|
|
if acc == nil {
|
|
|
|
|
return ctx, sdkerrors.Wrapf(
|
|
|
|
|
sdkerrors.ErrUnknownAddress,
|
|
|
|
|
"account %s (%s) is nil", common.BytesToAddress(addr.Bytes()), addr,
|
|
|
|
|
)
|
|
|
|
|
}
|
2020-05-04 22:41:17 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
if err := acc.SetSequence(acc.GetSequence() + 1); err != nil {
|
|
|
|
|
return ctx, err
|
|
|
|
|
}
|
2020-04-17 22:32:01 +00:00
|
|
|
|
|
2021-05-31 09:05:32 +00:00
|
|
|
|
issd.ak.SetAccount(infCtx, acc)
|
2020-04-17 22:32:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-04 22:41:17 +00:00
|
|
|
|
// set the original gas meter
|
2020-04-17 22:32:01 +00:00
|
|
|
|
return next(ctx, tx, simulate)
|
|
|
|
|
}
|