@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.
- 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 +7 -9
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +15 -24
- 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 +16 -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 +17 -25
- 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
|
@@ -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-
|
|
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-
|
|
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
|
-
|
|
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
|
-
*
|
|
2217
|
+
* Keep voteCurrentIndices and voteNextIndices the same length, as required by computeDeltas().
|
|
2224
2218
|
*
|
|
2225
|
-
*
|
|
2226
|
-
*
|
|
2227
|
-
*
|
|
2228
|
-
*
|
|
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
|
-
//
|
|
2239
|
-
//
|
|
2240
|
-
const nextIndex =
|
|
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
|
|
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,
|
|
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
|
|