Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export function createFastConfirmationCache(): FastConfirmationCache {
blockByRoot: new Map(),
ancestorRoots: new Map(),
committeeBySlot: new Map(),
isDescendantByRootPair: new Map(),
voteWeightBySource: new Map(),
checkpointStateByKey: new Map(),
};
}
Expand Down
55 changes: 52 additions & 3 deletions packages/fork-choice/src/forkChoice/fastConfirmation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ import {CheckpointWithPayloadStatus} from "../store.ts";
export type FastConfirmationBalanceSource = {
state: IBeaconStateView | null;
balances: EffectiveBalanceIncrements;
/**
* Per-validator effective balance, pre-zeroed for both inactive and slashed
* validators at the balance source epoch. Mirrors Lighthouse's `unslashed_balance`
* and is the single filter used by the per-validator hot loop in
* `precomputeChainAttestationScores` — removing all beacon-state access from
* that path.
*
* When `state` is available at construction, this is populated via
* `state.getEffectiveBalanceIncrementsZeroInactive()`, which zeros both
* inactive and slashed entries. When `state` is null, this equals `balances`
* (the fallback path's justified balances — inactive-zeroed but NOT
* slashed-zeroed).
*/
unslashedActiveBalances: EffectiveBalanceIncrements;
};

export type ForkChoiceStateGetter = (
Expand Down Expand Up @@ -69,13 +83,21 @@ export type FastConfirmationCache = {
blockByRoot: Map<RootHex, ProtoBlock | null>;
ancestorRoots: Map<string, RootHex[] | null>;
committeeBySlot: Map<Slot, Set<ValidatorIndex>>;
isDescendantByRootPair: Map<string, boolean>;
/** voteRoot -> totalWeight, keyed by sourceKey ("current" | "previous") */
voteWeightBySource: Map<string, Map<RootHex, number>>;
headState?: IBeaconStateView;
checkpointStateByKey: Map<string, IBeaconStateView | null>;
};

/**
* Minimal read-only view of a ProtoArray node, sufficient for parent-walking
* in `precomputeChainAttestationScores`. Narrowed from `ProtoNode` so mocks
* can satisfy this shape without constructing a real ProtoArray.
*/
export type ProtoNodeReadView = {
readonly parent?: number;
readonly slot: Slot;
readonly blockRoot: RootHex;
};

export type FastConfirmationContext = {
config: {
CONFIRMATION_BYZANTINE_THRESHOLD: number;
Expand All @@ -91,6 +113,33 @@ export type FastConfirmationContext = {
getFinalizedCheckpoint(): CheckpointWithPayloadStatus;
getEquivocatingIndices(): Set<ValidatorIndex>;
getTrackedVotesCount(): number;

/**
* Returns all ProtoArray node indices for this root.
* - Pre-Gloas: `[fullIdx]`
* - Gloas, payload not yet observed: `[pendingIdx, emptyIdx]`
* - Gloas, payload observed: `[pendingIdx, emptyIdx, fullIdx]`
* - Unknown root: `[]`
*
* Used once per chain block by `precomputeChainAttestationScores` to build
* the `indexToPosition` map covering every variant of each chain block.
*/
getNodeIndices(root: RootHex): readonly number[];

/**
* Read-only view of ProtoArray nodes for parent-walking in the precompute
* hot loop. Hoisted once at the top of `precomputeChainAttestationScores`
* so the inner walk does plain array access with no function-call overhead
* (walk runs up to O(V × depth) times per precompute invocation).
*/
getProtoNodeView(): {readonly nodes: ReadonlyArray<ProtoNodeReadView>};

/**
* Read-only handle on `voteNextIndices`. Hoisted once at the top of
* `precomputeChainAttestationScores` for direct indexed access in the
* per-validator loop. `NULL_VOTE_INDEX` sentinel is preserved.
*/
getVoteNextIndices(): readonly number[];
};

export interface IFastConfirmationRule {
Expand Down
Loading
Loading