Skip to content

Commit

Permalink
fix: remove SpendableCoins from vesting (#502)
Browse files Browse the repository at this point in the history
* fix: remove SpendableCoins from vesting

* changelog
  • Loading branch information
fedekunze committed Apr 19, 2022
1 parent 4ff7123 commit 6bf8829
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

- (vesting) [\#502](https://github.com/tharsis/evmos/pull/502) Fix gas exhaustion bug by removing `SpendableCoins` during vesting account clawback.
- (vesting) [\#483](https://github.com/tharsis/evmos/pull/483) Fix balance clawback when vesting start time is in the future

### Improvements
Expand Down
15 changes: 11 additions & 4 deletions x/vesting/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,20 @@ func (k Keeper) transferClawback(
// Compute clawback amount, unlock unvested tokens and remove future vesting events
updatedAcc, toClawBack := va.ComputeClawback(ctx.BlockTime().Unix())
if toClawBack.IsZero() {
// no-op, nothing to transfer
return nil
}

// set the account with the updated values of the vesting schedule
k.accountKeeper.SetAccount(ctx, &updatedAcc)

// Transfer clawback
addr := updatedAcc.GetAddress()
spendable := k.bankKeeper.SpendableCoins(ctx, addr)
transferAmt := toClawBack.Min(spendable)
return k.bankKeeper.SendCoins(ctx, addr, dest, transferAmt)

// NOTE: don't use `SpendableCoins` to get the minimum value to clawback since
// the amount is retrieved from `ComputeClawback`, which ensures correctness.
// `SpendableCoins` can result in gas exhaustion if the user has too many
// different denoms (because of store iteration).

// Transfer clawback to the destination (funder)
return k.bankKeeper.SendCoins(ctx, addr, dest, toClawBack)
}

0 comments on commit 6bf8829

Please sign in to comment.