From 2484de31021a92371e781aab69941a82a36dbd16 Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Fri, 10 Jan 2025 22:48:29 +0100 Subject: [PATCH 1/4] fix: Delete smt when proof is not affordable --- pkg/relayer/session/claim.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/relayer/session/claim.go b/pkg/relayer/session/claim.go index 61892f24c..89dfb5b3d 100644 --- a/pkg/relayer/session/claim.go +++ b/pkg/relayer/session/claim.go @@ -308,12 +308,19 @@ func (rs *relayerSessionsManager) payableProofsSessionTrees( continue } + // Delete the session tree from the KVStore since it won't be claimed. + if err := sessionTree.Delete(); err != nil { + logger.With( + "session_id", sessionTree.GetSessionHeader().GetSessionId(), + ).Error().Err(err).Msg("failed to delete session tree") + } + // Log a warning of any session that the supplier operator cannot afford to claim. logger.With( "session_id", sessionTree.GetSessionHeader().GetSessionId(), "supplier_operator_balance", supplierOperatorBalanceCoin, "proof_submission_fee", proofSubmissionFeeCoin, - ).Warn().Msg("supplier operator cannot afford to submit proof for claim, skipping") + ).Warn().Msg("supplier operator cannot afford to submit proof for claim, deleting session tree") } if len(claimableSessionTrees) < len(sessionTrees) { From 9daca57f20a85410f94983daae2ed56fc801db8d Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Mon, 13 Jan 2025 12:33:06 +0100 Subject: [PATCH 2/4] feat: Take C&P gas fees into account --- Tiltfile | 2 +- pkg/relayer/session/claim.go | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Tiltfile b/Tiltfile index b765db324..10935dcf5 100644 --- a/Tiltfile +++ b/Tiltfile @@ -363,7 +363,7 @@ for x in range(localnet_config["path_gateways"]["count"]): # ], # TODO_IMPROVE(@okdas): Add port forwards to grafana, pprof, like the other resources port_forwards=[ - str(2999 + actor_number) + ":3000" + str(2999 + actor_number) + ":3069" ], ) diff --git a/pkg/relayer/session/claim.go b/pkg/relayer/session/claim.go index 89dfb5b3d..2e9e44a70 100644 --- a/pkg/relayer/session/claim.go +++ b/pkg/relayer/session/claim.go @@ -5,8 +5,10 @@ import ( "fmt" "slices" + sdktypes "github.com/cosmos/cosmos-sdk/types" "github.com/pokt-network/smt" + "github.com/pokt-network/poktroll/app/volatile" "github.com/pokt-network/poktroll/pkg/client" "github.com/pokt-network/poktroll/pkg/either" "github.com/pokt-network/poktroll/pkg/observable" @@ -18,6 +20,13 @@ import ( sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) +// The cumulative cost of submitting a proof and creating a claim. +// This value corresponds to the sum of a single claim and proof message fee +// which was obtained empirically from the network by submitting a claim and +// proof message and observing the fee with a gas price of 0.01uPOKT. +// The value is subject to change as the network parameters change. +var clamAndProofGasCost = sdktypes.NewInt64Coin(volatile.DenomuPOKT, 50000) + // createClaims maps over the sessionsToClaimObs observable. For each claim batch, it: // 1. Calculates the earliest block height at which it is safe to CreateClaims // 2. Waits for said block and creates the claims on-chain @@ -260,7 +269,10 @@ func (rs *relayerSessionsManager) payableProofsSessionTrees( if err != nil { return nil, err } - proofSubmissionFeeCoin := proofParams.GetProofSubmissionFee() + + // Account for the gas cost of creating a claim and submitting a proof in addition + // to the ProofSubmissionFee. + claimAndProofSubmissionCost := proofParams.GetProofSubmissionFee().Add(clamAndProofGasCost) supplierOperatorBalanceCoin, err := rs.bankQueryClient.GetBalance( ctx, @@ -301,14 +313,15 @@ func (rs *relayerSessionsManager) payableProofsSessionTrees( for _, sessionTree := range sessionTrees { // If the supplier operator can afford to claim the session, add it to the // claimableSessionTrees slice. - if supplierOperatorBalanceCoin.IsGTE(*proofSubmissionFeeCoin) { + if supplierOperatorBalanceCoin.IsGTE(claimAndProofSubmissionCost) { claimableSessionTrees = append(claimableSessionTrees, sessionTree) - newSupplierOperatorBalanceCoin := supplierOperatorBalanceCoin.Sub(*proofSubmissionFeeCoin) + newSupplierOperatorBalanceCoin := supplierOperatorBalanceCoin.Sub(claimAndProofSubmissionCost) supplierOperatorBalanceCoin = &newSupplierOperatorBalanceCoin continue } - // Delete the session tree from the KVStore since it won't be claimed. + // Delete the session tree from the KVStore since it won't be claimed due to + // insufficient funds. if err := sessionTree.Delete(); err != nil { logger.With( "session_id", sessionTree.GetSessionHeader().GetSessionId(), @@ -319,7 +332,7 @@ func (rs *relayerSessionsManager) payableProofsSessionTrees( logger.With( "session_id", sessionTree.GetSessionHeader().GetSessionId(), "supplier_operator_balance", supplierOperatorBalanceCoin, - "proof_submission_fee", proofSubmissionFeeCoin, + "proof_submission_fee", claimAndProofSubmissionCost, ).Warn().Msg("supplier operator cannot afford to submit proof for claim, deleting session tree") } From 77e033e9429d5aabe49ff038613f067ceb43629d Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Tue, 14 Jan 2025 10:21:17 +0100 Subject: [PATCH 3/4] chore: Address review change requests --- Tiltfile | 2 ++ pkg/relayer/session/claim.go | 21 ++++++++++++--------- pkg/relayer/session/session_test.go | 5 ++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Tiltfile b/Tiltfile index 10935dcf5..7a9af482d 100644 --- a/Tiltfile +++ b/Tiltfile @@ -363,6 +363,8 @@ for x in range(localnet_config["path_gateways"]["count"]): # ], # TODO_IMPROVE(@okdas): Add port forwards to grafana, pprof, like the other resources port_forwards=[ + # See PATH for the default port used by the gateway. As of PR #1026, it is :3069. + # https://github.com/buildwithgrove/path/blob/main/config/router.go str(2999 + actor_number) + ":3069" ], ) diff --git a/pkg/relayer/session/claim.go b/pkg/relayer/session/claim.go index 3bb8ef64d..4d09fb2a7 100644 --- a/pkg/relayer/session/claim.go +++ b/pkg/relayer/session/claim.go @@ -20,12 +20,12 @@ import ( sharedtypes "github.com/pokt-network/poktroll/x/shared/types" ) -// The cumulative cost of submitting a proof and creating a claim. -// This value corresponds to the sum of a single claim and proof message fee -// which was obtained empirically from the network by submitting a claim and -// proof message and observing the fee with a gas price of 0.01uPOKT. +// The cumulative fees of creating a single claim, followed by submitting a single proof. +// The value was obtained empirically by observing logs during load testing and observing +// the claim & proof lifecycle. +// The gas price at the time of observance was 0.01uPOKT. // The value is subject to change as the network parameters change. -var clamAndProofGasCost = sdktypes.NewInt64Coin(volatile.DenomuPOKT, 50000) +var ClamAndProofGasCost = sdktypes.NewInt64Coin(volatile.DenomuPOKT, 50000) // createClaims maps over the sessionsToClaimObs observable. For each claim batch, it: // 1. Calculates the earliest block height at which it is safe to CreateClaims @@ -272,7 +272,7 @@ func (rs *relayerSessionsManager) payableProofsSessionTrees( // Account for the gas cost of creating a claim and submitting a proof in addition // to the ProofSubmissionFee. - claimAndProofSubmissionCost := proofParams.GetProofSubmissionFee().Add(clamAndProofGasCost) + claimAndProofSubmissionCost := proofParams.GetProofSubmissionFee().Add(ClamAndProofGasCost) supplierOperatorBalanceCoin, err := rs.bankQueryClient.GetBalance( ctx, @@ -313,15 +313,18 @@ func (rs *relayerSessionsManager) payableProofsSessionTrees( for _, sessionTree := range sessionTrees { // If the supplier operator can afford to claim the session, add it to the // claimableSessionTrees slice. - if supplierOperatorBalanceCoin.IsGTE(claimAndProofSubmissionCost) { + supplierCanAffordClaimAndProofFees := supplierOperatorBalanceCoin.IsGTE(claimAndProofSubmissionCost) + if supplierCanAffordClaimAndProofFees { claimableSessionTrees = append(claimableSessionTrees, sessionTree) newSupplierOperatorBalanceCoin := supplierOperatorBalanceCoin.Sub(claimAndProofSubmissionCost) supplierOperatorBalanceCoin = &newSupplierOperatorBalanceCoin continue } - // Delete the session tree from the KVStore since it won't be claimed due to - // insufficient funds. + // At this point supplierCanAffordClaimAndProofFees is false. + // Delete the session tree from the relayer sessions and the KVStore since + // it won't be claimed due to insufficient funds. + rs.removeFromRelayerSessions(sessionTree) if err := sessionTree.Delete(); err != nil { logger.With( "session_id", sessionTree.GetSessionHeader().GetSessionId(), diff --git a/pkg/relayer/session/session_test.go b/pkg/relayer/session/session_test.go index 5b5757040..a9017bcad 100644 --- a/pkg/relayer/session/session_test.go +++ b/pkg/relayer/session/session_test.go @@ -207,8 +207,11 @@ func TestRelayerSessionsManager_InsufficientBalanceForProofSubmission(t *testing supplierOperatorAddress := sample.AccAddress() supplierOperatorAccAddress := sdktypes.MustAccAddressFromBech32(supplierOperatorAddress) + + proofSubmissionFee := prooftypes.DefaultParams().ProofSubmissionFee.Amount.Int64() + claimAndProofGasCost := session.ClamAndProofGasCost.Amount.Int64() // Set the supplier operator balance to be able to submit only a single proof. - supplierOperatorBalance := prooftypes.DefaultParams().ProofSubmissionFee.Amount.Int64() + 1 + supplierOperatorBalance := proofSubmissionFee + claimAndProofGasCost + 1 supplierClientMock.EXPECT(). OperatorAddress(). Return(&supplierOperatorAccAddress). From 811d7788383f7e9c1b61f8d6c9f334095825faab Mon Sep 17 00:00:00 2001 From: Redouane Lakrache Date: Wed, 15 Jan 2025 13:20:46 +0100 Subject: [PATCH 4/4] Empty commit