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: send rewards in Unstake at once #208

Open
hallazzang opened this issue Nov 3, 2021 · 0 comments
Open

fix: send rewards in Unstake at once #208

hallazzang opened this issue Nov 3, 2021 · 0 comments
Assignees
Labels
help wanted Extra attention is needed wontfix This will not be worked on

Comments

@hallazzang
Copy link
Contributor

Currently we call WithdrawRewards for each staking coin denom, which sends rewards for that denom to the farmer:

for _, coin := range amount {
staking, found := k.GetStaking(ctx, coin.Denom, farmerAcc)
if !found {
staking.Amount = sdk.ZeroInt()
}
queuedStaking, found := k.GetQueuedStaking(ctx, coin.Denom, farmerAcc)
if !found {
queuedStaking.Amount = sdk.ZeroInt()
}
availableAmt := staking.Amount.Add(queuedStaking.Amount)
if availableAmt.LT(coin.Amount) {
return sdkerrors.Wrapf(
sdkerrors.ErrInsufficientFunds, "%s%s is smaller than %s%s", availableAmt, coin.Denom, coin.Amount, coin.Denom)
}
queuedStaking.Amount = queuedStaking.Amount.Sub(coin.Amount)
if queuedStaking.Amount.IsNegative() {
if _, err := k.WithdrawRewards(ctx, farmerAcc, coin.Denom); err != nil {
return err
}

We can optimize this to send total rewards only once at the end of the function.
To do this, we should change WithdrawRewards to not send coins, instead return just sdk.Coins.

But we need to discuss more about this optimization. It just reduces gas cost of MsgUnstake.

@hallazzang hallazzang added the help wanted Extra attention is needed label Nov 3, 2021
hallazzang added a commit to hallazzang/farming that referenced this issue Nov 3, 2021
this task now has a separate issue: tendermint#208
@hallazzang hallazzang added the wontfix This will not be worked on label Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant