Skip to content

Commit

Permalink
fix: Unbonding slashed suppliers
Browse files Browse the repository at this point in the history
  • Loading branch information
red-0ne committed Oct 22, 2024
1 parent 26e760f commit e987511
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
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.

6 changes: 4 additions & 2 deletions pkg/relayer/session/sessiontree.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,10 @@ 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 {
if err := st.treeStore.Stop(); err != nil {
return err
}
}

// Delete the KVStore from disk
Expand Down
2 changes: 1 addition & 1 deletion x/proof/keeper/msg_server_submit_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,5 +318,5 @@ func (k Keeper) getEarliestSupplierProofCommitBlockHash(
supplierOperatorAddress,
)

return k.sessionKeeper.GetBlockHash(ctx, earliestSupplierProofCommitHeight), nil
return k.sessionKeeper.GetBlockHash(ctx, earliestSupplierProofCommitHeight-1), nil
}
22 changes: 13 additions & 9 deletions x/supplier/keeper/unbond_suppliers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ 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.
if supplier.Stake.IsPositive() {
// 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.

0 comments on commit e987511

Please sign in to comment.