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

fix: x/gov ChargeDeposit delete deposits #15033

Merged
merged 1 commit into from
Feb 14, 2023
Merged
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
18 changes: 9 additions & 9 deletions x/gov/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,22 @@ func (keeper Keeper) ChargeDeposit(ctx sdk.Context, proposalID uint64, destAddre
rate := sdk.MustNewDecFromStr(proposalCancelRate)
var cancellationCharges sdk.Coins

for _, deposits := range keeper.GetDeposits(ctx, proposalID) {
depositerAddress := sdk.MustAccAddressFromBech32(deposits.Depositor)
for _, deposit := range keeper.GetDeposits(ctx, proposalID) {
depositerAddress := sdk.MustAccAddressFromBech32(deposit.Depositor)
var remainingAmount sdk.Coins

for _, deposit := range deposits.Amount {
burnAmount := sdk.NewDecFromInt(deposit.Amount).Mul(rate).TruncateInt()
for _, coins := range deposit.Amount {
burnAmount := sdk.NewDecFromInt(coins.Amount).Mul(rate).TruncateInt()
// remaining amount = deposits amount - burn amount
remainingAmount = remainingAmount.Add(
sdk.NewCoin(
deposit.Denom,
deposit.Amount.Sub(burnAmount),
coins.Denom,
coins.Amount.Sub(burnAmount),
),
)
cancellationCharges = cancellationCharges.Add(
sdk.NewCoin(
deposit.Denom,
coins.Denom,
burnAmount,
),
)
Expand All @@ -203,6 +203,8 @@ func (keeper Keeper) ChargeDeposit(ctx sdk.Context, proposalID uint64, destAddre
return err
}
}

store.Delete(types.DepositKey(deposit.ProposalId, depositerAddress))
Copy link
Member

Choose a reason for hiding this comment

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

Say a function below fails (BurnCoins, GetModuleAddress, FunCommunityPool), what happens to the deposit then?

Isn't it safer to store the deposit keys to delete and delete them at the end of his function?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we might not need to do that, because if we return an error all the changes done during the message execution won't get persisted, right? But now that you mention it I'm not that sure

}

// burn the cancellation fee or sent the cancellation charges to destination address.
Expand Down Expand Up @@ -232,8 +234,6 @@ func (keeper Keeper) ChargeDeposit(ctx sdk.Context, proposalID uint64, destAddre
}
}

store.Delete(types.DepositsKey(proposalID))

return nil
}

Expand Down