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

fix: make sure shuffling is calculated when querying next epoch proposers #7156

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/beacon-node/src/api/impl/validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ export function getValidatorApi(
case stateEpoch + 1:
// Requesting duties for next epoch is allowed since they can be predicted with high probabilities.
// @see `epochCtx.getBeaconProposersNextEpoch` JSDocs for rationale.
indexes = state.epochCtx.getBeaconProposersNextEpoch();
indexes = await state.epochCtx.getBeaconProposersNextEpoch();
break;

case stateEpoch - 1: {
Expand Down
14 changes: 12 additions & 2 deletions packages/state-transition/src/cache/epochCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,12 +918,22 @@ export class EpochCache {
* balances are sampled to adjust the probability of the next selection (32 per epoch on average). So to invalidate
* the prediction the effective of one of those 32 samples should change and change the random_byte inequality.
*/
getBeaconProposersNextEpoch(): ValidatorIndex[] {
async getBeaconProposersNextEpoch(): Promise<ValidatorIndex[]> {
matthewkeil marked this conversation as resolved.
Show resolved Hide resolved
if (!this.proposersNextEpoch.computed) {
if (!this.nextShuffling) {
this.nextShuffling = (await this.shufflingCache?.get(this.nextEpoch, this.nextDecisionRoot)) ?? null;
}
if (!this.nextShuffling) {
throw new EpochCacheError({
matthewkeil marked this conversation as resolved.
Show resolved Hide resolved
code: EpochCacheErrorCode.NEXT_SHUFFLING_NOT_AVAILABLE,
epoch: this.nextEpoch,
decisionRoot: this.getShufflingDecisionRoot(this.nextEpoch),
});
}
const indexes = computeProposers(
this.config.getForkSeqAtEpoch(this.epoch + 1),
this.proposersNextEpoch.seed,
this.getShufflingAtEpoch(this.nextEpoch),
matthewkeil marked this conversation as resolved.
Show resolved Hide resolved
this.nextShuffling,
this.effectiveBalanceIncrements
);
this.proposersNextEpoch = {computed: true, indexes};
Expand Down
Loading