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

[C&P] Fix Unbonding slashed suppliers #891

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 api/poktroll/application/event.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions pkg/relayer/session/sessiontree.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package session
import (
"bytes"
"crypto/sha256"
"fmt"
"os"
"path/filepath"
"sync"
Expand All @@ -12,6 +13,7 @@ import (
"github.com/pokt-network/smt/kvstore/pebble"

"github.com/pokt-network/poktroll/pkg/crypto/protocol"
"github.com/pokt-network/poktroll/pkg/polylog"
"github.com/pokt-network/poktroll/pkg/relayer"
sessiontypes "github.com/pokt-network/poktroll/x/session/types"
)
Expand All @@ -27,6 +29,8 @@ var _ relayer.SessionTree = (*sessionTree)(nil)
// default value for this should be -1, implying "unlimited".
// Ref discussion: https://github.com/pokt-network/poktroll/pull/755#discussion_r1737287860
type sessionTree struct {
logger polylog.Logger

// sessionMu is a mutex used to protect sessionTree operations from concurrent access.
sessionMu *sync.Mutex

Expand Down Expand Up @@ -273,8 +277,15 @@ func (st *sessionTree) Delete() error {
// This was intentionally removed to lower the IO load.
// When the database is closed, it is deleted it from disk right away.

if err := st.treeStore.Stop(); err != nil {
return err
if st.treeStore != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an error log if treeStore == nil?
I think it would be helpful if this condition is reached for whatever reason in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

if err := st.treeStore.Stop(); err != nil {
return err
}
} else {
st.logger.With(
"claim_root", fmt.Sprintf("%x", st.GetClaimRoot()),
"session_id", st.GetSessionHeader().SessionId,
).Info().Msg("KVStore is already stopped")
}

// Delete the KVStore from disk
Expand Down
14 changes: 8 additions & 6 deletions x/proof/keeper/msg_server_submit_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ func (k Keeper) ProofRequirementForClaim(ctx context.Context, claim *types.Claim
}

// Hash of block when proof submission is allowed.
earliestProofCommitBlockHash, err := k.getEarliestSupplierProofCommitBlockHash(ctx, claim)
proofRequirementSeedBlockHash, err := k.getProofRequirementSeedBlockHash(ctx, claim)
if err != nil {
return requirementReason, err
}

// The probability that a proof is required.
proofRequirementSampleValue, err := claim.GetProofRequirementSampleValue(earliestProofCommitBlockHash)
proofRequirementSampleValue, err := claim.GetProofRequirementSampleValue(proofRequirementSeedBlockHash)
if err != nil {
return requirementReason, err
}
Expand Down Expand Up @@ -292,9 +292,9 @@ func (k Keeper) ProofRequirementForClaim(ctx context.Context, claim *types.Claim
return requirementReason, nil
}

// getEarliestSupplierProofCommitBlockHash returns the block hash of the earliest
// block at which a claim may have its proof committed.
func (k Keeper) getEarliestSupplierProofCommitBlockHash(
// getProofRequirementSeedBlockHash returns the block hash of the seed block for
// the proof requirement probabilistic check.
func (k Keeper) getProofRequirementSeedBlockHash(
ctx context.Context,
claim *types.Claim,
) (blockHash []byte, err error) {
Expand All @@ -318,5 +318,7 @@ func (k Keeper) getEarliestSupplierProofCommitBlockHash(
supplierOperatorAddress,
)

return k.sessionKeeper.GetBlockHash(ctx, earliestSupplierProofCommitHeight), nil
// The proof requirement seed block is the last block of the session, and it is
// the block that is before the earliest block at which a proof can be committed.
return k.sessionKeeper.GetBlockHash(ctx, earliestSupplierProofCommitHeight-1), nil
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
}
23 changes: 14 additions & 9 deletions x/supplier/keeper/unbond_suppliers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,20 @@ func (k Keeper) EndBlockerUnbondSuppliers(ctx context.Context) error {
return err
}

// Send the coins from the supplier pool back to the supplier.
if err = k.bankKeeper.SendCoinsFromModuleToAccount(
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(), suppliertypes.ModuleName, ownerAddress, err,
))
return err
// If the supplier stake is 0 due to slashing, then do not move 0 coins
// to its account.
// Coin#IsPositive returns false if the coin is 0.
if supplier.Stake.IsPositive() {
red-0ne marked this conversation as resolved.
Show resolved Hide resolved
// Send the coins from the supplier pool back to the supplier.
if err = k.bankKeeper.SendCoinsFromModuleToAccount(
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(), suppliertypes.ModuleName, ownerAddress, err,
))
return err
}
}

// Remove the supplier from the store.
Expand Down
1 change: 0 additions & 1 deletion x/tokenomics/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading