@lodestar/fork-choice 2.1.0-dev.a046f269a1 → 2.1.0-dev.a243bacf81
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 +2 -2
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +3 -8
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +1 -0
- 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 +18 -2
- 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 +3 -9
- package/src/forkChoice/interface.ts +1 -0
- package/src/forkChoice/nativeForkChoice.ts +2000 -0
- package/src/index.ts +1 -0
- package/src/protoArray/protoArray.ts +19 -2
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,18 @@ export class ProtoArray {
|
|
|
1430
1431
|
});
|
|
1431
1432
|
}
|
|
1432
1433
|
|
|
1434
|
+
// Spec get_head returns the justified EMPTY node if no node is viable, never a PENDING node
|
|
1435
|
+
if (justifiedNode.payloadStatus === PayloadStatus.PENDING && justifiedNode.bestDescendant === undefined) {
|
|
1436
|
+
const emptyNode = this.getNode(justifiedRoot, PayloadStatus.EMPTY);
|
|
1437
|
+
if (emptyNode === undefined) {
|
|
1438
|
+
throw new ProtoArrayError({
|
|
1439
|
+
code: ProtoArrayErrorCode.JUSTIFIED_NODE_UNKNOWN,
|
|
1440
|
+
root: justifiedRoot,
|
|
1441
|
+
});
|
|
1442
|
+
}
|
|
1443
|
+
return emptyNode;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1433
1446
|
/**
|
|
1434
1447
|
* Perform a sanity check that the node is indeed valid to be the head
|
|
1435
1448
|
* The justified node is always considered viable for head per spec:
|
|
@@ -1655,7 +1668,11 @@ export class ProtoArray {
|
|
|
1655
1668
|
newChildAndDescendant = noChange;
|
|
1656
1669
|
break outer;
|
|
1657
1670
|
}
|
|
1658
|
-
|
|
1671
|
+
if (!childLeadsToViableHead && !bestChildLeadsToViableHead) {
|
|
1672
|
+
newChildAndDescendant = changeToNull;
|
|
1673
|
+
break outer;
|
|
1674
|
+
}
|
|
1675
|
+
// Both nodes lead to viable heads, need to pick winner
|
|
1659
1676
|
|
|
1660
1677
|
// Pre-fulu we pick whichever has higher weight, tie-breaker by root
|
|
1661
1678
|
// Post-fulu we pick whichever has higher weight, then tie-breaker by root, then tie-breaker by `getPayloadStatusTiebreaker`
|