diff --git a/x/application/keeper/msg_server_undelegate_from_gateway_test.go b/x/application/keeper/msg_server_undelegate_from_gateway_test.go index 388e19d02..b6030cd2c 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway_test.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway_test.go @@ -535,5 +535,13 @@ func createAppStakeDelegateAndUndelegate( func getUndelegationPruningBlockHeight(blockHeight int64) (pruningHeihgt int64) { nextSessionStartHeight := shared.GetDefaultSessionEndHeight(blockHeight) + 1 - return nextSessionStartHeight + keeper.GetDefaultNumBlocksUndelegationRetention() + return nextSessionStartHeight + getDefaultNumBlocksUndelegationRetention() +} + +// getNumBlocksUndelegationRetention returns the number of blocks for which +// undelegations should be kept before being pruned, given the default shared +// module parameters. +func getDefaultNumBlocksUndelegationRetention() int64 { + sharedParams := sharedtypes.DefaultParams() + return keeper.GetNumBlocksUndelegationRetention(&sharedParams) } diff --git a/x/application/keeper/prune_undelegations.go b/x/application/keeper/prune_undelegations.go index 9ac087a15..eb2e276e9 100644 --- a/x/application/keeper/prune_undelegations.go +++ b/x/application/keeper/prune_undelegations.go @@ -46,18 +46,17 @@ func (k Keeper) EndBlockerPruneAppToGatewayPendingUndelegation(ctx sdk.Context) } // GetNumBlocksUndelegationRetention returns the number of blocks for which -// undelegations should be kept before being pruned. +// undelegations should be kept before being pruned, given the current on-chain +// shared module parameters. func (k Keeper) GetNumBlocksUndelegationRetention(ctx context.Context) int64 { sharedParams := k.sharedKeeper.GetParams(ctx) - return getNumBlocksUndelegationRetention(&sharedParams) + return GetNumBlocksUndelegationRetention(&sharedParams) } -func GetDefaultNumBlocksUndelegationRetention() int64 { - sharedParams := sharedtypes.DefaultParams() - return getNumBlocksUndelegationRetention(&sharedParams) -} - -func getNumBlocksUndelegationRetention(sharedParams *sharedtypes.Params) int64 { +// GetNumBlocksUndelegationRetention returns the number of blocks for which +// undelegations should be kept before being pruned, given the passed shared +// module parameters. +func GetNumBlocksUndelegationRetention(sharedParams *sharedtypes.Params) int64 { numBlocksPerSession := int64(sharedParams.GetNumBlocksPerSession()) return shared.SessionGracePeriodBlocks + diff --git a/x/session/keeper/session_hydrator.go b/x/session/keeper/session_hydrator.go index 4d1d7bb29..54bc444e5 100644 --- a/x/session/keeper/session_hydrator.go +++ b/x/session/keeper/session_hydrator.go @@ -99,6 +99,9 @@ func (k Keeper) hydrateSessionMetadata(ctx context.Context, sh *sessionHydrator) ) } + // TODO_UPNEXT(#517): Refactor session module to use current on-chain shared + // parameters instead of their corresponding constant stand-ins. + sh.session.NumBlocksPerSession = shared.NumBlocksPerSession sh.session.SessionNumber = shared.GetDefaultSessionNumber(sh.blockHeight) diff --git a/x/shared/keeper/session.go b/x/shared/keeper/session.go index 20c37c4e2..fd4d29f09 100644 --- a/x/shared/keeper/session.go +++ b/x/shared/keeper/session.go @@ -6,16 +6,29 @@ import ( "github.com/pokt-network/poktroll/x/shared" ) +// GetSessionStartHeight returns the block height at which the session starts given +// the passed shared on-chain parameters. +// Returns 0 if the block height is not a consensus produced block. +// Example: If NumBlocksPerSession == 4, sessions start at blocks 1, 5, 9, etc. func (k Keeper) GetSessionStartHeight(ctx context.Context, queryHeight int64) int64 { sharedParams := k.GetParams(ctx) return shared.GetSessionStartHeight(&sharedParams, queryHeight) } +// GetSessionEndHeight returns the block height at which the session ends +// given the passed shared on-chain parameters. +// Returns 0 if the block height is not a consensus produced block. +// Example: If NumBlocksPerSession == 4, sessions end at blocks 4, 8, 11, etc. func (k Keeper) GetSessionEndHeight(ctx context.Context, queryHeight int64) int64 { sharedParams := k.GetParams(ctx) return shared.GetSessionEndHeight(&sharedParams, queryHeight) } +// GetSessionNumber returns the session number given the block height given the passed +// shared on-chain parameters. +// Returns session number 0 if the block height is not a consensus produced block. +// Returns session number 1 for block 1 to block NumBlocksPerSession - 1 (inclusive). +// i.e. If NubBlocksPerSession == 4, session == 1 for [1, 4], session == 2 for [5, 8], etc. func (k Keeper) GetSessionNumber(ctx context.Context, queryHeight int64) int64 { sharedParams := k.GetParams(ctx) return shared.GetSessionNumber(&sharedParams, queryHeight) diff --git a/x/shared/session.go b/x/shared/session.go index 6f14cbe1c..17b1346da 100644 --- a/x/shared/session.go +++ b/x/shared/session.go @@ -20,6 +20,8 @@ const SessionGracePeriodBlocks = 4 // given the default shared on-chain parameters. // Returns 0 if the block height is not a consensus produced block. // Example: If NumBlocksPerSession == 4, sessions start at blocks 1, 5, 9, etc. +// +// TODO_TECHDEBT(#517): Move this function to shared testutils. func GetDefaultSessionStartHeight(queryHeight int64) int64 { sharedParams := sharedtypes.DefaultParams() return GetSessionStartHeight(&sharedParams, queryHeight) @@ -45,6 +47,8 @@ func GetSessionStartHeight(sharedParams *sharedtypes.Params, queryHeight int64) // given the default shared on-chain parameters. // Returns 0 if the block height is not a consensus produced block. // Example: If NumBlocksPerSession == 4, sessions end at blocks 4, 8, 11, etc. +// +// TODO_TECHDEBT(#517): Move this function to shared testutils. func GetDefaultSessionEndHeight(queryHeight int64) int64 { sharedParams := sharedtypes.DefaultParams() return GetSessionEndHeight(&sharedParams, queryHeight) @@ -69,6 +73,8 @@ func GetSessionEndHeight(sharedParams *sharedtypes.Params, queryHeight int64) in // Returns session number 0 if the block height is not a consensus produced block. // Returns session number 1 for block 1 to block NumBlocksPerSession - 1 (inclusive). // i.e. If NubBlocksPerSession == 4, session == 1 for [1, 4], session == 2 for [5, 8], etc. +// +// TODO_TECHDEBT(#517): Move this function to shared testutils. func GetDefaultSessionNumber(queryHeight int64) int64 { sharedParams := sharedtypes.DefaultParams() return GetSessionNumber(&sharedParams, queryHeight)