Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Application] Refactor app module to fetch on-chain params #555

Merged
merged 90 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
a3d3d17
feat: add `num_blocks_per_session` session module param
bryanchriswhite May 14, 2024
99455d5
feat: add make target to update all session params
bryanchriswhite May 15, 2024
05e631a
chore: use default param values in param update msgs
bryanchriswhite May 15, 2024
bf3bff3
Empty commit
bryanchriswhite May 15, 2024
3aa53ec
fixup! feat: add `num_blocks_per_session` session module param
bryanchriswhite May 15, 2024
d7a04dc
test: add coverage for sessiontypes.Params#ValidateNumBlocksPerSession()
bryanchriswhite May 16, 2024
56ae9a8
fix: #ValidateNumBlocksPerSession()
bryanchriswhite May 16, 2024
b291bc1
chore: review feedback improvements
bryanchriswhite May 16, 2024
e9afc4c
Merge branch 'main' into issues/517/param-num_blocks_per_session
bryanchriswhite May 16, 2024
40e1e7f
refactor: rename param name vars
bryanchriswhite May 16, 2024
2c33381
fix: unit tests
bryanchriswhite May 16, 2024
9597876
Merge branch 'main' into issues/517/param-num_blocks_per_session
bryanchriswhite May 17, 2024
1eae173
Merge branch 'main' into issues/517/param-num_blocks_per_session
bryanchriswhite May 21, 2024
86e114d
Empty commit
bryanchriswhite May 21, 2024
eaf5f15
Empty commit
bryanchriswhite May 22, 2024
a757d5a
Empty commit
bryanchriswhite May 22, 2024
6c6ec62
chore: add "unauthorized" account to config.yml instead of creating i…
bryanchriswhite May 22, 2024
638f0c9
chore: add client.SessionQueryClient#GetParams interface method
bryanchriswhite May 16, 2024
a6667eb
chore: add ErrQuerySessionParams
bryanchriswhite May 16, 2024
42a63f1
feat: implement sessionQuerier#GetParams()
bryanchriswhite May 16, 2024
16dafd3
chore: add SessionQueryClient#GetSessionGracePeriodCount interface me…
bryanchriswhite May 17, 2024
48526a0
feat: implement sessionQuerier#GetSessionGracePeriodBlockCount()
bryanchriswhite May 17, 2024
3d59a5d
chore: add sessionQueryClient field to relayerSessionsManager
bryanchriswhite May 17, 2024
c24ba01
refactor: IsWithinGracePeriod from a static function to a method on r…
bryanchriswhite May 17, 2024
b23d9d8
chore: add IsWithinGracePeriod method to relayerProxy
bryanchriswhite May 17, 2024
43682ed
docs: update relayerProxy#sessoinQuerier godoc comment
bryanchriswhite May 17, 2024
7b64b2b
refactor: move duplicated #IsWithinGracePeriod methods to sessionQuerier
bryanchriswhite May 17, 2024
5c42c06
chore: add SessionQueryClient#IsPastGracePeriod() interface method
bryanchriswhite May 17, 2024
264edb2
refactor: IsPastGracePeriod from a static function to a sessionQuerie…
bryanchriswhite May 17, 2024
d75e5ae
refactor: factor static functions back out to session pkg w/ appropri…
bryanchriswhite May 21, 2024
79a141d
test: add #IsWithinGracePeriod & #IsPastGracePeriod to the mock sessi…
bryanchriswhite May 21, 2024
6ca2f88
test: fix failing test by supplying session query client dependency
bryanchriswhite May 21, 2024
05d8c73
wip: comment & simplify
bryanchriswhite May 21, 2024
eb983c1
refactor: factor out GetSessionGracePeriodEndHeight
bryanchriswhite May 22, 2024
f4d4d2e
chore: refactor & simplify claim/proof submission
bryanchriswhite May 22, 2024
3ceeb18
Empty commit
bryanchriswhite May 22, 2024
297b3f0
chore: self-review improvements
bryanchriswhite May 22, 2024
bf3ddc2
fix: typo
bryanchriswhite May 22, 2024
1e0a996
scaffold: module shared
bryanchriswhite May 23, 2024
4acef34
fix: linting
bryanchriswhite May 23, 2024
e084a3b
refactor: move `num_blocks_per_session` param to shared module
bryanchriswhite May 23, 2024
eb64733
Empty commit
bryanchriswhite May 23, 2024
bf31df8
fixup! refactor: move `num_blocks_per_session` param to shared module
bryanchriswhite May 23, 2024
8260bab
Merge remote-tracking branch 'pokt/main' into issues/517/refactor/ses…
bryanchriswhite May 23, 2024
ae7e013
Merge branch 'issues/517/refactor/move-num_blocks_per_session' into i…
bryanchriswhite May 23, 2024
c972ac9
fixup! refactor: move `num_blocks_per_session` param to shared module
bryanchriswhite May 23, 2024
ef8dcf9
Merge branch 'issues/517/refactor/move-num_blocks_per_session' into i…
bryanchriswhite May 23, 2024
e17e3c4
wip: triage & simplify
bryanchriswhite May 23, 2024
d8af996
refactor: session query client & shared query client
bryanchriswhite May 23, 2024
82a3567
refactor: simplify
bryanchriswhite May 23, 2024
3e24eda
chore: add missing comment in types.go
bryanchriswhite May 23, 2024
433236a
chore: self-review improvements
bryanchriswhite May 23, 2024
e00fe4b
fixup! chore: self-review improvements
bryanchriswhite May 23, 2024
a68ae8d
fixup! fixup! chore: self-review improvements
bryanchriswhite May 23, 2024
66e2be7
fixup! refactor: move `num_blocks_per_session` param to shared module
bryanchriswhite May 23, 2024
4d66581
fix: broken E2E test
bryanchriswhite May 23, 2024
93e01aa
fixup! refactor: move `num_blocks_per_session` param to shared module
bryanchriswhite May 23, 2024
b6ce1d4
fix: broken E2E test
bryanchriswhite May 23, 2024
9c80e77
Merge branch 'refs/heads/issues/517/refactor/move-num_blocks_per_sess…
bryanchriswhite May 23, 2024
bf24e6c
fix: typo
bryanchriswhite May 23, 2024
14e58a8
Merge branch 'main' into issues/517/scaffold/shared-module
bryanchriswhite May 24, 2024
44379b2
Merge branch 'issues/517/scaffold/shared-module' into issues/517/refa…
bryanchriswhite May 24, 2024
1ac355d
Merge branch 'refs/heads/issues/517/refactor/move-num_blocks_per_sess…
bryanchriswhite May 24, 2024
aff8853
Merge remote-tracking branch 'refs/remotes/pokt/main' into issues/517…
bryanchriswhite May 24, 2024
03a4079
Empty commit
bryanchriswhite May 27, 2024
89114f3
fix: add omitted pb.go file
bryanchriswhite May 27, 2024
5db7c9b
fix: linting
bryanchriswhite May 27, 2024
0613764
fix: go imports script: exclude *.pulsar.go files & fix buffer size
bryanchriswhite May 27, 2024
c269dc1
Merge branch 'issues/517/refactor/move-num_blocks_per_session' into i…
bryanchriswhite May 27, 2024
77f704e
Empty commit
bryanchriswhite May 27, 2024
1ccb926
Merge branch 'issues/517/refactor/move-num_blocks_per_session' into i…
bryanchriswhite May 27, 2024
c18ec7b
chore: review improvements
bryanchriswhite May 24, 2024
203de35
fix: update_params.feature reset
bryanchriswhite May 28, 2024
7d281a6
Merge branch 'issues/517/refactor/move-num_blocks_per_session' into i…
bryanchriswhite May 28, 2024
6352a5f
chore: review improvements
bryanchriswhite May 28, 2024
0d55060
Merge remote-tracking branch 'pokt/main' into issues/517/refactor/ses…
bryanchriswhite May 28, 2024
c7955a8
chore: add shared keeper as dependency of application keeper
bryanchriswhite May 23, 2024
b1a4565
refactor: rename static funcs & height vars
bryanchriswhite May 28, 2024
8f357d1
feat: add shared keeper methods
bryanchriswhite May 28, 2024
107a5e6
refactor: app undelegation pruning
bryanchriswhite May 28, 2024
3546ad3
chore: self-review improvements
bryanchriswhite May 28, 2024
a0a23b7
Merge branch 'main' into issues/517/refactor/session-params_relayminer
bryanchriswhite May 29, 2024
a58e553
refactor: rename methods which use default shared params with suffix …
bryanchriswhite May 29, 2024
a3b7abb
chore: udpate comments
bryanchriswhite May 29, 2024
6ec7f00
Merge branch 'issues/517/refactor/session-params_relayminer' into iss…
bryanchriswhite May 29, 2024
8ce12f5
Merge remote-tracking branch 'pokt/main' into issues/517/refactor/app…
bryanchriswhite May 29, 2024
15658c8
Merge branch 'main' into issues/517/refactor/app-module
bryanchriswhite May 29, 2024
56d2bfc
Merge branch 'main' into issues/517/refactor/app-module
Olshansk May 30, 2024
661219b
chore: review feedback improvements
bryanchriswhite May 30, 2024
3c47a24
Empty commit
bryanchriswhite May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions load-testing/tests/relays_stress_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ func (s *relaysSuite) mapSessionInfoForLoadTestDurationFn(

sessionInfo := &sessionInfoNotif{
blockHeight: blockHeight,
sessionNumber: shared.GetSessionNumber(blockHeight),
sessionStartBlockHeight: shared.GetSessionStartBlockHeight(blockHeight),
sessionEndBlockHeight: shared.GetSessionEndBlockHeight(blockHeight),
sessionNumber: shared.GetSessionNumberWithDefaultParams(blockHeight),
sessionStartBlockHeight: shared.GetSessionStartHeightWithDefaultParams(blockHeight),
sessionEndBlockHeight: shared.GetSessionEndHeightWithDefaultParams(blockHeight),
}

infoLogger := logger.Info().
Expand Down Expand Up @@ -720,7 +720,7 @@ func (plan *actorLoadTestIncrementPlan) shouldIncrementActorCount(
return false
}

initialSessionNumber := shared.GetSessionNumber(startBlockHeight)
initialSessionNumber := shared.GetSessionNumberWithDefaultParams(startBlockHeight)
// TODO_TECHDEBT(#21): replace with gov param query when available.
actorSessionIncRate := plan.blocksPerIncrement / shared.NumBlocksPerSession
nextSessionNumber := sessionInfo.sessionNumber + 1 - initialSessionNumber
Expand All @@ -746,7 +746,7 @@ func (plan *actorLoadTestIncrementPlan) shouldIncrementSupplierCount(
return false
}

initialSessionNumber := shared.GetSessionNumber(startBlockHeight)
initialSessionNumber := shared.GetSessionNumberWithDefaultParams(startBlockHeight)
// TODO_TECHDEBT(#21): replace with gov param query when available.
supplierSessionIncRate := plan.blocksPerIncrement / shared.NumBlocksPerSession
nextSessionNumber := sessionInfo.sessionNumber + 1 - initialSessionNumber
Expand Down
2 changes: 1 addition & 1 deletion pkg/crypto/rings/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (rc *ringClient) getRingPointsForAddressAtHeight(
// gateways that have been undelegated after the target session end height.
func GetRingAddressesAtBlock(app *apptypes.Application, blockHeight int64) []string {
// Get the target session end height at which we want to get the active delegations.
targetSessionEndHeight := uint64(shared.GetSessionEndBlockHeight(blockHeight))
targetSessionEndHeight := uint64(shared.GetSessionEndHeightWithDefaultParams(blockHeight))
// Get the current active delegations for the application and use them as a base.
activeDelegationsAtHeight := app.DelegateeGatewayAddresses

Expand Down
17 changes: 16 additions & 1 deletion testutil/keeper/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"

mocks "github.com/pokt-network/poktroll/testutil/application/mocks"
"github.com/pokt-network/poktroll/testutil/application/mocks"
"github.com/pokt-network/poktroll/x/application/keeper"
"github.com/pokt-network/poktroll/x/application/types"
gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types"
"github.com/pokt-network/poktroll/x/shared"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)

// stakedGatewayMap is used to mock whether a gateway is staked or not for use
Expand Down Expand Up @@ -67,6 +69,18 @@ func ApplicationKeeper(t testing.TB) (keeper.Keeper, context.Context) {
},
).AnyTimes()

mockSharedKeeper := mocks.NewMockSharedKeeper(ctrl)
mockSharedKeeper.EXPECT().GetParams(gomock.Any()).
DoAndReturn(func(_ context.Context) sharedtypes.Params {
return sharedtypes.DefaultParams()
}).
AnyTimes()
mockSharedKeeper.EXPECT().GetSessionEndHeight(gomock.Any(), gomock.Any()).
DoAndReturn(func(_ context.Context, queryHeight int64) int64 {
return shared.GetSessionEndHeightWithDefaultParams(queryHeight)
}).
AnyTimes()

k := keeper.NewKeeper(
cdc,
runtime.NewKVStoreService(storeKey),
Expand All @@ -75,6 +89,7 @@ func ApplicationKeeper(t testing.TB) (keeper.Keeper, context.Context) {
mockBankKeeper,
mockAccountKeeper,
mockGatewayKeeper,
mockSharedKeeper,
)

ctx := sdk.NewContext(stateStore, cmtproto.Header{}, false, log.NewNopLogger())
Expand Down
10 changes: 10 additions & 0 deletions testutil/keeper/proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
prooftypes "github.com/pokt-network/poktroll/x/proof/types"
sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
sharedkeeper "github.com/pokt-network/poktroll/x/shared/keeper"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
supplierkeeper "github.com/pokt-network/poktroll/x/supplier/keeper"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
Expand Down Expand Up @@ -142,6 +143,14 @@ func NewProofModuleKeepers(t testing.TB, opts ...ProofKeepersOpt) (_ *ProofModul
authority.String(),
)

// Construct a real shared keeper.
sharedKeeper := sharedkeeper.NewKeeper(
cdc,
runtime.NewKVStoreService(keys[sharedtypes.StoreKey]),
logger,
authority.String(),
)

// Construct gateway keeper with a mocked bank keeper.
gatewayKeeper := gatewaykeeper.NewKeeper(
cdc,
Expand All @@ -161,6 +170,7 @@ func NewProofModuleKeepers(t testing.TB, opts ...ProofKeepersOpt) (_ *ProofModul
applicationmocks.NewMockBankKeeper(ctrl),
accountKeeper,
gatewayKeeper,
sharedKeeper,
)
require.NoError(t, appKeeper.SetParams(ctx, apptypes.DefaultParams()))

Expand Down
12 changes: 11 additions & 1 deletion testutil/keeper/tokenomics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

"cosmossdk.io/log"
math "cosmossdk.io/math"
"cosmossdk.io/math"
"cosmossdk.io/store"
"cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -38,6 +38,7 @@ import (
prooftypes "github.com/pokt-network/poktroll/x/proof/types"
sessionkeeper "github.com/pokt-network/poktroll/x/session/keeper"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
sharedkeeper "github.com/pokt-network/poktroll/x/shared/keeper"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
supplierkeeper "github.com/pokt-network/poktroll/x/supplier/keeper"
suppliertypes "github.com/pokt-network/poktroll/x/supplier/types"
Expand Down Expand Up @@ -239,6 +240,14 @@ func NewTokenomicsModuleKeepers(
bankKeeper.MintCoins(ctx, suppliertypes.ModuleName, sdk.NewCoins(sdk.NewCoin("upokt", math.NewInt(1000000000000))))
bankKeeper.MintCoins(ctx, apptypes.ModuleName, sdk.NewCoins(sdk.NewCoin("upokt", math.NewInt(1000000000000))))

// Construct a real shared keeper.
sharedKeeper := sharedkeeper.NewKeeper(
cdc,
runtime.NewKVStoreService(keys[sharedtypes.StoreKey]),
logger,
authority.String(),
)

// Construct gateway keeper with a mocked bank keeper.
gatewayKeeper := gatewaykeeper.NewKeeper(
cdc,
Expand All @@ -258,6 +267,7 @@ func NewTokenomicsModuleKeepers(
bankKeeper,
accountKeeper,
gatewayKeeper,
sharedKeeper,
)
require.NoError(t, appKeeper.SetParams(ctx, apptypes.DefaultParams()))

Expand Down
6 changes: 3 additions & 3 deletions testutil/testclient/testqueryclients/sessionquerier.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func AddToExistingSessions(
Service: &sharedtypes.Service{Id: serviceId},
ApplicationAddress: appAddress,
SessionId: sessionId,
SessionStartBlockHeight: shared.GetSessionStartBlockHeight(blockHeight),
SessionEndBlockHeight: shared.GetSessionEndBlockHeight(blockHeight),
SessionStartBlockHeight: shared.GetSessionStartHeightWithDefaultParams(blockHeight),
SessionEndBlockHeight: shared.GetSessionEndHeightWithDefaultParams(blockHeight),
},
NumBlocksPerSession: shared.NumBlocksPerSession,
SessionNumber: shared.GetSessionNumber(blockHeight),
SessionNumber: shared.GetSessionNumberWithDefaultParams(blockHeight),
SessionId: sessionId,
Suppliers: []*sharedtypes.Supplier{},
}
Expand Down
4 changes: 2 additions & 2 deletions testutil/testproxy/relayerproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ func GenerateRelayRequest(
ApplicationAddress: appAddress,
SessionId: string(sessionId[:]),
Service: &sharedtypes.Service{Id: serviceId},
SessionStartBlockHeight: shared.GetSessionStartBlockHeight(blockHeight),
SessionEndBlockHeight: shared.GetSessionEndBlockHeight(blockHeight),
SessionStartBlockHeight: shared.GetSessionStartHeightWithDefaultParams(blockHeight),
SessionEndBlockHeight: shared.GetSessionEndHeightWithDefaultParams(blockHeight),
},
// The returned relay is unsigned and must be signed elsewhere for functionality
Signature: []byte(""),
Expand Down
3 changes: 3 additions & 0 deletions x/application/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type (
bankKeeper types.BankKeeper
accountKeeper types.AccountKeeper
gatewayKeeper types.GatewayKeeper
sharedKeeper types.SharedKeeper
}
)

Expand All @@ -36,6 +37,7 @@ func NewKeeper(
bankKeeper types.BankKeeper,
accountKeeper types.AccountKeeper,
gatewayKeeper types.GatewayKeeper,
sharedKeeper types.SharedKeeper,
) Keeper {
if _, err := sdk.AccAddressFromBech32(authority); err != nil {
panic(fmt.Sprintf("invalid authority address: %s", authority))
Expand All @@ -50,6 +52,7 @@ func NewKeeper(
bankKeeper: bankKeeper,
accountKeeper: accountKeeper,
gatewayKeeper: gatewayKeeper,
sharedKeeper: sharedKeeper,
}
}

Expand Down
6 changes: 3 additions & 3 deletions x/application/keeper/msg_server_undelegate_from_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/pokt-network/poktroll/telemetry"
"github.com/pokt-network/poktroll/x/application/types"
"github.com/pokt-network/poktroll/x/shared"
)

func (k msgServer) UndelegateFromGateway(ctx context.Context, msg *types.MsgUndelegateFromGateway) (*types.MsgUndelegateFromGatewayResponse, error) {
Expand Down Expand Up @@ -55,7 +54,7 @@ func (k msgServer) UndelegateFromGateway(ctx context.Context, msg *types.MsgUnde
sdkCtx := sdk.UnwrapSDKContext(ctx)
currentBlock := sdkCtx.BlockHeight()

k.recordPendingUndelegation(&foundApp, msg.GatewayAddress, currentBlock)
k.recordPendingUndelegation(ctx, &foundApp, msg.GatewayAddress, currentBlock)

// Update the application store with the new delegation
k.SetApplication(ctx, foundApp)
Expand All @@ -76,11 +75,12 @@ func (k msgServer) UndelegateFromGateway(ctx context.Context, msg *types.MsgUnde
// recordPendingUndelegation adds the given gateway address to the application's
// pending undelegations list.
func (k Keeper) recordPendingUndelegation(
ctx context.Context,
app *types.Application,
gatewayAddress string,
currentBlockHeight int64,
) {
sessionEndHeight := uint64(shared.GetSessionEndBlockHeight(currentBlockHeight))
sessionEndHeight := uint64(k.sharedKeeper.GetSessionEndHeight(ctx, currentBlockHeight))
undelegatingGatewayListAtBlock := app.PendingUndelegations[sessionEndHeight]

// Add the gateway address to the undelegated gateways list if it's not already there.
Expand Down
18 changes: 13 additions & 5 deletions x/application/keeper/msg_server_undelegate_from_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func TestMsgServer_UndelegateFromGateway_DelegationIsActiveUntilNextSession(t *t

// Verify that the gateway is added to the pending undelegation list with the
// right sessionEndHeight as the map key.
sessionEndHeight := uint64(shared.GetSessionEndBlockHeight(undelegationHeight))
sessionEndHeight := uint64(shared.GetSessionEndHeightWithDefaultParams(undelegationHeight))
require.Contains(t,
app.PendingUndelegations[sessionEndHeight].GatewayAddresses,
pendingUndelegateFromAddr,
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestMsgServer_UndelegateFromGateway_DelegationIsPrunedAfterRetentionPeriod(

// Verify that the the pending undelegation map no longer contains the
// sessionEndHeight key.
sessionEndHeight := uint64(shared.GetSessionEndBlockHeight(undelegationHeight))
sessionEndHeight := uint64(shared.GetSessionEndHeightWithDefaultParams(undelegationHeight))
require.Empty(t, app.PendingUndelegations[sessionEndHeight])

// Verify that the reconstructed delegatee gateway list can no longer include
Expand Down Expand Up @@ -423,7 +423,7 @@ func TestMsgServer_UndelegateFromGateway_RedelegationAfterUndelegationAtTheSameS

// Verify that the gateway is also present in the pending undelegation list with the
// right sessionEndHeight as the map key.
sessionEndHeight := uint64(shared.GetSessionEndBlockHeight(undelegationHeight))
sessionEndHeight := uint64(shared.GetSessionEndHeightWithDefaultParams(undelegationHeight))
require.Contains(t,
app.PendingUndelegations[sessionEndHeight].GatewayAddresses,
gatewayAddrToRedelegate,
Expand Down Expand Up @@ -533,7 +533,15 @@ func createAppStakeDelegateAndUndelegate(
// getUndelegationPruningBlockHeight returns the block height at which undelegations
// should be pruned for a given undlegation block height.
func getUndelegationPruningBlockHeight(blockHeight int64) (pruningHeihgt int64) {
nextSessionStartHeight := shared.GetSessionEndBlockHeight(blockHeight) + 1
nextSessionStartHeight := shared.GetSessionEndHeightWithDefaultParams(blockHeight) + 1

return nextSessionStartHeight + keeper.GetNumBlocksUndelegationRetention()
return nextSessionStartHeight + getNumBlocksUndelegationRetentionWithDefaultParams()
}

// getNumBlocksUndelegationRetentionWithDefaultParams returns the number of blocks for
// which undelegations should be kept before being pruned, given the default shared
// module parameters.
func getNumBlocksUndelegationRetentionWithDefaultParams() int64 {
sharedParams := sharedtypes.DefaultParams()
return keeper.GetNumBlocksUndelegationRetention(&sharedParams)
}
22 changes: 18 additions & 4 deletions x/application/keeper/prune_undelegations.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package keeper

import (
"context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/pokt-network/poktroll/x/shared"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)

// NumSessionsAppToGatewayUndelegationRetention is the number of sessions for which
Expand All @@ -20,7 +23,7 @@ func (k Keeper) EndBlockerPruneAppToGatewayPendingUndelegation(ctx sdk.Context)
currentHeight := ctx.BlockHeight()

// Calculate the block height at which undelegations should be pruned
numBlocksUndelegationRetention := GetNumBlocksUndelegationRetention()
numBlocksUndelegationRetention := k.GetNumBlocksUndelegationRetention(ctx)
if currentHeight <= numBlocksUndelegationRetention {
return nil
}
Expand All @@ -43,8 +46,19 @@ func (k Keeper) EndBlockerPruneAppToGatewayPendingUndelegation(ctx sdk.Context)
}

// GetNumBlocksUndelegationRetention returns the number of blocks for which
// undelegations should be kept before being pruned.
func GetNumBlocksUndelegationRetention() int64 {
// 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)
}

// 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 +
(shared.NumBlocksPerSession * NumSessionsAppToGatewayUndelegationRetention)
(numBlocksPerSession * NumSessionsAppToGatewayUndelegationRetention)
}
2 changes: 2 additions & 0 deletions x/application/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type ModuleInputs struct {
AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
GatewayKeeper types.GatewayKeeper
SharedKeeper types.SharedKeeper
}

type ModuleOutputs struct {
Expand All @@ -204,6 +205,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
in.BankKeeper,
in.AccountKeeper,
in.GatewayKeeper,
in.SharedKeeper,
)
m := NewAppModule(
in.Cdc,
Expand Down
9 changes: 8 additions & 1 deletion x/application/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate mockgen -destination ../../../testutil/application/mocks/expected_keepers_mock.go -package mocks . AccountKeeper,BankKeeper,GatewayKeeper
//go:generate mockgen -destination ../../../testutil/application/mocks/expected_keepers_mock.go -package mocks . AccountKeeper,BankKeeper,GatewayKeeper,SharedKeeper

package types

Expand All @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

gatewaytypes "github.com/pokt-network/poktroll/x/gateway/types"
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)

// AccountKeeper defines the expected interface for the Account module.
Expand All @@ -30,3 +31,9 @@ type BankKeeper interface {
type GatewayKeeper interface {
GetGateway(ctx context.Context, addr string) (gatewaytypes.Gateway, bool)
}

// SharedKeeper defines the expected interface needed to retrieve shared information.
type SharedKeeper interface {
GetParams(ctx context.Context) sharedtypes.Params
GetSessionEndHeight(ctx context.Context, queryHeight int64) int64
}
Olshansk marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion x/proof/keeper/msg_server_create_claim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func newTestClaimMsg(
Service: service,
SessionId: sessionId,
SessionStartBlockHeight: sessionStartHeight,
SessionEndBlockHeight: shared.GetSessionEndBlockHeight(sessionStartHeight),
SessionEndBlockHeight: shared.GetSessionEndHeightWithDefaultParams(sessionStartHeight),
},
merkleRoot,
)
Expand Down
2 changes: 1 addition & 1 deletion x/proof/keeper/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func createNProofs(keeper keeper.Keeper, ctx context.Context, n int) []types.Pro
Service: &sharedtypes.Service{Id: testServiceId},
SessionId: fmt.Sprintf("session-%d", i),
SessionStartBlockHeight: 1,
SessionEndBlockHeight: shared.GetSessionEndBlockHeight(1),
SessionEndBlockHeight: shared.GetSessionEndHeightWithDefaultParams(1),
},
ClosestMerkleProof: nil,
}
Expand Down
Loading
Loading