From dde70d65203e2ee060e8077107119a55ca94c435 Mon Sep 17 00:00:00 2001 From: jhernandezb Date: Tue, 7 Jan 2025 22:48:31 -0600 Subject: [PATCH] fix begin/end blockers --- x/alloc/abci.go | 4 +++- x/alloc/module.go | 6 ++++-- x/mint/abci.go | 4 +++- x/mint/module.go | 9 ++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/x/alloc/abci.go b/x/alloc/abci.go index 4c3d4779e..fa102d523 100644 --- a/x/alloc/abci.go +++ b/x/alloc/abci.go @@ -1,6 +1,7 @@ package alloc import ( + "context" "fmt" "time" @@ -11,7 +12,8 @@ import ( ) // BeginBlocker to distribute specific rewards on every begin block -func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { +func BeginBlocker(goCtx context.Context, k keeper.Keeper) { + ctx := sdk.UnwrapSDKContext(goCtx) defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) if err := k.DistributeInflation(ctx); err != nil { panic(fmt.Sprintf("Error distribute inflation: %s", err.Error())) diff --git a/x/alloc/module.go b/x/alloc/module.go index 6ffcb46ef..0bcab5215 100644 --- a/x/alloc/module.go +++ b/x/alloc/module.go @@ -7,6 +7,7 @@ import ( // this line is used by starport scaffolding # 1 + "cosmossdk.io/core/appmodule" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -23,8 +24,9 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ appmodule.HasBeginBlocker = AppModule{} ) // ---------------------------------------------------------------------------- diff --git a/x/mint/abci.go b/x/mint/abci.go index 48abeb37d..b8f15446d 100644 --- a/x/mint/abci.go +++ b/x/mint/abci.go @@ -1,6 +1,7 @@ package mint import ( + "context" "time" "github.com/cosmos/cosmos-sdk/telemetry" @@ -10,7 +11,8 @@ import ( ) // BeginBlocker mints new tokens for the previous block. -func BeginBlocker(ctx sdk.Context, k keeper.Keeper) { +func BeginBlocker(goCtx context.Context, k keeper.Keeper) { + ctx := sdk.UnwrapSDKContext(goCtx) defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) // fetch stored minter & params diff --git a/x/mint/module.go b/x/mint/module.go index 0de9d6e2c..a3fc69e69 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" + "cosmossdk.io/core/appmodule" abci "github.com/cometbft/cometbft/abci/types" "github.com/gorilla/mux" "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -21,8 +22,9 @@ import ( ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ appmodule.HasBeginBlocker = AppModule{} ) // AppModuleBasic defines the basic application module used by the mint module. @@ -145,8 +147,9 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) ConsensusVersion() uint64 { return 2 } // BeginBlock returns the begin blocker for the mint module. -func (am AppModule) BeginBlock(ctx sdk.Context) { +func (am AppModule) BeginBlock(ctx context.Context) error { BeginBlocker(ctx, am.keeper) + return nil } // EndBlock returns the end blocker for the mint module. It returns no validator