@lodestar/fork-choice 2.1.0-dev.52f6c9664e → 2.1.0-dev.5b89ed1248

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.
@@ -1734,7 +1734,7 @@ export class ForkChoice implements IForkChoice {
1734
1734
  * Return true if the block is "weak" ie. its weight is below REORG_HEAD_WEIGHT_THRESHOLD of the
1735
1735
  * total attester weight per slot.
1736
1736
  *
1737
- * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.11/specs/phase0/fork-choice.md#is_head_weak
1737
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/phase0/fork-choice.md#is_head_weak
1738
1738
  * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.11/specs/gloas/fork-choice.md#modified-is_head_weak
1739
1739
  */
1740
1740
  private isHeadWeak(blockRoot: RootHex): boolean {
@@ -1753,10 +1753,6 @@ export class ForkChoice implements IForkChoice {
1753
1753
  committeePercent: this.config.REORG_HEAD_WEIGHT_THRESHOLD,
1754
1754
  });
1755
1755
 
1756
- if (!isForkPostGloas(this.config.getForkName(node.slot))) {
1757
- return node.weight < reorgThreshold;
1758
- }
1759
-
1760
1756
  let headWeight = node.attestationScore;
1761
1757
 
1762
1758
  const {equivocatingIndices} = this.fcStore;
@@ -1797,7 +1793,7 @@ export class ForkChoice implements IForkChoice {
1797
1793
  * Return true if the parent block is "strong" ie. its weight exceeds REORG_PARENT_WEIGHT_THRESHOLD
1798
1794
  * of the total attester weight per slot.
1799
1795
  *
1800
- * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.12/specs/phase0/fork-choice.md#is_parent_strong
1796
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/phase0/fork-choice.md#is_parent_strong
1801
1797
  * https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.12/specs/gloas/fork-choice.md#modified-is_parent_strong
1802
1798
  */
1803
1799
  private isParentStrong(parentRoot: RootHex): boolean {
@@ -1812,9 +1808,7 @@ export class ForkChoice implements IForkChoice {
1812
1808
  committeePercent: this.config.REORG_PARENT_WEIGHT_THRESHOLD,
1813
1809
  });
1814
1810
 
1815
- // pre-gloas uses get_weight() (boost-inclusive), gloas uses get_attestation_score() (boost-excluded)
1816
- const parentWeight = isForkPostGloas(this.config.getForkName(node.slot)) ? node.attestationScore : node.weight;
1817
- return parentWeight > parentThreshold;
1811
+ return node.attestationScore > parentThreshold;
1818
1812
  }
1819
1813
 
1820
1814
  /**
@@ -2220,25 +2214,25 @@ export class ForkChoice implements IForkChoice {
2220
2214
 
2221
2215
  /**
2222
2216
  * Add a validator's latest message to the tracked votes.
2223
- * Always sync voteCurrentIndices and voteNextIndices so that it'll not throw in computeDeltas()
2217
+ * Keep voteCurrentIndices and voteNextIndices the same length, as required by computeDeltas().
2224
2218
  *
2225
- * Modified for Gloas to accept slot and payloadPresent.
2226
- * Spec: gloas/fork-choice.md#modified-update_latest_messages
2227
- *
2228
- * For backward compatibility with Fulu (pre-Gloas):
2229
- * - Accepts both epoch-derived and slot parameters
2230
- * - payloadPresent defaults to true for Fulu (payloads embedded in blocks)
2219
+ * Callers pass the attestation slot on every fork. Before Gloas, votes are compared by epoch
2220
+ * and the caller passes FULL (Fulu embeds the payload in the block). From Gloas, votes are
2221
+ * compared by slot and the caller passes the payload status supported by the attestation.
2222
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.5/specs/gloas/fork-choice.md#modified-update_latest_messages
2231
2223
  */
2232
2224
  private addLatestMessage(
2233
2225
  validatorIndex: ValidatorIndex,
2234
2226
  nextSlot: Slot,
2235
- nextRoot: RootHex,
2227
+ nextRoot: RootHex | null,
2236
2228
  nextPayloadStatus: PayloadStatus
2237
2229
  ): void {
2238
- // should not happen, attestation is validated before this step
2239
- // Get the node index for the voted block
2240
- const nextIndex = this.protoArray.getNodeIndexByRootAndStatus(nextRoot, nextPayloadStatus);
2230
+ // A null root means the queued vote's block was pruned after validation. If the vote is newer,
2231
+ // NULL_VOTE_INDEX lets computeDeltas remove the previous vote's weight without crediting a new block.
2232
+ const nextIndex =
2233
+ nextRoot === null ? NULL_VOTE_INDEX : this.protoArray.getNodeIndexByRootAndStatus(nextRoot, nextPayloadStatus);
2241
2234
  if (nextIndex === undefined) {
2235
+ // A supplied root must resolve to the node for the attestation's payload status.
2242
2236
  throw new Error(`Could not find proto index for nextRoot ${nextRoot} with payloadStatus ${nextPayloadStatus}`);
2243
2237
  }
2244
2238
 
@@ -2273,18 +2267,16 @@ export class ForkChoice implements IForkChoice {
2273
2267
  if (slot < currentSlot) {
2274
2268
  this.queuedAttestations.delete(slot);
2275
2269
  for (const [blockRoot, validatorVotes] of byRoot.entries()) {
2276
- const blockRootHex = blockRoot;
2270
+ const nextRoot = this.protoArray.hasBlock(blockRoot) ? blockRoot : null;
2277
2271
  for (const [validatorIndex, payloadStatus] of validatorVotes.entries()) {
2278
2272
  // equivocatingIndices was checked in onAttestation
2279
- this.addLatestMessage(validatorIndex, slot, blockRootHex, payloadStatus);
2273
+ this.addLatestMessage(validatorIndex, slot, nextRoot, payloadStatus);
2280
2274
  }
2281
2275
 
2282
- if (slot === currentSlot - 1) {
2276
+ if (nextRoot !== null && slot === currentSlot - 1) {
2283
2277
  this.queuedAttestationsPreviousSlot += validatorVotes.size;
2284
2278
  }
2285
2279
  }
2286
- } else {
2287
- break;
2288
2280
  }
2289
2281
  }
2290
2282
  }
@@ -70,6 +70,7 @@ export enum NotReorgedReason {
70
70
  NotProposingOnTime = "notProposingOnTime",
71
71
  NotProposerOfNextSlot = "notProposerOfNextSlot",
72
72
  HeadBlockNotAvailable = "headBlockNotAvailable", // Should not happen because head block should be in cache
73
+ HeadStateNotAvailable = "headStateNotAvailable",
73
74
  Unknown = "unknown", // A placeholder in case reason is not provided
74
75
  }
75
76