@lodestar/fork-choice 1.44.0-dev.6ef8199cfa → 1.44.0-dev.79c77e2e57
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/forkChoice.d.ts +16 -4
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +58 -30
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +19 -8
- package/lib/forkChoice/interface.d.ts.map +1 -1
- package/lib/forkChoice/interface.js.map +1 -1
- package/lib/protoArray/interface.d.ts +1 -0
- package/lib/protoArray/interface.d.ts.map +1 -1
- package/lib/protoArray/protoArray.d.ts +68 -21
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +172 -39
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +7 -7
- package/src/forkChoice/forkChoice.ts +78 -31
- package/src/forkChoice/interface.ts +36 -7
- package/src/protoArray/interface.ts +8 -0
- package/src/protoArray/protoArray.ts +186 -41
|
@@ -3,6 +3,11 @@ import { DataAvailabilityStatus } from "@lodestar/state-transition";
|
|
|
3
3
|
import { Epoch, RootHex, Slot } from "@lodestar/types";
|
|
4
4
|
import { LVHExecError } from "./errors.js";
|
|
5
5
|
import { LVHExecResponse, PayloadExecutionStatus, PayloadStatus, ProtoBlock, ProtoNode } from "./interface.js";
|
|
6
|
+
/**
|
|
7
|
+
* popcount(attended AND NOT yes) — explicit False-vote count.
|
|
8
|
+
* Excludes PTC members who didn't attest (the None state).
|
|
9
|
+
*/
|
|
10
|
+
export declare function countNoVotes(attended: BitArray, yes: BitArray): number;
|
|
6
11
|
export declare const DEFAULT_PRUNE_THRESHOLD = 0;
|
|
7
12
|
type ProposerBoost = {
|
|
8
13
|
root: RootHex;
|
|
@@ -40,12 +45,25 @@ export declare class ProtoArray {
|
|
|
40
45
|
/**
|
|
41
46
|
* PTC (Payload Timeliness Committee) votes per block as bitvectors
|
|
42
47
|
* Maps block root to BitArray of PTC_SIZE bits (512 mainnet, 2 minimal)
|
|
43
|
-
* Spec: gloas/fork-choice.md#modified-store (
|
|
48
|
+
* Spec: gloas/fork-choice.md#modified-store (payload_timeliness_vote)
|
|
44
49
|
*
|
|
45
|
-
* Bit i
|
|
46
|
-
|
|
50
|
+
* Bit i = PTC member i voted payloadPresent=true (timeliness YES vote)
|
|
51
|
+
*/
|
|
52
|
+
private payloadTimelinessVotes;
|
|
53
|
+
/**
|
|
54
|
+
* Blob data availability votes per block.
|
|
55
|
+
* Spec: gloas/fork-choice.md#modified-store (payload_data_availability_vote)
|
|
56
|
+
*
|
|
57
|
+
* Bit i = PTC member i voted blobDataAvailable=true (DA YES vote)
|
|
58
|
+
*/
|
|
59
|
+
private payloadDataAvailabilityVotes;
|
|
60
|
+
/**
|
|
61
|
+
* Tracks which PTC members have attested at all (any payload_status).
|
|
62
|
+
* Without this, we cannot tell "didn't vote" (None) from "voted false" —
|
|
63
|
+
* a distinction required by payload_timeliness/payload_data_availability
|
|
64
|
+
* when called with the negative parameter value.
|
|
47
65
|
*/
|
|
48
|
-
private
|
|
66
|
+
private ptcAttested;
|
|
49
67
|
constructor({ pruneThreshold, justifiedEpoch, justifiedRoot, finalizedEpoch, finalizedRoot }: {
|
|
50
68
|
pruneThreshold: number;
|
|
51
69
|
justifiedEpoch: Epoch;
|
|
@@ -150,29 +168,58 @@ export declare class ProtoArray {
|
|
|
150
168
|
*
|
|
151
169
|
* Spec: gloas/fork-choice.md (on_execution_payload event)
|
|
152
170
|
*/
|
|
153
|
-
onExecutionPayload(blockRoot: RootHex, currentSlot: Slot, executionPayloadBlockHash: RootHex, executionPayloadNumber: number, proposerBoostRoot: RootHex | null, executionStatus: PayloadExecutionStatus, dataAvailabilityStatus: DataAvailabilityStatus): void;
|
|
171
|
+
onExecutionPayload(blockRoot: RootHex, currentSlot: Slot, executionPayloadBlockHash: RootHex, executionPayloadNumber: number, executionPayloadGasLimit: number, proposerBoostRoot: RootHex | null, executionStatus: PayloadExecutionStatus, dataAvailabilityStatus: DataAvailabilityStatus): void;
|
|
154
172
|
/**
|
|
155
173
|
* Update PTC votes for multiple validators attesting to a block
|
|
156
|
-
* Spec: gloas/fork-choice.md#new-
|
|
157
|
-
*
|
|
158
|
-
* @param blockRoot - The beacon block root being attested
|
|
159
|
-
* @param ptcIndices - Array of PTC committee indices that voted (0..PTC_SIZE-1)
|
|
160
|
-
* @param payloadPresent - Whether the validators attest the payload is present
|
|
174
|
+
* Spec: gloas/fork-choice.md#new-notify_ptc_messages
|
|
161
175
|
*/
|
|
162
|
-
notifyPtcMessages(blockRoot: RootHex, ptcIndices: number[], payloadPresent: boolean): void;
|
|
176
|
+
notifyPtcMessages(blockRoot: RootHex, slot: Slot, ptcIndices: number[], payloadPresent: boolean, blobDataAvailable: boolean): void;
|
|
163
177
|
getPTCVotes(blockRootHex: RootHex): BitArray | null;
|
|
164
178
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
* Raw PTC vote tallies for a block root, for the debug fork choice endpoint.
|
|
180
|
+
* Returns `null` for pre-Gloas (or pruned) roots, which have no vote maps.
|
|
181
|
+
*/
|
|
182
|
+
getPTCVoteCounts(blockRootHex: RootHex): {
|
|
183
|
+
attesterCount: number;
|
|
184
|
+
payloadPresentCount: number;
|
|
185
|
+
dataAvailableCount: number;
|
|
186
|
+
} | null;
|
|
187
|
+
getPreviousProposerBoostRoot(): RootHex;
|
|
188
|
+
/**
|
|
189
|
+
* Timeliness votes per PTC position, `null` where the member has not attested.
|
|
190
|
+
* Returns `null` if the block is unknown or not a Gloas block.
|
|
191
|
+
*/
|
|
192
|
+
getPayloadTimelinessVotes(blockRootHex: RootHex): (boolean | null)[] | null;
|
|
193
|
+
/**
|
|
194
|
+
* Data-availability votes per PTC position, `null` where the member has not attested.
|
|
195
|
+
* Returns `null` if the block is unknown or not a Gloas block.
|
|
196
|
+
*/
|
|
197
|
+
getPayloadDataAvailabilityVotes(blockRootHex: RootHex): (boolean | null)[] | null;
|
|
198
|
+
private toAttendanceAwareVotes;
|
|
199
|
+
/**
|
|
200
|
+
* Spec: payload_timeliness(store, root, timely=True)
|
|
174
201
|
*/
|
|
175
202
|
isPayloadTimely(blockRoot: RootHex): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Spec: payload_timeliness(store, root, timely=False)
|
|
205
|
+
*/
|
|
206
|
+
isPayloadNotTimely(blockRoot: RootHex): boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Spec: payload_data_availability(store, root, available=True)
|
|
209
|
+
*/
|
|
210
|
+
isPayloadDataAvailable(blockRoot: RootHex): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Spec: payload_data_availability(store, root, available=False)
|
|
213
|
+
*/
|
|
214
|
+
isPayloadDataNotAvailable(blockRoot: RootHex): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Spec: should_build_on_full(store, head)
|
|
217
|
+
*
|
|
218
|
+
* The proposer is forced to build on the EMPTY variant (effectively reorging)
|
|
219
|
+
* when the PTC majority voted that the blob data is not available or that the
|
|
220
|
+
* payload was not timely.
|
|
221
|
+
*/
|
|
222
|
+
shouldBuildOnFull(head: ProtoBlock, slot: Slot): boolean;
|
|
176
223
|
/**
|
|
177
224
|
* Check if parent node is FULL
|
|
178
225
|
* Spec: gloas/fork-choice.md#new-is_parent_node_full
|
|
@@ -185,7 +232,7 @@ export declare class ProtoArray {
|
|
|
185
232
|
* Spec: gloas/fork-choice.md#new-should_extend_payload
|
|
186
233
|
*
|
|
187
234
|
* Returns true if payload is verified (FULL variant exists) AND:
|
|
188
|
-
* 1. Payload is timely, OR
|
|
235
|
+
* 1. Payload is timely AND data is available, OR
|
|
189
236
|
* 2. No proposer boost root (empty/zero hash), OR
|
|
190
237
|
* 3. Proposer boost root's parent is not this block, OR
|
|
191
238
|
* 4. Proposer boost root extends FULL parent
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protoArray.d.ts","sourceRoot":"","sources":["../../src/protoArray/protoArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAC,sBAAsB,EAA8C,MAAM,4BAA4B,CAAC;AAC/G,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAC,YAAY,EAAyD,MAAM,aAAa,CAAC;AACjG,OAAO,EAGL,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,UAAU,EACV,SAAS,EAEV,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"protoArray.d.ts","sourceRoot":"","sources":["../../src/protoArray/protoArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAC,sBAAsB,EAA8C,MAAM,4BAA4B,CAAC;AAC/G,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAC,YAAY,EAAyD,MAAM,aAAa,CAAC;AACjG,OAAO,EAGL,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,UAAU,EACV,SAAS,EAEV,MAAM,gBAAgB,CAAC;AAaxB;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAYtE;AAED,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,KAAK,aAAa,GAAG;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;AAIpD,yEAAyE;AACzE,KAAK,oBAAoB,GAAG,MAAM,CAAC;AACnC;;;;GAIG;AACH,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,MA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GAAG,IAAI,CAmCtE;IAED,MAAM,IAAI,MAAM,CAEf;IAED,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,eAAe;CAcxB"}
|
|
@@ -10,6 +10,28 @@ import { ExecutionStatus, HEX_ZERO_HASH, PayloadStatus, isGloasBlock, } from "./
|
|
|
10
10
|
* Spec: gloas/fork-choice.md (PAYLOAD_TIMELY_THRESHOLD = PTC_SIZE // 2)
|
|
11
11
|
*/
|
|
12
12
|
const PAYLOAD_TIMELY_THRESHOLD = Math.floor(PTC_SIZE / 2);
|
|
13
|
+
/**
|
|
14
|
+
* Threshold for blob data availability via PTC vote
|
|
15
|
+
* Spec: gloas/fork-choice.md (DATA_AVAILABILITY_TIMELY_THRESHOLD = PTC_SIZE // 2)
|
|
16
|
+
*/
|
|
17
|
+
const DATA_AVAILABILITY_TIMELY_THRESHOLD = Math.floor(PTC_SIZE / 2);
|
|
18
|
+
/**
|
|
19
|
+
* popcount(attended AND NOT yes) — explicit False-vote count.
|
|
20
|
+
* Excludes PTC members who didn't attest (the None state).
|
|
21
|
+
*/
|
|
22
|
+
export function countNoVotes(attended, yes) {
|
|
23
|
+
const a = attended.uint8Array;
|
|
24
|
+
const y = yes.uint8Array;
|
|
25
|
+
let count = 0;
|
|
26
|
+
for (let i = 0; i < a.length; i++) {
|
|
27
|
+
let byte = a[i] & ~y[i] & 0xff;
|
|
28
|
+
while (byte) {
|
|
29
|
+
byte &= byte - 1;
|
|
30
|
+
count++;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return count;
|
|
34
|
+
}
|
|
13
35
|
export const DEFAULT_PRUNE_THRESHOLD = 0;
|
|
14
36
|
const ZERO_HASH_HEX = toRootHex(Buffer.alloc(32, 0));
|
|
15
37
|
export class ProtoArray {
|
|
@@ -37,12 +59,25 @@ export class ProtoArray {
|
|
|
37
59
|
/**
|
|
38
60
|
* PTC (Payload Timeliness Committee) votes per block as bitvectors
|
|
39
61
|
* Maps block root to BitArray of PTC_SIZE bits (512 mainnet, 2 minimal)
|
|
40
|
-
* Spec: gloas/fork-choice.md#modified-store (
|
|
62
|
+
* Spec: gloas/fork-choice.md#modified-store (payload_timeliness_vote)
|
|
63
|
+
*
|
|
64
|
+
* Bit i = PTC member i voted payloadPresent=true (timeliness YES vote)
|
|
65
|
+
*/
|
|
66
|
+
payloadTimelinessVotes = new Map();
|
|
67
|
+
/**
|
|
68
|
+
* Blob data availability votes per block.
|
|
69
|
+
* Spec: gloas/fork-choice.md#modified-store (payload_data_availability_vote)
|
|
41
70
|
*
|
|
42
|
-
* Bit i
|
|
43
|
-
|
|
71
|
+
* Bit i = PTC member i voted blobDataAvailable=true (DA YES vote)
|
|
72
|
+
*/
|
|
73
|
+
payloadDataAvailabilityVotes = new Map();
|
|
74
|
+
/**
|
|
75
|
+
* Tracks which PTC members have attested at all (any payload_status).
|
|
76
|
+
* Without this, we cannot tell "didn't vote" (None) from "voted false" —
|
|
77
|
+
* a distinction required by payload_timeliness/payload_data_availability
|
|
78
|
+
* when called with the negative parameter value.
|
|
44
79
|
*/
|
|
45
|
-
|
|
80
|
+
ptcAttested = new Map();
|
|
46
81
|
constructor({ pruneThreshold, justifiedEpoch, justifiedRoot, finalizedEpoch, finalizedRoot, }) {
|
|
47
82
|
this.pruneThreshold = pruneThreshold;
|
|
48
83
|
this.justifiedEpoch = justifiedEpoch;
|
|
@@ -401,9 +436,11 @@ export class ProtoArray {
|
|
|
401
436
|
}
|
|
402
437
|
// Update bestChild for PENDING → EMPTY edge
|
|
403
438
|
this.maybeUpdateBestChildAndDescendant(pendingIndex, emptyIndex, currentSlot, proposerBoostRoot);
|
|
404
|
-
// Initialize PTC
|
|
405
|
-
// Spec: gloas/fork-choice.md#modified-on_block
|
|
406
|
-
this.
|
|
439
|
+
// Initialize PTC vote bitvectors for this block.
|
|
440
|
+
// Spec: gloas/fork-choice.md#modified-on_block
|
|
441
|
+
this.payloadTimelinessVotes.set(block.blockRoot, BitArray.fromBitLen(PTC_SIZE));
|
|
442
|
+
this.ptcAttested.set(block.blockRoot, BitArray.fromBitLen(PTC_SIZE));
|
|
443
|
+
this.payloadDataAvailabilityVotes.set(block.blockRoot, BitArray.fromBitLen(PTC_SIZE));
|
|
407
444
|
}
|
|
408
445
|
else {
|
|
409
446
|
// Pre-Gloas: Only create FULL node (payload embedded in block)
|
|
@@ -436,7 +473,7 @@ export class ProtoArray {
|
|
|
436
473
|
*
|
|
437
474
|
* Spec: gloas/fork-choice.md (on_execution_payload event)
|
|
438
475
|
*/
|
|
439
|
-
onExecutionPayload(blockRoot, currentSlot, executionPayloadBlockHash, executionPayloadNumber, proposerBoostRoot, executionStatus, dataAvailabilityStatus) {
|
|
476
|
+
onExecutionPayload(blockRoot, currentSlot, executionPayloadBlockHash, executionPayloadNumber, executionPayloadGasLimit, proposerBoostRoot, executionStatus, dataAvailabilityStatus) {
|
|
440
477
|
// First check if block exists
|
|
441
478
|
const variants = this.indices.get(blockRoot);
|
|
442
479
|
if (variants == null) {
|
|
@@ -483,6 +520,7 @@ export class ProtoArray {
|
|
|
483
520
|
executionStatus,
|
|
484
521
|
executionPayloadBlockHash,
|
|
485
522
|
executionPayloadNumber,
|
|
523
|
+
executionPayloadGasLimit,
|
|
486
524
|
dataAvailabilityStatus,
|
|
487
525
|
};
|
|
488
526
|
const fullIndex = this.nodes.length;
|
|
@@ -499,27 +537,33 @@ export class ProtoArray {
|
|
|
499
537
|
}
|
|
500
538
|
/**
|
|
501
539
|
* Update PTC votes for multiple validators attesting to a block
|
|
502
|
-
* Spec: gloas/fork-choice.md#new-
|
|
503
|
-
*
|
|
504
|
-
* @param blockRoot - The beacon block root being attested
|
|
505
|
-
* @param ptcIndices - Array of PTC committee indices that voted (0..PTC_SIZE-1)
|
|
506
|
-
* @param payloadPresent - Whether the validators attest the payload is present
|
|
540
|
+
* Spec: gloas/fork-choice.md#new-notify_ptc_messages
|
|
507
541
|
*/
|
|
508
|
-
notifyPtcMessages(blockRoot, ptcIndices, payloadPresent) {
|
|
509
|
-
const votes = this.
|
|
510
|
-
|
|
542
|
+
notifyPtcMessages(blockRoot, slot, ptcIndices, payloadPresent, blobDataAvailable) {
|
|
543
|
+
const votes = this.payloadTimelinessVotes.get(blockRoot);
|
|
544
|
+
const attended = this.ptcAttested.get(blockRoot);
|
|
545
|
+
const daVotes = this.payloadDataAvailabilityVotes.get(blockRoot);
|
|
546
|
+
if (votes === undefined || attended === undefined || daVotes === undefined) {
|
|
511
547
|
// Block not found or not a Gloas block, ignore
|
|
512
548
|
return;
|
|
513
549
|
}
|
|
550
|
+
// PTC votes can only change the vote for their assigned beacon block, return early otherwise
|
|
551
|
+
const nodeIndex = this.getDefaultNodeIndex(blockRoot);
|
|
552
|
+
const node = nodeIndex !== undefined ? this.getNodeByIndex(nodeIndex) : undefined;
|
|
553
|
+
if (node === undefined || node.slot !== slot) {
|
|
554
|
+
return;
|
|
555
|
+
}
|
|
514
556
|
for (const ptcIndex of ptcIndices) {
|
|
515
557
|
if (ptcIndex < 0 || ptcIndex >= PTC_SIZE) {
|
|
516
558
|
throw new Error(`Invalid PTC index: ${ptcIndex}, must be 0..${PTC_SIZE - 1}`);
|
|
517
559
|
}
|
|
518
560
|
votes.set(ptcIndex, payloadPresent);
|
|
561
|
+
daVotes.set(ptcIndex, blobDataAvailable);
|
|
562
|
+
attended.set(ptcIndex, true);
|
|
519
563
|
}
|
|
520
564
|
}
|
|
521
565
|
getPTCVotes(blockRootHex) {
|
|
522
|
-
const votes = this.
|
|
566
|
+
const votes = this.payloadTimelinessVotes.get(blockRootHex);
|
|
523
567
|
if (votes === undefined) {
|
|
524
568
|
// Block not found or not a Gloas block
|
|
525
569
|
return null;
|
|
@@ -527,29 +571,116 @@ export class ProtoArray {
|
|
|
527
571
|
return votes;
|
|
528
572
|
}
|
|
529
573
|
/**
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
574
|
+
* Raw PTC vote tallies for a block root, for the debug fork choice endpoint.
|
|
575
|
+
* Returns `null` for pre-Gloas (or pruned) roots, which have no vote maps.
|
|
576
|
+
*/
|
|
577
|
+
getPTCVoteCounts(blockRootHex) {
|
|
578
|
+
const attended = this.ptcAttested.get(blockRootHex);
|
|
579
|
+
const timelinessVotes = this.payloadTimelinessVotes.get(blockRootHex);
|
|
580
|
+
const daVotes = this.payloadDataAvailabilityVotes.get(blockRootHex);
|
|
581
|
+
// The three maps share a lifecycle (set together in onBlock, deleted together on prune)
|
|
582
|
+
if (attended === undefined || timelinessVotes === undefined || daVotes === undefined) {
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
return {
|
|
586
|
+
attesterCount: bitCount(attended.uint8Array),
|
|
587
|
+
payloadPresentCount: bitCount(timelinessVotes.uint8Array),
|
|
588
|
+
dataAvailableCount: bitCount(daVotes.uint8Array),
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
getPreviousProposerBoostRoot() {
|
|
592
|
+
return this.previousProposerBoost?.root ?? HEX_ZERO_HASH;
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Timeliness votes per PTC position, `null` where the member has not attested.
|
|
596
|
+
* Returns `null` if the block is unknown or not a Gloas block.
|
|
597
|
+
*/
|
|
598
|
+
getPayloadTimelinessVotes(blockRootHex) {
|
|
599
|
+
return this.toAttendanceAwareVotes(this.payloadTimelinessVotes.get(blockRootHex), blockRootHex);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Data-availability votes per PTC position, `null` where the member has not attested.
|
|
603
|
+
* Returns `null` if the block is unknown or not a Gloas block.
|
|
604
|
+
*/
|
|
605
|
+
getPayloadDataAvailabilityVotes(blockRootHex) {
|
|
606
|
+
return this.toAttendanceAwareVotes(this.payloadDataAvailabilityVotes.get(blockRootHex), blockRootHex);
|
|
607
|
+
}
|
|
608
|
+
toAttendanceAwareVotes(votes, blockRootHex) {
|
|
609
|
+
const attended = this.ptcAttested.get(blockRootHex);
|
|
610
|
+
if (votes === undefined || attended === undefined) {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
return Array.from({ length: PTC_SIZE }, (_, i) => (attended.get(i) ? votes.get(i) : null));
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* Spec: payload_timeliness(store, root, timely=True)
|
|
539
617
|
*/
|
|
540
618
|
isPayloadTimely(blockRoot) {
|
|
541
|
-
const votes = this.
|
|
542
|
-
if (votes === undefined)
|
|
543
|
-
// Block not found or not a Gloas block
|
|
619
|
+
const votes = this.payloadTimelinessVotes.get(blockRoot);
|
|
620
|
+
if (votes === undefined)
|
|
544
621
|
return false;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
622
|
+
if (!this.hasPayload(blockRoot))
|
|
623
|
+
return false;
|
|
624
|
+
return bitCount(votes.uint8Array) > PAYLOAD_TIMELY_THRESHOLD;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Spec: payload_timeliness(store, root, timely=False)
|
|
628
|
+
*/
|
|
629
|
+
isPayloadNotTimely(blockRoot) {
|
|
630
|
+
const votes = this.payloadTimelinessVotes.get(blockRoot);
|
|
631
|
+
const attended = this.ptcAttested.get(blockRoot);
|
|
632
|
+
if (votes === undefined || attended === undefined)
|
|
633
|
+
return false;
|
|
634
|
+
// Spec: not verified locally → returns `not False = True`
|
|
635
|
+
if (!this.hasPayload(blockRoot))
|
|
636
|
+
return true;
|
|
637
|
+
return countNoVotes(attended, votes) > PAYLOAD_TIMELY_THRESHOLD;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Spec: payload_data_availability(store, root, available=True)
|
|
641
|
+
*/
|
|
642
|
+
isPayloadDataAvailable(blockRoot) {
|
|
643
|
+
const daVotes = this.payloadDataAvailabilityVotes.get(blockRoot);
|
|
644
|
+
if (daVotes === undefined)
|
|
645
|
+
return false;
|
|
646
|
+
if (!this.hasPayload(blockRoot))
|
|
647
|
+
return false;
|
|
648
|
+
return bitCount(daVotes.uint8Array) > DATA_AVAILABILITY_TIMELY_THRESHOLD;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Spec: payload_data_availability(store, root, available=False)
|
|
652
|
+
*/
|
|
653
|
+
isPayloadDataNotAvailable(blockRoot) {
|
|
654
|
+
const daVotes = this.payloadDataAvailabilityVotes.get(blockRoot);
|
|
655
|
+
const attended = this.ptcAttested.get(blockRoot);
|
|
656
|
+
if (daVotes === undefined || attended === undefined)
|
|
548
657
|
return false;
|
|
658
|
+
// Spec: not verified locally → returns `not False = True`
|
|
659
|
+
if (!this.hasPayload(blockRoot))
|
|
660
|
+
return true;
|
|
661
|
+
return countNoVotes(attended, daVotes) > DATA_AVAILABILITY_TIMELY_THRESHOLD;
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Spec: should_build_on_full(store, head)
|
|
665
|
+
*
|
|
666
|
+
* The proposer is forced to build on the EMPTY variant (effectively reorging)
|
|
667
|
+
* when the PTC majority voted that the blob data is not available or that the
|
|
668
|
+
* payload was not timely.
|
|
669
|
+
*/
|
|
670
|
+
shouldBuildOnFull(head, slot) {
|
|
671
|
+
if (head.payloadStatus === PayloadStatus.PENDING) {
|
|
672
|
+
throw new Error("shouldBuildOnFull called with PENDING head");
|
|
549
673
|
}
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
674
|
+
if (head.payloadStatus === PayloadStatus.EMPTY)
|
|
675
|
+
return false;
|
|
676
|
+
// The PTC data availability and timeliness views are only consulted for a head from the
|
|
677
|
+
// previous slot. For an earlier head the empty/full variant has already been resolved by
|
|
678
|
+
// weight in getHead.
|
|
679
|
+
if (head.slot + 1 !== slot)
|
|
680
|
+
return true;
|
|
681
|
+
if (this.isPayloadDataNotAvailable(head.blockRoot))
|
|
682
|
+
return false;
|
|
683
|
+
return !this.isPayloadNotTimely(head.blockRoot);
|
|
553
684
|
}
|
|
554
685
|
/**
|
|
555
686
|
* Check if parent node is FULL
|
|
@@ -565,7 +696,7 @@ export class ProtoArray {
|
|
|
565
696
|
* Spec: gloas/fork-choice.md#new-should_extend_payload
|
|
566
697
|
*
|
|
567
698
|
* Returns true if payload is verified (FULL variant exists) AND:
|
|
568
|
-
* 1. Payload is timely, OR
|
|
699
|
+
* 1. Payload is timely AND data is available, OR
|
|
569
700
|
* 2. No proposer boost root (empty/zero hash), OR
|
|
570
701
|
* 3. Proposer boost root's parent is not this block, OR
|
|
571
702
|
* 4. Proposer boost root extends FULL parent
|
|
@@ -577,8 +708,8 @@ export class ProtoArray {
|
|
|
577
708
|
if (!this.hasPayload(blockRoot)) {
|
|
578
709
|
return false;
|
|
579
710
|
}
|
|
580
|
-
// Condition 1: Payload is timely
|
|
581
|
-
if (this.isPayloadTimely(blockRoot)) {
|
|
711
|
+
// Condition 1: Payload is timely AND data is available
|
|
712
|
+
if (this.isPayloadTimely(blockRoot) && this.isPayloadDataAvailable(blockRoot)) {
|
|
582
713
|
return true;
|
|
583
714
|
}
|
|
584
715
|
// Condition 2: No proposer boost root
|
|
@@ -933,7 +1064,9 @@ export class ProtoArray {
|
|
|
933
1064
|
this.indices.delete(root);
|
|
934
1065
|
// Prune PTC votes for this block to prevent memory leak
|
|
935
1066
|
// Spec: gloas/fork-choice.md (implicit - finalized blocks don't need PTC votes)
|
|
936
|
-
this.
|
|
1067
|
+
this.payloadTimelinessVotes.delete(root);
|
|
1068
|
+
this.ptcAttested.delete(root);
|
|
1069
|
+
this.payloadDataAvailabilityVotes.delete(root);
|
|
937
1070
|
}
|
|
938
1071
|
// Store nodes prior to finalization
|
|
939
1072
|
const removed = this.nodes.slice(0, finalizedIndex);
|