@lodestar/fork-choice 2.1.0-dev.c63474c8f3 → 2.1.0-dev.d00daf7fb4
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/errors.d.ts +11 -1
- package/lib/forkChoice/errors.d.ts.map +1 -1
- package/lib/forkChoice/errors.js +2 -0
- package/lib/forkChoice/errors.js.map +1 -1
- package/lib/forkChoice/forkChoice.d.ts +9 -11
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +36 -50
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +3 -1
- package/lib/forkChoice/interface.d.ts.map +1 -1
- package/lib/forkChoice/interface.js +1 -0
- package/lib/forkChoice/interface.js.map +1 -1
- package/lib/forkChoice/nativeForkChoice.d.ts +244 -0
- package/lib/forkChoice/nativeForkChoice.d.ts.map +1 -0
- package/lib/forkChoice/nativeForkChoice.js +1657 -0
- package/lib/forkChoice/nativeForkChoice.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/protoArray/protoArray.d.ts +2 -1
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +22 -10
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +9 -8
- package/src/forkChoice/errors.ts +5 -1
- package/src/forkChoice/forkChoice.ts +40 -53
- package/src/forkChoice/interface.ts +3 -1
- package/src/forkChoice/nativeForkChoice.ts +2000 -0
- package/src/index.ts +1 -0
- package/src/protoArray/protoArray.ts +27 -10
package/src/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ export {
|
|
|
28
28
|
NotReorgedReason,
|
|
29
29
|
type PtcQuorumEvent,
|
|
30
30
|
} from "./forkChoice/interface.js";
|
|
31
|
+
export {NativeForkChoice, type NativeForkChoiceAnchor} from "./forkChoice/nativeForkChoice.js";
|
|
31
32
|
export * from "./forkChoice/safeBlocks.js";
|
|
32
33
|
export {
|
|
33
34
|
type CheckpointWithHex,
|
|
@@ -1393,7 +1393,8 @@ export class ProtoArray {
|
|
|
1393
1393
|
*
|
|
1394
1394
|
* Returns the ProtoNode representing the head.
|
|
1395
1395
|
* For pre-Gloas forks, only FULL variants exist (payload embedded).
|
|
1396
|
-
* For Gloas,
|
|
1396
|
+
* For Gloas, once applyScoreChanges has refreshed the best-descendant links, returns an EMPTY or FULL variant,
|
|
1397
|
+
* or the justified EMPTY node if no descendant is viable.
|
|
1397
1398
|
*/
|
|
1398
1399
|
findHead(justifiedRoot: RootHex, currentSlot: Slot): ProtoNode {
|
|
1399
1400
|
// Get canonical node: FULL for pre-Gloas, PENDING for Gloas
|
|
@@ -1430,6 +1431,22 @@ export class ProtoArray {
|
|
|
1430
1431
|
});
|
|
1431
1432
|
}
|
|
1432
1433
|
|
|
1434
|
+
// The best descendant can still be set if no child is viable, so check its viability too
|
|
1435
|
+
const hasViableDescendant =
|
|
1436
|
+
bestDescendantIndex !== justifiedIndex && this.nodeIsViableForHead(bestNode, currentSlot);
|
|
1437
|
+
|
|
1438
|
+
// Spec get_head returns the justified EMPTY node if no node is viable, never a PENDING node
|
|
1439
|
+
if (justifiedNode.payloadStatus === PayloadStatus.PENDING && !hasViableDescendant) {
|
|
1440
|
+
const emptyNode = this.getNode(justifiedRoot, PayloadStatus.EMPTY);
|
|
1441
|
+
if (emptyNode === undefined) {
|
|
1442
|
+
throw new ProtoArrayError({
|
|
1443
|
+
code: ProtoArrayErrorCode.JUSTIFIED_NODE_UNKNOWN,
|
|
1444
|
+
root: justifiedRoot,
|
|
1445
|
+
});
|
|
1446
|
+
}
|
|
1447
|
+
return emptyNode;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1433
1450
|
/**
|
|
1434
1451
|
* Perform a sanity check that the node is indeed valid to be the head
|
|
1435
1452
|
* The justified node is always considered viable for head per spec:
|
|
@@ -1437,7 +1454,7 @@ export class ProtoArray {
|
|
|
1437
1454
|
* blocks = get_filtered_block_tree(store)
|
|
1438
1455
|
* head = store.justified_checkpoint.root
|
|
1439
1456
|
*/
|
|
1440
|
-
if (bestDescendantIndex !== justifiedIndex && !
|
|
1457
|
+
if (bestDescendantIndex !== justifiedIndex && !hasViableDescendant) {
|
|
1441
1458
|
throw new ProtoArrayError({
|
|
1442
1459
|
code: ProtoArrayErrorCode.INVALID_BEST_NODE,
|
|
1443
1460
|
startRoot: justifiedRoot,
|
|
@@ -1783,13 +1800,9 @@ export class ProtoArray {
|
|
|
1783
1800
|
continue;
|
|
1784
1801
|
}
|
|
1785
1802
|
if (this.justifiedEpoch !== GENESIS_EPOCH) {
|
|
1786
|
-
// Same-root short-circuit: every payload-status variant of the justified block itself is
|
|
1787
|
-
// in the filtered tree, but `isDescendant` from the default (PENDING) variant does not
|
|
1788
|
-
// reach the sibling EMPTY/FULL variants of the same root.
|
|
1789
1803
|
const descendsFromJustified =
|
|
1790
|
-
|
|
1791
|
-
(justifiedVariant
|
|
1792
|
-
this.isDescendant(this.justifiedRoot, justifiedVariant, node.blockRoot, node.payloadStatus));
|
|
1804
|
+
justifiedVariant !== undefined &&
|
|
1805
|
+
this.isDescendant(this.justifiedRoot, justifiedVariant, node.blockRoot, node.payloadStatus);
|
|
1793
1806
|
if (!descendsFromJustified) {
|
|
1794
1807
|
continue;
|
|
1795
1808
|
}
|
|
@@ -2268,8 +2281,12 @@ export class ProtoArray {
|
|
|
2268
2281
|
return false;
|
|
2269
2282
|
}
|
|
2270
2283
|
|
|
2271
|
-
if (ancestorRoot === descendantRoot
|
|
2272
|
-
|
|
2284
|
+
if (ancestorRoot === descendantRoot) {
|
|
2285
|
+
// The ancestor walk below starts at the parent block, so variants of the same block are compared here
|
|
2286
|
+
return (
|
|
2287
|
+
this.getNode(descendantRoot, descendantPayloadStatus) !== undefined &&
|
|
2288
|
+
(ancestorPayloadStatus === descendantPayloadStatus || ancestorPayloadStatus === PayloadStatus.PENDING)
|
|
2289
|
+
);
|
|
2273
2290
|
}
|
|
2274
2291
|
|
|
2275
2292
|
for (const node of this.iterateAncestorNodes(descendantRoot, descendantPayloadStatus)) {
|