Skip to content

Commit

Permalink
Merge branch 'issues/517/refactor/app-module' into issues/517/refacto…
Browse files Browse the repository at this point in the history
…r/ring-client
  • Loading branch information
bryanchriswhite authored May 28, 2024
2 parents f3e8ec6 + 3546ad3 commit ea0f044
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
10 changes: 9 additions & 1 deletion x/application/keeper/msg_server_undelegate_from_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,15 @@ 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)
}

// getDefaultRingAddressesAtBlock returns the active gateway addresses that need to be
Expand Down
15 changes: 7 additions & 8 deletions x/application/keeper/prune_undelegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down
3 changes: 3 additions & 0 deletions x/session/keeper/session_hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 13 additions & 0 deletions x/shared/keeper/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions x/shared/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit ea0f044

Please sign in to comment.