@lodestar/fork-choice 1.47.0-dev.f591cb177e → 1.47.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.
@@ -212,20 +212,12 @@ export declare class ForkChoice implements IForkChoice {
212
212
  };
213
213
  /** Very expensive function, iterates the entire ProtoArray. Called only in debug API */
214
214
  getHeads(): ProtoBlock[];
215
- /**
216
- * weight is in EFFECTIVE_BALANCE_INCREMENTS not gwei.
217
- * For compliance test use only
218
- */
215
+ /** Returns exact Gwei weights for the compliance test. */
219
216
  getViableHeads(): {
220
217
  root: RootHex;
221
218
  payloadStatus: PayloadStatus;
222
- weight: number;
219
+ weight: bigint;
223
220
  }[];
224
- /**
225
- * The cached justified total active balance, in EFFECTIVE_BALANCE_INCREMENT units.
226
- * For compliance test use only
227
- */
228
- getJustifiedTotalActiveBalanceByIncrement(): number;
229
221
  /** This is for the debug API only */
230
222
  getAllNodes(): ProtoNode[];
231
223
  getFinalizedCheckpoint(): CheckpointWithHex;
@@ -469,6 +461,32 @@ export declare class ForkChoice implements IForkChoice {
469
461
  * Child class can overwrite this for testing purpose.
470
462
  */
471
463
  protected isBlockTimely(block: BeaconBlock, blockDelaySec: number): boolean;
464
+ /**
465
+ * Return true if the block arrived before the PTC (payload-timeliness committee) deadline,
466
+ * ie. block_timeliness[PTC_TIMELINESS_INDEX]. should_apply_proposer_boost uses this as the
467
+ * definition of an "early" proposer equivocation: only a sibling seen by the PTC deadline
468
+ * proves the proposer equivocated soon enough that honest nodes could have withheld the boost.
469
+ *
470
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.14/specs/gloas/fork-choice.md#modified-record_block_timeliness
471
+ *
472
+ * Child class can overwrite this for testing purpose.
473
+ */
474
+ protected isBlockPtcTimely(block: BeaconBlock, blockDelaySec: number): boolean;
475
+ /**
476
+ * Determine whether proposer boost should be applied to `proposerBoostRoot`.
477
+ *
478
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.14/specs/gloas/fork-choice.md#new-should_apply_proposer_boost
479
+ *
480
+ * Pre-gloas blocks always receive the boost (unconditional, backward compatible). For gloas
481
+ * blocks the boost is withheld when the parent is a weak block from the previous slot and the
482
+ * proposer of that parent equivocated (published another PTC-timely block at the same slot).
483
+ */
484
+ private shouldApplyProposerBoost;
485
+ /**
486
+ * The proposer boost to apply to `proposerBoostRoot`, propagated up the branch by
487
+ * applyScoreChanges() together with the deltas.
488
+ */
489
+ private getProposerBoost;
472
490
  /**
473
491
  * https://github.com/ethereum/consensus-specs/blob/v1.5.0/specs/phase0/fork-choice.md#is_proposing_on_time
474
492
  */
@@ -495,6 +513,8 @@ export declare class ForkChoice implements IForkChoice {
495
513
  * May need the justified balances of:
496
514
  * - unrealizedJustified: Already available in `CheckpointWithBalance`
497
515
  * Since this balances are already available the getter is just `() => balances`, without cache interaction
516
+ *
517
+ * @returns Whether either checkpoint was updated.
498
518
  */
499
519
  private updateCheckpoints;
500
520
  /**
@@ -537,6 +557,8 @@ export declare class ForkChoice implements IForkChoice {
537
557
  * Equivalent to:
538
558
  *
539
559
  * https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/fork-choice.md#on_tick
560
+ *
561
+ * @returns Whether an epoch-boundary checkpoint was updated.
540
562
  */
541
563
  private onTick;
542
564
  /**
@@ -546,11 +568,8 @@ export declare class ForkChoice implements IForkChoice {
546
568
  *
547
569
  */
548
570
  private getPreliminaryProposerHead;
571
+ /** Returns whether it recomputed the head, so the caller can avoid a redundant `updateHead()`. */
549
572
  private runFastConfirmation;
550
573
  private createFastConfirmationContext;
551
574
  }
552
- export declare function getCommitteeFraction(justifiedTotalActiveBalanceByIncrement: number, config: {
553
- slotsPerEpoch: number;
554
- committeePercent: number;
555
- }): number;
556
575
  //# sourceMappingURL=forkChoice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"forkChoice.d.ts","sourceRoot":"","sources":["../../src/forkChoice/forkChoice.ts"],"names":[],"mappings":"A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EED_LOOKAHEAD, SLOTS_PER_EPOCH, isForkPostFulu, isForkPostGloas, } from "@lodestar/params";
2
2
  import { DataAvailabilityStatus, ZERO_HASH, computeEpochAtSlot, computeSlotsSinceEpochStart, computeStartSlotAtEpoch, getAttesterSlashableIndices, isExecutionBlockBodyType, isStatePostBellatrix, } from "@lodestar/state-transition";
3
3
  import { isGloasBeaconBlock, ssz, } from "@lodestar/types";
4
4
  import { MapDef, fromHex, toRootHex, withObservedDuration } from "@lodestar/utils";
@@ -9,6 +9,7 @@ import { ForkChoiceError, ForkChoiceErrorCode, InvalidAttestationCode, InvalidBl
9
9
  import { FastConfirmationRule, FastConfirmationSteps, } from "./fastConfirmation/fastConfirmationRule.js";
10
10
  import { AncestorStatus, NotReorgedReason, } from "./interface.js";
11
11
  import { toCheckpointWithHex } from "./store.js";
12
+ const EFFECTIVE_BALANCE_INCREMENT_BIGINT = BigInt(EFFECTIVE_BALANCE_INCREMENT);
12
13
  export var UpdateHeadOpt;
13
14
  (function (UpdateHeadOpt) {
14
15
  UpdateHeadOpt["GetCanonicalHead"] = "getCanonicalHead";
@@ -428,30 +429,45 @@ export class ForkChoice {
428
429
  computeDeltasMetrics?.unchangedVoteValidators.set(unchangedVoteValidators);
429
430
  computeDeltasMetrics?.newVoteValidators.set(newVoteValidators);
430
431
  this.balances = newBalances;
431
- /**
432
- * The structure in line with deltas to propagate boost up the branch
433
- * starting from the proposerIndex
434
- */
435
- let proposerBoost = null;
436
- if (this.opts?.proposerBoost && this.proposerBoostRoot) {
437
- const proposerBoostScore = this.justifiedProposerBoostScore ??
438
- getCommitteeFraction(this.fcStore.justified.totalBalance, {
439
- slotsPerEpoch: SLOTS_PER_EPOCH,
440
- committeePercent: this.config.PROPOSER_SCORE_BOOST,
441
- });
442
- proposerBoost = { root: this.proposerBoostRoot, score: proposerBoostScore };
443
- this.justifiedProposerBoostScore = proposerBoostScore;
444
- }
445
432
  const currentSlot = this.fcStore.currentSlot;
446
- this.protoArray.applyScoreChanges({
447
- attestationDeltas,
448
- proposerBoost,
433
+ const checkpoints = {
449
434
  justifiedEpoch: this.fcStore.justified.checkpoint.epoch,
450
435
  justifiedRoot: this.fcStore.justified.checkpoint.rootHex,
451
436
  finalizedEpoch: this.fcStore.finalizedCheckpoint.epoch,
452
437
  finalizedRoot: this.fcStore.finalizedCheckpoint.rootHex,
453
438
  currentSlot,
454
- });
439
+ };
440
+ const boostedBlock = this.opts?.proposerBoost && this.proposerBoostRoot ? this.getBlockHexDefaultStatus(this.proposerBoostRoot) : null;
441
+ if (boostedBlock && isGloasBlock(boostedBlock)) {
442
+ // should_apply_proposer_boost judges the parent against the attestations known to the store,
443
+ // via is_head_weak (which also assumes equivocators' votes were already discounted before
444
+ // their balance is added back). Apply the attestation deltas first so the decision reads
445
+ // post-delta scores, then apply the boost in a second pass.
446
+ // TODO GLOAS: applyScoreChanges() updates weights and best child/descendant in one call;
447
+ // splitting them would let the two passes update weights and recompute best child/descendant
448
+ // once at the end.
449
+ // https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.14/specs/gloas/fork-choice.md#new-should_apply_proposer_boost
450
+ this.protoArray.applyScoreChanges({ attestationDeltas, proposerBoost: null, ...checkpoints });
451
+ const proposerBoost = this.shouldApplyProposerBoost() ? this.getProposerBoost() : null;
452
+ // The first pass already rolled back the previous boost and left a coherent tree, so a
453
+ // withheld boost needs no second pass
454
+ if (proposerBoost !== null) {
455
+ this.protoArray.applyScoreChanges({
456
+ attestationDeltas: new Array(this.protoArray.nodes.length).fill(0),
457
+ proposerBoost,
458
+ ...checkpoints,
459
+ });
460
+ }
461
+ }
462
+ else {
463
+ // Pre-gloas the boost is unconditional, so attestation deltas and boost deltas can propagate
464
+ // up the branch in a single pass
465
+ this.protoArray.applyScoreChanges({
466
+ attestationDeltas,
467
+ proposerBoost: boostedBlock ? this.getProposerBoost() : null,
468
+ ...checkpoints,
469
+ });
470
+ }
455
471
  // findHead returns the ProtoNode representing the head
456
472
  const head = this.protoArray.findHead(this.fcStore.justified.checkpoint.rootHex, currentSlot);
457
473
  this.head = head;
@@ -472,20 +488,10 @@ export class ForkChoice {
472
488
  getHeads() {
473
489
  return this.protoArray.nodes.filter((node) => node.bestChild === undefined);
474
490
  }
475
- /**
476
- * weight is in EFFECTIVE_BALANCE_INCREMENTS not gwei.
477
- * For compliance test use only
478
- */
491
+ /** Returns exact Gwei weights for the compliance test. */
479
492
  getViableHeads() {
480
493
  return this.protoArray.getViableHeads(this.fcStore.currentSlot);
481
494
  }
482
- /**
483
- * The cached justified total active balance, in EFFECTIVE_BALANCE_INCREMENT units.
484
- * For compliance test use only
485
- */
486
- getJustifiedTotalActiveBalanceByIncrement() {
487
- return this.fcStore.justified.totalBalance;
488
- }
489
495
  /** This is for the debug API only */
490
496
  getAllNodes() {
491
497
  return this.protoArray.nodes;
@@ -642,6 +648,8 @@ export class ForkChoice {
642
648
  targetRoot: toRootHex(targetRoot),
643
649
  stateRoot: toRootHex(block.stateRoot),
644
650
  timeliness: isTimely,
651
+ ptcTimeliness: this.isBlockPtcTimely(block, blockDelaySec),
652
+ proposerIndex: block.proposerIndex,
645
653
  justifiedEpoch: stateJustifiedEpoch,
646
654
  justifiedRoot: toRootHex(state.currentJustifiedCheckpoint.root),
647
655
  finalizedEpoch: finalizedCheckpoint.epoch,
@@ -851,11 +859,18 @@ export class ForkChoice {
851
859
  while (this.fcStore.currentSlot < currentSlot) {
852
860
  const previousSlot = this.fcStore.currentSlot;
853
861
  // Note: we are relying upon `onTick` to update `fcStore.time` to ensure we don't get stuck in a loop.
854
- this.onTick(previousSlot + 1);
862
+ const didUpdateCheckpoints = this.onTick(previousSlot + 1);
855
863
  this.queuedAttestationsPreviousSlot = 0;
856
864
  // Process any attestations that might now be eligible before running FCR for this slot.
857
865
  this.processAttestationQueue();
858
- this.runFastConfirmation();
866
+ const didRecomputeHead = this.runFastConfirmation();
867
+ // An epoch-boundary checkpoint pull-up can move the head's dependent root and stale the cached
868
+ // head before block 0 of the new epoch is imported, making isProposerBoostSameDependentRoot()
869
+ // wrong for that block. Recompute the head so it reflects the new checkpoint and the queued
870
+ // votes — unless fast confirmation already did, to avoid a redundant head calculation.
871
+ if (didUpdateCheckpoints && !didRecomputeHead) {
872
+ this.updateHead();
873
+ }
859
874
  this.validatedAttestationDatas = new Set();
860
875
  }
861
876
  }
@@ -1290,7 +1305,8 @@ export class ForkChoice {
1290
1305
  // Only ever called on a block already in fork choice, so a miss is a broken invariant.
1291
1306
  const node = this.protoArray.getNodeDefaultStatus(blockRoot);
1292
1307
  if (node === undefined) {
1293
- // this is called for head so we should always have this in forkchoice, otherwise we have a serious error
1308
+ // this is called for head or the boosted block's parent, both of which should always be
1309
+ // in forkchoice, otherwise we have a serious error
1294
1310
  throw new ForkChoiceError({ code: ForkChoiceErrorCode.MISSING_PROTO_ARRAY_BLOCK, root: blockRoot });
1295
1311
  }
1296
1312
  const reorgThreshold = getCommitteeFraction(this.fcStore.justified.totalBalance, {
@@ -1306,7 +1322,7 @@ export class ForkChoice {
1306
1322
  // always 0. Return before fetching the state and walking the block's committees.
1307
1323
  if (equivocatingIndices.size > 0) {
1308
1324
  const state = this.fcStore.stateGetter({ stateRoot: node.stateRoot });
1309
- // Only ever called on the head, so the state is always cached.
1325
+ // Only ever called on the head or the boosted block's parent, so the state is always cached.
1310
1326
  // A miss is a broken invariant, not a recoverable state.
1311
1327
  if (state === null) {
1312
1328
  throw new ForkChoiceError({
@@ -1325,7 +1341,7 @@ export class ForkChoice {
1325
1341
  // the justified state) - fall back to the head state's effective balance
1326
1342
  balance = state.effectiveBalanceIncrements[validatorIndex];
1327
1343
  }
1328
- headWeight += balance;
1344
+ headWeight += BigInt(balance) * EFFECTIVE_BALANCE_INCREMENT_BIGINT;
1329
1345
  }
1330
1346
  }
1331
1347
  }
@@ -1362,6 +1378,70 @@ export class ForkChoice {
1362
1378
  const isBeforeLateBlockCutoff = blockDelaySec * 1000 < this.config.getAttestationDueMs(fork);
1363
1379
  return this.fcStore.currentSlot === block.slot && isBeforeLateBlockCutoff;
1364
1380
  }
1381
+ /**
1382
+ * Return true if the block arrived before the PTC (payload-timeliness committee) deadline,
1383
+ * ie. block_timeliness[PTC_TIMELINESS_INDEX]. should_apply_proposer_boost uses this as the
1384
+ * definition of an "early" proposer equivocation: only a sibling seen by the PTC deadline
1385
+ * proves the proposer equivocated soon enough that honest nodes could have withheld the boost.
1386
+ *
1387
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.14/specs/gloas/fork-choice.md#modified-record_block_timeliness
1388
+ *
1389
+ * Child class can overwrite this for testing purpose.
1390
+ */
1391
+ isBlockPtcTimely(block, blockDelaySec) {
1392
+ const ptcThresholdMs = this.config.getSlotComponentDurationMs(this.config.PAYLOAD_ATTESTATION_DUE_BPS);
1393
+ return this.fcStore.currentSlot === block.slot && blockDelaySec * 1000 < ptcThresholdMs;
1394
+ }
1395
+ /**
1396
+ * Determine whether proposer boost should be applied to `proposerBoostRoot`.
1397
+ *
1398
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.14/specs/gloas/fork-choice.md#new-should_apply_proposer_boost
1399
+ *
1400
+ * Pre-gloas blocks always receive the boost (unconditional, backward compatible). For gloas
1401
+ * blocks the boost is withheld when the parent is a weak block from the previous slot and the
1402
+ * proposer of that parent equivocated (published another PTC-timely block at the same slot).
1403
+ */
1404
+ shouldApplyProposerBoost() {
1405
+ if (!this.proposerBoostRoot) {
1406
+ return false;
1407
+ }
1408
+ const boostedBlock = this.getBlockHexDefaultStatus(this.proposerBoostRoot);
1409
+ // Pre-gloas blocks always get boost
1410
+ if (!boostedBlock || !isGloasBlock(boostedBlock)) {
1411
+ return true;
1412
+ }
1413
+ const parentBlock = this.getBlockHexDefaultStatus(boostedBlock.parentRoot);
1414
+ if (!parentBlock) {
1415
+ return true;
1416
+ }
1417
+ // Apply proposer boost if parent is not from the previous slot
1418
+ if (parentBlock.slot + 1 < boostedBlock.slot) {
1419
+ return true;
1420
+ }
1421
+ // Apply proposer boost if parent is not weak
1422
+ if (!this.isHeadWeak(parentBlock.blockRoot)) {
1423
+ return true;
1424
+ }
1425
+ // Parent is weak and from the previous slot: apply boost only if there are no early
1426
+ // equivocations, ie. no other PTC-timely block at the parent's slot from the same proposer.
1427
+ return !this.protoArray.hasEquivocatingBlock(parentBlock.proposerIndex, parentBlock.slot, parentBlock.blockRoot);
1428
+ }
1429
+ /**
1430
+ * The proposer boost to apply to `proposerBoostRoot`, propagated up the branch by
1431
+ * applyScoreChanges() together with the deltas.
1432
+ */
1433
+ getProposerBoost() {
1434
+ if (!this.proposerBoostRoot) {
1435
+ return null;
1436
+ }
1437
+ const proposerBoostScore = this.justifiedProposerBoostScore ??
1438
+ getCommitteeFraction(this.fcStore.justified.totalBalance, {
1439
+ slotsPerEpoch: SLOTS_PER_EPOCH,
1440
+ committeePercent: this.config.PROPOSER_SCORE_BOOST,
1441
+ });
1442
+ this.justifiedProposerBoostScore = proposerBoostScore;
1443
+ return { root: this.proposerBoostRoot, score: proposerBoostScore };
1444
+ }
1365
1445
  /**
1366
1446
  * https://github.com/ethereum/consensus-specs/blob/v1.5.0/specs/phase0/fork-choice.md#is_proposing_on_time
1367
1447
  */
@@ -1404,18 +1484,24 @@ export class ForkChoice {
1404
1484
  * May need the justified balances of:
1405
1485
  * - unrealizedJustified: Already available in `CheckpointWithBalance`
1406
1486
  * Since this balances are already available the getter is just `() => balances`, without cache interaction
1487
+ *
1488
+ * @returns Whether either checkpoint was updated.
1407
1489
  */
1408
1490
  updateCheckpoints(justifiedCheckpoint, finalizedCheckpoint, getJustifiedBalances) {
1491
+ let updated = false;
1409
1492
  // Update justified checkpoint.
1410
1493
  if (justifiedCheckpoint.epoch > this.fcStore.justified.checkpoint.epoch) {
1411
1494
  this.fcStore.justified = { checkpoint: justifiedCheckpoint, balances: getJustifiedBalances() };
1412
1495
  this.justifiedProposerBoostScore = null;
1496
+ updated = true;
1413
1497
  }
1414
1498
  // Update finalized checkpoint.
1415
1499
  if (finalizedCheckpoint.epoch > this.fcStore.finalizedCheckpoint.epoch) {
1416
1500
  this.fcStore.finalizedCheckpoint = finalizedCheckpoint;
1417
1501
  this.justifiedProposerBoostScore = null;
1502
+ updated = true;
1418
1503
  }
1504
+ return updated;
1419
1505
  }
1420
1506
  /**
1421
1507
  * Update unrealized checkpoints in store if necessary
@@ -1659,6 +1745,8 @@ export class ForkChoice {
1659
1745
  * Equivalent to:
1660
1746
  *
1661
1747
  * https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/fork-choice.md#on_tick
1748
+ *
1749
+ * @returns Whether an epoch-boundary checkpoint was updated.
1662
1750
  */
1663
1751
  onTick(time) {
1664
1752
  const previousSlot = this.fcStore.currentSlot;
@@ -1678,10 +1766,10 @@ export class ForkChoice {
1678
1766
  }
1679
1767
  // Not a new epoch, return.
1680
1768
  if (computeSlotsSinceEpochStart(time) !== 0) {
1681
- return;
1769
+ return false;
1682
1770
  }
1683
- // If a new epoch, pull-up justification and finalization from previous epoch
1684
- this.updateCheckpoints(this.fcStore.unrealizedJustified.checkpoint, this.fcStore.unrealizedFinalizedCheckpoint, () => this.fcStore.unrealizedJustified.balances);
1771
+ // If a new epoch, pull-up justification and finalization from previous epoch.
1772
+ return this.updateCheckpoints(this.fcStore.unrealizedJustified.checkpoint, this.fcStore.unrealizedFinalizedCheckpoint, () => this.fcStore.unrealizedJustified.balances);
1685
1773
  }
1686
1774
  /**
1687
1775
  *
@@ -1724,11 +1812,12 @@ export class ForkChoice {
1724
1812
  prelimProposerHead = parentBlock;
1725
1813
  return { prelimProposerHead };
1726
1814
  }
1815
+ /** Returns whether it recomputed the head, so the caller can avoid a redundant `updateHead()`. */
1727
1816
  runFastConfirmation() {
1728
1817
  const fastConfirmationRule = this.fastConfirmationRule;
1729
1818
  const fastConfirmationContext = this.fastConfirmationContext;
1730
1819
  if (!fastConfirmationRule || !fastConfirmationContext)
1731
- return;
1820
+ return false;
1732
1821
  if (this.fastConfirmationPaused) {
1733
1822
  // Keep consumers on a safe, available root while the rule is paused
1734
1823
  this.fcStore.confirmedRoot = this.fcStore.finalizedCheckpoint.rootHex;
@@ -1739,7 +1828,7 @@ export class ForkChoice {
1739
1828
  // Runs outside the timed try/catch below; a throw would escape to the clock listener
1740
1829
  this.logger?.debug("Fast confirmation notify failed", { slot: this.fcStore.currentSlot }, err);
1741
1830
  }
1742
- return;
1831
+ return false;
1743
1832
  }
1744
1833
  withObservedDuration(this.metrics?.fastConfirmation.totalDuration.startTimer(), () => {
1745
1834
  try {
@@ -1754,6 +1843,7 @@ export class ForkChoice {
1754
1843
  this.logger?.debug("Fast confirmation failed", { slot: this.fcStore.currentSlot, head: this.head.blockRoot, confirmedRoot: this.fcStore.confirmedRoot }, err);
1755
1844
  }
1756
1845
  });
1846
+ return true;
1757
1847
  }
1758
1848
  createFastConfirmationContext() {
1759
1849
  const confirmationByzantineThreshold = this.config.CONFIRMATION_BYZANTINE_THRESHOLD;
@@ -1804,10 +1894,11 @@ export class ForkChoice {
1804
1894
  };
1805
1895
  }
1806
1896
  }
1807
- // Approximate https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/fork-choice.md#calculate_committee_fraction
1897
+ // https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/fork-choice.md#calculate_committee_fraction
1808
1898
  // Calculates proposer boost score when committeePercent = config.PROPOSER_SCORE_BOOST
1809
- export function getCommitteeFraction(justifiedTotalActiveBalanceByIncrement, config) {
1810
- const committeeWeight = Math.floor(justifiedTotalActiveBalanceByIncrement / config.slotsPerEpoch);
1811
- return Math.floor((committeeWeight * config.committeePercent) / 100);
1899
+ function getCommitteeFraction(justifiedTotalActiveBalanceByIncrement, config) {
1900
+ const committeeWeightGwei = (BigInt(justifiedTotalActiveBalanceByIncrement) * EFFECTIVE_BALANCE_INCREMENT_BIGINT) /
1901
+ BigInt(config.slotsPerEpoch);
1902
+ return (committeeWeightGwei * BigInt(config.committeePercent)) / 100n;
1812
1903
  }
1813
1904
  //# sourceMappingURL=forkChoice.js.map