From 632e527a224d49428dc0b35224b0003714f53655 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Tue, 15 Oct 2024 10:47:31 +0200 Subject: [PATCH] [Code Health] refactor: share helpers to consolidate avoid dependency cycles (#855) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Consolidates pkg `x/shared` with `x/shared/types`. #### Before ``` x └── shared ├── helpers // pkg removed │ ├── service_configs.go // moved to x/shared/types/service_configs.go │ └── service_test.go // moved to x/shared/types/service_test.go ├── session.go // moved to x/shared/types/session.go ├── session_test.go // moved to x/shared/types/session_test.go ├── supplier.go // combined with x/shared/types/supplier.go └── types ├── supplier.go └── ... ``` #### After ``` x └── shared └── types ├── service_configs.go ├── service_test.go ├── session.go ├── session_test.go ├── supplier.go └── ... ``` ## Issue I went looking for `GetSessionEndToProofWindowCloseBlocks()` knowing it exists but was unable to find it easily. This PR attempts to resolve a structural inconsistency within the shared module's packages. - #N/A ## Type of change Select one or more from the following: - [ ] New feature, functionality or library - [ ] Consensus breaking; add the `consensus-breaking` label if so. See #791 for details - [ ] Bug fix - [x] Code health or cleanup - [ ] Documentation - [ ] Other (specify) ## Testing - [ ] **Documentation**: `make docusaurus_start`; only needed if you make doc changes - [ ] **Unit Tests**: `make go_develop_and_test` - [ ] **LocalNet E2E Tests**: `make test_e2e` - [ ] **DevNet E2E Tests**: Add the `devnet-test-e2e` label to the PR. ## Sanity Checklist - [ ] I have tested my changes using the available tooling - [ ] I have commented my code - [x] I have performed a self-review of my own code; both comments & source code - [ ] I create and reference any new tickets, if applicable - [ ] I have left TODOs throughout the codebase, if applicable --- e2e/tests/init_test.go | 3 +- .../tests/relays_stress_helpers_test.go | 5 +-- pkg/client/query/sharedquerier.go | 15 +++---- pkg/crypto/rings/client.go | 3 +- pkg/relayer/proxy/proxy_test.go | 7 ++- pkg/relayer/proxy/relay_verifier.go | 10 ++--- pkg/relayer/session/claim.go | 11 ++--- pkg/relayer/session/proof.go | 11 +++-- pkg/relayer/session/session.go | 7 ++- pkg/relayer/session/session_test.go | 9 ++-- .../application/application_transfer_test.go | 5 +-- .../integration/application/min_stake_test.go | 3 +- .../service/relay_mining_difficulty_test.go | 7 ++- .../tokenomics/tokenomics_example_test.go | 3 +- testutil/session/session.go | 17 ++++---- .../testqueryclients/sharedquerier.go | 11 +++-- .../msg_server_transfer_application_test.go | 3 +- ...msg_server_undelegate_from_gateway_test.go | 3 +- .../keeper/msg_server_unstake_application.go | 18 ++++---- x/application/keeper/transfer_applications.go | 28 ++++++------ x/application/keeper/unbond_applications.go | 4 +- x/application/types/application.go | 4 +- x/application/types/genesis.go | 4 +- .../types/message_stake_application.go | 3 +- .../keeper/msg_server_create_claim_test.go | 15 +++---- x/proof/keeper/msg_server_submit_proof.go | 5 +-- .../keeper/msg_server_submit_proof_test.go | 29 ++++++------- x/proof/keeper/proof_validation_test.go | 5 +-- x/proof/keeper/session.go | 9 ++-- x/proof/types/shared_query_client.go | 15 +++---- x/session/keeper/session_hydrator.go | 9 ++-- .../keeper/msg_server_update_param_test.go | 6 +-- x/shared/keeper/session.go | 10 ++--- x/shared/supplier.go | 16 ------- x/shared/types/params.go | 11 ----- .../{helpers => types}/service_configs.go | 36 ++++++++-------- x/shared/{helpers => types}/service_test.go | 15 +++---- x/shared/{ => types}/session.go | 43 ++++++++++--------- x/shared/{ => types}/session_test.go | 22 +++++----- x/shared/types/supplier.go | 11 +++++ x/supplier/config/supplier_configs_reader.go | 3 +- .../keeper/msg_server_stake_supplier.go | 5 +-- .../keeper/msg_server_unstake_supplier.go | 5 +-- .../msg_server_unstake_supplier_test.go | 7 ++- x/supplier/keeper/unbond_suppliers.go | 14 +++--- x/supplier/types/genesis.go | 3 +- x/supplier/types/message_stake_supplier.go | 3 +- .../keeper_settle_pending_claims_test.go | 31 +++++++------ x/tokenomics/keeper/settle_pending_claims.go | 3 +- 49 files changed, 239 insertions(+), 286 deletions(-) delete mode 100644 x/shared/supplier.go rename x/shared/{helpers => types}/service_configs.go (70%) rename x/shared/{helpers => types}/service_test.go (92%) rename x/shared/{ => types}/session.go (84%) rename x/shared/{ => types}/session_test.go (85%) diff --git a/e2e/tests/init_test.go b/e2e/tests/init_test.go index 7ea4359ea..c4df34b45 100644 --- a/e2e/tests/init_test.go +++ b/e2e/tests/init_test.go @@ -38,7 +38,6 @@ import ( prooftypes "github.com/pokt-network/poktroll/x/proof/types" servicetypes "github.com/pokt-network/poktroll/x/service/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -781,7 +780,7 @@ func (s *suite) getSupplierUnbondingHeight(accName string) int64 { responseBz := []byte(strings.TrimSpace(res.Stdout)) s.cdc.MustUnmarshalJSON(responseBz, &resp) - return shared.GetSupplierUnbondingHeight(&resp.Params, supplier) + return sharedtypes.GetSupplierUnbondingHeight(&resp.Params, supplier) } // getApplicationInfo returns the application information for a given application address. diff --git a/load-testing/tests/relays_stress_helpers_test.go b/load-testing/tests/relays_stress_helpers_test.go index a6e618d9b..97d5b1339 100644 --- a/load-testing/tests/relays_stress_helpers_test.go +++ b/load-testing/tests/relays_stress_helpers_test.go @@ -40,7 +40,6 @@ import ( "github.com/pokt-network/poktroll/testutil/testclient/testeventsquery" apptypes "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" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -379,9 +378,9 @@ func (plans *actorLoadTestIncrementPlans) totalDurationBlocks( // The last block of the last session SHOULD align with the last block of the // last increment duration (i.e. **after** maxActorCount actors are activated). blocksToFinalSessionEnd := plans.maxActorBlocksToFinalIncrementEnd() - finalSessionEndHeight := shared.GetSessionEndHeight(sharedParams, currentHeight+blocksToFinalSessionEnd) + finalSessionEndHeight := sharedtypes.GetSessionEndHeight(sharedParams, currentHeight+blocksToFinalSessionEnd) - return shared.GetProofWindowCloseHeight(sharedParams, finalSessionEndHeight) - currentHeight + return sharedtypes.GetProofWindowCloseHeight(sharedParams, finalSessionEndHeight) - currentHeight } // blocksToFinalIncrementStart returns the number of blocks that will have diff --git a/pkg/client/query/sharedquerier.go b/pkg/client/query/sharedquerier.go index 4f0fb7691..d3f3308d9 100644 --- a/pkg/client/query/sharedquerier.go +++ b/pkg/client/query/sharedquerier.go @@ -7,7 +7,6 @@ import ( "github.com/cosmos/gogoproto/grpc" "github.com/pokt-network/poktroll/pkg/client" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -71,7 +70,7 @@ func (sq *sharedQuerier) GetClaimWindowOpenHeight(ctx context.Context, queryHeig if err != nil { return 0, err } - return shared.GetClaimWindowOpenHeight(sharedParams, queryHeight), nil + return sharedtypes.GetClaimWindowOpenHeight(sharedParams, queryHeight), nil } // GetProofWindowOpenHeight returns the block height at which the proof window of @@ -87,7 +86,7 @@ func (sq *sharedQuerier) GetProofWindowOpenHeight(ctx context.Context, queryHeig if err != nil { return 0, err } - return shared.GetProofWindowOpenHeight(sharedParams, queryHeight), nil + return sharedtypes.GetProofWindowOpenHeight(sharedParams, queryHeight), nil } // GetSessionGracePeriodEndHeight returns the block height at which the grace period @@ -108,7 +107,7 @@ func (sq *sharedQuerier) GetSessionGracePeriodEndHeight( if err != nil { return 0, err } - return shared.GetSessionGracePeriodEndHeight(sharedParams, queryHeight), nil + return sharedtypes.GetSessionGracePeriodEndHeight(sharedParams, queryHeight), nil } // GetEarliestSupplierClaimCommitHeight returns the earliest block height at which a claim @@ -127,7 +126,7 @@ func (sq *sharedQuerier) GetEarliestSupplierClaimCommitHeight(ctx context.Contex // Fetch the block at the proof window open height. Its hash is used as part // of the seed to the pseudo-random number generator. - claimWindowOpenHeight := shared.GetClaimWindowOpenHeight(sharedParams, queryHeight) + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight(sharedParams, queryHeight) claimWindowOpenBlock, err := sq.blockQuerier.Block(ctx, &claimWindowOpenHeight) if err != nil { return 0, err @@ -136,7 +135,7 @@ func (sq *sharedQuerier) GetEarliestSupplierClaimCommitHeight(ctx context.Contex // NB: Byte slice representation of block hashes don't need to be normalized. claimWindowOpenBlockHash := claimWindowOpenBlock.BlockID.Hash.Bytes() - return shared.GetEarliestSupplierClaimCommitHeight( + return sharedtypes.GetEarliestSupplierClaimCommitHeight( sharedParams, queryHeight, claimWindowOpenBlockHash, @@ -160,13 +159,13 @@ func (sq *sharedQuerier) GetEarliestSupplierProofCommitHeight(ctx context.Contex // Fetch the block at the proof window open height. Its hash is used as part // of the seed to the pseudo-random number generator. - proofWindowOpenHeight := shared.GetProofWindowOpenHeight(sharedParams, queryHeight) + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight(sharedParams, queryHeight) proofWindowOpenBlock, err := sq.blockQuerier.Block(ctx, &proofWindowOpenHeight) if err != nil { return 0, err } - return shared.GetEarliestSupplierProofCommitHeight( + return sharedtypes.GetEarliestSupplierProofCommitHeight( sharedParams, queryHeight, proofWindowOpenBlock.BlockID.Hash, diff --git a/pkg/crypto/rings/client.go b/pkg/crypto/rings/client.go index 53ab1f3ae..c33d5832e 100644 --- a/pkg/crypto/rings/client.go +++ b/pkg/crypto/rings/client.go @@ -16,7 +16,6 @@ import ( "github.com/pokt-network/poktroll/pkg/polylog" apptypes "github.com/pokt-network/poktroll/x/application/types" "github.com/pokt-network/poktroll/x/service/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -294,7 +293,7 @@ func GetRingAddressesAtBlock( blockHeight int64, ) []string { // Get the target session end height at which we want to get the active delegations. - targetSessionEndHeight := uint64(shared.GetSessionEndHeight(sharedParams, blockHeight)) + targetSessionEndHeight := uint64(sharedtypes.GetSessionEndHeight(sharedParams, blockHeight)) return GetRingAddressesAtSessionEndHeight(app, targetSessionEndHeight) } diff --git a/pkg/relayer/proxy/proxy_test.go b/pkg/relayer/proxy/proxy_test.go index b4481e8d8..3a022bc25 100644 --- a/pkg/relayer/proxy/proxy_test.go +++ b/pkg/relayer/proxy/proxy_test.go @@ -18,7 +18,6 @@ import ( "github.com/pokt-network/poktroll/pkg/relayer/config" "github.com/pokt-network/poktroll/pkg/relayer/proxy" "github.com/pokt-network/poktroll/testutil/testproxy" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -356,17 +355,17 @@ func TestRelayerProxy_Relays(t *testing.T) { sharedParams := sharedtypes.DefaultParams() - sessionTwoStartHeight := shared.GetSessionEndHeight(&sharedParams, blockHeight) + 1 + sessionTwoStartHeight := sharedtypes.GetSessionEndHeight(&sharedParams, blockHeight) + 1 // blockOutsideSessionGracePeriod is the block height that is after the first // session's grace period and within the second session's grace period, // meaning a relay should be handled as part of the session two AND NOT session one. - blockOutsideSessionGracePeriod := shared.GetSessionGracePeriodEndHeight(&sharedParams, sessionTwoStartHeight) + blockOutsideSessionGracePeriod := sharedtypes.GetSessionGracePeriodEndHeight(&sharedParams, sessionTwoStartHeight) // blockWithinSessionGracePeriod is the block height that is after the first // session but within its session's grace period, meaning a relay should be // handled at this block height. - blockWithinSessionGracePeriod := shared.GetSessionGracePeriodEndHeight(&sharedParams, blockHeight) - 1 + blockWithinSessionGracePeriod := sharedtypes.GetSessionGracePeriodEndHeight(&sharedParams, blockHeight) - 1 tests := []struct { desc string diff --git a/pkg/relayer/proxy/relay_verifier.go b/pkg/relayer/proxy/relay_verifier.go index d4888fbe7..f3b998c0f 100644 --- a/pkg/relayer/proxy/relay_verifier.go +++ b/pkg/relayer/proxy/relay_verifier.go @@ -3,15 +3,15 @@ package proxy import ( "context" - "github.com/pokt-network/poktroll/x/service/types" - "github.com/pokt-network/poktroll/x/shared" + servicetypes "github.com/pokt-network/poktroll/x/service/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // VerifyRelayRequest is a shared method used by RelayServers to check the relay // request signature and session validity. func (rp *relayerProxy) VerifyRelayRequest( ctx context.Context, - relayRequest *types.RelayRequest, + relayRequest *servicetypes.RelayRequest, supplierServiceId string, ) error { // Get the block height at which the relayRequest should be processed. @@ -97,7 +97,7 @@ func (rp *relayerProxy) VerifyRelayRequest( // If the session has expired, then return an error. func (rp *relayerProxy) getTargetSessionBlockHeight( ctx context.Context, - relayRequest *types.RelayRequest, + relayRequest *servicetypes.RelayRequest, ) (sessionHeight int64, err error) { currentHeight := rp.blockClient.LastBlock(ctx).Height() sessionEndHeight := relayRequest.Meta.SessionHeader.GetSessionEndBlockHeight() @@ -116,7 +116,7 @@ func (rp *relayerProxy) getTargetSessionBlockHeight( if sessionEndHeight < currentHeight { // Do not process the `RelayRequest` if the session has expired and the current // block height is outside the session's grace period. - if !shared.IsGracePeriodElapsed(sharedParams, sessionEndHeight, currentHeight) { + if !sharedtypes.IsGracePeriodElapsed(sharedParams, sessionEndHeight, currentHeight) { // The RelayRequest's session has expired but is still within the // grace period so process it as if the session is still active. return sessionEndHeight, nil diff --git a/pkg/relayer/session/claim.go b/pkg/relayer/session/claim.go index 7bf05924b..ea508d1d8 100644 --- a/pkg/relayer/session/claim.go +++ b/pkg/relayer/session/claim.go @@ -5,6 +5,8 @@ import ( "fmt" "slices" + "github.com/pokt-network/smt" + "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/either" "github.com/pokt-network/poktroll/pkg/observable" @@ -13,8 +15,7 @@ import ( "github.com/pokt-network/poktroll/pkg/observable/logging" "github.com/pokt-network/poktroll/pkg/relayer" prooftypes "github.com/pokt-network/poktroll/x/proof/types" - "github.com/pokt-network/poktroll/x/shared" - "github.com/pokt-network/smt" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // createClaims maps over the sessionsToClaimObs observable. For each claim batch, it: @@ -56,7 +57,7 @@ func (rs *relayerSessionsManager) createClaims( // Delete expired session trees so they don't get claimed again. channel.ForEach( ctx, failedCreateClaimSessionsObs, - rs.deleteExpiredSessionTreesFn(shared.GetClaimWindowCloseHeight), + rs.deleteExpiredSessionTreesFn(sharedtypes.GetClaimWindowCloseHeight), ) // Map eitherClaimedSessions to a new observable of []relayer.SessionTree @@ -115,7 +116,7 @@ func (rs *relayerSessionsManager) waitForEarliestCreateClaimsHeight( return nil } - claimWindowOpenHeight := shared.GetClaimWindowOpenHeight(sharedParams, sessionEndHeight) + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight(sharedParams, sessionEndHeight) // we wait for claimWindowOpenHeight to be received before proceeding since we need its hash // to know where this servicer's claim submission window opens. @@ -149,7 +150,7 @@ func (rs *relayerSessionsManager) waitForEarliestCreateClaimsHeight( // Get the earliest claim commit height for this supplier. supplierOperatorAddr := sessionTrees[0].GetSupplierOperatorAddress().String() - earliestSupplierClaimsCommitHeight := shared.GetEarliestSupplierClaimCommitHeight( + earliestSupplierClaimsCommitHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( sharedParams, sessionEndHeight, claimsWindowOpenBlock.Hash(), diff --git a/pkg/relayer/session/proof.go b/pkg/relayer/session/proof.go index 05f6b4cbe..9a1b61b03 100644 --- a/pkg/relayer/session/proof.go +++ b/pkg/relayer/session/proof.go @@ -12,9 +12,8 @@ import ( "github.com/pokt-network/poktroll/pkg/observable/filter" "github.com/pokt-network/poktroll/pkg/observable/logging" "github.com/pokt-network/poktroll/pkg/relayer" - "github.com/pokt-network/poktroll/x/proof/types" prooftypes "github.com/pokt-network/poktroll/x/proof/types" - "github.com/pokt-network/poktroll/x/shared" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // submitProofs maps over the given claimedSessions observable. @@ -53,7 +52,7 @@ func (rs *relayerSessionsManager) submitProofs( // Delete expired session trees so they don't get proven again. channel.ForEach( ctx, failedSubmitProofsSessionsObs, - rs.deleteExpiredSessionTreesFn(shared.GetProofWindowCloseHeight), + rs.deleteExpiredSessionTreesFn(sharedtypes.GetProofWindowCloseHeight), ) } @@ -102,7 +101,7 @@ func (rs *relayerSessionsManager) waitForEarliestSubmitProofsHeightAndGeneratePr return nil } - proofWindowOpenHeight := shared.GetProofWindowOpenHeight(sharedParams, sessionEndHeight) + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight(sharedParams, sessionEndHeight) // we wait for proofWindowOpenHeight to be received before proceeding since we need // its hash to seed the pseudo-random number generator for the proof submission @@ -127,7 +126,7 @@ func (rs *relayerSessionsManager) waitForEarliestSubmitProofsHeightAndGeneratePr // Get the earliest proof commit height for this supplier. supplierOperatorAddr := sessionTrees[0].GetSupplierOperatorAddress().String() - earliestSupplierProofsCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofsCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( sharedParams, sessionEndHeight, proofsWindowOpenBlock.Hash(), @@ -170,7 +169,7 @@ func (rs *relayerSessionsManager) newMapProveSessionsFn( // Map key is the supplier operator address. proofMsgs := make([]client.MsgSubmitProof, len(sessionTrees)) for idx, session := range sessionTrees { - proofMsgs[idx] = &types.MsgSubmitProof{ + proofMsgs[idx] = &prooftypes.MsgSubmitProof{ Proof: session.GetProofBz(), SessionHeader: session.GetSessionHeader(), SupplierOperatorAddress: session.GetSupplierOperatorAddress().String(), diff --git a/pkg/relayer/session/session.go b/pkg/relayer/session/session.go index 2578d1b15..d3999f7d6 100644 --- a/pkg/relayer/session/session.go +++ b/pkg/relayer/session/session.go @@ -14,8 +14,7 @@ import ( "github.com/pokt-network/poktroll/pkg/observable/logging" "github.com/pokt-network/poktroll/pkg/polylog" "github.com/pokt-network/poktroll/pkg/relayer" - "github.com/pokt-network/poktroll/x/service/types" - "github.com/pokt-network/poktroll/x/shared" + servicetypes "github.com/pokt-network/poktroll/x/service/types" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -157,7 +156,7 @@ func (rs *relayerSessionsManager) InsertRelays(relays relayer.MinedRelaysObserva // corresponding to the relay request metadata. // If no tree for the session exists, a new SessionTree is created before returning. func (rs *relayerSessionsManager) ensureSessionTree( - relayRequestMetadata *types.RelayRequestMetadata, + relayRequestMetadata *servicetypes.RelayRequestMetadata, ) (relayer.SessionTree, error) { rs.sessionsTreesMu.Lock() defer rs.sessionsTreesMu.Unlock() @@ -257,7 +256,7 @@ func (rs *relayerSessionsManager) forEachBlockClaimSessionsFn( // before emitting the on-time sessions. var lateSessions []relayer.SessionTree - claimWindowOpenHeight := shared.GetClaimWindowOpenHeight(sharedParams, sessionEndHeight) + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight(sharedParams, sessionEndHeight) // Checking for sessions to claim with <= operator, // which means that it would include sessions that were supposed to be diff --git a/pkg/relayer/session/session_test.go b/pkg/relayer/session/session_test.go index 31e094a42..f00f6d58b 100644 --- a/pkg/relayer/session/session_test.go +++ b/pkg/relayer/session/session_test.go @@ -33,7 +33,6 @@ import ( "github.com/pokt-network/poktroll/testutil/testrelayer" prooftypes "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -370,8 +369,8 @@ func playClaimAndProofSubmissionBlocks( // Calculate the session grace period end block height to emit that block height // to the blockPublishCh to trigger session trees processing for the session number. sharedParams := sharedtypes.DefaultParams() - claimWindowOpenHeight := shared.GetClaimWindowOpenHeight(&sharedParams, sessionEndHeight) - earliestSupplierClaimCommitHeight := shared.GetEarliestSupplierClaimCommitHeight( + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight(&sharedParams, sessionEndHeight) + earliestSupplierClaimCommitHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionEndHeight, blockHash, @@ -389,14 +388,14 @@ func playClaimAndProofSubmissionBlocks( waitSimulateIO() - proofWindowOpenHeight := shared.GetProofWindowOpenHeight(&sharedParams, sessionEndHeight) + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight(&sharedParams, sessionEndHeight) proofPathSeedBlock := testblock.NewAnyTimesBlock(t, blockHash, proofWindowOpenHeight) blockPublishCh <- proofPathSeedBlock waitSimulateIO() // Publish a block to the blockPublishCh to trigger proof submission for the session. - earliestSupplierProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, sessionEndHeight, blockHash, diff --git a/tests/integration/application/application_transfer_test.go b/tests/integration/application/application_transfer_test.go index 1e3ef2b09..d9b842fb5 100644 --- a/tests/integration/application/application_transfer_test.go +++ b/tests/integration/application/application_transfer_test.go @@ -15,7 +15,6 @@ import ( "github.com/pokt-network/poktroll/testutil/integration/suites" "github.com/pokt-network/poktroll/testutil/testkeyring" apptypes "github.com/pokt-network/poktroll/x/application/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -95,7 +94,7 @@ func (s *appTransferTestSuite) TestSingleSourceToNonexistentDestinationSucceeds( require.NoError(s.T(), err) sharedParams := sharedParamsAny.(sharedtypes.Params) - sessionEndHeight := shared.GetSessionEndHeight(&sharedParams, s.SdkCtx().BlockHeight()) + sessionEndHeight := sharedtypes.GetSessionEndHeight(&sharedParams, s.SdkCtx().BlockHeight()) transferBeginHeight := s.SdkCtx().BlockHeight() @@ -192,7 +191,7 @@ func (s *appTransferTestSuite) TestMultipleSourceToSameNonexistentDestinationMer sharedParams := sharedParamsAny.(sharedtypes.Params) msgTransferAppTypeURL := cosmostypes.MsgTypeURL(&apptypes.MsgTransferApplication{}) - sessionEndHeight := shared.GetSessionEndHeight(&sharedParams, s.SdkCtx().BlockHeight()) + sessionEndHeight := sharedtypes.GetSessionEndHeight(&sharedParams, s.SdkCtx().BlockHeight()) transferBeginHeight := s.SdkCtx().BlockHeight() diff --git a/tests/integration/application/min_stake_test.go b/tests/integration/application/min_stake_test.go index 0815dba96..1c85cbc04 100644 --- a/tests/integration/application/min_stake_test.go +++ b/tests/integration/application/min_stake_test.go @@ -20,7 +20,6 @@ import ( apptypes "github.com/pokt-network/poktroll/x/application/types" prooftypes "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -94,7 +93,7 @@ func (s *applicationMinStakeTestSuite) TestAppIsUnbondedIfBelowMinStakeWhenSettl sdkCtx := cosmostypes.UnwrapSDKContext(s.ctx) currentHeight := sdkCtx.BlockHeight() sharedParams := s.keepers.SharedKeeper.GetParams(s.ctx) - currentSessionEndHeight := shared.GetSessionEndHeight(&sharedParams, currentHeight) + currentSessionEndHeight := sharedtypes.GetSessionEndHeight(&sharedParams, currentHeight) claimSettlementHeight := currentSessionEndHeight + int64(sharedtypes.GetSessionEndToProofWindowCloseBlocks(&sharedParams)) + 1 sdkCtx = sdkCtx.WithBlockHeight(claimSettlementHeight) s.ctx = sdkCtx diff --git a/tests/integration/service/relay_mining_difficulty_test.go b/tests/integration/service/relay_mining_difficulty_test.go index 7b34bd71e..a8589307e 100644 --- a/tests/integration/service/relay_mining_difficulty_test.go +++ b/tests/integration/service/relay_mining_difficulty_test.go @@ -20,7 +20,6 @@ import ( prooftypes "github.com/pokt-network/poktroll/x/proof/types" servicetypes "github.com/pokt-network/poktroll/x/service/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -63,19 +62,19 @@ func TestUpdateRelayMiningDifficulty_NewServiceSeenForTheFirstTime(t *testing.T) // Compute the number of blocks to wait between different events // TODO_BLOCKER(@bryanchriswhite): See this comment: https://github.com/pokt-network/poktroll/pull/610#discussion_r1645777322 sessionEndHeight := session.Header.SessionEndBlockHeight - earliestSupplierClaimCommitHeight := shared.GetEarliestSupplierClaimCommitHeight( + earliestSupplierClaimCommitHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionEndHeight, claimWindowOpenBlockHash, integrationApp.DefaultSupplier.GetOperatorAddress(), ) - earliestSupplierProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, sessionEndHeight, proofWindowOpenBlockHash, integrationApp.DefaultSupplier.GetOperatorAddress(), ) - proofWindowCloseHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + proofWindowCloseHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) // Wait until the earliest claim commit height. currentBlockHeight := sdkCtx.BlockHeight() diff --git a/tests/integration/tokenomics/tokenomics_example_test.go b/tests/integration/tokenomics/tokenomics_example_test.go index fe6bd7dd5..6ef5dcf35 100644 --- a/tests/integration/tokenomics/tokenomics_example_test.go +++ b/tests/integration/tokenomics/tokenomics_example_test.go @@ -10,7 +10,6 @@ import ( testutilproof "github.com/pokt-network/poktroll/testutil/proof" prooftypes "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -55,7 +54,7 @@ func TestTokenomicsIntegrationExample(t *testing.T) { // Figure out how many blocks we need to wait until the earliest claim commit height // Query and validate the default shared params var claimWindowOpenBlockHash []byte - earliestClaimCommitHeight := shared.GetEarliestSupplierClaimCommitHeight( + earliestClaimCommitHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, session.GetHeader().GetSessionEndBlockHeight(), claimWindowOpenBlockHash, diff --git a/testutil/session/session.go b/testutil/session/session.go index aac62eb5b..84f9c4495 100644 --- a/testutil/session/session.go +++ b/testutil/session/session.go @@ -2,8 +2,7 @@ package session import ( "github.com/pokt-network/poktroll/x/session/keeper" - "github.com/pokt-network/poktroll/x/shared" - "github.com/pokt-network/poktroll/x/shared/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // GetSessionIdWithDefaultParams returns the string and bytes representation of the @@ -15,7 +14,7 @@ func GetSessionIdWithDefaultParams( blockHashBz []byte, blockHeight int64, ) (sessionId string, sessionIdBz []byte) { - sharedParams := types.DefaultParams() + sharedParams := sharedtypes.DefaultParams() return keeper.GetSessionId(&sharedParams, appPubKey, serviceId, blockHashBz, blockHeight) } @@ -24,22 +23,22 @@ func GetSessionIdWithDefaultParams( // parameters. // See shared.GetSessionStartHeight for more details. func GetSessionStartHeightWithDefaultParams(queryHeight int64) int64 { - sharedParams := types.DefaultParams() - return shared.GetSessionStartHeight(&sharedParams, queryHeight) + sharedParams := sharedtypes.DefaultParams() + return sharedtypes.GetSessionStartHeight(&sharedParams, queryHeight) } // GetSessionEndHeightWithDefaultParams returns the block height at which the session // containing queryHeight ends, given the default shared on-chain parameters. // See shared.GetSessionEndHeight for more details. func GetSessionEndHeightWithDefaultParams(queryHeight int64) int64 { - sharedParams := types.DefaultParams() - return shared.GetSessionEndHeight(&sharedParams, queryHeight) + sharedParams := sharedtypes.DefaultParams() + return sharedtypes.GetSessionEndHeight(&sharedParams, queryHeight) } // GetSessionNumberWithDefaultParams returns the session number of the session // containing queryHeight, given the default on-chain shared parameters. // See shared.GetSessionNumber for more details. func GetSessionNumberWithDefaultParams(queryHeight int64) int64 { - sharedParams := types.DefaultParams() - return shared.GetSessionNumber(&sharedParams, queryHeight) + sharedParams := sharedtypes.DefaultParams() + return sharedtypes.GetSessionNumber(&sharedParams, queryHeight) } diff --git a/testutil/testclient/testqueryclients/sharedquerier.go b/testutil/testclient/testqueryclients/sharedquerier.go index 8abb9c312..7bbb2b976 100644 --- a/testutil/testclient/testqueryclients/sharedquerier.go +++ b/testutil/testclient/testqueryclients/sharedquerier.go @@ -7,7 +7,6 @@ import ( "github.com/golang/mock/gomock" "github.com/pokt-network/poktroll/testutil/mockclient" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -31,7 +30,7 @@ func NewTestSharedQueryClient( DoAndReturn( func(ctx context.Context, queryHeight int64) (int64, error) { sharedParams := sharedtypes.DefaultParams() - return shared.GetClaimWindowOpenHeight(&sharedParams, queryHeight), nil + return sharedtypes.GetClaimWindowOpenHeight(&sharedParams, queryHeight), nil }, ). AnyTimes() @@ -41,7 +40,7 @@ func NewTestSharedQueryClient( DoAndReturn( func(ctx context.Context, queryHeight int64) (int64, error) { sharedParams := sharedtypes.DefaultParams() - return shared.GetProofWindowOpenHeight(&sharedParams, queryHeight), nil + return sharedtypes.GetProofWindowOpenHeight(&sharedParams, queryHeight), nil }, ). AnyTimes() @@ -51,7 +50,7 @@ func NewTestSharedQueryClient( DoAndReturn( func(ctx context.Context, queryHeight int64) (int64, error) { sharedParams := sharedtypes.DefaultParams() - return shared.GetSessionGracePeriodEndHeight(&sharedParams, queryHeight), nil + return sharedtypes.GetSessionGracePeriodEndHeight(&sharedParams, queryHeight), nil }, ). AnyTimes() @@ -65,7 +64,7 @@ func NewTestSharedQueryClient( supplierOperatorAddr string, ) (int64, error) { sharedParams := sharedtypes.DefaultParams() - return shared.GetEarliestSupplierClaimCommitHeight( + return sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionEndHeight, []byte{}, @@ -84,7 +83,7 @@ func NewTestSharedQueryClient( supplierOperatorAddr string, ) (int64, error) { sharedParams := sharedtypes.DefaultParams() - return shared.GetEarliestSupplierProofCommitHeight( + return sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, sessionEndHeight, []byte{}, diff --git a/x/application/keeper/msg_server_transfer_application_test.go b/x/application/keeper/msg_server_transfer_application_test.go index f301a0339..5c3f3e3cf 100644 --- a/x/application/keeper/msg_server_transfer_application_test.go +++ b/x/application/keeper/msg_server_transfer_application_test.go @@ -12,7 +12,6 @@ import ( "github.com/pokt-network/poktroll/testutil/sample" appkeeper "github.com/pokt-network/poktroll/x/application/keeper" apptypes "github.com/pokt-network/poktroll/x/application/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -55,7 +54,7 @@ func TestMsgServer_TransferApplication_Success(t *testing.T) { require.Equal(t, "svc1", srcApp.GetServiceConfigs()[0].GetServiceId()) transferBeginHeight := cosmostypes.UnwrapSDKContext(ctx).BlockHeight() - transferSessionEndHeight := shared.GetSessionEndHeight(&sharedParams, transferBeginHeight) + transferSessionEndHeight := sharedtypes.GetSessionEndHeight(&sharedParams, transferBeginHeight) expectedPendingTransfer := &apptypes.PendingApplicationTransfer{ DestinationAddress: dstBech32, SessionEndHeight: uint64(transferSessionEndHeight), 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 a3f1abf8b..b9395182a 100644 --- a/x/application/keeper/msg_server_undelegate_from_gateway_test.go +++ b/x/application/keeper/msg_server_undelegate_from_gateway_test.go @@ -16,7 +16,6 @@ import ( "github.com/pokt-network/poktroll/x/application/types" apptypes "github.com/pokt-network/poktroll/x/application/types" gwtypes "github.com/pokt-network/poktroll/x/gateway/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -344,7 +343,7 @@ func TestMsgServer_UndelegateFromGateway_DelegationIsActiveUntilNextSession(t *t // Increment the block height past the tested session's grace period and run // the pruning undelegations logic again. sharedParams := sharedtypes.DefaultParams() - afterSessionGracePeriodEndHeight := shared.GetSessionGracePeriodEndHeight(&sharedParams, sessionEndHeight) + 1 + afterSessionGracePeriodEndHeight := sharedtypes.GetSessionGracePeriodEndHeight(&sharedParams, sessionEndHeight) + 1 sdkCtx = sdkCtx.WithBlockHeight(afterSessionGracePeriodEndHeight) k.EndBlockerPruneAppToGatewayPendingUndelegation(sdkCtx) diff --git a/x/application/keeper/msg_server_unstake_application.go b/x/application/keeper/msg_server_unstake_application.go index f077fce85..51cadbbe4 100644 --- a/x/application/keeper/msg_server_unstake_application.go +++ b/x/application/keeper/msg_server_unstake_application.go @@ -7,15 +7,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pokt-network/poktroll/telemetry" - "github.com/pokt-network/poktroll/x/application/types" - "github.com/pokt-network/poktroll/x/shared" + apptypes "github.com/pokt-network/poktroll/x/application/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // TODO(#489): Determine if an application needs an unbonding period after unstaking. func (k msgServer) UnstakeApplication( ctx context.Context, - msg *types.MsgUnstakeApplication, -) (*types.MsgUnstakeApplicationResponse, error) { + msg *apptypes.MsgUnstakeApplication, +) (*apptypes.MsgUnstakeApplicationResponse, error) { isSuccessful := false defer telemetry.EventSuccessCounter( "unstake_application", @@ -30,14 +30,14 @@ func (k msgServer) UnstakeApplication( foundApp, isAppFound := k.GetApplication(ctx, msg.GetAddress()) if !isAppFound { logger.Info(fmt.Sprintf("Application not found. Cannot unstake address (%s)", msg.GetAddress())) - return nil, types.ErrAppNotFound.Wrapf("application (%s)", msg.GetAddress()) + return nil, apptypes.ErrAppNotFound.Wrapf("application (%s)", msg.GetAddress()) } logger.Info(fmt.Sprintf("Application found. Unstaking application for address (%s)", msg.GetAddress())) // Check if the application has already initiated the unstaking process. if foundApp.IsUnbonding() { logger.Warn(fmt.Sprintf("Application (%s) is still unbonding from previous unstaking", msg.GetAddress())) - return nil, types.ErrAppIsUnstaking.Wrapf("application (%s)", msg.GetAddress()) + return nil, apptypes.ErrAppIsUnstaking.Wrapf("application (%s)", msg.GetAddress()) } // Check if the application has already initiated a transfer process. @@ -47,7 +47,7 @@ func (k msgServer) UnstakeApplication( "Application (%s) has a pending transfer to (%s)", msg.Address, foundApp.GetPendingTransfer().GetDestinationAddress()), ) - return nil, types.ErrAppHasPendingTransfer.Wrapf("application (%s)", msg.GetAddress()) + return nil, apptypes.ErrAppHasPendingTransfer.Wrapf("application (%s)", msg.GetAddress()) } sdkCtx := sdk.UnwrapSDKContext(ctx) @@ -58,11 +58,11 @@ func (k msgServer) UnstakeApplication( // no longer be able to request services. // The application MAY continue to request service until the end of the current // session. After that, the application will be considered inactive. - foundApp.UnstakeSessionEndHeight = uint64(shared.GetSessionEndHeight(&sharedParams, currentHeight)) + foundApp.UnstakeSessionEndHeight = uint64(sharedtypes.GetSessionEndHeight(&sharedParams, currentHeight)) k.SetApplication(ctx, foundApp) // TODO_UPNEXT:(@bryanchriswhite): emit a new EventApplicationUnbondingBegin event. isSuccessful = true - return &types.MsgUnstakeApplicationResponse{}, nil + return &apptypes.MsgUnstakeApplicationResponse{}, nil } diff --git a/x/application/keeper/transfer_applications.go b/x/application/keeper/transfer_applications.go index 95184c47c..29e8deda3 100644 --- a/x/application/keeper/transfer_applications.go +++ b/x/application/keeper/transfer_applications.go @@ -7,8 +7,8 @@ import ( cosmostypes "github.com/cosmos/cosmos-sdk/types" "github.com/pokt-network/poktroll/telemetry" - "github.com/pokt-network/poktroll/x/application/types" - "github.com/pokt-network/poktroll/x/shared" + apptypes "github.com/pokt-network/poktroll/x/application/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // EndBlockerTransferApplication completes pending application transfers. @@ -28,7 +28,7 @@ func (k Keeper) EndBlockerTransferApplication(ctx context.Context) error { sdkCtx := cosmostypes.UnwrapSDKContext(ctx) currentHeight := sdkCtx.BlockHeight() sharedParams := k.sharedKeeper.GetParams(ctx) - sessionEndHeight := shared.GetSessionEndHeight(&sharedParams, currentHeight) + sessionEndHeight := sharedtypes.GetSessionEndHeight(&sharedParams, currentHeight) logger := k.Logger(). With("method", "EndBlockerTransferApplication"). With("current_height", currentHeight). @@ -36,7 +36,7 @@ func (k Keeper) EndBlockerTransferApplication(ctx context.Context) error { // Only process application transfers at the end of the session in // order to avoid inconsistent/unpredictable mid-session behavior. - if !shared.IsSessionEndHeight(&sharedParams, currentHeight) { + if !sharedtypes.IsSessionEndHeight(&sharedParams, currentHeight) { return nil } @@ -52,7 +52,7 @@ func (k Keeper) EndBlockerTransferApplication(ctx context.Context) error { // Ignore applications that have initiated a transfer but still active. // This spans the period from the end of the session in which the transfer // began to the end of settlement for that session. - transferEndHeight := types.GetApplicationTransferHeight(&sharedParams, &srcApp) + transferEndHeight := apptypes.GetApplicationTransferHeight(&sharedParams, &srcApp) if sdkCtx.BlockHeight() < transferEndHeight { continue } @@ -67,7 +67,7 @@ func (k Keeper) EndBlockerTransferApplication(ctx context.Context) error { srcApp.PendingTransfer = nil k.SetApplication(ctx, srcApp) - if err := sdkCtx.EventManager().EmitTypedEvent(&types.EventTransferError{ + if err := sdkCtx.EventManager().EmitTypedEvent(&apptypes.EventTransferError{ SourceAddress: srcApp.GetAddress(), DestinationAddress: dstBech32, SourceApplication: &srcApp, @@ -99,14 +99,14 @@ func (k Keeper) EndBlockerTransferApplication(ctx context.Context) error { // Duplicate pending undelegations resolve to the destination application's. // // It is intended to be called during the EndBlock ABCI method. -func (k Keeper) transferApplication(ctx context.Context, srcApp types.Application) error { +func (k Keeper) transferApplication(ctx context.Context, srcApp apptypes.Application) error { logger := k.Logger().With("method", "transferApplication") // Double-check that the source application is not unbonding. // NB: This SHOULD NOT be possible because applications SHOULD NOT be able // to unstake when they have a pending transfer. if srcApp.IsUnbonding() { - return types.ErrAppIsUnstaking.Wrapf("cannot transfer stake of unbonding source application (%s)", srcApp.GetAddress()) + return apptypes.ErrAppIsUnstaking.Wrapf("cannot transfer stake of unbonding source application (%s)", srcApp.GetAddress()) } // Check if the destination application already exists: @@ -147,7 +147,7 @@ func (k Keeper) transferApplication(ctx context.Context, srcApp types.Applicatio logger.Info(fmt.Sprintf("Successfully transferred application stake from (%s) to (%s)", srcApp.GetAddress(), dstApp.GetAddress())) sdkCtx := cosmostypes.UnwrapSDKContext(ctx) - if err := sdkCtx.EventManager().EmitTypedEvent(&types.EventTransferEnd{ + if err := sdkCtx.EventManager().EmitTypedEvent(&apptypes.EventTransferEnd{ SourceAddress: srcApp.GetAddress(), DestinationAddress: dstApp.GetAddress(), DestinationApplication: &dstApp, @@ -160,7 +160,7 @@ func (k Keeper) transferApplication(ctx context.Context, srcApp types.Applicatio // mergeAppDelegatees takes the union of the srcApp and dstApp's delegatees and // sets the result in dstApp. -func mergeAppDelegatees(srcApp, dstApp *types.Application) { +func mergeAppDelegatees(srcApp, dstApp *apptypes.Application) { // Build a set of the destination application's delegatees. delagateeBech32Set := make(map[string]struct{}) for _, dstDelegateeBech32 := range dstApp.DelegateeGatewayAddresses { @@ -186,7 +186,7 @@ func mergeAppDelegatees(srcApp, dstApp *types.Application) { // (i.e. this undelegation is unchanged) and that gateway address is excluded from the // gateway address union at the height which it is present in the source application's // pending undelegations. -func mergeAppPendingUndelegations(srcApp, dstApp *types.Application) { +func mergeAppPendingUndelegations(srcApp, dstApp *apptypes.Application) { // Build a map from all gateway addresses which have pending undelegations to // their respective undelegation session end heights. If the source and destination // applications both contain pending undelegations from the same gateway address, the @@ -210,11 +210,11 @@ func mergeAppPendingUndelegations(srcApp, dstApp *types.Application) { // Reset the destination application's pending undelegations and rebuild it // from the undelegations union map. - dstApp.PendingUndelegations = make(map[uint64]types.UndelegatingGatewayList) + dstApp.PendingUndelegations = make(map[uint64]apptypes.UndelegatingGatewayList) for gatewayAddr, height := range undelegationsUnionAddrToHeightMap { dstPendingUndelegationsAtHeight, ok := dstApp.PendingUndelegations[height] if !ok { - dstApp.PendingUndelegations[height] = types.UndelegatingGatewayList{ + dstApp.PendingUndelegations[height] = apptypes.UndelegatingGatewayList{ GatewayAddresses: []string{gatewayAddr}, } } else { @@ -226,7 +226,7 @@ func mergeAppPendingUndelegations(srcApp, dstApp *types.Application) { // mergeAppServiceConfigs takes the union of the srcApp and dstApp's service configs // and sets the result in dstApp. -func mergeAppServiceConfigs(srcApp, dstApp *types.Application) { +func mergeAppServiceConfigs(srcApp, dstApp *apptypes.Application) { // Build a set of the destination application's service configs. serviceIDSet := make(map[string]struct{}) for _, dstServiceConfig := range dstApp.ServiceConfigs { diff --git a/x/application/keeper/unbond_applications.go b/x/application/keeper/unbond_applications.go index 1ff38f4eb..548e4cf4e 100644 --- a/x/application/keeper/unbond_applications.go +++ b/x/application/keeper/unbond_applications.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" apptypes "github.com/pokt-network/poktroll/x/application/types" - "github.com/pokt-network/poktroll/x/shared" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // EndBlockerUnbondApplications unbonds applications whose unbonding period has elapsed. @@ -18,7 +18,7 @@ func (k Keeper) EndBlockerUnbondApplications(ctx context.Context) error { currentHeight := sdkCtx.BlockHeight() // Only process unbonding applications at the end of the session. - if shared.IsSessionEndHeight(&sharedParams, currentHeight) { + if sharedtypes.IsSessionEndHeight(&sharedParams, currentHeight) { return nil } diff --git a/x/application/types/application.go b/x/application/types/application.go index c584d75a1..2570489ba 100644 --- a/x/application/types/application.go +++ b/x/application/types/application.go @@ -1,6 +1,8 @@ package types -import sharedtypes "github.com/pokt-network/poktroll/x/shared/types" +import ( + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" +) // ApplicationNotUnstaking is the value of `unstake_session_end_height` if the // application is not actively in the unbonding period. diff --git a/x/application/types/genesis.go b/x/application/types/genesis.go index 094a4205f..9d111846e 100644 --- a/x/application/types/genesis.go +++ b/x/application/types/genesis.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - servicehelpers "github.com/pokt-network/poktroll/x/shared/helpers" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // DefaultGenesis returns the default genesis state @@ -60,7 +60,7 @@ func (gs GenesisState) Validate() error { } // Validate the application service configs - if err := servicehelpers.ValidateAppServiceConfigs(app.ServiceConfigs); err != nil { + if err := sharedtypes.ValidateAppServiceConfigs(app.ServiceConfigs); err != nil { return ErrAppInvalidServiceConfigs.Wrapf("%s", err.Error()) } } diff --git a/x/application/types/message_stake_application.go b/x/application/types/message_stake_application.go index 7668e73d9..fb9f4ab0c 100644 --- a/x/application/types/message_stake_application.go +++ b/x/application/types/message_stake_application.go @@ -3,7 +3,6 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - servicehelpers "github.com/pokt-network/poktroll/x/shared/helpers" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -49,7 +48,7 @@ func (msg *MsgStakeApplication) ValidateBasic() error { } // Validate the application service configs - if err := servicehelpers.ValidateAppServiceConfigs(msg.Services); err != nil { + if err := sharedtypes.ValidateAppServiceConfigs(msg.Services); err != nil { return ErrAppInvalidServiceConfigs.Wrapf("%s", err.Error()) } diff --git a/x/proof/keeper/msg_server_create_claim_test.go b/x/proof/keeper/msg_server_create_claim_test.go index 87a8a81fd..2a86aee7d 100644 --- a/x/proof/keeper/msg_server_create_claim_test.go +++ b/x/proof/keeper/msg_server_create_claim_test.go @@ -19,7 +19,6 @@ import ( "github.com/pokt-network/poktroll/x/proof/types" prooftypes "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -57,7 +56,7 @@ func TestMsgServer_CreateClaim_Success(t *testing.T) { { desc: "claim message height equals supplier's earliest claim commit height", getClaimMsgHeight: func(sharedParams *sharedtypes.Params, queryHeight int64) int64 { - return shared.GetEarliestSupplierClaimCommitHeight( + return sharedtypes.GetEarliestSupplierClaimCommitHeight( sharedParams, queryHeight, claimWindowOpenBlockHash, @@ -70,14 +69,14 @@ func TestMsgServer_CreateClaim_Success(t *testing.T) { }, { desc: "claim message height equals claim window close height", - getClaimMsgHeight: shared.GetClaimWindowCloseHeight, + getClaimMsgHeight: sharedtypes.GetClaimWindowCloseHeight, merkleRoot: defaultMerkleRoot, serviceComputeUnitsPerRelay: computeUnitsPerRelay, expectedNumClaimedComputeUnits: expectedNumComputeUnits, }, { desc: "claim message for service with >1 compute units per relay", - getClaimMsgHeight: shared.GetClaimWindowCloseHeight, + getClaimMsgHeight: sharedtypes.GetClaimWindowCloseHeight, merkleRoot: customComputeUnitsPerRelayMerkleRoot, serviceComputeUnitsPerRelay: nonDefaultComputeUnitsPerRelay, expectedNumClaimedComputeUnits: expectedNonDefaultNumComputeUnits, @@ -228,12 +227,12 @@ func TestMsgServer_CreateClaim_Error_OutsideOfWindow(t *testing.T) { sessionHeader := sessionRes.GetSession().GetHeader() - claimWindowCloseHeight := shared.GetClaimWindowCloseHeight( + claimWindowCloseHeight := sharedtypes.GetClaimWindowCloseHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), ) - earliestClaimCommitHeight := shared.GetEarliestSupplierClaimCommitHeight( + earliestClaimCommitHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), claimWindowOpenBlockHash, @@ -253,7 +252,7 @@ func TestMsgServer_CreateClaim_Error_OutsideOfWindow(t *testing.T) { types.ErrProofClaimOutsideOfWindow.Wrapf( "current block height (%d) is less than the session's earliest claim commit height (%d)", earliestClaimCommitHeight-1, - shared.GetEarliestSupplierClaimCommitHeight( + sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), claimWindowOpenBlockHash, @@ -583,7 +582,7 @@ func TestMsgServer_CreateClaim_Error_ComputeUnitsMismatch(t *testing.T) { // Increment the block height to the test claim height. sessionHeader := sessionRes.GetSession().GetHeader() sharedParams := keepers.SharedKeeper.GetParams(ctx) - testClaimHeight := shared.GetClaimWindowCloseHeight(&sharedParams, sessionHeader.GetSessionEndBlockHeight()) + testClaimHeight := sharedtypes.GetClaimWindowCloseHeight(&sharedParams, sessionHeader.GetSessionEndBlockHeight()) sdkCtx = sdkCtx.WithBlockHeight(testClaimHeight) ctx = sdkCtx diff --git a/x/proof/keeper/msg_server_submit_proof.go b/x/proof/keeper/msg_server_submit_proof.go index 4101cbfed..db155546d 100644 --- a/x/proof/keeper/msg_server_submit_proof.go +++ b/x/proof/keeper/msg_server_submit_proof.go @@ -16,7 +16,6 @@ import ( "github.com/pokt-network/poktroll/telemetry" "github.com/pokt-network/poktroll/x/proof/types" servicekeeper "github.com/pokt-network/poktroll/x/service/keeper" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -307,12 +306,12 @@ func (k Keeper) getEarliestSupplierProofCommitBlockHash( sessionEndHeight := claim.GetSessionHeader().GetSessionEndBlockHeight() supplierOperatorAddress := claim.GetSupplierOperatorAddress() - proofWindowOpenHeight := shared.GetProofWindowOpenHeight(sharedParams, sessionEndHeight) + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight(sharedParams, sessionEndHeight) proofWindowOpenBlockHash := k.sessionKeeper.GetBlockHash(ctx, proofWindowOpenHeight) // TODO_TECHDEBT(@red-0ne): Update the method header of this function to accept (sharedParams, Claim, BlockHash). // After doing so, please review all calling sites and simplify them accordingly. - earliestSupplierProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( sharedParams, sessionEndHeight, proofWindowOpenBlockHash, diff --git a/x/proof/keeper/msg_server_submit_proof_test.go b/x/proof/keeper/msg_server_submit_proof_test.go index d05e0a7d1..c9326a30d 100644 --- a/x/proof/keeper/msg_server_submit_proof_test.go +++ b/x/proof/keeper/msg_server_submit_proof_test.go @@ -27,7 +27,6 @@ import ( "github.com/pokt-network/poktroll/x/proof/keeper" prooftypes "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -67,7 +66,7 @@ func TestMsgServer_SubmitProof_Success(t *testing.T) { { desc: "proof message height equals supplier's earliest proof commit height", getProofMsgHeight: func(sharedParams *sharedtypes.Params, queryHeight int64, supplierOperatorAddr string) int64 { - return shared.GetEarliestSupplierProofCommitHeight( + return sharedtypes.GetEarliestSupplierProofCommitHeight( sharedParams, queryHeight, blockHeaderHash, @@ -78,7 +77,7 @@ func TestMsgServer_SubmitProof_Success(t *testing.T) { { desc: "proof message height equals proof window close height", getProofMsgHeight: func(sharedParams *sharedtypes.Params, queryHeight int64, _ string) int64 { - return shared.GetProofWindowCloseHeight(sharedParams, queryHeight) + return sharedtypes.GetProofWindowCloseHeight(sharedParams, queryHeight) }, }, } @@ -166,7 +165,7 @@ func TestMsgServer_SubmitProof_Success(t *testing.T) { ) // Advance the block height to the test claim msg height. - claimMsgHeight := shared.GetEarliestSupplierClaimCommitHeight( + claimMsgHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -187,7 +186,7 @@ func TestMsgServer_SubmitProof_Success(t *testing.T) { ) // Advance the block height to the proof path seed height. - earliestSupplierProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -325,7 +324,7 @@ func TestMsgServer_SubmitProof_Error_OutsideOfWindow(t *testing.T) { // Advance the block height to the claim window open height. sharedParams := keepers.SharedKeeper.GetParams(ctx) - claimMsgHeight := shared.GetEarliestSupplierClaimCommitHeight( + claimMsgHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), claimWindowOpenHeightBlockHash, @@ -347,13 +346,13 @@ func TestMsgServer_SubmitProof_Error_OutsideOfWindow(t *testing.T) { keepers, ) - earliestProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), proofWindowOpenHeightBlockHash, supplierOperatorAddr, ) - proofWindowCloseHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionHeader.GetSessionEndBlockHeight()) + proofWindowCloseHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionHeader.GetSessionEndBlockHeight()) tests := []struct { desc string @@ -523,7 +522,7 @@ func TestMsgServer_SubmitProof_Error(t *testing.T) { // Advance the block height to the earliest claim commit height. sharedParams := keepers.SharedKeeper.GetParams(ctx) - claimMsgHeight := shared.GetEarliestSupplierClaimCommitHeight( + claimMsgHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, validSessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -653,7 +652,7 @@ func TestMsgServer_SubmitProof_Error(t *testing.T) { msgSubmitProof := test.newProofMsg(t) // Advance the block height to the proof path seed height. - earliestSupplierProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, msgSubmitProof.GetSessionHeader().GetSessionEndBlockHeight(), blockHeaderHash, @@ -770,7 +769,7 @@ func TestMsgServer_SubmitProof_FailSubmittingNonRequiredProof(t *testing.T) { ) // Advance the block height to the test claim msg height. - claimMsgHeight := shared.GetEarliestSupplierClaimCommitHeight( + claimMsgHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -791,7 +790,7 @@ func TestMsgServer_SubmitProof_FailSubmittingNonRequiredProof(t *testing.T) { ) // Advance the block height to the proof path seed height. - earliestSupplierProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -807,7 +806,7 @@ func TestMsgServer_SubmitProof_FailSubmittingNonRequiredProof(t *testing.T) { expectedMerkleProofPath = protocol.GetPathForProof(blockHeaderHash, sessionHeader.GetSessionId()) // Advance the block height to the test proof msg height. - proofMsgHeight := shared.GetEarliestSupplierProofCommitHeight( + proofMsgHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -885,7 +884,7 @@ func createClaimAndStoreBlockHash( sharedParams := keepers.SharedKeeper.GetParams(ctx) - claimWindowOpenHeight := shared.GetClaimWindowOpenHeight( + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight( &sharedParams, sessionStartHeight, ) @@ -893,7 +892,7 @@ func createClaimAndStoreBlockHash( ctx = keepertest.SetBlockHeight(ctx, claimWindowOpenHeight) sdkCtx := cosmostypes.UnwrapSDKContext(ctx) - earliestSupplierClaimCommitHeight := shared.GetEarliestSupplierClaimCommitHeight( + earliestSupplierClaimCommitHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionStartHeight, sdkCtx.HeaderHash(), diff --git a/x/proof/keeper/proof_validation_test.go b/x/proof/keeper/proof_validation_test.go index 8d118eade..f00022d2a 100644 --- a/x/proof/keeper/proof_validation_test.go +++ b/x/proof/keeper/proof_validation_test.go @@ -26,7 +26,6 @@ import ( prooftypes "github.com/pokt-network/poktroll/x/proof/types" servicekeeper "github.com/pokt-network/poktroll/x/service/keeper" servicetypes "github.com/pokt-network/poktroll/x/service/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -133,7 +132,7 @@ func TestEnsureValidProof_Error(t *testing.T) { // Advance the block height to the earliest claim commit height. sharedParams := keepers.SharedKeeper.GetParams(ctx) - claimMsgHeight := shared.GetEarliestSupplierClaimCommitHeight( + claimMsgHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, validSessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -756,7 +755,7 @@ func TestEnsureValidProof_Error(t *testing.T) { proof := test.newProof(t) // Advance the block height to the proof path seed height. - earliestSupplierProofCommitHeight := shared.GetEarliestSupplierProofCommitHeight( + earliestSupplierProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, proof.GetSessionHeader().GetSessionEndBlockHeight(), blockHeaderHash, diff --git a/x/proof/keeper/session.go b/x/proof/keeper/session.go index aa0edab43..0d8bb446a 100644 --- a/x/proof/keeper/session.go +++ b/x/proof/keeper/session.go @@ -7,7 +7,6 @@ import ( "github.com/pokt-network/poktroll/x/proof/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -88,8 +87,8 @@ func (k Keeper) validateClaimWindow( sessionEndHeight := sessionHeader.GetSessionEndBlockHeight() // Get the claim window open and close heights for the given session header. - claimWindowOpenHeight := shared.GetClaimWindowOpenHeight(&sharedParams, sessionEndHeight) - claimWindowCloseHeight := shared.GetClaimWindowCloseHeight(&sharedParams, sessionEndHeight) + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight(&sharedParams, sessionEndHeight) + claimWindowCloseHeight := sharedtypes.GetClaimWindowCloseHeight(&sharedParams, sessionEndHeight) // Get the earliest claim commit height for the given supplier. earliestClaimCommitHeight, err := k.sharedQuerier.GetEarliestSupplierClaimCommitHeight( @@ -156,8 +155,8 @@ func (k Keeper) validateProofWindow( sessionEndHeight := sessionHeader.GetSessionEndBlockHeight() // Get the proof window open and close heights for the given session header. - proofWindowOpenHeight := shared.GetProofWindowOpenHeight(&sharedParams, sessionEndHeight) - proofWindowCloseHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight(&sharedParams, sessionEndHeight) + proofWindowCloseHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) // Get the earliest proof commit height for the given supplier. earliestProofCommitHeight, err := k.sharedQuerier.GetEarliestSupplierProofCommitHeight( diff --git a/x/proof/types/shared_query_client.go b/x/proof/types/shared_query_client.go index b30a5c2f8..df05ec113 100644 --- a/x/proof/types/shared_query_client.go +++ b/x/proof/types/shared_query_client.go @@ -4,7 +4,6 @@ import ( "context" "github.com/pokt-network/poktroll/pkg/client" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -50,7 +49,7 @@ func (sqc *SharedKeeperQueryClient) GetSessionGracePeriodEndHeight( queryHeight int64, ) (int64, error) { sharedParams := sqc.sharedKeeper.GetParams(ctx) - return shared.GetSessionGracePeriodEndHeight(&sharedParams, queryHeight), nil + return sharedtypes.GetSessionGracePeriodEndHeight(&sharedParams, queryHeight), nil } // GetClaimWindowOpenHeight returns the block height at which the claim window of @@ -63,7 +62,7 @@ func (sqc *SharedKeeperQueryClient) GetClaimWindowOpenHeight( queryHeight int64, ) (int64, error) { sharedParams := sqc.sharedKeeper.GetParams(ctx) - return shared.GetClaimWindowOpenHeight(&sharedParams, queryHeight), nil + return sharedtypes.GetClaimWindowOpenHeight(&sharedParams, queryHeight), nil } // GetProofWindowOpenHeight returns the block height at which the proof window of @@ -76,7 +75,7 @@ func (sqc *SharedKeeperQueryClient) GetProofWindowOpenHeight( queryHeight int64, ) (int64, error) { sharedParams := sqc.sharedKeeper.GetParams(ctx) - return shared.GetProofWindowOpenHeight(&sharedParams, queryHeight), nil + return sharedtypes.GetProofWindowOpenHeight(&sharedParams, queryHeight), nil } // GetEarliestSupplierClaimCommitHeight returns the earliest block height at which a claim @@ -87,7 +86,7 @@ func (sqc *SharedKeeperQueryClient) GetEarliestSupplierClaimCommitHeight( supplierOperatorAddr string, ) (int64, error) { sharedParams := sqc.sharedKeeper.GetParams(ctx) - claimWindowOpenHeight := shared.GetClaimWindowOpenHeight(&sharedParams, queryHeight) + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight(&sharedParams, queryHeight) // Fetch the claim window open block hash so that it can be used as part of the // pseudo-random seed for generating the claim distribution offset. @@ -95,7 +94,7 @@ func (sqc *SharedKeeperQueryClient) GetEarliestSupplierClaimCommitHeight( claimWindowOpenBlockHashBz := sqc.sessionKeeper.GetBlockHash(ctx, claimWindowOpenHeight) // Get the earliest claim commit height for the given supplier. - return shared.GetEarliestSupplierClaimCommitHeight( + return sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, queryHeight, claimWindowOpenBlockHashBz, @@ -111,7 +110,7 @@ func (sqc *SharedKeeperQueryClient) GetEarliestSupplierProofCommitHeight( supplierOperatorAddr string, ) (int64, error) { sharedParams := sqc.sharedKeeper.GetParams(ctx) - proofWindowOpenHeight := shared.GetProofWindowOpenHeight(&sharedParams, queryHeight) + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight(&sharedParams, queryHeight) // Fetch the proof window open block hash so that it can be used as part of the // pseudo-random seed for generating the proof distribution offset. @@ -119,7 +118,7 @@ func (sqc *SharedKeeperQueryClient) GetEarliestSupplierProofCommitHeight( proofWindowOpenBlockHash := sqc.sessionKeeper.GetBlockHash(ctx, proofWindowOpenHeight) // Get the earliest proof commit height for the given supplier. - return shared.GetEarliestSupplierProofCommitHeight( + return sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, queryHeight, proofWindowOpenBlockHash, diff --git a/x/session/keeper/session_hydrator.go b/x/session/keeper/session_hydrator.go index 2d66b5844..bde2f6dbf 100644 --- a/x/session/keeper/session_hydrator.go +++ b/x/session/keeper/session_hydrator.go @@ -13,7 +13,6 @@ import ( _ "golang.org/x/crypto/sha3" "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -107,10 +106,10 @@ func (k Keeper) hydrateSessionMetadata(ctx context.Context, sh *sessionHydrator) // this function may cause unexpected behavior for historical sessions. sharedParams := k.sharedKeeper.GetParams(ctx) sh.session.NumBlocksPerSession = int64(sharedParams.NumBlocksPerSession) - sh.session.SessionNumber = shared.GetSessionNumber(&sharedParams, sh.blockHeight) + sh.session.SessionNumber = sharedtypes.GetSessionNumber(&sharedParams, sh.blockHeight) - sh.sessionHeader.SessionStartBlockHeight = shared.GetSessionStartHeight(&sharedParams, sh.blockHeight) - sh.sessionHeader.SessionEndBlockHeight = shared.GetSessionEndHeight(&sharedParams, sh.blockHeight) + sh.sessionHeader.SessionStartBlockHeight = sharedtypes.GetSessionStartHeight(&sharedParams, sh.blockHeight) + sh.sessionHeader.SessionEndBlockHeight = sharedtypes.GetSessionEndHeight(&sharedParams, sh.blockHeight) return nil } @@ -322,7 +321,7 @@ func GetSessionId( // start height for the session containing blockHeight, given the shared on-chain // parameters. func getSessionStartBlockHeightBz(sharedParams *sharedtypes.Params, blockHeight int64) []byte { - sessionStartBlockHeight := shared.GetSessionStartHeight(sharedParams, blockHeight) + sessionStartBlockHeight := sharedtypes.GetSessionStartHeight(sharedParams, blockHeight) sessionStartBlockHeightBz := make([]byte, 8) binary.LittleEndian.PutUint64(sessionStartBlockHeightBz, uint64(sessionStartBlockHeight)) return sessionStartBlockHeightBz diff --git a/x/shared/keeper/msg_server_update_param_test.go b/x/shared/keeper/msg_server_update_param_test.go index 74869bf3a..bb7f635c1 100644 --- a/x/shared/keeper/msg_server_update_param_test.go +++ b/x/shared/keeper/msg_server_update_param_test.go @@ -9,10 +9,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/pokt-network/poktroll/x/shared/keeper" - "github.com/pokt-network/poktroll/x/shared/types" - testkeeper "github.com/pokt-network/poktroll/testutil/keeper" + "github.com/pokt-network/poktroll/x/shared/keeper" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -404,6 +402,6 @@ func getMinActorUnbondingPeriodSessions( newParamBlocksValue uint64, ) uint64 { deltaBlocks := newParamBlocksValue - oldParamBlocksValue - newProofWindowCloseBlocks := types.GetSessionEndToProofWindowCloseBlocks(params) + deltaBlocks + newProofWindowCloseBlocks := sharedtypes.GetSessionEndToProofWindowCloseBlocks(params) + deltaBlocks return (newProofWindowCloseBlocks / params.NumBlocksPerSession) + 1 } diff --git a/x/shared/keeper/session.go b/x/shared/keeper/session.go index 3e5619bc8..3eaebb044 100644 --- a/x/shared/keeper/session.go +++ b/x/shared/keeper/session.go @@ -3,7 +3,7 @@ package keeper import ( "context" - "github.com/pokt-network/poktroll/x/shared" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) // GetSessionStartHeight returns the block height at which the session containing @@ -12,7 +12,7 @@ import ( // 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) + return sharedtypes.GetSessionStartHeight(&sharedParams, queryHeight) } // GetSessionEndHeight returns the block height at which the session containing @@ -21,7 +21,7 @@ func (k Keeper) GetSessionStartHeight(ctx context.Context, queryHeight int64) in // 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) + return sharedtypes.GetSessionEndHeight(&sharedParams, queryHeight) } // GetSessionNumber returns the session number for the session containing queryHeight, @@ -31,12 +31,12 @@ func (k Keeper) GetSessionEndHeight(ctx context.Context, queryHeight int64) int6 // 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) + return sharedtypes.GetSessionNumber(&sharedParams, queryHeight) } // GetProofWindowCloseHeight returns the block height at which the proof window of // the session that includes queryHeight closes, given the passed sharedParams. func (k Keeper) GetProofWindowCloseHeight(ctx context.Context, queryHeight int64) int64 { sharedParams := k.GetParams(ctx) - return shared.GetProofWindowCloseHeight(&sharedParams, queryHeight) + return sharedtypes.GetProofWindowCloseHeight(&sharedParams, queryHeight) } diff --git a/x/shared/supplier.go b/x/shared/supplier.go deleted file mode 100644 index f81b7aaff..000000000 --- a/x/shared/supplier.go +++ /dev/null @@ -1,16 +0,0 @@ -package shared - -import ( - sharedtypes "github.com/pokt-network/poktroll/x/shared/types" -) - -// GetSupplierUnbondingHeight returns the session end height at which the given -// supplier finishes unbonding. -func GetSupplierUnbondingHeight( - sharedParams *sharedtypes.Params, - supplier *sharedtypes.Supplier, -) int64 { - supplierUnbondingPeriodBlocks := sharedParams.SupplierUnbondingPeriodSessions * sharedParams.NumBlocksPerSession - - return int64(supplier.UnstakeSessionEndHeight + supplierUnbondingPeriodBlocks) -} diff --git a/x/shared/types/params.go b/x/shared/types/params.go index 27887310c..70666ba30 100644 --- a/x/shared/types/params.go +++ b/x/shared/types/params.go @@ -347,14 +347,3 @@ func validateApplicationUnbondingPeriodIsGreaterThanCumulativeProofWindowCloseBl return nil } - -// GetSessionEndToProofWindowCloseBlocks returns the total number of blocks -// from the moment a session ends until the proof window closes. -// NB: Using shared.GetProofWindowCloseOffsetHeight is not possible because of the -// circular dependency between the shared and session modules. -func GetSessionEndToProofWindowCloseBlocks(params *Params) uint64 { - return params.ClaimWindowOpenOffsetBlocks + - params.ClaimWindowCloseOffsetBlocks + - params.ProofWindowOpenOffsetBlocks + - params.ProofWindowCloseOffsetBlocks -} diff --git a/x/shared/helpers/service_configs.go b/x/shared/types/service_configs.go similarity index 70% rename from x/shared/helpers/service_configs.go rename to x/shared/types/service_configs.go index 6e7a7a4b1..076ebd6ee 100644 --- a/x/shared/helpers/service_configs.go +++ b/x/shared/types/service_configs.go @@ -1,11 +1,9 @@ -package helpers +package types import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - - sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) const ( @@ -13,7 +11,7 @@ const ( ) // ValidateAppServiceConfigs returns an error if any of the application service configs are invalid -func ValidateAppServiceConfigs(services []*sharedtypes.ApplicationServiceConfig) error { +func ValidateAppServiceConfigs(services []*ApplicationServiceConfig) error { if len(services) == 0 { return fmt.Errorf("no services configs provided for application: %v", services) } @@ -22,15 +20,15 @@ func ValidateAppServiceConfigs(services []*sharedtypes.ApplicationServiceConfig) return fmt.Errorf("serviceConfig cannot be nil: %v", services) } // Check the Service ID - if !sharedtypes.IsValidServiceId(serviceConfig.GetServiceId()) { - return sharedtypes.ErrSharedInvalidService.Wrapf("invalid service ID: %q", serviceConfig.GetServiceId()) + if !IsValidServiceId(serviceConfig.GetServiceId()) { + return ErrSharedInvalidService.Wrapf("invalid service ID: %q", serviceConfig.GetServiceId()) } } return nil } // ValidateSupplierServiceConfigs returns an error if any of the supplier service configs are invalid -func ValidateSupplierServiceConfigs(services []*sharedtypes.SupplierServiceConfig) error { +func ValidateSupplierServiceConfigs(services []*SupplierServiceConfig) error { if len(services) == 0 { return fmt.Errorf("no services provided for supplier: %v", services) } @@ -40,8 +38,8 @@ func ValidateSupplierServiceConfigs(services []*sharedtypes.SupplierServiceConfi } // Check the Service ID - if !sharedtypes.IsValidServiceId(serviceConfig.GetServiceId()) { - return sharedtypes.ErrSharedInvalidService.Wrapf("invalid service ID: %s", serviceConfig.GetServiceId()) + if !IsValidServiceId(serviceConfig.GetServiceId()) { + return ErrSharedInvalidService.Wrapf("invalid service ID: %s", serviceConfig.GetServiceId()) } // Check the Endpoints @@ -62,15 +60,15 @@ func ValidateSupplierServiceConfigs(services []*sharedtypes.SupplierServiceConfi if endpoint.Url == "" { return fmt.Errorf("endpoint.Url cannot be empty: %v", serviceConfig) } - if !sharedtypes.IsValidEndpointUrl(endpoint.Url) { + if !IsValidEndpointUrl(endpoint.Url) { return fmt.Errorf("invalid endpoint.Url: %v", serviceConfig) } // Validate the RPC type - if endpoint.RpcType == sharedtypes.RPCType_UNKNOWN_RPC { + if endpoint.RpcType == RPCType_UNKNOWN_RPC { return fmt.Errorf("endpoint.RpcType cannot be UNKNOWN_RPC: %v", serviceConfig) } - if _, ok := sharedtypes.RPCType_name[int32(endpoint.RpcType)]; !ok { + if _, ok := RPCType_name[int32(endpoint.RpcType)]; !ok { return fmt.Errorf("endpoint.RpcType is not a valid RPCType: %v", serviceConfig) } @@ -96,29 +94,29 @@ func ValidateSupplierServiceConfigs(services []*sharedtypes.SupplierServiceConfi // ValidateServiceRevShare validates the supplier's service revenue share, // ensuring that the sum of the revenue share percentages is 100. // NB: This function is unit tested via the supplier staking config tests. -func ValidateServiceRevShare(revShareList []*sharedtypes.ServiceRevenueShare) error { +func ValidateServiceRevShare(revShareList []*ServiceRevenueShare) error { revSharePercentageSum := float32(0) if len(revShareList) == 0 { - return sharedtypes.ErrSharedInvalidRevShare.Wrap("no rev share configurations") + return ErrSharedInvalidRevShare.Wrap("no rev share configurations") } for _, revShare := range revShareList { if revShare == nil { - return sharedtypes.ErrSharedInvalidRevShare.Wrap("rev share cannot be nil") + return ErrSharedInvalidRevShare.Wrap("rev share cannot be nil") } // Validate the revshare address if revShare.Address == "" { - return sharedtypes.ErrSharedInvalidRevShare.Wrapf("rev share address cannot be empty: %v", revShare) + return ErrSharedInvalidRevShare.Wrapf("rev share address cannot be empty: %v", revShare) } if _, err := sdk.AccAddressFromBech32(revShare.Address); err != nil { - return sharedtypes.ErrSharedInvalidRevShare.Wrapf("invalid rev share address %s; (%v)", revShare.Address, err) + return ErrSharedInvalidRevShare.Wrapf("invalid rev share address %s; (%v)", revShare.Address, err) } if revShare.RevSharePercentage <= 0 || revShare.RevSharePercentage > 100 { - return sharedtypes.ErrSharedInvalidRevShare.Wrapf( + return ErrSharedInvalidRevShare.Wrapf( "invalid rev share value %v; must be between 0 and 100", revShare.RevSharePercentage, ) @@ -128,7 +126,7 @@ func ValidateServiceRevShare(revShareList []*sharedtypes.ServiceRevenueShare) er } if revSharePercentageSum != requiredRevSharePercentageSum { - return sharedtypes.ErrSharedInvalidRevShare.Wrapf( + return ErrSharedInvalidRevShare.Wrapf( "invalid rev share percentage sum %v; must be equal to %v", revSharePercentageSum, requiredRevSharePercentageSum, diff --git a/x/shared/helpers/service_test.go b/x/shared/types/service_test.go similarity index 92% rename from x/shared/helpers/service_test.go rename to x/shared/types/service_test.go index cdc742fe3..f7367136d 100644 --- a/x/shared/helpers/service_test.go +++ b/x/shared/types/service_test.go @@ -1,4 +1,4 @@ -package helpers +package types import ( "testing" @@ -6,7 +6,6 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/poktroll/testutil/sample" - sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) func TestIsValidService(t *testing.T) { @@ -70,7 +69,7 @@ func TestIsValidService(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - service := &sharedtypes.Service{ + service := &Service{ Id: test.serviceId, Name: test.serviceName, ComputeUnitsPerRelay: 1, @@ -131,7 +130,7 @@ func TestIsValidServiceName(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - service := &sharedtypes.Service{ + service := &Service{ Id: "svc", Name: test.serviceName, ComputeUnitsPerRelay: 1, @@ -141,7 +140,7 @@ func TestIsValidServiceName(t *testing.T) { if test.expectedIsValid { require.NoError(t, err) } else { - require.ErrorIs(t, err, sharedtypes.ErrSharedInvalidService.Wrapf("invalid service name: %s", test.serviceName)) + require.ErrorIs(t, err, ErrSharedInvalidService.Wrapf("invalid service name: %s", test.serviceName)) } }) } @@ -212,7 +211,7 @@ func TestIsValidServiceId(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - service := &sharedtypes.Service{ + service := &Service{ Id: test.serviceId, ComputeUnitsPerRelay: 1, OwnerAddress: sample.AccAddress(), @@ -221,7 +220,7 @@ func TestIsValidServiceId(t *testing.T) { if test.expectedIsValid { require.NoError(t, err) } else { - require.ErrorIs(t, err, sharedtypes.ErrSharedInvalidService.Wrapf("invalid service ID: %s", test.serviceId)) + require.ErrorIs(t, err, ErrSharedInvalidService.Wrapf("invalid service ID: %s", test.serviceId)) } }) } @@ -280,7 +279,7 @@ func TestIsValidEndpointUrl(t *testing.T) { for _, test := range tests { t.Run(test.desc, func(t *testing.T) { - isValid := sharedtypes.IsValidEndpointUrl(test.endpointURL) + isValid := IsValidEndpointUrl(test.endpointURL) require.Equal(t, test.expectedIsValid, isValid) }) } diff --git a/x/shared/session.go b/x/shared/types/session.go similarity index 84% rename from x/shared/session.go rename to x/shared/types/session.go index 3b2f8a459..e9e3742a5 100644 --- a/x/shared/session.go +++ b/x/shared/types/session.go @@ -1,16 +1,10 @@ -package shared - -import ( - sharedtypes "github.com/pokt-network/poktroll/x/shared/types" -) - -// TODO_DOCUMENT(@bryanchriswhite): Move this into the documentation: https://github.com/pokt-network/poktroll/pull/571#discussion_r1630923625 +package types // GetSessionStartHeight returns the block height at which the session containing // queryHeight 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 GetSessionStartHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetSessionStartHeight(sharedParams *Params, queryHeight int64) int64 { if queryHeight <= 0 { return 0 } @@ -26,7 +20,7 @@ func GetSessionStartHeight(sharedParams *sharedtypes.Params, queryHeight int64) // queryHeight 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 GetSessionEndHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetSessionEndHeight(sharedParams *Params, queryHeight int64) int64 { if queryHeight <= 0 { return 0 } @@ -43,7 +37,7 @@ 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. -func GetSessionNumber(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetSessionNumber(sharedParams *Params, queryHeight int64) int64 { if queryHeight <= 0 { return 0 } @@ -59,20 +53,20 @@ func GetSessionNumber(sharedParams *sharedtypes.Params, queryHeight int64) int64 // for the session that includes queryHeight elapses, given the passed sharedParams. // The grace period is the number of blocks after the session ends during which relays // SHOULD be included in the session which most recently ended. -func GetSessionGracePeriodEndHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetSessionGracePeriodEndHeight(sharedParams *Params, queryHeight int64) int64 { sessionEndHeight := GetSessionEndHeight(sharedParams, queryHeight) return sessionEndHeight + int64(sharedParams.GetGracePeriodEndOffsetBlocks()) } // IsGracePeriodElapsed returns true if the grace period for the session ending with // sessionEndHeight has elapsed, given currentHeight. -func IsGracePeriodElapsed(sharedParams *sharedtypes.Params, queryHeight, currentHeight int64) bool { +func IsGracePeriodElapsed(sharedParams *Params, queryHeight, currentHeight int64) bool { return currentHeight > GetSessionGracePeriodEndHeight(sharedParams, queryHeight) } // GetClaimWindowOpenHeight returns the block height at which the claim window of // the session that includes queryHeight opens, for the provided sharedParams. -func GetClaimWindowOpenHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetClaimWindowOpenHeight(sharedParams *Params, queryHeight int64) int64 { sessionEndHeight := GetSessionEndHeight(sharedParams, queryHeight) claimWindowOpenOffsetBlocks := int64(sharedParams.GetClaimWindowOpenOffsetBlocks()) // NB: An additional block (+1) is added to permit to relays arriving at the @@ -82,7 +76,7 @@ func GetClaimWindowOpenHeight(sharedParams *sharedtypes.Params, queryHeight int6 // GetClaimWindowCloseHeight returns the block height at which the claim window of // the session that includes queryHeight closes, for the provided sharedParams. -func GetClaimWindowCloseHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetClaimWindowCloseHeight(sharedParams *Params, queryHeight int64) int64 { claimWindowOpenHeight := GetClaimWindowOpenHeight(sharedParams, queryHeight) claimWindowCloseOffsetBlocks := int64(sharedParams.GetClaimWindowCloseOffsetBlocks()) return claimWindowOpenHeight + claimWindowCloseOffsetBlocks @@ -90,14 +84,14 @@ func GetClaimWindowCloseHeight(sharedParams *sharedtypes.Params, queryHeight int // GetProofWindowOpenHeight returns the block height at which the claim window of // the session that includes queryHeight opens, given the passed sharedParams. -func GetProofWindowOpenHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetProofWindowOpenHeight(sharedParams *Params, queryHeight int64) int64 { return GetClaimWindowCloseHeight(sharedParams, queryHeight) + int64(sharedParams.GetProofWindowOpenOffsetBlocks()) } // GetProofWindowCloseHeight returns the block height at which the proof window of // the session that includes queryHeight closes, given the passed sharedParams. -func GetProofWindowCloseHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetProofWindowCloseHeight(sharedParams *Params, queryHeight int64) int64 { return GetProofWindowOpenHeight(sharedParams, queryHeight) + int64(sharedParams.GetProofWindowCloseOffsetBlocks()) } @@ -111,7 +105,7 @@ func GetProofWindowCloseHeight(sharedParams *sharedtypes.Params, queryHeight int // of #711 are tengentially related to this requirement, after which the functions, // helpers, comments and docs for claim distribution can either be repurposed or deleted. func GetEarliestSupplierClaimCommitHeight( - sharedParams *sharedtypes.Params, + sharedParams *Params, queryHeight int64, claimWindowOpenBlockHash []byte, supplierOperatorAddr string, @@ -138,7 +132,7 @@ func GetEarliestSupplierClaimCommitHeight( // of #711 are tengentially related to this requirement, after which the functions, // helpers, comments and docs for claim distribution can either be repurposed or deleted. func GetEarliestSupplierProofCommitHeight( - sharedParams *sharedtypes.Params, + sharedParams *Params, queryHeight int64, proofWindowOpenBlockHash []byte, supplierOperatorAddr string, @@ -158,11 +152,20 @@ func GetEarliestSupplierProofCommitHeight( // GetNextSessionStartHeight returns the start block height of the session // following the session that includes queryHeight, given the passed sharedParams. -func GetNextSessionStartHeight(sharedParams *sharedtypes.Params, queryHeight int64) int64 { +func GetNextSessionStartHeight(sharedParams *Params, queryHeight int64) int64 { return GetSessionEndHeight(sharedParams, queryHeight) + 1 } // IsSessionEndHeight returns true if the queryHeight is the last block of the session. -func IsSessionEndHeight(sharedParams *sharedtypes.Params, queryHeight int64) bool { +func IsSessionEndHeight(sharedParams *Params, queryHeight int64) bool { return queryHeight != GetSessionEndHeight(sharedParams, queryHeight) } + +// GetSessionEndToProofWindowCloseBlocks returns the total number of blocks +// from the moment a session ends until the proof window closes. +func GetSessionEndToProofWindowCloseBlocks(params *Params) uint64 { + return params.GetClaimWindowOpenOffsetBlocks() + + params.GetClaimWindowCloseOffsetBlocks() + + params.GetProofWindowOpenOffsetBlocks() + + params.GetProofWindowCloseOffsetBlocks() +} diff --git a/x/shared/session_test.go b/x/shared/types/session_test.go similarity index 85% rename from x/shared/session_test.go rename to x/shared/types/session_test.go index 9e38706d6..12a5a71ec 100644 --- a/x/shared/session_test.go +++ b/x/shared/types/session_test.go @@ -1,4 +1,4 @@ -package shared +package types_test import ( "context" @@ -40,7 +40,7 @@ func TestGetEarliestSupplierClaimCommitHeight_IsDeterministic(t *testing.T) { _, err := rand.Read(claimWindowOpenBlockHash[:]) //nolint:staticcheck // We need a deterministic pseudo-random source. require.NoError(t, err) - expected := GetEarliestSupplierClaimCommitHeight( + expected := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, queryHeight, claimWindowOpenBlockHash[:], @@ -58,7 +58,7 @@ func TestGetEarliestSupplierClaimCommitHeight_IsDeterministic(t *testing.T) { wg.Add(1) go func(deterministicIdx int) { - actual := GetEarliestSupplierClaimCommitHeight( + actual := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, queryHeight, claimWindowOpenBlockHash[:], @@ -107,7 +107,7 @@ func TestGetEarliestSupplierProofCommitHeight_IsDeterministic(t *testing.T) { } // Compute expected value. - expected := GetEarliestSupplierProofCommitHeight( + expected := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, queryHeight, proofWindowOpenBlockHash[:], @@ -126,7 +126,7 @@ func TestGetEarliestSupplierProofCommitHeight_IsDeterministic(t *testing.T) { // NB: sample concurrently to save time. go func(deterministicIdx int) { - actual := GetEarliestSupplierProofCommitHeight( + actual := sharedtypes.GetEarliestSupplierProofCommitHeight( &sharedParams, queryHeight, proofWindowOpenBlockHash[:], @@ -187,18 +187,18 @@ func TestClaimProofWindows(t *testing.T) { // This will produce different randomized earliest claim & proof offsets. supplierOperatorAddr := sample.AccAddress() - claimWindowOpenHeight := GetClaimWindowOpenHeight(&test.sharedParams, test.queryHeight) - claimWindowCloseHeight := GetClaimWindowCloseHeight(&test.sharedParams, test.queryHeight) + claimWindowOpenHeight := sharedtypes.GetClaimWindowOpenHeight(&test.sharedParams, test.queryHeight) + claimWindowCloseHeight := sharedtypes.GetClaimWindowCloseHeight(&test.sharedParams, test.queryHeight) require.Greater(t, claimWindowCloseHeight, claimWindowOpenHeight) - proofWindowOpenHeight := GetProofWindowOpenHeight(&test.sharedParams, test.queryHeight) - proofWindowCloseHeight := GetProofWindowCloseHeight(&test.sharedParams, test.queryHeight) + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight(&test.sharedParams, test.queryHeight) + proofWindowCloseHeight := sharedtypes.GetProofWindowCloseHeight(&test.sharedParams, test.queryHeight) require.GreaterOrEqual(t, proofWindowOpenHeight, claimWindowCloseHeight) require.Greater(t, proofWindowCloseHeight, proofWindowOpenHeight) - earliestClaimCommitHeight := GetEarliestSupplierClaimCommitHeight( + earliestClaimCommitHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &test.sharedParams, test.queryHeight, blockHash, @@ -207,7 +207,7 @@ func TestClaimProofWindows(t *testing.T) { require.Greater(t, claimWindowCloseHeight, earliestClaimCommitHeight) - earliestProofCommitHeight := GetEarliestSupplierProofCommitHeight( + earliestProofCommitHeight := sharedtypes.GetEarliestSupplierProofCommitHeight( &test.sharedParams, test.queryHeight, blockHash, diff --git a/x/shared/types/supplier.go b/x/shared/types/supplier.go index 49802c397..701492aa9 100644 --- a/x/shared/types/supplier.go +++ b/x/shared/types/supplier.go @@ -41,3 +41,14 @@ func (s *Supplier) HasOwner(address string) bool { func (s *Supplier) HasOperator(address string) bool { return s.OperatorAddress == address } + +// GetSupplierUnbondingHeight returns the session end height at which the given +// supplier finishes unbonding. +func GetSupplierUnbondingHeight( + sharedParams *Params, + supplier *Supplier, +) int64 { + supplierUnbondingPeriodBlocks := sharedParams.GetSupplierUnbondingPeriodSessions() * sharedParams.GetNumBlocksPerSession() + + return int64(supplier.GetUnstakeSessionEndHeight() + supplierUnbondingPeriodBlocks) +} diff --git a/x/supplier/config/supplier_configs_reader.go b/x/supplier/config/supplier_configs_reader.go index fef39c69c..c2f009c2e 100644 --- a/x/supplier/config/supplier_configs_reader.go +++ b/x/supplier/config/supplier_configs_reader.go @@ -10,7 +10,6 @@ import ( "github.com/pokt-network/poktroll/pkg/polylog" _ "github.com/pokt-network/poktroll/pkg/polylog/polyzero" - "github.com/pokt-network/poktroll/x/shared/helpers" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -163,7 +162,7 @@ func ParseSupplierConfigs(ctx context.Context, configContent []byte) (*SupplierS }) } - if err := helpers.ValidateServiceRevShare(service.RevShare); err != nil { + if err := sharedtypes.ValidateServiceRevShare(service.RevShare); err != nil { return nil, err } diff --git a/x/supplier/keeper/msg_server_stake_supplier.go b/x/supplier/keeper/msg_server_stake_supplier.go index 3ed4add08..e128849f0 100644 --- a/x/supplier/keeper/msg_server_stake_supplier.go +++ b/x/supplier/keeper/msg_server_stake_supplier.go @@ -9,7 +9,6 @@ import ( "google.golang.org/grpc/status" "github.com/pokt-network/poktroll/telemetry" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -163,7 +162,7 @@ func (k msgServer) createSupplier( sharedParams := k.sharedKeeper.GetParams(ctx) sdkCtx := sdk.UnwrapSDKContext(ctx) currentHeight := sdkCtx.BlockHeight() - nextSessionStartHeight := shared.GetNextSessionStartHeight(&sharedParams, currentHeight) + nextSessionStartHeight := sharedtypes.GetNextSessionStartHeight(&sharedParams, currentHeight) // Register activation height for each service. Since the supplier is new, // all services are activated at the end of the current session. @@ -208,7 +207,7 @@ func (k msgServer) updateSupplier( sharedParams := k.sharedKeeper.GetParams(ctx) sdkCtx := sdk.UnwrapSDKContext(ctx) currentHeight := sdkCtx.BlockHeight() - nextSessionStartHeight := shared.GetNextSessionStartHeight(&sharedParams, currentHeight) + nextSessionStartHeight := sharedtypes.GetNextSessionStartHeight(&sharedParams, currentHeight) // Update activation height for services update. New services are activated at the // end of the current session, while existing ones keep their activation height. diff --git a/x/supplier/keeper/msg_server_unstake_supplier.go b/x/supplier/keeper/msg_server_unstake_supplier.go index c96feb66b..c4ad7ba19 100644 --- a/x/supplier/keeper/msg_server_unstake_supplier.go +++ b/x/supplier/keeper/msg_server_unstake_supplier.go @@ -7,7 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pokt-network/poktroll/telemetry" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/types" ) @@ -66,11 +65,11 @@ func (k msgServer) UnstakeSupplier( // Removing it right away could have undesired effects on the network // (e.g. a session with less than the minimum or 0 number of suppliers, // off-chain actors that need to listen to session supplier's change mid-session, etc). - supplier.UnstakeSessionEndHeight = uint64(shared.GetSessionEndHeight(&sharedParams, currentHeight)) + supplier.UnstakeSessionEndHeight = uint64(sharedtypes.GetSessionEndHeight(&sharedParams, currentHeight)) k.SetSupplier(ctx, supplier) // Emit an event which signals that the supplier successfully began unbonding their stake. - unbondingHeight := shared.GetSupplierUnbondingHeight(&sharedParams, &supplier) + unbondingHeight := sharedtypes.GetSupplierUnbondingHeight(&sharedParams, &supplier) event := &types.EventSupplierUnbondingBegin{ Supplier: &supplier, UnbondingHeight: unbondingHeight, diff --git a/x/supplier/keeper/msg_server_unstake_supplier_test.go b/x/supplier/keeper/msg_server_unstake_supplier_test.go index 262d1caa9..2ccee80d2 100644 --- a/x/supplier/keeper/msg_server_unstake_supplier_test.go +++ b/x/supplier/keeper/msg_server_unstake_supplier_test.go @@ -9,7 +9,6 @@ import ( keepertest "github.com/pokt-network/poktroll/testutil/keeper" "github.com/pokt-network/poktroll/testutil/sample" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" "github.com/pokt-network/poktroll/x/supplier/keeper" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" @@ -67,7 +66,7 @@ func TestMsgServer_UnstakeSupplier_Success(t *testing.T) { require.True(t, foundSupplier.IsUnbonding()) // Move block height to the end of the unbonding period - unbondingHeight := shared.GetSupplierUnbondingHeight(&sharedParams, &foundSupplier) + unbondingHeight := sharedtypes.GetSupplierUnbondingHeight(&sharedParams, &foundSupplier) ctx = keepertest.SetBlockHeight(ctx, int64(unbondingHeight)) // Run the endblocker to unbond suppliers @@ -118,7 +117,7 @@ func TestMsgServer_UnstakeSupplier_CancelUnbondingIfRestaked(t *testing.T) { require.True(t, isSupplierFound) require.True(t, foundSupplier.IsUnbonding()) - unbondingHeight := shared.GetSupplierUnbondingHeight(&sharedParams, &foundSupplier) + unbondingHeight := sharedtypes.GetSupplierUnbondingHeight(&sharedParams, &foundSupplier) // Stake the supplier again stakeMsg = createStakeMsg(supplierOperatorAddr, initialStake+1) @@ -224,7 +223,7 @@ func TestMsgServer_UnstakeSupplier_OperatorCanUnstake(t *testing.T) { // Move block height to the end of the unbonding period sharedParams := supplierModuleKeepers.SharedKeeper.GetParams(ctx) - unbondingHeight := shared.GetSupplierUnbondingHeight(&sharedParams, &foundSupplier) + unbondingHeight := sharedtypes.GetSupplierUnbondingHeight(&sharedParams, &foundSupplier) ctx = keepertest.SetBlockHeight(ctx, int64(unbondingHeight)) // Ensure that the initial stake is not returned to the owner yet diff --git a/x/supplier/keeper/unbond_suppliers.go b/x/supplier/keeper/unbond_suppliers.go index a7dec76a7..1a67f838c 100644 --- a/x/supplier/keeper/unbond_suppliers.go +++ b/x/supplier/keeper/unbond_suppliers.go @@ -6,8 +6,8 @@ import ( cosmostypes "github.com/cosmos/cosmos-sdk/types" - "github.com/pokt-network/poktroll/x/shared" - "github.com/pokt-network/poktroll/x/supplier/types" + sharedtypes "github.com/pokt-network/poktroll/x/shared/types" + suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" ) // EndBlockerUnbondSuppliers unbonds suppliers whose unbonding period has elapsed. @@ -17,7 +17,7 @@ func (k Keeper) EndBlockerUnbondSuppliers(ctx context.Context) error { currentHeight := sdkCtx.BlockHeight() // Only process unbonding suppliers at the end of the session. - if shared.IsSessionEndHeight(&sharedParams, currentHeight) { + if sharedtypes.IsSessionEndHeight(&sharedParams, currentHeight) { return nil } @@ -32,7 +32,7 @@ func (k Keeper) EndBlockerUnbondSuppliers(ctx context.Context) error { continue } - unbondingHeight := shared.GetSupplierUnbondingHeight(&sharedParams, &supplier) + unbondingHeight := sharedtypes.GetSupplierUnbondingHeight(&sharedParams, &supplier) // If the unbonding height is ahead of the current height, the supplier // stays in the unbonding state. @@ -56,11 +56,11 @@ func (k Keeper) EndBlockerUnbondSuppliers(ctx context.Context) error { // Send the coins from the supplier pool back to the supplier. if err = k.bankKeeper.SendCoinsFromModuleToAccount( - ctx, types.ModuleName, ownerAddress, []cosmostypes.Coin{*supplier.Stake}, + ctx, suppliertypes.ModuleName, ownerAddress, []cosmostypes.Coin{*supplier.Stake}, ); err != nil { logger.Error(fmt.Sprintf( "could not send %s coins from module %s to account %s due to %s", - supplier.Stake.String(), types.ModuleName, ownerAddress, err, + supplier.Stake.String(), suppliertypes.ModuleName, ownerAddress, err, )) return err } @@ -70,7 +70,7 @@ func (k Keeper) EndBlockerUnbondSuppliers(ctx context.Context) error { logger.Info(fmt.Sprintf("Successfully removed the supplier: %+v", supplier)) // Emit an event which signals that the supplier has sucessfully unbonded. - event := &types.EventSupplierUnbondingEnd{ + event := &suppliertypes.EventSupplierUnbondingEnd{ Supplier: &supplier, UnbondingHeight: unbondingHeight, } diff --git a/x/supplier/types/genesis.go b/x/supplier/types/genesis.go index 167be1dd2..d63612fd1 100644 --- a/x/supplier/types/genesis.go +++ b/x/supplier/types/genesis.go @@ -5,7 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - servicehelpers "github.com/pokt-network/poktroll/x/shared/helpers" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -53,7 +52,7 @@ func (gs GenesisState) Validate() error { } // Validate the application service configs - if err := servicehelpers.ValidateSupplierServiceConfigs(supplier.Services); err != nil { + if err := sharedtypes.ValidateSupplierServiceConfigs(supplier.Services); err != nil { return ErrSupplierInvalidServiceConfig.Wrapf("%s", err.Error()) } diff --git a/x/supplier/types/message_stake_supplier.go b/x/supplier/types/message_stake_supplier.go index 96a86cd39..07f86e96b 100644 --- a/x/supplier/types/message_stake_supplier.go +++ b/x/supplier/types/message_stake_supplier.go @@ -3,7 +3,6 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" - servicehelpers "github.com/pokt-network/poktroll/x/shared/helpers" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) @@ -64,7 +63,7 @@ func (msg *MsgStakeSupplier) ValidateBasic() error { } // Validate the supplier service configs - if err := servicehelpers.ValidateSupplierServiceConfigs(msg.Services); err != nil { + if err := sharedtypes.ValidateSupplierServiceConfigs(msg.Services); err != nil { return ErrSupplierInvalidServiceConfig.Wrapf("%s", err.Error()) } diff --git a/x/tokenomics/keeper/keeper_settle_pending_claims_test.go b/x/tokenomics/keeper/keeper_settle_pending_claims_test.go index 87a90d2ad..6b5169fa8 100644 --- a/x/tokenomics/keeper/keeper_settle_pending_claims_test.go +++ b/x/tokenomics/keeper/keeper_settle_pending_claims_test.go @@ -30,7 +30,6 @@ import ( servicekeeper "github.com/pokt-network/poktroll/x/service/keeper" servicetypes "github.com/pokt-network/poktroll/x/service/types" sessiontypes "github.com/pokt-network/poktroll/x/session/types" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" ) @@ -179,7 +178,7 @@ func (s *TestSuite) SetupTest() { expectedMerkleProofPath := protocol.GetPathForProof(blockHeaderHash, sessionHeader.SessionId) // Advance the block height to the earliest claim commit height. - claimMsgHeight := shared.GetEarliestSupplierClaimCommitHeight( + claimMsgHeight := sharedtypes.GetEarliestSupplierClaimCommitHeight( &sharedParams, sessionHeader.GetSessionEndBlockHeight(), blockHeaderHash, @@ -228,10 +227,10 @@ func (s *TestSuite) TestSettlePendingClaims_ClaimPendingBeforeSettlement() { require.Len(t, claims, 1) // Calculate a block height which is within the proof window. - proofWindowOpenHeight := shared.GetProofWindowOpenHeight( + proofWindowOpenHeight := sharedtypes.GetProofWindowOpenHeight( &sharedParams, s.claim.SessionHeader.SessionEndBlockHeight, ) - proofWindowCloseHeight := shared.GetProofWindowCloseHeight( + proofWindowCloseHeight := sharedtypes.GetProofWindowCloseHeight( &sharedParams, s.claim.SessionHeader.SessionEndBlockHeight, ) blockHeight = (proofWindowCloseHeight - proofWindowOpenHeight) / 2 @@ -284,7 +283,7 @@ func (s *TestSuite) TestSettlePendingClaims_ClaimExpired_ProofRequiredAndNotProv // Expectation: All (1) claims should be expired. // NB: proofs should be rejected when the current height equals the proof window close height. sessionEndHeight := s.claim.SessionHeader.SessionEndBlockHeight - blockHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + blockHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) sdkCtx := cosmostypes.UnwrapSDKContext(ctx).WithBlockHeight(blockHeight) settledResult, expiredResult, err := s.keepers.SettlePendingClaims(sdkCtx) require.NoError(t, err) @@ -361,7 +360,7 @@ func (s *TestSuite) TestSettlePendingClaims_ClaimSettled_ProofRequiredAndProvide // Expectation: All (1) claims should be claimed. // NB: proofs should be rejected when the current height equals the proof window close height. sessionEndHeight := s.claim.SessionHeader.SessionEndBlockHeight - blockHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + blockHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) sdkCtx := cosmostypes.UnwrapSDKContext(ctx).WithBlockHeight(blockHeight) settledResult, expiredResult, err := s.keepers.SettlePendingClaims(sdkCtx) require.NoError(t, err) @@ -417,7 +416,7 @@ func (s *TestSuite) TestSettlePendingClaims_ClaimExpired_ProofRequired_InvalidOn // Expectation: All (1) claims should be expired. // NB: proofs should be rejected when the current height equals the proof window close height. sessionEndHeight := s.claim.SessionHeader.SessionEndBlockHeight - blockHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + blockHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) sdkCtx := cosmostypes.UnwrapSDKContext(ctx).WithBlockHeight(blockHeight) settledResult, expiredResult, err := s.keepers.SettlePendingClaims(sdkCtx) require.NoError(t, err) @@ -494,7 +493,7 @@ func (s *TestSuite) TestClaimSettlement_ClaimSettled_ProofRequiredAndProvided_Vi // Expectation: All (1) claims should be claimed. // NB: proof window has definitely closed at this point sessionEndHeight := s.claim.SessionHeader.SessionEndBlockHeight - blockHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + blockHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) sdkCtx := cosmostypes.UnwrapSDKContext(ctx).WithBlockHeight(blockHeight) settledResult, expiredResult, err := s.keepers.SettlePendingClaims(sdkCtx) require.NoError(t, err) @@ -549,7 +548,7 @@ func (s *TestSuite) TestSettlePendingClaims_Settles_WhenAProofIsNotRequired() { // Expectation: All (1) claims should be claimed. // NB: proofs should be rejected when the current height equals the proof window close height. sessionEndHeight := s.claim.SessionHeader.SessionEndBlockHeight - blockHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + blockHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) sdkCtx := cosmostypes.UnwrapSDKContext(ctx).WithBlockHeight(blockHeight) settledResult, expiredResult, err := s.keepers.SettlePendingClaims(sdkCtx) require.NoError(t, err) @@ -628,16 +627,16 @@ func (s *TestSuite) TestSettlePendingClaims_ClaimPendingAfterSettlement() { s.numRelays, ) - sessionOneProofWindowCloseHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionOneEndHeight) - sessionTwoStartHeight := shared.GetSessionStartHeight(&sharedParams, sessionOneProofWindowCloseHeight+1) - sessionTwoProofWindowCloseHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionTwoStartHeight) + sessionOneProofWindowCloseHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionOneEndHeight) + sessionTwoStartHeight := sharedtypes.GetSessionStartHeight(&sharedParams, sessionOneProofWindowCloseHeight+1) + sessionTwoProofWindowCloseHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionTwoStartHeight) sessionTwoClaim.SessionHeader = &sessiontypes.SessionHeader{ ApplicationAddress: sessionOneClaim.GetSessionHeader().GetApplicationAddress(), ServiceId: s.claim.GetSessionHeader().GetServiceId(), SessionId: "session_two_id", SessionStartBlockHeight: sessionTwoStartHeight, - SessionEndBlockHeight: shared.GetSessionEndHeight(&sharedParams, sessionTwoStartHeight), + SessionEndBlockHeight: sharedtypes.GetSessionEndHeight(&sharedParams, sessionTwoStartHeight), } s.keepers.UpsertClaim(ctx, sessionTwoClaim) @@ -646,7 +645,7 @@ func (s *TestSuite) TestSettlePendingClaims_ClaimPendingAfterSettlement() { // 1. Settle pending claims while the session is still active. // Expectations: No claims should be settled because the session is still ongoing - blockHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionOneEndHeight) + blockHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionOneEndHeight) sdkCtx = sdkCtx.WithBlockHeight(blockHeight) settledResult, expiredResult, err := s.keepers.SettlePendingClaims(sdkCtx) require.NoError(t, err) @@ -710,12 +709,12 @@ func (s *TestSuite) TestSettlePendingClaims_ClaimExpired_SupplierUnstaked() { // Expectation: All (1) claims should expire. // NB: proofs should be rejected when the current height equals the proof window close height. sessionEndHeight := s.claim.SessionHeader.SessionEndBlockHeight - blockHeight := shared.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) + blockHeight := sharedtypes.GetProofWindowCloseHeight(&sharedParams, sessionEndHeight) sdkCtx := cosmostypes.UnwrapSDKContext(ctx).WithBlockHeight(blockHeight) _, _, err = s.keepers.SettlePendingClaims(sdkCtx) require.NoError(t, err) - upcomingSessionEndHeight := uint64(shared.GetNextSessionStartHeight(&sharedParams, int64(blockHeight))) - 1 + upcomingSessionEndHeight := uint64(sharedtypes.GetNextSessionStartHeight(&sharedParams, int64(blockHeight))) - 1 // Slashing should have occurred and the supplier is unstaked but still unbonding. slashedSupplier, supplierFound := s.keepers.GetSupplier(sdkCtx, s.claim.SupplierOperatorAddress) diff --git a/x/tokenomics/keeper/settle_pending_claims.go b/x/tokenomics/keeper/settle_pending_claims.go index 3045a304f..88aea8965 100644 --- a/x/tokenomics/keeper/settle_pending_claims.go +++ b/x/tokenomics/keeper/settle_pending_claims.go @@ -12,7 +12,6 @@ import ( apptypes "github.com/pokt-network/poktroll/x/application/types" prooftypes "github.com/pokt-network/poktroll/x/proof/types" servicekeeper "github.com/pokt-network/poktroll/x/service/keeper" - "github.com/pokt-network/poktroll/x/shared" sharedtypes "github.com/pokt-network/poktroll/x/shared/types" suppliertypes "github.com/pokt-network/poktroll/x/supplier/types" tokenomicstypes "github.com/pokt-network/poktroll/x/tokenomics/types" @@ -396,7 +395,7 @@ func (k Keeper) slashSupplierStake( sharedParams := k.sharedKeeper.GetParams(ctx) sdkCtx := sdk.UnwrapSDKContext(ctx) currentHeight := sdkCtx.BlockHeight() - unstakeSessionEndHeight := uint64(shared.GetSessionEndHeight(&sharedParams, currentHeight)) + unstakeSessionEndHeight := uint64(sharedtypes.GetSessionEndHeight(&sharedParams, currentHeight)) logger.Warn(fmt.Sprintf( "unstaking supplier %q owned by %q due to stake (%s) below the minimum (%s)",