Skip to content

Commit 20dea4b

Browse files
Alex | Interchain Labsgithub-actions[bot]
andauthored
chore: move evmd ante options to evm lib (#443)
* fix * move-to-lib * godoc * cl * Auto-fix markdown lint issues * bump for ci * bump for ci * fix * fix * fix --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent a6d5dea commit 20dea4b

File tree

9 files changed

+56
-25
lines changed

9 files changed

+56
-25
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,7 @@
5252

5353
### API-BREAKING
5454

55+
- [\#443](https://github.com/cosmos/evm/pull/443) Move `ante` logic from the `evmd` Go package to the `evm` package to
56+
be exported as a library.
5557
- [\#422](https://github.com/cosmos/evm/pull/422) Align function and package names for consistency.
5658
- [\#305](https://github.com/cosmos/evm/pull/305) Remove evidence precompile due to lack of use cases

evmd/ante/handler_options.go renamed to ante/ante.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,10 @@ func (options HandlerOptions) Validate() error {
6262
if options.TxFeeChecker == nil {
6363
return errorsmod.Wrap(errortypes.ErrLogic, "tx fee checker is required for AnteHandler")
6464
}
65+
66+
if options.PendingTxListener == nil {
67+
return errorsmod.Wrap(errortypes.ErrLogic, "pending tx listener is required for AnteHandler")
68+
}
69+
6570
return nil
6671
}

evmd/ante/tx_listener.go renamed to ante/tx_listener.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package ante
22

33
import (
4-
sdk "github.com/cosmos/cosmos-sdk/types"
5-
evmtypes "github.com/cosmos/evm/x/vm/types"
64
"github.com/ethereum/go-ethereum/common"
5+
6+
evmtypes "github.com/cosmos/evm/x/vm/types"
7+
8+
sdk "github.com/cosmos/cosmos-sdk/types"
79
)
810

911
type PendingTxListener func(common.Hash)

evmd/ante/ante.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ante
22

33
import (
44
errorsmod "cosmossdk.io/errors"
5+
"github.com/cosmos/evm/ante"
56

67
sdk "github.com/cosmos/cosmos-sdk/types"
78
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
@@ -12,7 +13,7 @@ import (
1213
// Ethereum or SDK transaction to an internal ante handler for performing
1314
// transaction-level processing (e.g. fee payment, signature verification) before
1415
// being passed onto it's respective handler.
15-
func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
16+
func NewAnteHandler(options ante.HandlerOptions) sdk.AnteHandler {
1617
return func(
1718
ctx sdk.Context, tx sdk.Tx, sim bool,
1819
) (newCtx sdk.Context, err error) {

evmd/ante/cosmos_handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package ante
22

33
import (
4+
baseevmante "github.com/cosmos/evm/ante"
45
cosmosante "github.com/cosmos/evm/ante/cosmos"
56
evmante "github.com/cosmos/evm/ante/evm"
67
evmtypes "github.com/cosmos/evm/x/vm/types"
@@ -12,7 +13,7 @@ import (
1213
)
1314

1415
// newCosmosAnteHandler creates the default ante handler for Cosmos transactions
15-
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
16+
func newCosmosAnteHandler(options baseevmante.HandlerOptions) sdk.AnteHandler {
1617
return sdk.ChainAnteDecorators(
1718
cosmosante.NewRejectMessagesDecorator(), // reject MsgEthereumTxs
1819
cosmosante.NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field

evmd/ante/evm_antehandler_benchmark_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ func (s *benchmarkSuite) generateTxType(txType string) (sdktypes.Tx, error) {
142142
}
143143
}
144144

145-
func (s *benchmarkSuite) generateHandlerOptions() evmdante.HandlerOptions {
145+
func (s *benchmarkSuite) generateHandlerOptions() ante.HandlerOptions {
146146
encCfg := s.network.GetEncodingConfig()
147-
return evmdante.HandlerOptions{
147+
return ante.HandlerOptions{
148148
Cdc: s.network.App.AppCodec(),
149149
AccountKeeper: s.network.App.GetAccountKeeper(),
150150
BankKeeper: s.network.App.GetBankKeeper(),

evmd/ante/evm_handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package ante
22

33
import (
4+
"github.com/cosmos/evm/ante"
45
evmante "github.com/cosmos/evm/ante/evm"
56

67
sdk "github.com/cosmos/cosmos-sdk/types"
78
)
89

910
// newMonoEVMAnteHandler creates the sdk.AnteHandler implementation for the EVM transactions.
10-
func newMonoEVMAnteHandler(options HandlerOptions) sdk.AnteHandler {
11+
func newMonoEVMAnteHandler(options ante.HandlerOptions) sdk.AnteHandler {
1112
decorators := []sdk.AnteDecorator{
1213
evmante.NewEVMMonoDecorator(
1314
options.AccountKeeper,
1415
options.FeeMarketKeeper,
1516
options.EvmKeeper,
1617
options.MaxTxGasWanted,
1718
),
19+
ante.NewTxListenerDecorator(options.PendingTxListener),
1820
}
19-
if options.PendingTxListener != nil {
20-
decorators = append(decorators, NewTxListenerDecorator(options.PendingTxListener))
21-
}
21+
2222
return sdk.ChainAnteDecorators(decorators...)
2323
}

evmd/ante/validate_handler_options_test.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package ante_test
33
import (
44
"testing"
55

6+
"github.com/ethereum/go-ethereum/common"
67
"github.com/stretchr/testify/require"
78

89
"github.com/cosmos/evm/ante"
910
ethante "github.com/cosmos/evm/ante/evm"
10-
evmdante "github.com/cosmos/evm/evmd/ante"
1111
"github.com/cosmos/evm/evmd/tests/integration"
1212
"github.com/cosmos/evm/testutil/integration/evm/network"
1313
"github.com/cosmos/evm/types"
@@ -18,25 +18,25 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
1818
nw := network.NewUnitTestNetwork(create, options...)
1919
cases := []struct {
2020
name string
21-
options evmdante.HandlerOptions
21+
options ante.HandlerOptions
2222
expPass bool
2323
}{
2424
{
2525
"fail - empty options",
26-
evmdante.HandlerOptions{},
26+
ante.HandlerOptions{},
2727
false,
2828
},
2929
{
3030
"fail - empty account keeper",
31-
evmdante.HandlerOptions{
31+
ante.HandlerOptions{
3232
Cdc: nw.App.AppCodec(),
3333
AccountKeeper: nil,
3434
},
3535
false,
3636
},
3737
{
3838
"fail - empty bank keeper",
39-
evmdante.HandlerOptions{
39+
ante.HandlerOptions{
4040
Cdc: nw.App.AppCodec(),
4141
AccountKeeper: nw.App.GetAccountKeeper(),
4242
BankKeeper: nil,
@@ -45,7 +45,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
4545
},
4646
{
4747
"fail - empty IBC keeper",
48-
evmdante.HandlerOptions{
48+
ante.HandlerOptions{
4949
Cdc: nw.App.AppCodec(),
5050
AccountKeeper: nw.App.GetAccountKeeper(),
5151
BankKeeper: nw.App.GetBankKeeper(),
@@ -55,7 +55,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
5555
},
5656
{
5757
"fail - empty fee market keeper",
58-
evmdante.HandlerOptions{
58+
ante.HandlerOptions{
5959
Cdc: nw.App.AppCodec(),
6060
AccountKeeper: nw.App.GetAccountKeeper(),
6161
BankKeeper: nw.App.GetBankKeeper(),
@@ -66,7 +66,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
6666
},
6767
{
6868
"fail - empty EVM keeper",
69-
evmdante.HandlerOptions{
69+
ante.HandlerOptions{
7070
Cdc: nw.App.AppCodec(),
7171
AccountKeeper: nw.App.GetAccountKeeper(),
7272
BankKeeper: nw.App.GetBankKeeper(),
@@ -78,7 +78,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
7878
},
7979
{
8080
"fail - empty signature gas consumer",
81-
evmdante.HandlerOptions{
81+
ante.HandlerOptions{
8282
Cdc: nw.App.AppCodec(),
8383
AccountKeeper: nw.App.GetAccountKeeper(),
8484
BankKeeper: nw.App.GetBankKeeper(),
@@ -91,7 +91,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
9191
},
9292
{
9393
"fail - empty signature mode handler",
94-
evmdante.HandlerOptions{
94+
ante.HandlerOptions{
9595
Cdc: nw.App.AppCodec(),
9696
AccountKeeper: nw.App.GetAccountKeeper(),
9797
BankKeeper: nw.App.GetBankKeeper(),
@@ -105,7 +105,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
105105
},
106106
{
107107
"fail - empty tx fee checker",
108-
evmdante.HandlerOptions{
108+
ante.HandlerOptions{
109109
Cdc: nw.App.AppCodec(),
110110
AccountKeeper: nw.App.GetAccountKeeper(),
111111
BankKeeper: nw.App.GetBankKeeper(),
@@ -118,9 +118,28 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
118118
},
119119
false,
120120
},
121+
{
122+
"fail - empty pending tx listener",
123+
ante.HandlerOptions{
124+
Cdc: nw.App.AppCodec(),
125+
AccountKeeper: nw.App.GetAccountKeeper(),
126+
BankKeeper: nw.App.GetBankKeeper(),
127+
ExtensionOptionChecker: types.HasDynamicFeeExtensionOption,
128+
EvmKeeper: nw.App.GetEVMKeeper(),
129+
FeegrantKeeper: nw.App.GetFeeGrantKeeper(),
130+
IBCKeeper: nw.App.GetIBCKeeper(),
131+
FeeMarketKeeper: nw.App.GetFeeMarketKeeper(),
132+
SignModeHandler: nw.GetEncodingConfig().TxConfig.SignModeHandler(),
133+
SigGasConsumer: ante.SigVerificationGasConsumer,
134+
MaxTxGasWanted: 40000000,
135+
TxFeeChecker: ethante.NewDynamicFeeChecker(nw.App.GetFeeMarketKeeper()),
136+
PendingTxListener: nil,
137+
},
138+
false,
139+
},
121140
{
122141
"success - default app options",
123-
evmdante.HandlerOptions{
142+
ante.HandlerOptions{
124143
Cdc: nw.App.AppCodec(),
125144
AccountKeeper: nw.App.GetAccountKeeper(),
126145
BankKeeper: nw.App.GetBankKeeper(),
@@ -133,6 +152,7 @@ func RunValidateHandlerOptionsTest(t *testing.T, create network.CreateEvmApp, op
133152
SigGasConsumer: ante.SigVerificationGasConsumer,
134153
MaxTxGasWanted: 40000000,
135154
TxFeeChecker: ethante.NewDynamicFeeChecker(nw.App.GetFeeMarketKeeper()),
155+
PendingTxListener: func(hash common.Hash) {},
136156
},
137157
true,
138158
},

evmd/app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ type EVMD struct {
162162
interfaceRegistry types.InterfaceRegistry
163163
txConfig client.TxConfig
164164

165-
pendingTxListeners []ante.PendingTxListener
165+
pendingTxListeners []evmante.PendingTxListener
166166

167167
// keys to access the substores
168168
keys map[string]*storetypes.KVStoreKey
@@ -439,7 +439,7 @@ func NewExampleApp(
439439

440440
app.GovKeeper = *govKeeper.SetHooks(
441441
govtypes.NewMultiGovHooks(
442-
// register the governance hooks
442+
// register the governance hooks
443443
),
444444
)
445445

@@ -801,7 +801,7 @@ func NewExampleApp(
801801
}
802802

803803
func (app *EVMD) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64) {
804-
options := ante.HandlerOptions{
804+
options := evmante.HandlerOptions{
805805
Cdc: app.appCodec,
806806
AccountKeeper: app.AccountKeeper,
807807
BankKeeper: app.BankKeeper,

0 commit comments

Comments
 (0)