Skip to content

[Staking] Rotate era reward pots through a fixed-size pool#11930

Merged
Ank4n merged 20 commits into
masterfrom
ankn-era-pot-pool
Apr 29, 2026
Merged

[Staking] Rotate era reward pots through a fixed-size pool#11930
Ank4n merged 20 commits into
masterfrom
ankn-era-pot-pool

Conversation

@Ank4n

@Ank4n Ank4n commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Era reward pot accounts are now drawn from a fixed pool of POT_POOL_SIZE = 200 accounts, indexed by era % POT_POOL_SIZE, instead of one fresh account per era.

This ensure we only use a fixed size of pot accounts for the lifetime of the chain rather than growing per era.

@Ank4n Ank4n requested a review from a team as a code owner April 29, 2026 07:45
@Ank4n Ank4n changed the title Reuse from pool of accounts for Era based pot [Staking] Reuse from pool of accounts for Era based pot Apr 29, 2026
@Ank4n Ank4n changed the title [Staking] Reuse from pool of accounts for Era based pot [Staking] Rotate era reward pots through a fixed-size pool Apr 29, 2026
/// Must be strictly greater than [`Config::HistoryDepth`] so that a slot is only
/// reused after its previous era has been pruned and drained. The
/// [`integrity_test`] enforces this invariant at runtime startup.
pub(crate) const POT_POOL_SIZE: u32 = 200;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Didn't expose this as config since it doesn't practically need to be configured. Only requirement is that it's bigger than HistoryDepth (enforced by integrity_test). Also intended to keep it independent of HistoryDepth so changing it doesn't affect pot account assignment.

)]
pub enum RewardKind {
/// Staker rewards (nominators + validators).
#[codec(index = 0)]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pinned variant indices to be safe from any future mishappenings

@Ank4n Ank4n added the T2-pallets This PR/Issue is related to a particular pallet. label Apr 29, 2026
Comment thread prdoc/pr_11930.prdoc Outdated
&pot_account,
remaining,
Precision::BestEffort,
Preservation::Expendable,

@kianenigma kianenigma Apr 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was worried for a sec that this would cause the account to die, while it still has a provider, and it cannot due, causing us to not be able to drain the remaining balance. I still think this part is tricky, and should be double checked.

An existing test is surely validating that it works.

ATM I think Fortitude::Force is basically saving us, otherwise on paper this transfer should fail: Account has a provider, but is requesting all of its funds to be drained.

All in all, the intersection of Consumer/Provider and Preservation/Fortitude is quite tricky.

@Ank4n Ank4n Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Its okay even if it dies, no? At create, we check if account has a provider and if not add one. The intention for adding an explicit provider was to ensure no funds gets cleaned up from here as dust while the pot is active.

@kianenigma kianenigma left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ank4n and others added 2 commits April 29, 2026 10:56
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

@cirko33 cirko33 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Comment thread prdoc/pr_11930.prdoc
This ensure we only use a fixed size of pot accounts for the lifetime of the
chain rather than growing per era.

An `integrity_test` enforces `POT_POOL_SIZE > HistoryDepth` so a slot is only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since HistoryDepth is 84 for Westend / Kusama / Polkadot, isn't 200 too high? Why not 100 maybe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was looking to make it at least 2x to protect against history depth changing, which tbh is unlikely in itself. That said, I think 200 is a safe number. Much larger than history depth, and still gives the bounded protection.

@Ank4n Ank4n added this pull request to the merge queue Apr 29, 2026
Merged via the queue into master with commit eb8daca Apr 29, 2026
319 of 354 checks passed
@Ank4n Ank4n deleted the ankn-era-pot-pool branch April 29, 2026 19:01
ggwpez added a commit to polkadot-fellows/runtimes that referenced this pull request May 4, 2026
Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T2-pallets This PR/Issue is related to a particular pallet.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants