@lodestar/fork-choice 1.45.0-dev.f535421f29 → 1.45.0-rc.0

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.
Files changed (33) hide show
  1. package/lib/forkChoice/fastConfirmation/data.d.ts.map +1 -1
  2. package/lib/forkChoice/fastConfirmation/data.js +1 -0
  3. package/lib/forkChoice/fastConfirmation/data.js.map +1 -1
  4. package/lib/forkChoice/fastConfirmation/types.d.ts +3 -0
  5. package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -1
  6. package/lib/forkChoice/fastConfirmation/types.js.map +1 -1
  7. package/lib/forkChoice/fastConfirmation/utils.d.ts +3 -3
  8. package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -1
  9. package/lib/forkChoice/fastConfirmation/utils.js +27 -19
  10. package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
  11. package/lib/forkChoice/forkChoice.d.ts +11 -7
  12. package/lib/forkChoice/forkChoice.d.ts.map +1 -1
  13. package/lib/forkChoice/forkChoice.js +20 -19
  14. package/lib/forkChoice/forkChoice.js.map +1 -1
  15. package/lib/forkChoice/interface.d.ts +11 -3
  16. package/lib/forkChoice/interface.d.ts.map +1 -1
  17. package/lib/forkChoice/interface.js +1 -1
  18. package/lib/forkChoice/interface.js.map +1 -1
  19. package/lib/protoArray/computeDeltas.d.ts.map +1 -1
  20. package/lib/protoArray/computeDeltas.js +19 -15
  21. package/lib/protoArray/computeDeltas.js.map +1 -1
  22. package/lib/protoArray/protoArray.d.ts +13 -0
  23. package/lib/protoArray/protoArray.d.ts.map +1 -1
  24. package/lib/protoArray/protoArray.js +40 -4
  25. package/lib/protoArray/protoArray.js.map +1 -1
  26. package/package.json +8 -8
  27. package/src/forkChoice/fastConfirmation/data.ts +1 -0
  28. package/src/forkChoice/fastConfirmation/types.ts +4 -0
  29. package/src/forkChoice/fastConfirmation/utils.ts +39 -16
  30. package/src/forkChoice/forkChoice.ts +21 -19
  31. package/src/forkChoice/interface.ts +8 -13
  32. package/src/protoArray/computeDeltas.ts +21 -17
  33. package/src/protoArray/protoArray.ts +43 -4
@@ -672,6 +672,35 @@ export class ProtoArray {
672
672
  this.maybeUpdateBestChildAndDescendant(pendingIndex, fullIndex, currentSlot, proposerBoostRoot);
673
673
  }
674
674
 
675
+ /**
676
+ * Count gloas blocks with fromSlot <= slot <= toSlot and how many of them have a revealed
677
+ * payload (FULL variant exists). Used by the builder circuit breaker.
678
+ */
679
+ getPayloadRevealCounts(fromSlot: Slot, toSlot: Slot): {blocksPresent: number; payloadsRevealed: number} {
680
+ let blocksPresent = 0;
681
+ let payloadsRevealed = 0;
682
+ // Iterate backward as recent blocks are at the end of the nodes array. Only break on block
683
+ // nodes below the window since FULL variants are appended late when the envelope is imported
684
+ for (let i = this.nodes.length - 1; i >= 0; i--) {
685
+ const node = this.nodes[i];
686
+ if (node.slot < fromSlot) {
687
+ if (isGloasBlock(node) && node.payloadStatus === PayloadStatus.FULL) {
688
+ continue;
689
+ }
690
+ break;
691
+ }
692
+ // Count each gloas block once via its PENDING variant, pre-gloas nodes are FULL only
693
+ if (node.slot > toSlot || node.payloadStatus !== PayloadStatus.PENDING) {
694
+ continue;
695
+ }
696
+ blocksPresent++;
697
+ if (this.hasPayload(node.blockRoot)) {
698
+ payloadsRevealed++;
699
+ }
700
+ }
701
+ return {blocksPresent, payloadsRevealed};
702
+ }
703
+
675
704
  /**
676
705
  * Update PTC votes for multiple validators attesting to a block
677
706
  * Spec: gloas/fork-choice.md#new-notify_ptc_messages
@@ -1941,6 +1970,11 @@ export class ProtoArray {
1941
1970
  * Returns `true` if the `descendantRoot` has an ancestor with `ancestorRoot`.
1942
1971
  * Always returns `false` if either input roots are unknown.
1943
1972
  * Still returns `true` if `ancestorRoot` === `descendantRoot` and payload statuses match.
1973
+ *
1974
+ * Gloas payload-status matching: a `PENDING` ancestor matches any payload variant
1975
+ * (PENDING/EMPTY/FULL) of the same block, so this can also return `true` for the same
1976
+ * root when statuses differ (e.g. ancestor `PENDING`, descendant `EMPTY`/`FULL`).
1977
+ * `EMPTY` and `FULL` are mutually exclusive siblings and never match each other.
1944
1978
  */
1945
1979
  isDescendant(
1946
1980
  ancestorRoot: RootHex,
@@ -1958,11 +1992,16 @@ export class ProtoArray {
1958
1992
  }
1959
1993
 
1960
1994
  for (const node of this.iterateAncestorNodes(descendantRoot, descendantPayloadStatus)) {
1961
- if (node.slot < ancestorNode.slot) {
1962
- return false;
1995
+ if (node.blockRoot === ancestorNode.blockRoot) {
1996
+ // Gloas is_ancestor: a PENDING ancestor matches any payload variant of the same block.
1997
+ return (
1998
+ node.payloadStatus === ancestorNode.payloadStatus || ancestorNode.payloadStatus === PayloadStatus.PENDING
1999
+ );
1963
2000
  }
1964
- if (node.blockRoot === ancestorNode.blockRoot && node.payloadStatus === ancestorNode.payloadStatus) {
1965
- return true;
2001
+ // Ancestors are iterated in decreasing slot, so once we reach the ancestor's slot
2002
+ // without a root match it cannot be in this chain.
2003
+ if (node.slot <= ancestorNode.slot) {
2004
+ return false;
1966
2005
  }
1967
2006
  }
1968
2007
  return false;