From 2a7f7e6afd51137960b6d540be5354b3ad85bbed Mon Sep 17 00:00:00 2001 From: Matthew Keil Date: Mon, 14 Oct 2024 19:27:04 +0700 Subject: [PATCH] fix: make sure shuffling is calculated when querying next epoch proposers (#7156) * feat: make getBeaconProposersNextEpoch async to await for shuffling calculation * fix: build error in getBeaconProposersNextEpoch * fix: failed unit test * refactor: use tuyen suggestion to await for shuffling keeping state-transition sync --- packages/beacon-node/src/api/impl/validator/index.ts | 2 ++ packages/state-transition/src/cache/epochCache.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/beacon-node/src/api/impl/validator/index.ts b/packages/beacon-node/src/api/impl/validator/index.ts index 9c5e6c2987f..1fccf083070 100644 --- a/packages/beacon-node/src/api/impl/validator/index.ts +++ b/packages/beacon-node/src/api/impl/validator/index.ts @@ -957,6 +957,8 @@ export function getValidatorApi( break; case stateEpoch + 1: + // make sure shuffling is calculated and ready for next call to calculate nextProposers + await chain.shufflingCache.get(state.epochCtx.nextEpoch, state.epochCtx.nextDecisionRoot); // 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(); diff --git a/packages/state-transition/src/cache/epochCache.ts b/packages/state-transition/src/cache/epochCache.ts index 4eb16fa4992..5601162b2c2 100644 --- a/packages/state-transition/src/cache/epochCache.ts +++ b/packages/state-transition/src/cache/epochCache.ts @@ -921,7 +921,7 @@ export class EpochCache { getBeaconProposersNextEpoch(): ValidatorIndex[] { if (!this.proposersNextEpoch.computed) { const indexes = computeProposers( - this.config.getForkSeqAtEpoch(this.epoch + 1), + this.config.getForkSeqAtEpoch(this.nextEpoch), this.proposersNextEpoch.seed, this.getShufflingAtEpoch(this.nextEpoch), this.effectiveBalanceIncrements