@lodestar/fork-choice 2.0.0-rc.0 → 2.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/forkChoice/fastConfirmation/data.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/data.js +3 -2
- package/lib/forkChoice/fastConfirmation/data.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/types.d.ts +30 -4
- package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/types.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/utils.d.ts +3 -5
- package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/utils.js +155 -72
- package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
- package/lib/forkChoice/forkChoice.d.ts +1 -1
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +1 -1
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +2 -0
- package/lib/forkChoice/interface.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/forkChoice/fastConfirmation/data.ts +3 -2
- package/src/forkChoice/fastConfirmation/types.ts +28 -4
- package/src/forkChoice/fastConfirmation/utils.ts +173 -89
- package/src/forkChoice/forkChoice.ts +2 -5
- package/src/forkChoice/interface.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/data.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAGpB,wBAAgB,2BAA2B,IAAI,qBAAqB,
|
|
1
|
+
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/data.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAGpB,wBAAgB,2BAA2B,IAAI,qBAAqB,CAWnE;AAED,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,GAC3B,wBAAwB,CAkB1B"}
|
|
@@ -4,10 +4,11 @@ export function createFastConfirmationCache() {
|
|
|
4
4
|
return {
|
|
5
5
|
blockByRoot: new Map(),
|
|
6
6
|
ancestorRoots: new Map(),
|
|
7
|
-
|
|
7
|
+
committeeSweepByEndSlot: new Map(),
|
|
8
|
+
participantsByRange: new Map(),
|
|
8
9
|
isDescendantByRootPair: new Map(),
|
|
9
10
|
voteWeightBySource: new Map(),
|
|
10
|
-
|
|
11
|
+
activeBalancesByKey: new Map(),
|
|
11
12
|
checkpointStateByKey: new Map(),
|
|
12
13
|
};
|
|
13
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAO9D,OAAO,EAAC,QAAQ,EAAE,0BAA0B,EAAC,MAAM,YAAY,CAAC;AAEhE,MAAM,UAAU,2BAA2B;IACzC,OAAO;QACL,WAAW,EAAE,IAAI,GAAG,EAAE;QACtB,aAAa,EAAE,IAAI,GAAG,EAAE;QACxB,
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAC;AAO9D,OAAO,EAAC,QAAQ,EAAE,0BAA0B,EAAC,MAAM,YAAY,CAAC;AAEhE,MAAM,UAAU,2BAA2B;IACzC,OAAO;QACL,WAAW,EAAE,IAAI,GAAG,E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
+
export type BalanceSourceCacheKey = IBeaconStateView | EffectiveBalanceIncrements;
|
|
11
|
+
/**
|
|
12
|
+
* Effective balances of the validators active at the balance source epoch, slashed included, their sum,
|
|
13
|
+
* and the sum over the unslashed ones (`calculate_committee_fraction`)
|
|
14
|
+
*/
|
|
15
|
+
export type ActiveBalances = {
|
|
16
|
+
balances: EffectiveBalanceIncrements;
|
|
17
|
+
total: number;
|
|
18
|
+
unslashedTotal: number;
|
|
19
|
+
};
|
|
11
20
|
export type ForkChoiceStateGetter = (opts: {
|
|
12
21
|
stateRoot: RootHex;
|
|
13
22
|
checkpoint?: never;
|
|
@@ -75,15 +84,32 @@ export type FastConfirmationRunResult = FastConfirmationDecision & {
|
|
|
75
84
|
};
|
|
76
85
|
export type FastConfirmationRule = (snapshot: FastConfirmationSnapshot, ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, decision: FastConfirmationDecision, logger?: Logger) => FastConfirmationDecision;
|
|
77
86
|
export type BalanceSourceKey = "current" | "previous";
|
|
87
|
+
/**
|
|
88
|
+
* Committees of the slots ending at a fixed slot, swept backwards one slot at a time over the head
|
|
89
|
+
* state shuffling. A validator is recorded at the latest slot it is assigned to, so the committees of
|
|
90
|
+
* any range ending at that slot are a prefix of `order` with no duplicates, even when the range
|
|
91
|
+
* crosses an epoch boundary and the two epochs' committees overlap.
|
|
92
|
+
*/
|
|
93
|
+
export type CommitteeSweep = {
|
|
94
|
+
/** Marks validators already placed in `order`, indexed by validator index */
|
|
95
|
+
seen: Uint8Array;
|
|
96
|
+
/** Validators of the end slot, then those first seen one slot earlier, and so on */
|
|
97
|
+
order: Uint32Array;
|
|
98
|
+
/** Length of the `order` prefix covering the last `i + 1` slots, for each swept slot `i` */
|
|
99
|
+
lengths: number[];
|
|
100
|
+
/** Committee weight of the last `i + 1` slots, per balance source, filled on demand */
|
|
101
|
+
weightsByKey: Map<BalanceSourceCacheKey, number[]>;
|
|
102
|
+
};
|
|
78
103
|
export type FastConfirmationCache = {
|
|
79
104
|
blockByRoot: Map<RootHex, ProtoBlock | null>;
|
|
80
105
|
ancestorRoots: Map<string, RootHex[] | null>;
|
|
81
|
-
|
|
106
|
+
committeeSweepByEndSlot: Map<Slot, CommitteeSweep>;
|
|
107
|
+
participantsByRange: Map<string, Uint32Array>;
|
|
82
108
|
isDescendantByRootPair: Map<string, boolean>;
|
|
83
109
|
/** voteRoot -> totalWeight, keyed by sourceKey */
|
|
84
110
|
voteWeightBySource: Map<BalanceSourceKey, Map<RootHex, number>>;
|
|
85
|
-
/**
|
|
86
|
-
|
|
111
|
+
/** active balances and their total, keyed by the balance source's state or balances reference */
|
|
112
|
+
activeBalancesByKey: Map<BalanceSourceCacheKey, ActiveBalances>;
|
|
87
113
|
headState?: IBeaconStateView;
|
|
88
114
|
pulledUpHeadState?: IBeaconStateView;
|
|
89
115
|
checkpointStateByKey: Map<string, IBeaconStateView | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAE,gBAAgB,EAAC,MAAM,4BAA4B,CAAC;AACxF,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAC,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAC,MAAM,EAAC,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC/B,QAAQ,EAAE,0BAA0B,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/types.ts"],"names":[],"mappings":"A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.js","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/types.ts"],"names":[],"mappings":"AA0DA,MAAM,CAAN,IAAY,8BAQX;AARD,WAAY,8BAA8B;IACxC,yDAAuB,CAAA;IACvB,2EAAyC,CAAA;IACzC,8DAA4B,CAAA;IAC5B,yEAAuC,CAAA;IACvC,yEAAuC,CAAA;IACvC,0EAAwC,CAAA;IACxC,8EAA4C,CAAA;AAC9C,CAAC,EARW,8BAA8B,KAA9B,8BAA8B,QAQzC;AAED,qGAAqG;AACrG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAiC;IAC5D,8BAA8B,CAAC,iBAAiB;IAChD,8BAA8B,CAAC,WAAW;IAC1C,8BAA8B,CAAC,gBAAgB;IAC/C,8BAA8B,CAAC,gBAAgB;CAChD,CAAC,CAAC;AAEH,MAAM,UAAU,aAAa,CAAC,MAAsC;IAClE,OAAO,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IBeaconStateView } from "@lodestar/state-transition";
|
|
2
|
-
import { Epoch, RootHex, Slot
|
|
2
|
+
import { Epoch, RootHex, Slot } from "@lodestar/types";
|
|
3
3
|
import { Logger } from "@lodestar/utils";
|
|
4
4
|
import { PayloadStatus, ProtoBlock } from "../../protoArray/interface.js";
|
|
5
5
|
import { CheckpointWithHex } from "../store.js";
|
|
@@ -13,17 +13,15 @@ export declare function isAncestor(ctx: FastConfirmationContext, cache: FastConf
|
|
|
13
13
|
export declare function getHeadState(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): IBeaconStateView;
|
|
14
14
|
export declare function getPulledUpHeadState(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache): IBeaconStateView;
|
|
15
15
|
export declare function getCheckpointState(store: IFastConfirmationStore, cache: FastConfirmationCache, checkpoint: CheckpointWithHex): IBeaconStateView | null;
|
|
16
|
-
export declare function getSlotCommittee(cache: FastConfirmationCache, state: IBeaconStateView, slot: Slot): Set<ValidatorIndex>;
|
|
17
16
|
export declare function getBalanceSource(store: IFastConfirmationStore, cache: FastConfirmationCache, kind: "previous" | "current"): FastConfirmationBalanceSource;
|
|
18
17
|
export declare function getCurrentBalanceSource(store: IFastConfirmationStore, cache: FastConfirmationCache): FastConfirmationBalanceSource;
|
|
19
18
|
export declare function getPreviousBalanceSource(store: IFastConfirmationStore, cache: FastConfirmationCache): FastConfirmationBalanceSource;
|
|
20
19
|
export declare function getTotalActiveBalance(balanceSource: FastConfirmationBalanceSource, cache: FastConfirmationCache): number;
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function adjustCommitteeWeightEstimateToEnsureSafety(estimate: bigint): bigint;
|
|
20
|
+
export declare function computeCommitteeWeightBetweenSlots(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, startSlot: Slot, endSlot: Slot): bigint;
|
|
23
21
|
export declare function isFullValidatorSetCovered(startSlot: Slot, endSlot: Slot): boolean;
|
|
24
22
|
export declare function computeProposerScore(ctx: FastConfirmationContext, balanceSource: FastConfirmationBalanceSource, cache: FastConfirmationCache): bigint;
|
|
25
23
|
export declare function getAttestationScore(ctx: FastConfirmationContext, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex, sourceKey: BalanceSourceKey): number;
|
|
26
|
-
export declare function getNodeSupportBetweenSlots(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, nodeRoot: RootHex,
|
|
24
|
+
export declare function getNodeSupportBetweenSlots(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, nodeRoot: RootHex, nodePayloadStatuses: readonly PayloadStatus[], startSlot: Slot, endSlot: Slot): number;
|
|
27
25
|
export declare function getEquivocationScore(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, startSlot: Slot, endSlot: Slot): number;
|
|
28
26
|
export declare function computeAdversarialWeight(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, startSlot: Slot, endSlot: Slot): bigint;
|
|
29
27
|
export declare function getAdversarialWeight(ctx: FastConfirmationContext, store: IFastConfirmationStore, cache: FastConfirmationCache, balanceSource: FastConfirmationBalanceSource, blockRoot: RootHex): bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,gBAAgB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/forkChoice/fastConfirmation/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,gBAAgB,EAKjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAC,MAAM,EAAU,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAkB,aAAa,EAAE,UAAU,EAAC,MAAM,+BAA+B,CAAC;AACzF,OAAO,EAAC,iBAAiB,EAA8C,MAAM,aAAa,CAAC;AAC3F,OAAO,EAGL,KAAK,gBAAgB,EAErB,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAYpB,wBAAgB,QAAQ,CAAC,GAAG,EAAE,uBAAuB,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAOrH;AAED,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,qBAAqB,EAC5B,SAAS,EAAE,OAAO,GACjB,iBAAiB,GAAG,IAAI,CAQ1B;A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AC7B,KAAK,EAAE,qBAAqB,GAC3B,gBAAgB,GAAG,IAAI,CAEzB;AAED,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,GAC3B,MAAM,CAoCR;AAeD,wBAAgB,uCAAuC,CACrD,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,GAC3B,MAAM,CAiCR;AAED,wBAAgB,sCAAsC,CACpD,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAaT;AAED,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAQT;AAED,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,EAC5B,aAAa,EAAE,OAAO,EACtB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CA4DT;AAID,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,wBAAwB,EAClC,GAAG,EAAE,uBAAuB,EAC5B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,qBAAqB,EAC5B,mBAAmB,EAAE,OAAO,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAmIT"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { EFFECTIVE_BALANCE_INCREMENT, SLOTS_PER_EPOCH } from "@lodestar/params";
|
|
2
|
-
import { computeEpochAtSlot,
|
|
2
|
+
import { computeEpochAtSlot, computeStartSlotAtEpoch, isActiveValidator, isStartSlotOfEpoch, } from "@lodestar/state-transition";
|
|
3
3
|
import { fromHex } from "@lodestar/utils";
|
|
4
4
|
import { ExecutionStatus } from "../../protoArray/interface.js";
|
|
5
5
|
import { computeTotalBalance, equalCheckpointWithHex } from "../store.js";
|
|
6
|
-
// Spec: adjust_committee_weight_estimate_to_ensure_safety
|
|
7
|
-
// https://github.com/ethereum/consensus-specs/blob/master/specs/phase0/fast-confirmation.md#adjust_committee_weight_estimate_to_ensure_safety
|
|
8
|
-
const COMMITTEE_WEIGHT_ESTIMATION_ADJUSTMENT_FACTOR = 5n;
|
|
9
6
|
const EFFECTIVE_BALANCE_INCREMENT_BIGINT = BigInt(EFFECTIVE_BALANCE_INCREMENT);
|
|
10
7
|
const SAFETY_THRESHOLD_UNREACHABLE = Object.freeze({
|
|
11
8
|
threshold: 2n ** 64n,
|
|
@@ -118,31 +115,81 @@ export function getCheckpointState(store, cache, checkpoint) {
|
|
|
118
115
|
cache.checkpointStateByKey.set(key, state ?? null);
|
|
119
116
|
return state ?? null;
|
|
120
117
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Spec: get_slot_committee, for the slots `startSlot..endSlot`.
|
|
120
|
+
* Chain-walk queries ending at `current_slot - 1` share this sweep across many start slots.
|
|
121
|
+
* Extending it backwards avoids rebuilding a union of up to the full validator set per block.
|
|
122
|
+
*/
|
|
123
|
+
function getCommitteeSweep(ctx, store, cache, startSlot, endSlot) {
|
|
124
|
+
const headState = getHeadState(ctx, store, cache);
|
|
125
|
+
let sweep = cache.committeeSweepByEndSlot.get(endSlot);
|
|
126
|
+
if (sweep === undefined) {
|
|
127
|
+
sweep = {
|
|
128
|
+
seen: new Uint8Array(headState.validatorCount),
|
|
129
|
+
order: new Uint32Array(headState.validatorCount),
|
|
130
|
+
lengths: [],
|
|
131
|
+
weightsByKey: new Map(),
|
|
132
|
+
};
|
|
133
|
+
cache.committeeSweepByEndSlot.set(endSlot, sweep);
|
|
134
|
+
}
|
|
135
|
+
let length = sweep.lengths.at(-1) ?? 0;
|
|
136
|
+
for (let slot = endSlot - sweep.lengths.length; slot >= startSlot; slot--) {
|
|
137
|
+
const committeesCount = headState.getBeaconCommitteeCountPerSlot(computeEpochAtSlot(slot));
|
|
138
|
+
for (let i = 0; i < committeesCount; i++) {
|
|
139
|
+
for (const index of headState.getBeaconCommittee(slot, i)) {
|
|
140
|
+
if (sweep.seen[index] === 1)
|
|
141
|
+
continue;
|
|
142
|
+
sweep.seen[index] = 1;
|
|
143
|
+
sweep.order[length++] = index;
|
|
144
|
+
}
|
|
132
145
|
}
|
|
146
|
+
sweep.lengths.push(length);
|
|
133
147
|
}
|
|
134
|
-
|
|
135
|
-
return participants;
|
|
148
|
+
return sweep;
|
|
136
149
|
}
|
|
137
150
|
function getSlotRangeParticipants(ctx, store, cache, startSlot, endSlot) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
151
|
+
// Empty-slot discounts end at different block slots. A sweep per endpoint would allocate
|
|
152
|
+
// 5 bytes per registered validator for each gap, even when the gap spans just one slot.
|
|
153
|
+
// Cache compact participants instead, shared by support and adversarial-weight calculations.
|
|
154
|
+
if (endSlot !== ctx.getCurrentSlot() - 1) {
|
|
155
|
+
const key = `${startSlot}:${endSlot}`;
|
|
156
|
+
const cached = cache.participantsByRange.get(key);
|
|
157
|
+
if (cached !== undefined)
|
|
158
|
+
return cached;
|
|
159
|
+
const state = getHeadState(ctx, store, cache);
|
|
160
|
+
const committees = [];
|
|
161
|
+
let length = 0;
|
|
162
|
+
for (let slot = startSlot; slot <= endSlot; slot++) {
|
|
163
|
+
const count = state.getBeaconCommitteeCountPerSlot(computeEpochAtSlot(slot));
|
|
164
|
+
for (let i = 0; i < count; i++) {
|
|
165
|
+
const committee = state.getBeaconCommittee(slot, i);
|
|
166
|
+
committees.push(committee);
|
|
167
|
+
length += committee.length;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
let participants;
|
|
171
|
+
// Within an epoch committees partition the active validator set.
|
|
172
|
+
if (computeEpochAtSlot(startSlot) === computeEpochAtSlot(endSlot)) {
|
|
173
|
+
participants = new Uint32Array(length);
|
|
174
|
+
let offset = 0;
|
|
175
|
+
for (const committee of committees) {
|
|
176
|
+
participants.set(committee, offset);
|
|
177
|
+
offset += committee.length;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const unique = new Set();
|
|
182
|
+
for (const committee of committees) {
|
|
183
|
+
for (const index of committee)
|
|
184
|
+
unique.add(index);
|
|
185
|
+
}
|
|
186
|
+
participants = Uint32Array.from(unique);
|
|
143
187
|
}
|
|
188
|
+
cache.participantsByRange.set(key, participants);
|
|
189
|
+
return participants;
|
|
144
190
|
}
|
|
145
|
-
|
|
191
|
+
const sweep = getCommitteeSweep(ctx, store, cache, startSlot, endSlot);
|
|
192
|
+
return sweep.order.subarray(0, sweep.lengths[endSlot - startSlot]);
|
|
146
193
|
}
|
|
147
194
|
function isDescendantCached(ctx, cache, ancestorRoot, descendantRoot) {
|
|
148
195
|
const cacheKey = `${ancestorRoot}:${descendantRoot}`;
|
|
@@ -179,45 +226,79 @@ function getZeroInactiveBalances(balanceSource) {
|
|
|
179
226
|
// Fallback balances come from the justified-balance path and already zero inactive validators
|
|
180
227
|
return balanceSource.state?.getEffectiveBalanceIncrementsZeroInactive() ?? balanceSource.balances;
|
|
181
228
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
229
|
+
/**
|
|
230
|
+
* Balances read by `get_total_active_balance` and `compute_committee_weight_between_slots`. Unlike the
|
|
231
|
+
* vote scans, these keep slashed validators: the maximum support and the adversarial budget they bound
|
|
232
|
+
* must cover slashed equivocators, whose weight `getEquivocationScore` subtracts. `unslashedTotal` serves
|
|
233
|
+
* `compute_proposer_score`, whose `calculate_committee_fraction` excludes slashed validators.
|
|
234
|
+
* Invariant per balance source within a run, but read many times per is_one_confirmed evaluation
|
|
235
|
+
* across the epoch-boundary chain walk; memoized so the full validator-set scan runs once per run.
|
|
236
|
+
*/
|
|
237
|
+
function getActiveBalances(balanceSource, cache) {
|
|
185
238
|
const key = balanceSource.state ?? balanceSource.balances;
|
|
186
|
-
const cached = cache.
|
|
239
|
+
const cached = cache.activeBalancesByKey.get(key);
|
|
187
240
|
if (cached !== undefined)
|
|
188
241
|
return cached;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
242
|
+
let active;
|
|
243
|
+
if (balanceSource.state) {
|
|
244
|
+
const { effectiveBalanceIncrements } = balanceSource.state;
|
|
245
|
+
const unslashedBalances = balanceSource.state.getEffectiveBalanceIncrementsZeroInactive();
|
|
246
|
+
const balances = new Uint16Array(balanceSource.state.validatorCount);
|
|
247
|
+
let total = 0;
|
|
248
|
+
let unslashedTotal = 0;
|
|
249
|
+
for (const i of balanceSource.state.getCurrentShuffling().activeIndices) {
|
|
250
|
+
balances[i] = effectiveBalanceIncrements[i];
|
|
251
|
+
total += balances[i];
|
|
252
|
+
unslashedTotal += unslashedBalances[i];
|
|
253
|
+
}
|
|
254
|
+
active = { balances, total, unslashedTotal };
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// Fallback balances come from the justified-balance path, which also zeroes slashed validators
|
|
258
|
+
const total = computeTotalBalance(balanceSource.balances);
|
|
259
|
+
active = { balances: balanceSource.balances, total, unslashedTotal: total };
|
|
260
|
+
}
|
|
261
|
+
cache.activeBalancesByKey.set(key, active);
|
|
262
|
+
return active;
|
|
192
263
|
}
|
|
193
|
-
export function
|
|
264
|
+
export function getTotalActiveBalance(balanceSource, cache) {
|
|
265
|
+
return getActiveBalances(balanceSource, cache).total;
|
|
266
|
+
}
|
|
267
|
+
export function computeCommitteeWeightBetweenSlots(ctx, store, cache, balanceSource, startSlot, endSlot) {
|
|
194
268
|
if (startSlot > endSlot)
|
|
195
269
|
return 0n;
|
|
196
|
-
const totalActiveBalance = BigInt(getTotalActiveBalance(balanceSource, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
197
|
-
const startEpoch = computeEpochAtSlot(startSlot);
|
|
198
|
-
const endEpoch = computeEpochAtSlot(endSlot);
|
|
199
270
|
if (isFullValidatorSetCovered(startSlot, endSlot)) {
|
|
200
|
-
return
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
271
|
+
return BigInt(getTotalActiveBalance(balanceSource, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
272
|
+
}
|
|
273
|
+
// Only the shared endpoint benefits from incremental weight prefixes across the chain walk.
|
|
274
|
+
// Other ranges reuse their compact participants without allocating a validator-sized sweep.
|
|
275
|
+
if (endSlot !== ctx.getCurrentSlot() - 1) {
|
|
276
|
+
const { balances } = getActiveBalances(balanceSource, cache);
|
|
277
|
+
let weight = 0;
|
|
278
|
+
for (const index of getSlotRangeParticipants(ctx, store, cache, startSlot, endSlot)) {
|
|
279
|
+
weight += balances[index] ?? 0;
|
|
280
|
+
}
|
|
281
|
+
return BigInt(weight) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
282
|
+
}
|
|
283
|
+
const sweep = getCommitteeSweep(ctx, store, cache, startSlot, endSlot);
|
|
284
|
+
const key = balanceSource.state ?? balanceSource.balances;
|
|
285
|
+
let weights = sweep.weightsByKey.get(key);
|
|
286
|
+
if (weights === undefined) {
|
|
287
|
+
weights = [];
|
|
288
|
+
sweep.weightsByKey.set(key, weights);
|
|
289
|
+
}
|
|
290
|
+
const slotCount = endSlot - startSlot + 1;
|
|
291
|
+
if (weights.length < slotCount) {
|
|
292
|
+
const { balances } = getActiveBalances(balanceSource, cache);
|
|
293
|
+
let weight = weights.at(-1) ?? 0;
|
|
294
|
+
for (let i = weights.length; i < slotCount; i++) {
|
|
295
|
+
for (let j = i > 0 ? sweep.lengths[i - 1] : 0; j < sweep.lengths[i]; j++) {
|
|
296
|
+
weight += balances[sweep.order[j]] ?? 0;
|
|
297
|
+
}
|
|
298
|
+
weights.push(weight);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return BigInt(weights[slotCount - 1]) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
221
302
|
}
|
|
222
303
|
export function isFullValidatorSetCovered(startSlot, endSlot) {
|
|
223
304
|
const startFullEpoch = computeEpochAtSlot(startSlot + (SLOTS_PER_EPOCH - 1));
|
|
@@ -225,8 +306,8 @@ export function isFullValidatorSetCovered(startSlot, endSlot) {
|
|
|
225
306
|
return startFullEpoch < endFullEpoch;
|
|
226
307
|
}
|
|
227
308
|
export function computeProposerScore(ctx, balanceSource, cache) {
|
|
228
|
-
const
|
|
229
|
-
const committeeWeight =
|
|
309
|
+
const unslashedTotal = BigInt(getActiveBalances(balanceSource, cache).unslashedTotal) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
310
|
+
const committeeWeight = unslashedTotal / BigInt(SLOTS_PER_EPOCH);
|
|
230
311
|
return (committeeWeight * BigInt(ctx.config.PROPOSER_SCORE_BOOST)) / 100n;
|
|
231
312
|
}
|
|
232
313
|
/**
|
|
@@ -266,12 +347,12 @@ export function getAttestationScore(ctx, cache, balanceSource, blockRoot, source
|
|
|
266
347
|
}
|
|
267
348
|
return score;
|
|
268
349
|
}
|
|
269
|
-
export function getNodeSupportBetweenSlots(ctx, store, cache, balanceSource, nodeRoot,
|
|
350
|
+
export function getNodeSupportBetweenSlots(ctx, store, cache, balanceSource, nodeRoot, nodePayloadStatuses, startSlot, endSlot) {
|
|
270
351
|
if (startSlot > endSlot)
|
|
271
352
|
return 0;
|
|
272
353
|
const balances = getZeroInactiveBalances(balanceSource);
|
|
273
354
|
const participants = getSlotRangeParticipants(ctx, store, cache, startSlot, endSlot);
|
|
274
|
-
if (participants.
|
|
355
|
+
if (participants.length === 0)
|
|
275
356
|
return 0;
|
|
276
357
|
const equivocating = ctx.getEquivocatingIndices();
|
|
277
358
|
let score = 0;
|
|
@@ -282,7 +363,7 @@ export function getNodeSupportBetweenSlots(ctx, store, cache, balanceSource, nod
|
|
|
282
363
|
if (equivocating.has(i))
|
|
283
364
|
continue;
|
|
284
365
|
const latestMessage = ctx.getLatestMessage(i);
|
|
285
|
-
if (latestMessage?.root === nodeRoot && latestMessage.payloadStatus
|
|
366
|
+
if (latestMessage?.root === nodeRoot && nodePayloadStatuses.includes(latestMessage.payloadStatus)) {
|
|
286
367
|
score += weight;
|
|
287
368
|
}
|
|
288
369
|
}
|
|
@@ -302,7 +383,7 @@ export function getEquivocationScore(ctx, store, cache, balanceSource, startSlot
|
|
|
302
383
|
const state = balanceSource.state;
|
|
303
384
|
const stateEpoch = state ? computeEpochAtSlot(state.slot) : null;
|
|
304
385
|
const participants = getSlotRangeParticipants(ctx, store, cache, startSlot, endSlot);
|
|
305
|
-
if (participants.
|
|
386
|
+
if (participants.length === 0)
|
|
306
387
|
return 0;
|
|
307
388
|
let score = 0;
|
|
308
389
|
for (const i of participants) {
|
|
@@ -320,7 +401,7 @@ export function getEquivocationScore(ctx, store, cache, balanceSource, startSlot
|
|
|
320
401
|
return score;
|
|
321
402
|
}
|
|
322
403
|
export function computeAdversarialWeight(ctx, store, cache, balanceSource, startSlot, endSlot) {
|
|
323
|
-
const maximumWeight =
|
|
404
|
+
const maximumWeight = computeCommitteeWeightBetweenSlots(ctx, store, cache, balanceSource, startSlot, endSlot);
|
|
324
405
|
const maxAdversarialWeight = (maximumWeight / 100n) * BigInt(ctx.config.CONFIRMATION_BYZANTINE_THRESHOLD);
|
|
325
406
|
const equivocationScore = BigInt(getEquivocationScore(ctx, store, cache, balanceSource, startSlot, endSlot)) *
|
|
326
407
|
EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
@@ -354,12 +435,13 @@ export function computeEmptySlotSupportDiscount(ctx, store, cache, balanceSource
|
|
|
354
435
|
if (parentBlock.slot + 1 === block.slot) {
|
|
355
436
|
return 0n;
|
|
356
437
|
}
|
|
357
|
-
// Post-Gloas the parent block has PENDING, EMPTY and FULL nodes.
|
|
358
|
-
// block
|
|
438
|
+
// Post-Gloas the parent block has PENDING, EMPTY and FULL nodes. Support for PENDING(P) and for the
|
|
439
|
+
// payload node this block extends is discounted. Support for the other payload node counts against
|
|
440
|
+
// this block. `parentBlock` is the default variant, PENDING post-Gloas and the only node pre-Gloas.
|
|
359
441
|
const parentNodePayloadStatus = ctx.getParentNodePayloadStatus(blockRoot);
|
|
360
442
|
if (parentNodePayloadStatus === null)
|
|
361
443
|
return 0n;
|
|
362
|
-
const parentSupportInEmptySlots = BigInt(getNodeSupportBetweenSlots(ctx, store, cache, balanceSource, block.parentRoot, parentNodePayloadStatus, (parentBlock.slot + 1), (block.slot - 1))) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
444
|
+
const parentSupportInEmptySlots = BigInt(getNodeSupportBetweenSlots(ctx, store, cache, balanceSource, block.parentRoot, [parentBlock.payloadStatus, parentNodePayloadStatus], (parentBlock.slot + 1), (block.slot - 1))) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
363
445
|
const adversarialWeight = computeAdversarialWeight(ctx, store, cache, balanceSource, (parentBlock.slot + 1), (block.slot - 1));
|
|
364
446
|
return parentSupportInEmptySlots > adversarialWeight ? parentSupportInEmptySlots - adversarialWeight : 0n;
|
|
365
447
|
}
|
|
@@ -377,14 +459,15 @@ export function computeSafetyThreshold(ctx, store, cache, balanceSource, blockRo
|
|
|
377
459
|
// Build the threshold from the same terms used in the paper/spec:
|
|
378
460
|
// max possible committee support, proposer boost, empty-slot discount, and adversarial budget.
|
|
379
461
|
const proposerScore = computeProposerScore(ctx, balanceSource, cache);
|
|
380
|
-
const maximumSupport =
|
|
462
|
+
const maximumSupport = computeCommitteeWeightBetweenSlots(ctx, store, cache, balanceSource, (parentBlock.slot + 1), (currentSlot - 1));
|
|
381
463
|
const supportDiscount = computeEmptySlotSupportDiscount(ctx, store, cache, balanceSource, blockRoot);
|
|
382
464
|
const adversarialWeight = getAdversarialWeight(ctx, store, cache, balanceSource, blockRoot);
|
|
383
|
-
//
|
|
384
|
-
//
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
465
|
+
// The discounted votes come from committees within the maximum support range and are weighed with
|
|
466
|
+
// the same balances, so exceeding it means the computation is wrong rather than an underflow to guard.
|
|
467
|
+
if (supportDiscount > maximumSupport) {
|
|
468
|
+
throw new Error(`Fast confirmation support discount ${supportDiscount} exceeds maximum support ${maximumSupport}`);
|
|
469
|
+
}
|
|
470
|
+
const threshold = (maximumSupport + proposerScore + 2n * adversarialWeight - supportDiscount) / 2n;
|
|
388
471
|
return { threshold, proposerScore, maximumSupport, supportDiscount, adversarialWeight };
|
|
389
472
|
}
|
|
390
473
|
export function isOneConfirmed(ctx, store, cache, balanceSource, blockRoot, sourceKey, logger) {
|
|
@@ -481,7 +564,7 @@ export function computeHonestFfgSupportForCurrentTarget(ctx, store, cache) {
|
|
|
481
564
|
const targetBalanceSource = { state: targetState, balances: targetState.effectiveBalanceIncrements };
|
|
482
565
|
const totalActiveBalance = BigInt(getTotalActiveBalance(targetBalanceSource, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
483
566
|
const ffgSupport = BigInt(getCurrentTargetScore(ctx, store, cache)) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
|
|
484
|
-
const tillNowFFGWeight =
|
|
567
|
+
const tillNowFFGWeight = computeCommitteeWeightBetweenSlots(ctx, store, cache, targetBalanceSource, computeStartSlotAtEpoch(currentEpoch), (currentSlot - 1));
|
|
485
568
|
const adversarialWeight = computeAdversarialWeight(ctx, store, cache, { state: targetState, balances: targetState.effectiveBalanceIncrements }, computeStartSlotAtEpoch(currentEpoch), (currentSlot - 1));
|
|
486
569
|
return computeHonestFfgSupport(totalActiveBalance, ffgSupport, tillNowFFGWeight, adversarialWeight, ctx.config.CONFIRMATION_BYZANTINE_THRESHOLD);
|
|
487
570
|
}
|