-
Notifications
You must be signed in to change notification settings - Fork 73
/
decorator.go
164 lines (154 loc) · 8.11 KB
/
decorator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package ante
import (
"github.com/artela-network/artela/x/evm/txs"
"github.com/cosmos/cosmos-sdk/baseapp"
errorsmod "cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
cosmos "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authmodule "github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
anteutils "github.com/artela-network/artela/app/ante/utils"
"github.com/artela-network/artela/app/interfaces"
cosmosante "github.com/artela-network/artela/app/ante/cosmos"
evmante "github.com/artela-network/artela/app/ante/evm"
evmmodule "github.com/artela-network/artela/x/evm/types"
// vestingtypes "github.com/artela-network/artela/x/vesting/types"
sdkvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)
// AnteDecorators defines the list of module keepers required to run the Artela
// AnteHandler decorators.
type AnteDecorators struct {
Cdc codec.BinaryCodec
AccountKeeper evmmodule.AccountKeeper
BankKeeper evmmodule.BankKeeper
DistributionKeeper anteutils.DistributionKeeper
IBCKeeper *ibckeeper.Keeper
// StakingKeeper vestingtypes.StakingKeeper
FeeKeeper interfaces.FeeKeeper
EvmKeeper interfaces.EVMKeeper
FeegrantKeeper ante.FeegrantKeeper
ExtensionOptionChecker ante.ExtensionOptionChecker
SignModeHandler authsigning.SignModeHandler
SigGasConsumer func(meter cosmos.GasMeter, sig signing.SignatureV2, params authmodule.Params) error
MaxTxGasWanted uint64
TxFeeChecker anteutils.TxFeeChecker
}
// Validate checks if the keepers are defined
func (options AnteDecorators) Validate() error {
if options.Cdc == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "codec is required for AnteHandler")
}
if options.AccountKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "account keeper is required for AnteHandler")
}
if options.BankKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "bank keeper is required for AnteHandler")
}
if options.IBCKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "ibc keeper is required for AnteHandler")
}
// if options.StakingKeeper == nil {
// return errorsmod.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler")
// }
if options.FeeKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "fee market keeper is required for AnteHandler")
}
if options.EvmKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler")
}
if options.SigGasConsumer == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "signature gas consumer is required for AnteHandler")
}
if options.SignModeHandler == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "sign mode handler is required for AnteHandler")
}
if options.DistributionKeeper == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "distribution keeper is required for AnteHandler")
}
if options.TxFeeChecker == nil {
return errorsmod.Wrap(errortypes.ErrLogic, "tx fee checker is required for AnteHandler")
}
return nil
}
// newEVMAnteHandler creates the default ante handler for Ethereum transactions
func newEVMAnteHandler(app *baseapp.BaseApp, options AnteDecorators) cosmos.AnteHandler {
return cosmos.ChainAnteDecorators(
// outermost AnteDecorator. SetUpContext must be called first
evmante.NewEthSetUpContextDecorator(options.EvmKeeper),
// Check eth effective gas price against the node's minimal-gas-prices config
evmante.NewEthMempoolFeeDecorator(options.EvmKeeper),
// Check eth effective gas price against the global MinGasPrice
evmante.NewEthMinGasPriceDecorator(options.FeeKeeper, options.EvmKeeper),
evmante.NewEthValidateBasicDecorator(options.EvmKeeper),
evmante.NewAspectRuntimeContextDecorator(app, options.EvmKeeper),
evmante.NewEthSigVerificationDecorator(app, options.EvmKeeper),
evmante.NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper),
evmante.NewCanTransferDecorator(options.EvmKeeper),
// evmante.NewEthVestingTransactionDecorator(options.AccountKeeper, options.BankKeeper, options.EvmKeeper),
evmante.NewEthGasConsumeDecorator(options.BankKeeper, options.DistributionKeeper, options.EvmKeeper, nil, options.MaxTxGasWanted),
evmante.NewEthIncrementSenderSequenceDecorator(options.AccountKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeKeeper),
// emit eth tx hash and index at the very last ante handler.
evmante.NewEthEmitEventDecorator(options.EvmKeeper),
)
}
// newCosmosAnteHandler creates the default ante handler for Cosmos transactions
func newCosmosAnteHandler(options AnteDecorators) cosmos.AnteHandler {
return cosmos.ChainAnteDecorators(
cosmosante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmosante.NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field
cosmos.MsgTypeURL(&txs.MsgEthereumTx{}),
cosmos.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
),
ante.NewSetUpContextDecorator(),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
cosmosante.NewMinGasPriceDecorator(options.FeeKeeper, options.EvmKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
// cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
// cosmosante.NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeKeeper),
)
}
// newCosmosAnteHandlerEip712 creates the ante handler for transactions signed with EIP712
func newLegacyCosmosAnteHandlerEip712(options AnteDecorators) cosmos.AnteHandler {
return cosmos.ChainAnteDecorators(
cosmosante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmosante.NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field
cosmos.MsgTypeURL(&txs.MsgEthereumTx{}),
cosmos.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
),
ante.NewSetUpContextDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
cosmosante.NewMinGasPriceDecorator(options.FeeKeeper, options.EvmKeeper),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
// cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
// cosmosante.NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc),
// 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
// nolint: staticcheck
cosmosante.NewLegacyEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeKeeper),
)
}