Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[RelayMiner] Fix non deleted smt when funds are insufficient to submit C&P #1026

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
],
)

Expand Down
30 changes: 25 additions & 5 deletions pkg/relayer/session/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
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 onchain
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -301,19 +313,27 @@ 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) {
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
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 due to
// insufficient funds.
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
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")
"proof_submission_fee", claimAndProofSubmissionCost,
).Warn().Msg("supplier operator cannot afford to submit proof for claim, deleting session tree")
}

if len(claimableSessionTrees) < len(sessionTrees) {
Expand Down
Loading