Skip to content

Optimise vested amounts computation using math/big#3456

Open
masih wants to merge 1 commit into
mainfrom
masih/math-perf-optimisation
Open

Optimise vested amounts computation using math/big#3456
masih wants to merge 1 commit into
mainfrom
masih/math-perf-optimisation

Conversation

@masih
Copy link
Copy Markdown
Collaborator

@masih masih commented May 18, 2026

Continuous-vesting proration is amount * elapsed / duration, which is an integer computation. Going through sdk.Dec allocates a scaled big.Int per coin only to truncate the extra precision back away. Use math/big.Int directly and skip the round trip.

While at it:

  • rename the loop-local "x" in PeriodicVestingAccount.GetVestedCoins to "elapsed" so it matches the continuous-vesting variable naming
  • correct the Validate() error string on continuous and periodic vesting accounts: the predicate fails when start-time >= end-time, so "cannot be before end-time" was reversed
  • cover two non-aligned timestamps in TestGetVestedCoinsContVestingAcc

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 18, 2026

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMay 22, 2026, 6:43 PM

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.11%. Comparing base (7dbd3e5) to head (c530ac3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3456      +/-   ##
==========================================
- Coverage   59.11%   59.11%   -0.01%     
==========================================
  Files        2187     2187              
  Lines      182236   182173      -63     
==========================================
- Hits       107732   107684      -48     
+ Misses      64852    64839      -13     
+ Partials     9652     9650       -2     
Flag Coverage Δ
sei-db 70.62% <ø> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
giga/deps/xbank/keeper/send.go 85.09% <ø> (-0.19%) ⬇️
giga/deps/xevm/keeper/balance.go 100.00% <ø> (ø)
sei-cosmos/x/auth/vesting/types/msgs.go 33.33% <ø> (+10.47%) ⬆️
sei-cosmos/x/auth/vesting/types/vesting_account.go 89.45% <ø> (-0.18%) ⬇️
sei-cosmos/x/bank/keeper/send.go 92.30% <ø> (-0.15%) ⬇️
x/evm/keeper/abci.go 59.32% <ø> (ø)
x/evm/keeper/balance.go 100.00% <ø> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@masih masih requested review from arajasek and sei-will May 18, 2026 13:04
@masih masih marked this pull request as ready for review May 18, 2026 13:04
@cursor
Copy link
Copy Markdown

cursor Bot commented May 18, 2026

PR Summary

Medium Risk
Touches vesting proration and bank/EVM spendable-balance calculations; mistakes here could incorrectly allow/deny spending or change EVM-visible balances. Changes are localized and backed by updated tests.

Overview
Optimizes continuous vesting proration by computing vested amounts via a single scaled big.Int fraction per call (instead of per-coin sdk.Dec allocations), and expands/refactors vesting tests (including extra non-aligned timestamp cases) while tightening some validation error strings.

Comment thread sei-cosmos/x/auth/vesting/types/vesting_account.go Outdated
@masih masih requested a review from arajasek May 22, 2026 09:08
Comment thread sei-cosmos/x/bank/keeper/send.go Outdated
@masih masih force-pushed the masih/math-perf-optimisation branch 2 times, most recently from dedf4c6 to 2ba4418 Compare May 22, 2026 11:37
Comment thread sei-cosmos/x/bank/keeper/send.go Outdated
Continuous-vesting proration is amount * elapsed / duration, which is
an integer computation. Going through sdk.Dec allocates a scaled
big.Int per coin only to truncate the extra precision back away. Use
math/big.Int directly and skip the round trip.

While at it:
* rename the loop-local "x" in PeriodicVestingAccount.GetVestedCoins
  to "elapsed" so it matches the continuous-vesting variable naming
* correct the Validate() error string on continuous and periodic
  vesting accounts: the predicate fails when start-time >= end-time,
  so "cannot be before end-time" was reversed
* cover two non-aligned timestamps in TestGetVestedCoinsContVestingAcc
@masih masih force-pushed the masih/math-perf-optimisation branch from ed60a56 to c530ac3 Compare May 22, 2026 18:41
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c530ac3. Configure here.

newUsei, newWei := SplitUseiWeiAmount(postTotal)
lockedUsei := k.LockedCoins(ctx, addr).AmountOf(denom)
if newUsei.LT(lockedUsei) {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%suei is smaller than locked %suei", newUsei, lockedUsei)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Error message misspells denomination as "uei" instead of "usei"

Low Severity

The format string "%suei is smaller than locked %suei" produces output like 100uei instead of 100usei. The %s format verb consumes the numeric argument, and uei is the literal suffix — but the denomination is usei, not uei. The nearby wei error correctly uses "%swei". The fix is "%susei is smaller than locked %susei".

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c530ac3. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants