v2.0: runtime: use leader schedule epoch to serve sol_get_epoch_stake
(backport of #3279)
#3312
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theN + 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 epochN
, when it actually should return the epoch stakes for leader schedule epochN + 1
.For example, if you activate stake in epoch
N
, it becomes active in epochN + 1
, but the existing bank implementation for serving thesol_get_epoch_stakes
syscall actually wouldn't return this new stake until epochN + 2
.Summary of Changes
Use Bank's
current_epoch_stakes
method - which fetches the leader schedule epochbank.epoch() + 1
- to serve the epoch stake information forsol_get_epoch_stakes
, properly returning the current epoch stake.This is an automatic backport of pull request #3279 done by Mergify.