-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
74 changed files
with
58,627 additions
and
48,279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
package app | ||
package ante | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
errortypes "github.com/cosmos/cosmos-sdk/types/errors" | ||
authante "github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
|
||
guardiankeeper "github.com/irisnet/irishub/modules/guardian/keeper" | ||
|
||
oraclekeeper "github.com/irisnet/irismod/modules/oracle/keeper" | ||
tokenkeeper "github.com/irisnet/irismod/modules/token/keeper" | ||
ethante "github.com/evmos/ethermint/app/ante" | ||
) | ||
|
||
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC | ||
// channel keeper. | ||
type HandlerOptions struct { | ||
ante.HandlerOptions | ||
BankKeeper bankkeeper.Keeper | ||
TokenKeeper tokenkeeper.Keeper | ||
OracleKeeper oraclekeeper.Keeper | ||
GuardianKeeper guardiankeeper.Keeper | ||
BypassMinFeeMsgTypes []string | ||
} | ||
// 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 { | ||
return func( | ||
ctx sdk.Context, tx sdk.Tx, sim bool, | ||
) (newCtx sdk.Context, err error) { | ||
var anteHandler sdk.AnteHandler | ||
|
||
defer ethante.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) | ||
default: | ||
return ctx, errorsmod.Wrapf( | ||
errortypes.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, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid transaction type: %T", tx) | ||
} | ||
|
||
// NewAnteHandler returns an AnteHandler that checks and increments sequence | ||
// numbers, checks signatures & account numbers, and deducts fees from the first | ||
// signer. | ||
func NewAnteHandler(opts HandlerOptions) (sdk.AnteHandler, error) { | ||
var sigGasConsumer = opts.SigGasConsumer | ||
if sigGasConsumer == nil { | ||
sigGasConsumer = ante.DefaultSigVerificationGasConsumer | ||
return anteHandler(ctx, tx, sim) | ||
} | ||
return sdk.ChainAnteDecorators( | ||
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first | ||
ante.NewExtensionOptionsDecorator(opts.ExtensionOptionChecker), | ||
ante.NewValidateBasicDecorator(), | ||
ante.NewTxTimeoutHeightDecorator(), | ||
ante.NewValidateMemoDecorator(opts.AccountKeeper), | ||
ante.NewConsumeGasForTxSizeDecorator(opts.AccountKeeper), | ||
ante.NewDeductFeeDecorator(opts.AccountKeeper, opts.BankKeeper, opts.FeegrantKeeper, opts.TxFeeChecker), | ||
ante.NewSetPubKeyDecorator(opts.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators | ||
ante.NewValidateSigCountDecorator(opts.AccountKeeper), | ||
ante.NewSigGasConsumeDecorator(opts.AccountKeeper, sigGasConsumer), | ||
ante.NewSigVerificationDecorator(opts.AccountKeeper, opts.SignModeHandler), | ||
NewValidateTokenDecorator(opts.TokenKeeper), | ||
tokenkeeper.NewValidateTokenFeeDecorator(opts.TokenKeeper, opts.BankKeeper), | ||
oraclekeeper.NewValidateOracleAuthDecorator(opts.OracleKeeper, opts.GuardianKeeper), | ||
NewValidateServiceDecorator(), | ||
ante.NewIncrementSequenceDecorator(opts.AccountKeeper), | ||
), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package ante | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" | ||
|
||
ibcante "github.com/cosmos/ibc-go/v5/modules/core/ante" | ||
ibckeeper "github.com/cosmos/ibc-go/v5/modules/core/keeper" | ||
|
||
ethante "github.com/evmos/ethermint/app/ante" | ||
|
||
oraclekeeper "github.com/irisnet/irismod/modules/oracle/keeper" | ||
tokenkeeper "github.com/irisnet/irismod/modules/token/keeper" | ||
|
||
guardiankeeper "github.com/irisnet/irishub/modules/guardian/keeper" | ||
) | ||
|
||
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC | ||
// channel keeper. | ||
type HandlerOptions struct { | ||
ante.HandlerOptions | ||
BankKeeper bankkeeper.Keeper | ||
AccountKeeper authkeeper.AccountKeeper | ||
IBCKeeper *ibckeeper.Keeper | ||
TokenKeeper tokenkeeper.Keeper | ||
OracleKeeper oraclekeeper.Keeper | ||
GuardianKeeper guardiankeeper.Keeper | ||
EvmKeeper ethante.EVMKeeper | ||
FeeMarketKeeper ethante.FeeMarketKeeper | ||
BypassMinFeeMsgTypes []string | ||
MaxTxGasWanted uint64 | ||
} | ||
|
||
// newCosmosAnteHandler creates the default ante handler for Ethereum transactions | ||
func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { | ||
return sdk.ChainAnteDecorators( | ||
ethante.NewEthSetUpContextDecorator(options.EvmKeeper), // outermost AnteDecorator. SetUpContext must be called first | ||
ethante.NewEthMempoolFeeDecorator(options.EvmKeeper), // Check eth effective gas price against the node's minimal-gas-prices config | ||
ethante.NewEthMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), // Check eth effective gas price against the global MinGasPrice | ||
ethante.NewEthValidateBasicDecorator(options.EvmKeeper), | ||
ethante.NewEthSigVerificationDecorator(options.EvmKeeper), | ||
ethante.NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper), | ||
ethante.NewEthFeeGrantValidator(options.EvmKeeper, options.FeegrantKeeper), | ||
ethante.NewCanTransferDecorator(options.EvmKeeper), | ||
ethante.NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted), | ||
ethante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), | ||
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper), | ||
ethante.NewEthEmitEventDecorator(options.EvmKeeper), // emit eth tx hash and index at the very last ante handler. | ||
) | ||
} | ||
|
||
// newCosmosAnteHandler creates the default ante handler for Cosmos transactions | ||
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler { | ||
return sdk.ChainAnteDecorators( | ||
RejectMessagesDecorator{}, | ||
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first | ||
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker), | ||
ante.NewValidateBasicDecorator(), | ||
ante.NewTxTimeoutHeightDecorator(), | ||
ante.NewValidateMemoDecorator(options.AccountKeeper), | ||
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), | ||
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), | ||
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators | ||
ante.NewValidateSigCountDecorator(options.AccountKeeper), | ||
ante.NewSigGasConsumeDecorator(options.AccountKeeper, DefaultSigVerificationGasConsumer), | ||
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), | ||
NewValidateTokenDecorator(options.TokenKeeper), | ||
tokenkeeper.NewValidateTokenFeeDecorator(options.TokenKeeper, options.BankKeeper), | ||
oraclekeeper.NewValidateOracleAuthDecorator(options.OracleKeeper, options.GuardianKeeper), | ||
NewValidateServiceDecorator(), | ||
ante.NewIncrementSequenceDecorator(options.AccountKeeper), | ||
ibcante.NewRedundantRelayDecorator(options.IBCKeeper), | ||
) | ||
} | ||
|
||
// newCosmosAnteHandlerEip712 creates the ante handler for transactions signed with EIP712 | ||
func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler { | ||
return sdk.ChainAnteDecorators( | ||
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs | ||
ante.NewSetUpContextDecorator(), | ||
ante.NewValidateBasicDecorator(), | ||
ante.NewTxTimeoutHeightDecorator(), | ||
ethante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper), | ||
ante.NewValidateMemoDecorator(options.AccountKeeper), | ||
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), | ||
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), | ||
// SetPubKeyDecorator must be called before all signature verification decorators | ||
ante.NewSetPubKeyDecorator(options.AccountKeeper), | ||
ante.NewValidateSigCountDecorator(options.AccountKeeper), | ||
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), | ||
// Note: signature verification uses EIP instead of the cosmos signature validator | ||
ethante.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), | ||
ante.NewIncrementSequenceDecorator(options.AccountKeeper), | ||
ibcante.NewRedundantRelayDecorator(options.IBCKeeper), | ||
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper), | ||
) | ||
} |
Oops, something went wrong.