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

Use EpochContext.epoch as current epoch #4302

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/balancesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class CheckpointBalancesCache {
* add the effective balances from the `state` to the cache.
*/
processState(blockRootHex: RootHex, state: CachedBeaconStateAllForks): void {
const epoch = state.epochCtx.currentShuffling.epoch;
const epoch = state.epochCtx.epoch;
const epochBoundarySlot = computeStartSlotAtEpoch(epoch);
const epochBoundaryRoot =
epochBoundarySlot === state.slot ? blockRootHex : toHexString(getBlockRootAtSlot(state, epochBoundarySlot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class StateContextCache {
}
this.metrics?.adds.inc();
this.cache.set(key, item.clone());
const epoch = item.epochCtx.currentShuffling.epoch;
const epoch = item.epochCtx.epoch;
const blockRoots = this.epochIndex.get(epoch);
if (blockRoots) {
blockRoots.add(key);
Expand All @@ -78,7 +78,7 @@ export class StateContextCache {
const key = toHexString(root);
const item = this.cache.get(key);
if (!item) return;
this.epochIndex.get(item.epochCtx.currentShuffling.epoch)?.delete(key);
this.epochIndex.get(item.epochCtx.epoch)?.delete(key);
this.cache.delete(key);
}

Expand Down Expand Up @@ -107,7 +107,7 @@ export class StateContextCache {
if (key !== headStateRootHex) {
const item = this.cache.get(key);
if (item) {
this.epochIndex.get(item.epochCtx.currentShuffling.epoch)?.delete(key);
this.epochIndex.get(item.epochCtx.epoch)?.delete(key);
this.cache.delete(key);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function processAttestationPhase0(
proposerIndex: epochCtx.getBeaconProposer(slot),
});

if (data.target.epoch === epochCtx.currentShuffling.epoch) {
if (data.target.epoch === epochCtx.epoch) {
if (!ssz.phase0.Checkpoint.equals(data.source, state.currentJustifiedCheckpoint)) {
throw new Error(
`Attestation source does not equal current justified checkpoint: source=${checkpointToStr(
Expand Down Expand Up @@ -68,12 +68,10 @@ export function validateAttestation(state: CachedBeaconStateAllForks, attestatio
`committeeIndex=${data.index} committeeCount=${committeeCount}`
);
}
if (
!(data.target.epoch === epochCtx.previousShuffling.epoch || data.target.epoch === epochCtx.currentShuffling.epoch)
) {
if (!(data.target.epoch === epochCtx.previousShuffling.epoch || data.target.epoch === epochCtx.epoch)) {
throw new Error(
"Attestation target epoch not in previous or current epoch: " +
`targetEpoch=${data.target.epoch} currentEpoch=${epochCtx.currentShuffling.epoch}`
`targetEpoch=${data.target.epoch} currentEpoch=${epochCtx.epoch}`
);
}
if (!(data.target.epoch === computedEpoch)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function processAttestationsAltair(
const {effectiveBalanceIncrements} = epochCtx;
const stateSlot = state.slot;
const rootCache = new RootCache(state);
const currentEpoch = epochCtx.currentShuffling.epoch;
const currentEpoch = epochCtx.epoch;

// Process all attestations first and then increase the balance of the proposer once
let proposerReward = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function processAttesterSlashing(
const validators = state.validators; // Get the validators sub tree once for all indices
// Spec requires to sort indexes beforehand
for (const index of intersectingIndices.sort((a, b) => a - b)) {
if (isSlashableValidator(validators.get(index), state.epochCtx.currentShuffling.epoch)) {
if (isSlashableValidator(validators.get(index), state.epochCtx.epoch)) {
slashValidator(fork, state, index);
slashedAny = true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/src/block/processRandao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function processRandao(
verifySignature = true
): void {
const {epochCtx} = state;
const epoch = epochCtx.currentShuffling.epoch;
const epoch = epochCtx.epoch;
const randaoReveal = block.body.randaoReveal;

// verify RANDAO reveal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function isValidVoluntaryExit(
const {config, epochCtx} = state;
const voluntaryExit = signedVoluntaryExit.message;
const validator = state.validators.get(voluntaryExit.validatorIndex);
const currentEpoch = epochCtx.currentShuffling.epoch;
const currentEpoch = epochCtx.epoch;

return (
// verify the validator is active
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/src/block/slashValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function slashValidator(
whistleblowerIndex?: ValidatorIndex
): void {
const {epochCtx} = state;
const epoch = epochCtx.currentShuffling.epoch;
const epoch = epochCtx.epoch;
const validator = state.validators.get(slashedIndex);

// TODO: Bellatrix initiateValidatorExit validators.update() with the one below
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/src/cache/epochProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export interface EpochProcess {
export function beforeProcessEpoch(state: CachedBeaconStateAllForks, opts?: EpochProcessOpts): EpochProcess {
const {config, epochCtx} = state;
const forkSeq = config.getForkSeq(state.slot);
const currentEpoch = epochCtx.currentShuffling.epoch;
const currentEpoch = epochCtx.epoch;
const prevEpoch = epochCtx.previousShuffling.epoch;
const nextEpoch = currentEpoch + 1;
// active validator indices for nextShuffling is ready, we want to precalculate for the one after that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function processRegistryUpdates(state: CachedBeaconStateAllForks, epochPr

// set new activation eligibilities
for (const index of epochProcess.indicesEligibleForActivationQueue) {
validators.get(index).activationEligibilityEpoch = epochCtx.currentShuffling.epoch + 1;
validators.get(index).activationEligibilityEpoch = epochCtx.epoch + 1;
}

const finalityEpoch = state.finalizedCheckpoint.epoch;
Expand Down
2 changes: 1 addition & 1 deletion packages/state-transition/src/util/weakSubjectivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function getLatestWeakSubjectivityCheckpointEpoch(
config: IChainForkConfig,
state: CachedBeaconStateAllForks
): Epoch {
return state.epochCtx.currentShuffling.epoch - computeWeakSubjectivityPeriodCachedState(config, state);
return state.epochCtx.epoch - computeWeakSubjectivityPeriodCachedState(config, state);
}

/**
Expand Down