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

runtime: use leader schedule epoch to serve sol_get_epoch_stake #3279

Merged

Conversation

buffalojoec
Copy link

@buffalojoec buffalojoec commented Oct 23, 2024

Problem

The bank epoch stakes cache stores stakes according to the leader schedule epoch, which means the epoch stake for a given epoch N actually corresponds to the N + 1 epoch in the epoch stakes cache.

The sol_get_epoch_stake syscall is designed to vend to on-chain programs the epoch stakes for the current epoch, but the existing implementation is returning the epoch stakes for leader schedule epoch N, when it actually should return the epoch stakes for leader schedule epoch N + 1.

For example, if you activate stake in epoch N, it becomes active in epoch N + 1, but the existing bank implementation for serving the sol_get_epoch_stakes syscall actually wouldn't return this new stake until epoch N + 2.

Summary of Changes

Use Bank's current_epoch_stakes method - which fetches the leader schedule epoch bank.epoch() + 1 - to serve the epoch stake information for sol_get_epoch_stakes, properly returning the current epoch stake.

runtime/src/bank.rs Outdated Show resolved Hide resolved
@buffalojoec buffalojoec marked this pull request as ready for review October 24, 2024 06:18
@buffalojoec buffalojoec merged commit aa84789 into anza-xyz:master Oct 25, 2024
51 checks passed
@buffalojoec buffalojoec added the v2.0 Backport to v2.0 branch label Oct 25, 2024
Copy link

mergify bot commented Oct 25, 2024

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

mergify bot pushed a commit that referenced this pull request Oct 25, 2024
)

* runtime: bank: use `get_current_epoch_stake` for SVM processing env

* runtime: bank: expand on `test_bank_epoch_stakes`

* add SBF test for `sol_get_epoch_stake`

* use existing `current_epoch_stakes` for new methods

(cherry picked from commit aa84789)

# Conflicts:
#	programs/sbf/Cargo.toml
#	runtime/src/bank/tests.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v2.0 Backport to v2.0 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants