Skip to content

Commit dc2ecd5

Browse files
committed
evm and feemarket module must implement beginBlocker and endBlocker interface
1 parent 4dfa007 commit dc2ecd5

File tree

5 files changed

+43
-45
lines changed

5 files changed

+43
-45
lines changed

x/evm/keeper/abci.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,30 @@
1616
package keeper
1717

1818
import (
19+
"context"
20+
1921
storetypes "cosmossdk.io/store/types"
20-
abci "github.com/cometbft/cometbft/abci/types"
2122
sdk "github.com/cosmos/cosmos-sdk/types"
2223

2324
ethtypes "github.com/ethereum/go-ethereum/core/types"
2425
)
2526

2627
// BeginBlock sets the sdk Context and EIP155 chain id to the Keeper.
27-
func (k *Keeper) BeginBlock(ctx sdk.Context) {
28-
k.WithChainID(ctx)
28+
func (k *Keeper) BeginBlock(goCtx context.Context) error{
29+
ctx := sdk.UnwrapSDKContext(goCtx)
30+
return k.WithChainID(ctx)
2931
}
3032

3133
// EndBlock also retrieves the bloom filter value from the transient store and commits it to the
3234
// KVStore. The EVM end block logic doesn't update the validator set, thus it returns
3335
// an empty slice.
34-
func (k *Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate {
36+
func (k *Keeper) EndBlock(goCtx context.Context) error {
37+
ctx := sdk.UnwrapSDKContext(goCtx)
3538
// Gas costs are handled within msg handler so costs should be ignored
3639
infCtx := ctx.WithGasMeter(storetypes.NewInfiniteGasMeter())
3740

3841
bloom := ethtypes.BytesToBloom(k.GetBlockBloomTransient(infCtx).Bytes())
3942
k.EmitBlockBloomEvent(infCtx, bloom)
4043

41-
return []abci.ValidatorUpdate{}
44+
return nil
4245
}

x/evm/keeper/keeper.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package keeper
1717

1818
import (
19+
"errors"
1920
"math/big"
2021

2122
errorsmod "cosmossdk.io/errors"
@@ -138,17 +139,18 @@ func (k *Keeper) WithOptions(opts types.Options) *Keeper {
138139
}
139140

140141
// WithChainID sets the chain id to the local variable in the keeper
141-
func (k *Keeper) WithChainID(ctx sdk.Context) {
142+
func (k *Keeper) WithChainID(ctx sdk.Context) error {
142143
chainID, err := ethermint.ParseChainID(ctx.ChainID())
143144
if err != nil {
144-
panic(err)
145+
return err
145146
}
146147

147148
if k.eip155ChainID != nil && k.eip155ChainID.Cmp(chainID) != 0 {
148-
panic("chain id already set")
149+
return errors.New("chain id already set")
149150
}
150151

151152
k.eip155ChainID = chainID
153+
return nil
152154
}
153155

154156
// ChainID returns the EIP155 chain ID for the EVM context

x/evm/module.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import (
2020
"encoding/json"
2121
"fmt"
2222

23-
"github.com/gorilla/mux"
2423
"github.com/grpc-ecosystem/grpc-gateway/runtime"
2524
"github.com/spf13/cobra"
2625

2726
abci "github.com/cometbft/cometbft/abci/types"
2827

28+
"cosmossdk.io/core/appmodule"
2929
"github.com/cosmos/cosmos-sdk/client"
3030
"github.com/cosmos/cosmos-sdk/codec"
3131
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
@@ -39,8 +39,10 @@ import (
3939
)
4040

4141
var (
42-
_ module.AppModule = AppModule{}
43-
_ module.AppModuleBasic = AppModuleBasic{}
42+
_ module.AppModule = AppModule{}
43+
_ appmodule.HasBeginBlocker = AppModule{}
44+
_ appmodule.HasEndBlocker = AppModule{}
45+
_ module.AppModuleBasic = AppModuleBasic{}
4446
)
4547

4648
// AppModuleBasic defines the basic application module used by the evm module.
@@ -81,11 +83,7 @@ func (AppModuleBasic) ValidateGenesis(
8183
return genesisState.Validate()
8284
}
8385

84-
// RegisterRESTRoutes performs a no-op as the EVM module doesn't expose REST
85-
// endpoints
86-
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {
87-
}
88-
86+
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the evm module.
8987
func (b AppModuleBasic) RegisterGRPCGatewayRoutes(c client.Context, serveMux *runtime.ServeMux) {
9088
if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(c)); err != nil {
9189
panic(err)
@@ -166,13 +164,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
166164
func (AppModule) QuerierRoute() string { return types.RouterKey }
167165

168166
// BeginBlock returns the begin block for the evm module.
169-
func (am AppModule) BeginBlock(ctx sdk.Context) {
170-
am.keeper.BeginBlock(ctx)
167+
func (am AppModule) BeginBlock(ctx context.Context) error {
168+
return am.keeper.BeginBlock(ctx)
171169
}
172170

173171
// EndBlock returns the end blocker for the evm module. It returns no validator
174172
// updates.
175-
func (am AppModule) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate {
173+
func (am AppModule) EndBlock(ctx context.Context) error {
176174
return am.keeper.EndBlock(ctx)
177175
}
178176

x/feemarket/keeper/abci.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package keeper
1717

1818
import (
19+
"context"
1920
"fmt"
2021

2122
"cosmossdk.io/math"
@@ -26,12 +27,13 @@ import (
2627
)
2728

2829
// BeginBlock updates base fee
29-
func (k *Keeper) BeginBlock(ctx sdk.Context) {
30+
func (k *Keeper) BeginBlock(goCtx context.Context) error {
31+
ctx := sdk.UnwrapSDKContext(goCtx)
3032
baseFee := k.CalculateBaseFee(ctx)
3133

3234
// return immediately if base fee is nil
3335
if baseFee == nil {
34-
return
36+
return nil
3537
}
3638

3739
k.SetBaseFee(ctx, baseFee)
@@ -47,15 +49,17 @@ func (k *Keeper) BeginBlock(ctx sdk.Context) {
4749
sdk.NewAttribute(types.AttributeKeyBaseFee, baseFee.String()),
4850
),
4951
})
52+
return nil
5053
}
5154

5255
// EndBlock update block gas wanted.
5356
// The EVM end block logic doesn't update the validator set, thus it returns
5457
// an empty slice.
55-
func (k *Keeper) EndBlock(ctx sdk.Context) {
58+
func (k *Keeper) EndBlock(goCtx context.Context) error {
59+
ctx := sdk.UnwrapSDKContext(goCtx)
5660
if ctx.BlockGasMeter() == nil {
5761
k.Logger(ctx).Error("block gas meter is nil when setting block gas wanted")
58-
return
62+
return nil
5963
}
6064

6165
gasWanted := k.GetTransientGasWanted(ctx)
@@ -79,4 +83,5 @@ func (k *Keeper) EndBlock(ctx sdk.Context) {
7983
sdk.NewAttribute("height", fmt.Sprintf("%d", ctx.BlockHeight())),
8084
sdk.NewAttribute("amount", fmt.Sprintf("%d", gasWanted)),
8185
))
86+
return nil
8287
}

x/feemarket/module.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import (
2020
"encoding/json"
2121
"fmt"
2222

23-
"github.com/gorilla/mux"
2423
"github.com/grpc-ecosystem/grpc-gateway/runtime"
2524
"github.com/spf13/cobra"
2625

2726
abci "github.com/cometbft/cometbft/abci/types"
2827

28+
"cosmossdk.io/core/appmodule"
2929
"github.com/cosmos/cosmos-sdk/client"
3030
"github.com/cosmos/cosmos-sdk/codec"
3131
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
@@ -39,8 +39,10 @@ import (
3939
)
4040

4141
var (
42-
_ module.AppModule = AppModule{}
43-
_ module.AppModuleBasic = AppModuleBasic{}
42+
_ module.AppModule = AppModule{}
43+
_ appmodule.HasBeginBlocker = AppModule{}
44+
_ appmodule.HasEndBlocker = AppModule{}
45+
_ module.AppModuleBasic = AppModuleBasic{}
4446
)
4547

4648
// AppModuleBasic defines the basic application module used by the fee market module.
@@ -81,11 +83,7 @@ func (AppModuleBasic) ValidateGenesis(
8183
return genesisState.Validate()
8284
}
8385

84-
// RegisterRESTRoutes performs a no-op as the EVM module doesn't expose REST
85-
// endpoints
86-
func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {
87-
}
88-
86+
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the fee market module.
8987
func (b AppModuleBasic) RegisterGRPCGatewayRoutes(c client.Context, serveMux *runtime.ServeMux) {
9088
if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(c)); err != nil {
9189
panic(err)
@@ -156,19 +154,15 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
156154
}
157155
}
158156

159-
// QuerierRoute returns the fee market module's querier route name.
160-
func (AppModule) QuerierRoute() string { return types.RouterKey }
161-
162157
// BeginBlock returns the begin block for the fee market module.
163-
func (am AppModule) BeginBlock(ctx sdk.Context) {
164-
am.keeper.BeginBlock(ctx)
158+
func (am AppModule) BeginBlock(ctx context.Context) error {
159+
return am.keeper.BeginBlock(ctx)
165160
}
166161

167162
// EndBlock returns the end blocker for the fee market module. It returns no validator
168163
// updates.
169-
func (am AppModule) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate {
170-
am.keeper.EndBlock(ctx)
171-
return []abci.ValidatorUpdate{}
164+
func (am AppModule) EndBlock(ctx context.Context) error {
165+
return am.keeper.EndBlock(ctx)
172166
}
173167

174168
// InitGenesis performs genesis initialization for the fee market module. It returns
@@ -192,12 +186,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
192186
return cdc.MustMarshalJSON(gs)
193187
}
194188

195-
// RegisterStoreDecoder registers a decoder for fee market module's types
196-
func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {}
197-
198-
// ProposalContents doesn't return any content functions for governance proposals.
199-
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent {
200-
return nil
189+
// RegisterStoreDecoder registers a decoder for fee module's types
190+
func (am AppModule) RegisterStoreDecoder(_ simtypes.StoreDecoderRegistry) {
201191
}
202192

203193
// GenerateGenesisState creates a randomized GenState of the fee market module.

0 commit comments

Comments
 (0)