Skip to content

Commit

Permalink
Merge 935276d into 6ee2d6b
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jul 15, 2022
2 parents 6ee2d6b + 935276d commit 057b1be
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 17 deletions.
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

0 comments on commit 057b1be

Please sign in to comment.