From f56749855e59c1227ba57273278e181cffa0e60d Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Fri, 2 Feb 2024 16:19:46 +0100 Subject: [PATCH 1/3] Change usages of HeaderInfo().heigh to BlockHeight() --- app/export.go | 2 +- testutil/datagen/tendermint.go | 2 +- x/btcstaking/keeper/btc_height_index.go | 4 ++-- x/btcstaking/keeper/finality_providers.go | 2 +- x/btcstaking/keeper/incentive.go | 2 +- x/btcstaking/keeper/keeper_test.go | 2 +- x/btcstaking/keeper/voting_power_table.go | 2 +- x/checkpointing/keeper/keeper_test.go | 2 +- x/checkpointing/types/types.go | 2 +- x/epoching/keeper/apphash_chain.go | 2 +- x/epoching/keeper/drop_validator_msg_decorator.go | 3 ++- x/epoching/keeper/epochs.go | 6 +++--- x/epoching/keeper/grpc_query_test.go | 7 +++---- x/epoching/keeper/lifecycle_delegation.go | 2 +- x/epoching/keeper/lifecycle_validator.go | 2 +- x/epoching/keeper/modified_staking.go | 2 +- x/epoching/keeper/msg_server.go | 6 +++--- x/epoching/types/epoching.go | 10 +++++----- x/finality/keeper/evidence.go | 2 +- x/finality/keeper/msg_server_test.go | 4 ++-- x/finality/keeper/tallying.go | 4 ++-- x/finality/keeper/votes.go | 2 +- x/incentive/abci.go | 2 +- x/incentive/keeper/btc_staking_gauge.go | 2 +- 24 files changed, 38 insertions(+), 38 deletions(-) diff --git a/app/export.go b/app/export.go index 105c96987..a13680dce 100644 --- a/app/export.go +++ b/app/export.go @@ -117,7 +117,7 @@ func (app *BabylonApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) // set context height to zero - height := ctx.HeaderInfo().Height + height := ctx.BlockHeight() headerInfo := ctx.HeaderInfo() headerInfo.Height = 0 ctx = ctx.WithHeaderInfo(headerInfo) diff --git a/testutil/datagen/tendermint.go b/testutil/datagen/tendermint.go index cea24c2e5..e5a717037 100644 --- a/testutil/datagen/tendermint.go +++ b/testutil/datagen/tendermint.go @@ -56,6 +56,6 @@ func HeaderToHeaderInfo(header *ibctmtypes.Header) *zctypes.HeaderInfo { func WithCtxHeight(ctx sdk.Context, height uint64) sdk.Context { headerInfo := ctx.HeaderInfo() headerInfo.Height = int64(height) - ctx = ctx.WithHeaderInfo(headerInfo) + ctx = ctx.WithHeaderInfo(headerInfo).WithBlockHeader(cmtproto.Header{Height: int64(height)}) return ctx } diff --git a/x/btcstaking/keeper/btc_height_index.go b/x/btcstaking/keeper/btc_height_index.go index 9ed5e3961..7dfb4822f 100644 --- a/x/btcstaking/keeper/btc_height_index.go +++ b/x/btcstaking/keeper/btc_height_index.go @@ -11,7 +11,7 @@ import ( // IndexBTCHeight indexes the current BTC height, and saves it to KVStore func (k Keeper) IndexBTCHeight(ctx context.Context) { - babylonHeight := uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + babylonHeight := uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) btcTip := k.btclcKeeper.GetTipInfo(ctx) if btcTip == nil { return @@ -31,7 +31,7 @@ func (k Keeper) GetBTCHeightAtBabylonHeight(ctx context.Context, babylonHeight u } func (k Keeper) GetCurrentBTCHeight(ctx context.Context) (uint64, error) { - babylonHeight := uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + babylonHeight := uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) return k.GetBTCHeightAtBabylonHeight(ctx, babylonHeight) } diff --git a/x/btcstaking/keeper/finality_providers.go b/x/btcstaking/keeper/finality_providers.go index 01b7e0c77..77341d114 100644 --- a/x/btcstaking/keeper/finality_providers.go +++ b/x/btcstaking/keeper/finality_providers.go @@ -46,7 +46,7 @@ func (k Keeper) SlashFinalityProvider(ctx context.Context, fpBTCPK []byte) error if fp.IsSlashed() { return types.ErrFpAlreadySlashed } - fp.SlashedBabylonHeight = uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + fp.SlashedBabylonHeight = uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) btcTip := k.btclcKeeper.GetTipInfo(ctx) if btcTip == nil { panic(fmt.Errorf("failed to get current BTC tip")) diff --git a/x/btcstaking/keeper/incentive.go b/x/btcstaking/keeper/incentive.go index 622397ed4..439ff5596 100644 --- a/x/btcstaking/keeper/incentive.go +++ b/x/btcstaking/keeper/incentive.go @@ -69,7 +69,7 @@ func (k Keeper) RecordRewardDistCache(ctx context.Context) { } // all good, set the reward distribution cache of the current height - k.setRewardDistCache(ctx, uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height), rdc) + k.setRewardDistCache(ctx, uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()), rdc) } func (k Keeper) setRewardDistCache(ctx context.Context, height uint64, rdc *types.RewardDistCache) { diff --git a/x/btcstaking/keeper/keeper_test.go b/x/btcstaking/keeper/keeper_test.go index 3d3c30a50..fef834ed8 100644 --- a/x/btcstaking/keeper/keeper_test.go +++ b/x/btcstaking/keeper/keeper_test.go @@ -35,7 +35,7 @@ type Helper struct { func NewHelper(t testing.TB, btclcKeeper *types.MockBTCLightClientKeeper, btccKeeper *types.MockBtcCheckpointKeeper) *Helper { k, ctx := keepertest.BTCStakingKeeper(t, btclcKeeper, btccKeeper) - ctx = ctx.WithHeaderInfo(header.Info{Height: 1}) + ctx = ctx.WithHeaderInfo(header.Info{Height: 1}).WithBlockHeight(1) msgSrvr := keeper.NewMsgServerImpl(*k) return &Helper{ diff --git a/x/btcstaking/keeper/voting_power_table.go b/x/btcstaking/keeper/voting_power_table.go index b2981c12a..652aaedc5 100644 --- a/x/btcstaking/keeper/voting_power_table.go +++ b/x/btcstaking/keeper/voting_power_table.go @@ -18,7 +18,7 @@ import ( func (k Keeper) RecordVotingPowerTable(ctx context.Context) { covenantQuorum := k.GetParams(ctx).CovenantQuorum // tip of Babylon and Bitcoin - babylonTipHeight := uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + babylonTipHeight := uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) btcTipHeight, err := k.GetCurrentBTCHeight(ctx) if err != nil { return diff --git a/x/checkpointing/keeper/keeper_test.go b/x/checkpointing/keeper/keeper_test.go index 4dd46f58d..3112473c3 100644 --- a/x/checkpointing/keeper/keeper_test.go +++ b/x/checkpointing/keeper/keeper_test.go @@ -261,7 +261,7 @@ func makeBtcCkptBytes(r *rand.Rand, epoch uint64, appHash []byte, bitmap []byte, } func curStateUpdate(ctx sdk.Context, status types.CheckpointStatus) *types.CheckpointStateUpdate { - height, time := ctx.HeaderInfo().Height, ctx.HeaderInfo().Time + height, time := ctx.BlockHeight(), ctx.HeaderInfo().Time return &types.CheckpointStateUpdate{ State: status, BlockHeight: uint64(height), diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index 49bb68f62..dcb81428c 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -115,7 +115,7 @@ func (cm *RawCheckpointWithMeta) IsMoreMatureThanStatus(status CheckpointStatus) // where the time/height are captured by the current ctx func (cm *RawCheckpointWithMeta) RecordStateUpdate(ctx context.Context, status CheckpointStatus) { sdkCtx := sdk.UnwrapSDKContext(ctx) - height, time := sdkCtx.HeaderInfo().Height, sdkCtx.HeaderInfo().Time + height, time := sdkCtx.BlockHeight(), sdkCtx.HeaderInfo().Time stateUpdate := &CheckpointStateUpdate{ State: status, BlockHeight: uint64(height), diff --git a/x/epoching/keeper/apphash_chain.go b/x/epoching/keeper/apphash_chain.go index 3a36b85f4..8dad6b41e 100644 --- a/x/epoching/keeper/apphash_chain.go +++ b/x/epoching/keeper/apphash_chain.go @@ -35,7 +35,7 @@ func (k Keeper) GetAppHash(ctx context.Context, height uint64) ([]byte, error) { // RecordAppHash stores the AppHash of the current header to KVStore func (k Keeper) RecordAppHash(ctx context.Context) { sdkCtx := sdk.UnwrapSDKContext(ctx) - height := uint64(sdkCtx.HeaderInfo().Height) + height := uint64(sdkCtx.BlockHeight()) appHash := sdkCtx.HeaderInfo().AppHash // HACK: the app hash for the first height is set to nil // instead of the hash of an empty byte slice as intended diff --git a/x/epoching/keeper/drop_validator_msg_decorator.go b/x/epoching/keeper/drop_validator_msg_decorator.go index 54fff1349..da4d6ac02 100644 --- a/x/epoching/keeper/drop_validator_msg_decorator.go +++ b/x/epoching/keeper/drop_validator_msg_decorator.go @@ -27,9 +27,10 @@ func NewDropValidatorMsgDecorator(ek Keeper) *DropValidatorMsgDecorator { // - MsgCancelUnbondingDelegation func (qmd DropValidatorMsgDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { // skip if at genesis block, as genesis state contains txs that bootstrap the initial validator set - if ctx.HeaderInfo().Height == 0 { + if ctx.BlockHeight() == 0 { return next(ctx, tx, simulate) } + // BlockHeight() // after genesis, if validator-related message, reject msg for _, msg := range tx.GetMsgs() { if qmd.IsValidatorRelatedMsg(msg) { diff --git a/x/epoching/keeper/epochs.go b/x/epoching/keeper/epochs.go index 48ff16606..4db992c89 100644 --- a/x/epoching/keeper/epochs.go +++ b/x/epoching/keeper/epochs.go @@ -88,7 +88,7 @@ func (k Keeper) RecordSealerAppHashForPrevEpoch(ctx context.Context) *types.Epoc epoch := k.GetEpoch(ctx) if !epoch.IsFirstBlock(ctx) { panic(fmt.Errorf("RecordSealerAppHashForPrevEpoch can only be invoked at the first header of a non-zero epoch. "+ - "current epoch: %v, current height: %d", epoch, sdk.UnwrapSDKContext(ctx).HeaderInfo().Height)) + "current epoch: %v, current height: %d", epoch, sdk.UnwrapSDKContext(ctx).BlockHeight())) } header := sdk.UnwrapSDKContext(ctx).HeaderInfo() @@ -112,7 +112,7 @@ func (k Keeper) RecordSealerBlockHashForEpoch(ctx context.Context) *types.Epoch epoch := k.GetEpoch(ctx) if !epoch.IsLastBlock(ctx) { panic(fmt.Errorf("RecordSealerBlockHashForEpoch can only be invoked at the last header of a non-zero epoch. "+ - "current epoch: %v, current height: %d", epoch, sdk.UnwrapSDKContext(ctx).HeaderInfo().Height)) + "current epoch: %v, current height: %d", epoch, sdk.UnwrapSDKContext(ctx).BlockHeight())) } header := sdk.UnwrapSDKContext(ctx).HeaderInfo() @@ -131,7 +131,7 @@ func (k Keeper) IncEpoch(ctx context.Context) types.Epoch { incrementedEpochNumber := epochNumber + 1 epochInterval := k.GetParams(ctx).EpochInterval - newEpoch := types.NewEpoch(incrementedEpochNumber, epochInterval, uint64(sdkCtx.HeaderInfo().Height), nil) + newEpoch := types.NewEpoch(incrementedEpochNumber, epochInterval, uint64(sdkCtx.BlockHeight()), nil) k.setEpochInfo(ctx, incrementedEpochNumber, &newEpoch) return newEpoch diff --git a/x/epoching/keeper/grpc_query_test.go b/x/epoching/keeper/grpc_query_test.go index 8e528da99..033e45655 100644 --- a/x/epoching/keeper/grpc_query_test.go +++ b/x/epoching/keeper/grpc_query_test.go @@ -7,12 +7,11 @@ import ( "cosmossdk.io/core/header" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" - "github.com/babylonchain/babylon/testutil/datagen" testhelper "github.com/babylonchain/babylon/testutil/helper" "github.com/babylonchain/babylon/x/epoching/types" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/stretchr/testify/require" ) // FuzzParamsQuery fuzzes queryClient.Params @@ -85,7 +84,7 @@ func FuzzCurrentEpoch(f *testing.F) { Time: randomHeader.Time, ChainID: randomHeader.ChainID, } - ctx = ctx.WithHeaderInfo(headerInfo) + ctx = ctx.WithHeaderInfo(headerInfo).WithBlockHeader(*randomHeader) keeper.IncEpoch(ctx) } req := types.QueryCurrentEpochRequest{} diff --git a/x/epoching/keeper/lifecycle_delegation.go b/x/epoching/keeper/lifecycle_delegation.go index d00859908..9ba7211c3 100644 --- a/x/epoching/keeper/lifecycle_delegation.go +++ b/x/epoching/keeper/lifecycle_delegation.go @@ -21,7 +21,7 @@ func (k Keeper) RecordNewDelegationState(ctx context.Context, delAddr sdk.AccAdd } } sdkCtx := sdk.UnwrapSDKContext(ctx) - height, time := sdkCtx.HeaderInfo().Height, sdkCtx.HeaderInfo().Time + height, time := sdkCtx.BlockHeight(), sdkCtx.HeaderInfo().Time DelegationStateUpdate := types.DelegationStateUpdate{ State: state, ValAddr: valAddr.String(), diff --git a/x/epoching/keeper/lifecycle_validator.go b/x/epoching/keeper/lifecycle_validator.go index 75f6250bf..d201eda76 100644 --- a/x/epoching/keeper/lifecycle_validator.go +++ b/x/epoching/keeper/lifecycle_validator.go @@ -20,7 +20,7 @@ func (k Keeper) RecordNewValState(ctx sdk.Context, valAddr sdk.ValAddress, state ValLife: []*types.ValStateUpdate{}, } } - height, time := ctx.HeaderInfo().Height, ctx.HeaderInfo().Time + height, time := ctx.BlockHeight(), ctx.HeaderInfo().Time valStateUpdate := types.ValStateUpdate{ State: state, BlockHeight: uint64(height), diff --git a/x/epoching/keeper/modified_staking.go b/x/epoching/keeper/modified_staking.go index 44c193494..edcc68194 100644 --- a/x/epoching/keeper/modified_staking.go +++ b/x/epoching/keeper/modified_staking.go @@ -170,7 +170,7 @@ func (k Keeper) getAllMatureValidators(ctx sdk.Context) []sdk.ValAddress { matureValAddrs := []sdk.ValAddress{} blockTime := ctx.HeaderInfo().Time - blockHeight := ctx.HeaderInfo().Height + blockHeight := ctx.BlockHeight() // unbondingValIterator will contains all validator addresses indexed under // the ValidatorQueueKey prefix. Note, the entire index key is composed as diff --git a/x/epoching/keeper/msg_server.go b/x/epoching/keeper/msg_server.go index 3db5b554d..7548aaa46 100644 --- a/x/epoching/keeper/msg_server.go +++ b/x/epoching/keeper/msg_server.go @@ -51,7 +51,7 @@ func (ms msgServer) WrappedDelegate(goCtx context.Context, msg *types.MsgWrapped ) } - blockHeight := uint64(ctx.HeaderInfo().Height) + blockHeight := uint64(ctx.BlockHeight()) if blockHeight == 0 { return nil, types.ErrZeroEpochMsg } @@ -110,7 +110,7 @@ func (ms msgServer) WrappedUndelegate(goCtx context.Context, msg *types.MsgWrapp ) } - blockHeight := uint64(ctx.HeaderInfo().Height) + blockHeight := uint64(ctx.BlockHeight()) if blockHeight == 0 { return nil, types.ErrZeroEpochMsg } @@ -172,7 +172,7 @@ func (ms msgServer) WrappedBeginRedelegate(goCtx context.Context, msg *types.Msg return nil, err } - blockHeight := uint64(ctx.HeaderInfo().Height) + blockHeight := uint64(ctx.BlockHeight()) if blockHeight == 0 { return nil, types.ErrZeroEpochMsg } diff --git a/x/epoching/types/epoching.go b/x/epoching/types/epoching.go index 295fe7671..be46dbfa6 100644 --- a/x/epoching/types/epoching.go +++ b/x/epoching/types/epoching.go @@ -46,7 +46,7 @@ func (e Epoch) GetSecondBlockHeight() uint64 { } func (e Epoch) IsLastBlock(ctx context.Context) bool { - return e.GetLastBlockHeight() == uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + return e.GetLastBlockHeight() == uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) } func (e Epoch) IsLastBlockByHeight(height int64) bool { @@ -54,14 +54,14 @@ func (e Epoch) IsLastBlockByHeight(height int64) bool { } func (e Epoch) IsFirstBlock(ctx context.Context) bool { - return e.FirstBlockHeight == uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + return e.FirstBlockHeight == uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) } func (e Epoch) IsSecondBlock(ctx context.Context) bool { if e.EpochNumber == 0 { return false } - return e.GetSecondBlockHeight() == uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + return e.GetSecondBlockHeight() == uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) } func (e Epoch) IsVoteExtensionProposal(ctx context.Context) bool { @@ -79,9 +79,9 @@ func (e Epoch) IsVoteExtensionProposal(ctx context.Context) bool { func (e Epoch) IsFirstBlockOfNextEpoch(ctx context.Context) bool { sdkCtx := sdk.UnwrapSDKContext(ctx) if e.EpochNumber == 0 { - return sdkCtx.HeaderInfo().Height == 1 + return sdkCtx.BlockHeight() == 1 } else { - height := uint64(sdkCtx.HeaderInfo().Height) + height := uint64(sdkCtx.BlockHeight()) return e.FirstBlockHeight+e.CurrentEpochInterval == height } } diff --git a/x/finality/keeper/evidence.go b/x/finality/keeper/evidence.go index 0d9f610ad..8b6678e59 100644 --- a/x/finality/keeper/evidence.go +++ b/x/finality/keeper/evidence.go @@ -21,7 +21,7 @@ func (k Keeper) HasEvidence(ctx context.Context, fpBtcPK *bbn.BIP340PubKey, heig } func (k Keeper) GetEvidence(ctx context.Context, fpBtcPK *bbn.BIP340PubKey, height uint64) (*types.Evidence, error) { - if uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) < height { + if uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) < height { return nil, types.ErrHeightTooHigh } store := k.evidenceStore(ctx, fpBtcPK) diff --git a/x/finality/keeper/msg_server_test.go b/x/finality/keeper/msg_server_test.go index a2420df4a..70fd72cf9 100644 --- a/x/finality/keeper/msg_server_test.go +++ b/x/finality/keeper/msg_server_test.go @@ -4,7 +4,7 @@ import ( "context" "math/rand" "testing" - + cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" "cosmossdk.io/core/header" "github.com/babylonchain/babylon/testutil/datagen" keepertest "github.com/babylonchain/babylon/testutil/keeper" @@ -156,7 +156,7 @@ func FuzzAddFinalitySig(f *testing.F) { // Case 3: successful if the finality provider has voting power and has not casted this vote yet // index this block first - ctx = ctx.WithHeaderInfo(header.Info{Height: int64(blockHeight), AppHash: blockHash}) + ctx = ctx.WithHeaderInfo(header.Info{Height: int64(blockHeight), AppHash: blockHash}).WithBlockHeader(cmtproto.Header{Height: int64(blockHeight), AppHash: blockHash}) fKeeper.IndexBlock(ctx) bsKeeper.EXPECT().GetFinalityProvider(gomock.Any(), gomock.Eq(fpBTCPKBytes)).Return(fp, nil).Times(1) // add vote and it should work diff --git a/x/finality/keeper/tallying.go b/x/finality/keeper/tallying.go index 68c1a4f0d..d9a447b3f 100644 --- a/x/finality/keeper/tallying.go +++ b/x/finality/keeper/tallying.go @@ -22,7 +22,7 @@ func (k Keeper) TallyBlocks(ctx context.Context) { if err != nil { // invoking TallyBlocks when BTC staking protocol is not activated is a programming error panic(fmt.Errorf("cannot tally a block when the BTC staking protocol hasn't been activated yet, current height: %v, activated height: %v", - sdkCtx.HeaderInfo().Height, activatedHeight)) + sdkCtx.BlockHeight(), activatedHeight)) } // start finalising blocks since max(activatedHeight, nextHeightToFinalize) @@ -38,7 +38,7 @@ func (k Keeper) TallyBlocks(ctx context.Context) { // - has finality providers, finalised: impossible to happen, panic // - does not have finality providers, finalised: impossible to happen, panic // After this for loop, the blocks since earliest activated height are either finalised or non-finalisable - for i := startHeight; i <= uint64(sdkCtx.HeaderInfo().Height); i++ { + for i := startHeight; i <= uint64(sdkCtx.BlockHeight()); i++ { ib, err := k.GetBlock(ctx, i) if err != nil { panic(err) // failing to get an existing block is a programming error diff --git a/x/finality/keeper/votes.go b/x/finality/keeper/votes.go index 44bd6352b..220a58b3c 100644 --- a/x/finality/keeper/votes.go +++ b/x/finality/keeper/votes.go @@ -23,7 +23,7 @@ func (k Keeper) HasSig(ctx context.Context, height uint64, fpBtcPK *bbn.BIP340Pu } func (k Keeper) GetSig(ctx context.Context, height uint64, fpBtcPK *bbn.BIP340PubKey) (*bbn.SchnorrEOTSSig, error) { - if uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) < height { + if uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) < height { return nil, types.ErrHeightTooHigh } store := k.voteStore(ctx, height) diff --git a/x/incentive/abci.go b/x/incentive/abci.go index 66cdb7da9..e8e685d09 100644 --- a/x/incentive/abci.go +++ b/x/incentive/abci.go @@ -18,7 +18,7 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error { // - send a portion of coins in the fee collector account to the incentive module account // - accumulate BTC staking gauge at the current height // - accumulate BTC timestamping gauge at the current epoch - if sdk.UnwrapSDKContext(ctx).HeaderInfo().Height > 0 { + if sdk.UnwrapSDKContext(ctx).BlockHeight() > 0 { k.HandleCoinsInFeeCollector(ctx) } return nil diff --git a/x/incentive/keeper/btc_staking_gauge.go b/x/incentive/keeper/btc_staking_gauge.go index b3067ab65..a690f3ed6 100644 --- a/x/incentive/keeper/btc_staking_gauge.go +++ b/x/incentive/keeper/btc_staking_gauge.go @@ -41,7 +41,7 @@ func (k Keeper) RewardBTCStaking(ctx context.Context, height uint64, rdc *bstype func (k Keeper) accumulateBTCStakingReward(ctx context.Context, btcStakingReward sdk.Coins) { // update BTC staking gauge - height := uint64(sdk.UnwrapSDKContext(ctx).HeaderInfo().Height) + height := uint64(sdk.UnwrapSDKContext(ctx).BlockHeight()) gauge := types.NewGauge(btcStakingReward...) k.SetBTCStakingGauge(ctx, height, gauge) From 0959b53f4679e8e63c5a8b9e7fdbbe0aa407dc81 Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Fri, 2 Feb 2024 16:27:18 +0100 Subject: [PATCH 2/3] Do not use HeaderInfo() in other places --- x/checkpointing/keeper/keeper_test.go | 2 +- x/checkpointing/types/types.go | 2 +- x/epoching/keeper/apphash_chain.go | 2 +- x/epoching/keeper/lifecycle_delegation.go | 2 +- x/epoching/keeper/lifecycle_validator.go | 2 +- x/epoching/keeper/modified_staking.go | 2 +- x/epoching/keeper/msg_server.go | 6 +++--- x/epoching/keeper/staking_functions.go | 2 +- x/zoneconcierge/keeper/ibc_packet.go | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/x/checkpointing/keeper/keeper_test.go b/x/checkpointing/keeper/keeper_test.go index 3112473c3..34f560ccc 100644 --- a/x/checkpointing/keeper/keeper_test.go +++ b/x/checkpointing/keeper/keeper_test.go @@ -261,7 +261,7 @@ func makeBtcCkptBytes(r *rand.Rand, epoch uint64, appHash []byte, bitmap []byte, } func curStateUpdate(ctx sdk.Context, status types.CheckpointStatus) *types.CheckpointStateUpdate { - height, time := ctx.BlockHeight(), ctx.HeaderInfo().Time + height, time := ctx.BlockHeight(), ctx.BlockTime() return &types.CheckpointStateUpdate{ State: status, BlockHeight: uint64(height), diff --git a/x/checkpointing/types/types.go b/x/checkpointing/types/types.go index dcb81428c..9c39a9731 100644 --- a/x/checkpointing/types/types.go +++ b/x/checkpointing/types/types.go @@ -115,7 +115,7 @@ func (cm *RawCheckpointWithMeta) IsMoreMatureThanStatus(status CheckpointStatus) // where the time/height are captured by the current ctx func (cm *RawCheckpointWithMeta) RecordStateUpdate(ctx context.Context, status CheckpointStatus) { sdkCtx := sdk.UnwrapSDKContext(ctx) - height, time := sdkCtx.BlockHeight(), sdkCtx.HeaderInfo().Time + height, time := sdkCtx.BlockHeight(), sdkCtx.BlockTime() stateUpdate := &CheckpointStateUpdate{ State: status, BlockHeight: uint64(height), diff --git a/x/epoching/keeper/apphash_chain.go b/x/epoching/keeper/apphash_chain.go index 8dad6b41e..f97559237 100644 --- a/x/epoching/keeper/apphash_chain.go +++ b/x/epoching/keeper/apphash_chain.go @@ -36,7 +36,7 @@ func (k Keeper) GetAppHash(ctx context.Context, height uint64) ([]byte, error) { func (k Keeper) RecordAppHash(ctx context.Context) { sdkCtx := sdk.UnwrapSDKContext(ctx) height := uint64(sdkCtx.BlockHeight()) - appHash := sdkCtx.HeaderInfo().AppHash + appHash := sdkCtx.BlockHeader().AppHash // HACK: the app hash for the first height is set to nil // instead of the hash of an empty byte slice as intended // see proposed fix: https://github.com/cosmos/cosmos-sdk/pull/18524 diff --git a/x/epoching/keeper/lifecycle_delegation.go b/x/epoching/keeper/lifecycle_delegation.go index 9ba7211c3..b127e3762 100644 --- a/x/epoching/keeper/lifecycle_delegation.go +++ b/x/epoching/keeper/lifecycle_delegation.go @@ -21,7 +21,7 @@ func (k Keeper) RecordNewDelegationState(ctx context.Context, delAddr sdk.AccAdd } } sdkCtx := sdk.UnwrapSDKContext(ctx) - height, time := sdkCtx.BlockHeight(), sdkCtx.HeaderInfo().Time + height, time := sdkCtx.BlockHeight(), sdkCtx.BlockTime() DelegationStateUpdate := types.DelegationStateUpdate{ State: state, ValAddr: valAddr.String(), diff --git a/x/epoching/keeper/lifecycle_validator.go b/x/epoching/keeper/lifecycle_validator.go index d201eda76..30ca62c56 100644 --- a/x/epoching/keeper/lifecycle_validator.go +++ b/x/epoching/keeper/lifecycle_validator.go @@ -20,7 +20,7 @@ func (k Keeper) RecordNewValState(ctx sdk.Context, valAddr sdk.ValAddress, state ValLife: []*types.ValStateUpdate{}, } } - height, time := ctx.BlockHeight(), ctx.HeaderInfo().Time + height, time := ctx.BlockHeight(), ctx.BlockTime() valStateUpdate := types.ValStateUpdate{ State: state, BlockHeight: uint64(height), diff --git a/x/epoching/keeper/modified_staking.go b/x/epoching/keeper/modified_staking.go index edcc68194..6edde61ce 100644 --- a/x/epoching/keeper/modified_staking.go +++ b/x/epoching/keeper/modified_staking.go @@ -169,7 +169,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) []abci.Va func (k Keeper) getAllMatureValidators(ctx sdk.Context) []sdk.ValAddress { matureValAddrs := []sdk.ValAddress{} - blockTime := ctx.HeaderInfo().Time + blockTime := ctx.BlockTime() blockHeight := ctx.BlockHeight() // unbondingValIterator will contains all validator addresses indexed under diff --git a/x/epoching/keeper/msg_server.go b/x/epoching/keeper/msg_server.go index 7548aaa46..52001a60b 100644 --- a/x/epoching/keeper/msg_server.go +++ b/x/epoching/keeper/msg_server.go @@ -55,7 +55,7 @@ func (ms msgServer) WrappedDelegate(goCtx context.Context, msg *types.MsgWrapped if blockHeight == 0 { return nil, types.ErrZeroEpochMsg } - blockTime := ctx.HeaderInfo().Time + blockTime := ctx.BlockTime() txid := tmhash.Sum(ctx.TxBytes()) queuedMsg, err := types.NewQueuedMessage(blockHeight, blockTime, txid, msg) @@ -114,7 +114,7 @@ func (ms msgServer) WrappedUndelegate(goCtx context.Context, msg *types.MsgWrapp if blockHeight == 0 { return nil, types.ErrZeroEpochMsg } - blockTime := ctx.HeaderInfo().Time + blockTime := ctx.BlockTime() txid := tmhash.Sum(ctx.TxBytes()) queuedMsg, err := types.NewQueuedMessage(blockHeight, blockTime, txid, msg) @@ -176,7 +176,7 @@ func (ms msgServer) WrappedBeginRedelegate(goCtx context.Context, msg *types.Msg if blockHeight == 0 { return nil, types.ErrZeroEpochMsg } - blockTime := ctx.HeaderInfo().Time + blockTime := ctx.BlockTime() txid := tmhash.Sum(ctx.TxBytes()) queuedMsg, err := types.NewQueuedMessage(blockHeight, blockTime, txid, msg) diff --git a/x/epoching/keeper/staking_functions.go b/x/epoching/keeper/staking_functions.go index 577e7c88e..a94e9b7f9 100644 --- a/x/epoching/keeper/staking_functions.go +++ b/x/epoching/keeper/staking_functions.go @@ -92,7 +92,7 @@ func (k Keeper) CheckMsgCreateValidator(ctx context.Context, msg *stakingtypes.M // check if SetInitialCommission fails or not commission := stakingtypes.NewCommissionWithTime( msg.Commission.Rate, msg.Commission.MaxRate, - msg.Commission.MaxChangeRate, sdkCtx.HeaderInfo().Time, + msg.Commission.MaxChangeRate, sdkCtx.BlockTime(), ) if _, err := validator.SetInitialCommission(commission); err != nil { return err diff --git a/x/zoneconcierge/keeper/ibc_packet.go b/x/zoneconcierge/keeper/ibc_packet.go index 266e8fd35..e0d848af2 100644 --- a/x/zoneconcierge/keeper/ibc_packet.go +++ b/x/zoneconcierge/keeper/ibc_packet.go @@ -36,7 +36,7 @@ func (k Keeper) SendIBCPacket(ctx context.Context, channel channeltypes.Identifi // timeout timeoutPeriod := time.Duration(k.GetParams(sdkCtx).IbcPacketTimeoutSeconds) * time.Second - timeoutTime := uint64(sdkCtx.HeaderInfo().Time.Add(timeoutPeriod).UnixNano()) + timeoutTime := uint64(sdkCtx.BlockTime().Add(timeoutPeriod).UnixNano()) zeroheight := clienttypes.ZeroHeight() seq, err := k.ics4Wrapper.SendPacket( From 80b86e3573fa9654c5d09d8bca389a8daee2bc8a Mon Sep 17 00:00:00 2001 From: KonradStaniec Date: Fri, 2 Feb 2024 16:34:45 +0100 Subject: [PATCH 3/3] Do not use HeaderInfo() in other places some left overs --- app/export.go | 4 ++-- x/epoching/keeper/epochs.go | 9 ++++----- x/finality/keeper/indexed_blocks.go | 6 +++--- x/zoneconcierge/keeper/header_handler.go | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/export.go b/app/export.go index a13680dce..bda770619 100644 --- a/app/export.go +++ b/app/export.go @@ -120,7 +120,7 @@ func (app *BabylonApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr height := ctx.BlockHeight() headerInfo := ctx.HeaderInfo() headerInfo.Height = 0 - ctx = ctx.WithHeaderInfo(headerInfo) + ctx = ctx.WithHeaderInfo(headerInfo).WithBlockHeight(0) // reinitialize all validators err = app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { @@ -169,7 +169,7 @@ func (app *BabylonApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr // reset context height headerInfo = ctx.HeaderInfo() headerInfo.Height = height - ctx = ctx.WithHeaderInfo(headerInfo) + ctx = ctx.WithHeaderInfo(headerInfo).WithBlockHeight(height) /* Handle staking state. */ diff --git a/x/epoching/keeper/epochs.go b/x/epoching/keeper/epochs.go index 4db992c89..1dcfaba13 100644 --- a/x/epoching/keeper/epochs.go +++ b/x/epoching/keeper/epochs.go @@ -34,7 +34,7 @@ func (k Keeper) getEpochInfo(ctx context.Context, epochNumber uint64) (*types.Ep // InitEpoch sets the zero epoch number to DB func (k Keeper) InitEpoch(ctx context.Context) { - header := sdk.UnwrapSDKContext(ctx).HeaderInfo() + header := sdk.UnwrapSDKContext(ctx).BlockHeader() if header.Height > 0 { panic("InitEpoch can be invoked only at genesis") } @@ -68,7 +68,7 @@ func (k Keeper) RecordLastHeaderAndAppHashRoot(ctx context.Context) error { return errorsmod.Wrapf(types.ErrInvalidHeight, "RecordLastBlockHeader can only be invoked at the last block of an epoch") } // record last block header - header := sdk.UnwrapSDKContext(ctx).HeaderInfo() + header := sdk.UnwrapSDKContext(ctx).BlockHeader() epoch.LastBlockTime = &header.Time // calculate and record the Merkle root appHashes, err := k.GetAllAppHashesForEpoch(ctx, epoch) @@ -90,7 +90,7 @@ func (k Keeper) RecordSealerAppHashForPrevEpoch(ctx context.Context) *types.Epoc panic(fmt.Errorf("RecordSealerAppHashForPrevEpoch can only be invoked at the first header of a non-zero epoch. "+ "current epoch: %v, current height: %d", epoch, sdk.UnwrapSDKContext(ctx).BlockHeight())) } - header := sdk.UnwrapSDKContext(ctx).HeaderInfo() + header := sdk.UnwrapSDKContext(ctx).BlockHeader() // get the sealed epoch, i.e., the epoch earlier than the current epoch sealedEpoch, err := k.GetHistoricalEpoch(ctx, epoch.EpochNumber-1) @@ -114,10 +114,9 @@ func (k Keeper) RecordSealerBlockHashForEpoch(ctx context.Context) *types.Epoch panic(fmt.Errorf("RecordSealerBlockHashForEpoch can only be invoked at the last header of a non-zero epoch. "+ "current epoch: %v, current height: %d", epoch, sdk.UnwrapSDKContext(ctx).BlockHeight())) } - header := sdk.UnwrapSDKContext(ctx).HeaderInfo() // record the sealer block hash for the sealing epoch - epoch.SealerBlockHash = header.Hash + epoch.SealerBlockHash = sdk.UnwrapSDKContext(ctx).HeaderHash() k.setEpochInfo(ctx, epoch.EpochNumber, epoch) return epoch diff --git a/x/finality/keeper/indexed_blocks.go b/x/finality/keeper/indexed_blocks.go index fd7fc0771..e9ae9994d 100644 --- a/x/finality/keeper/indexed_blocks.go +++ b/x/finality/keeper/indexed_blocks.go @@ -12,10 +12,10 @@ import ( // IndexBlock indexes the current block, saves the corresponding indexed block // to KVStore func (k Keeper) IndexBlock(ctx context.Context) { - headerInfo := sdk.UnwrapSDKContext(ctx).HeaderInfo() + header := sdk.UnwrapSDKContext(ctx).BlockHeader() ib := &types.IndexedBlock{ - Height: uint64(headerInfo.Height), - AppHash: headerInfo.AppHash, + Height: uint64(header.Height), + AppHash: header.AppHash, Finalized: false, } k.SetBlock(ctx, ib) diff --git a/x/zoneconcierge/keeper/header_handler.go b/x/zoneconcierge/keeper/header_handler.go index 3bfdd046e..99ededeae 100644 --- a/x/zoneconcierge/keeper/header_handler.go +++ b/x/zoneconcierge/keeper/header_handler.go @@ -12,7 +12,7 @@ import ( // HandleHeaderWithValidCommit handles a CZ header with a valid QC func (k Keeper) HandleHeaderWithValidCommit(ctx context.Context, txHash []byte, header *types.HeaderInfo, isOnFork bool) { sdkCtx := sdk.UnwrapSDKContext(ctx) - babylonHeader := sdkCtx.HeaderInfo() + babylonHeader := sdkCtx.BlockHeader() indexedHeader := types.IndexedHeader{ ChainId: header.ChainId, Hash: header.AppHash,