Skip to content

Conversation

@abelmarnk
Copy link
Contributor

Corrected the calculation of the remainder of the epoch stake from let remainder = target_total % num_accounts; to let remainder = target_total % base_stake;

abelmarnk and others added 2 commits October 12, 2025 00:49
Corrected the calculation of the epoch stake from 
`let remainder = target_total % num_accounts;` to `let remainder = target_total % base_stake;`
buffalojoec
buffalojoec previously approved these changes Oct 13, 2025
Copy link
Collaborator

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

Hey thanks for the fix! Turns out this function is actually more broken than I thought.

Let target_total = 2.5 SOL (2,500,000,000).

num_accounts = 2_500_000_000.div_ceil(1_000_000_000) = 3
base_stake = 2_500_000_000 / 3 = 833_333_333
remainder = 2_500_000_000 % 3 = 1

That gives us three accounts:

  1. 833_333_333 lamports
  2. 833_333_333 lamports
  3. 833_333_334 lamports

What it should actually be is this:

num_accounts = 2_500_000_000 / 1_000_000_000) = 2
base_stake = 2_500_000_000 / 2 = 1_000_000_000
remainder = 2_500_000_000 % 2 = 500_000_000

That gives us two accounts:

  1. 1 SOL
  2. 1.5 SOL

I pushed a commit to overhaul this and add some tests. Good spot!

@buffalojoec buffalojoec merged commit 50bc84f into anza-xyz:main Oct 13, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants