feat: add endblocker with valsetupdate type (#15829)

This commit is contained in:
Marko
2023-04-14 09:41:29 +00:00
committed by GitHub
parent 722bea5b40
commit 8d6c23faa4
18 changed files with 200 additions and 73 deletions
@@ -1,27 +1,26 @@
package staking
package keeper
import (
"context"
"time"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
// BeginBlocker will persist the current header and validator set as a historical entry
// and prune the oldest entry based on the HistoricalEntries parameter
func BeginBlocker(ctx sdk.Context, k *keeper.Keeper) {
func (k *Keeper) BeginBlocker(ctx sdk.Context) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker)
k.TrackHistoricalInfo(ctx)
}
// Called every block, update validator set
func EndBlocker(ctx sdk.Context, k *keeper.Keeper) []abci.ValidatorUpdate {
func (k *Keeper) EndBlocker(ctx context.Context) ([]abci.ValidatorUpdate, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker)
return k.BlockValidatorUpdates(ctx)
return k.BlockValidatorUpdates(sdk.UnwrapSDKContext(ctx)), nil
}
+14 -14
View File
@@ -6,28 +6,25 @@ import (
"fmt"
"sort"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/staking/exported"
modulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
store "cosmossdk.io/store/types"
abci "github.com/cometbft/cometbft/abci/types"
gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"
"golang.org/x/exp/maps"
modulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/depinject"
store "cosmossdk.io/store/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/staking/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking/exported"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/simulation"
"github.com/cosmos/cosmos-sdk/x/staking/types"
@@ -38,7 +35,9 @@ const (
)
var (
_ module.EndBlockAppModule = AppModule{}
_ appmodule.AppModule = AppModule{}
_ appmodule.HasBeginBlocker = AppModule{}
_ module.HasABCIEndblock = AppModule{}
_ module.AppModuleBasic = AppModuleBasic{}
_ module.AppModuleSimulation = AppModule{}
)
@@ -191,14 +190,15 @@ func (AppModule) ConsensusVersion() uint64 { return consensusVersion }
// BeginBlock returns the begin blocker for the staking module.
func (am AppModule) BeginBlock(ctx context.Context) error {
c := sdk.UnwrapSDKContext(ctx)
BeginBlocker(c, am.keeper)
am.keeper.BeginBlocker(c)
return nil
}
// EndBlock returns the end blocker for the staking module. It returns no validator
// updates.
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate {
return EndBlocker(ctx, am.keeper)
func (am AppModule) EndBlock(ctx context.Context) ([]abci.ValidatorUpdate, error) {
return am.keeper.EndBlocker(ctx)
}
func init() {
+2 -3
View File
@@ -10,7 +10,6 @@ import (
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
@@ -127,7 +126,7 @@ func (sh *Helper) CheckDelegator(delegator sdk.AccAddress, val sdk.ValAddress, f
// TurnBlock calls EndBlocker and updates the block time
func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context {
sh.Ctx = sh.Ctx.WithBlockTime(newTime)
staking.EndBlocker(sh.Ctx, sh.k)
sh.k.EndBlocker(sh.Ctx)
return sh.Ctx
}
@@ -135,7 +134,7 @@ func (sh *Helper) TurnBlock(newTime time.Time) sdk.Context {
// duration to the current block time
func (sh *Helper) TurnBlockTimeDiff(diff time.Duration) sdk.Context {
sh.Ctx = sh.Ctx.WithBlockTime(sh.Ctx.BlockHeader().Time.Add(diff))
staking.EndBlocker(sh.Ctx, sh.k)
sh.k.EndBlocker(sh.Ctx)
return sh.Ctx
}