@lodestar/fork-choice 2.1.0-dev.2c328e4c17 → 2.1.0-dev.3a93673fb5
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 -10
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +34 -49
- 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 +38 -52
- 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
|
@@ -73,7 +73,6 @@ import {CheckpointWithHex, IForkChoiceStore, JustifiedBalances, toCheckpointWith
|
|
|
73
73
|
export type ForkChoiceOpts = {
|
|
74
74
|
proposerBoost?: boolean;
|
|
75
75
|
proposerBoostReorg?: boolean;
|
|
76
|
-
computeUnrealized?: boolean;
|
|
77
76
|
fastConfirmation?: boolean;
|
|
78
77
|
};
|
|
79
78
|
|
|
@@ -882,33 +881,28 @@ export class ForkChoice implements IForkChoice {
|
|
|
882
881
|
// performing optimally.
|
|
883
882
|
let unrealizedJustifiedCheckpoint: CheckpointWithHex;
|
|
884
883
|
let unrealizedFinalizedCheckpoint: CheckpointWithHex;
|
|
885
|
-
if (
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
};
|
|
903
|
-
} else {
|
|
904
|
-
// compute new, happens 2/3 first blocks of epoch as monitored in mainnet
|
|
905
|
-
const unrealized = state.computeUnrealizedCheckpoints();
|
|
906
|
-
unrealizedJustifiedCheckpoint = toCheckpointWithHex(unrealized.justifiedCheckpoint);
|
|
907
|
-
unrealizedFinalizedCheckpoint = toCheckpointWithHex(unrealized.finalizedCheckpoint);
|
|
908
|
-
}
|
|
884
|
+
if (
|
|
885
|
+
block.body.proposerSlashings.length === 0 &&
|
|
886
|
+
block.body.attesterSlashings.length === 0 &&
|
|
887
|
+
parentBlock.unrealizedJustifiedEpoch === blockEpoch &&
|
|
888
|
+
parentBlock.unrealizedFinalizedEpoch + 1 >= blockEpoch
|
|
889
|
+
) {
|
|
890
|
+
// reuse from parent, happens at 1/3 last blocks of epoch as monitored in mainnet
|
|
891
|
+
unrealizedJustifiedCheckpoint = {
|
|
892
|
+
epoch: parentBlock.unrealizedJustifiedEpoch,
|
|
893
|
+
root: fromHex(parentBlock.unrealizedJustifiedRoot),
|
|
894
|
+
rootHex: parentBlock.unrealizedJustifiedRoot,
|
|
895
|
+
};
|
|
896
|
+
unrealizedFinalizedCheckpoint = {
|
|
897
|
+
epoch: parentBlock.unrealizedFinalizedEpoch,
|
|
898
|
+
root: fromHex(parentBlock.unrealizedFinalizedRoot),
|
|
899
|
+
rootHex: parentBlock.unrealizedFinalizedRoot,
|
|
900
|
+
};
|
|
909
901
|
} else {
|
|
910
|
-
|
|
911
|
-
|
|
902
|
+
// compute new, happens 2/3 first blocks of epoch as monitored in mainnet
|
|
903
|
+
const unrealized = state.computeUnrealizedCheckpoints();
|
|
904
|
+
unrealizedJustifiedCheckpoint = toCheckpointWithHex(unrealized.justifiedCheckpoint);
|
|
905
|
+
unrealizedFinalizedCheckpoint = toCheckpointWithHex(unrealized.finalizedCheckpoint);
|
|
912
906
|
}
|
|
913
907
|
|
|
914
908
|
const targetSlot = computeStartSlotAtEpoch(blockEpoch);
|
|
@@ -1740,7 +1734,7 @@ export class ForkChoice implements IForkChoice {
|
|
|
1740
1734
|
* Return true if the block is "weak" ie. its weight is below REORG_HEAD_WEIGHT_THRESHOLD of the
|
|
1741
1735
|
* total attester weight per slot.
|
|
1742
1736
|
*
|
|
1743
|
-
* 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
|
|
1744
1738
|
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.11/specs/gloas/fork-choice.md#modified-is_head_weak
|
|
1745
1739
|
*/
|
|
1746
1740
|
private isHeadWeak(blockRoot: RootHex): boolean {
|
|
@@ -1759,10 +1753,6 @@ export class ForkChoice implements IForkChoice {
|
|
|
1759
1753
|
committeePercent: this.config.REORG_HEAD_WEIGHT_THRESHOLD,
|
|
1760
1754
|
});
|
|
1761
1755
|
|
|
1762
|
-
if (!isForkPostGloas(this.config.getForkName(node.slot))) {
|
|
1763
|
-
return node.weight < reorgThreshold;
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
1756
|
let headWeight = node.attestationScore;
|
|
1767
1757
|
|
|
1768
1758
|
const {equivocatingIndices} = this.fcStore;
|
|
@@ -1803,7 +1793,7 @@ export class ForkChoice implements IForkChoice {
|
|
|
1803
1793
|
* Return true if the parent block is "strong" ie. its weight exceeds REORG_PARENT_WEIGHT_THRESHOLD
|
|
1804
1794
|
* of the total attester weight per slot.
|
|
1805
1795
|
*
|
|
1806
|
-
* 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
|
|
1807
1797
|
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.12/specs/gloas/fork-choice.md#modified-is_parent_strong
|
|
1808
1798
|
*/
|
|
1809
1799
|
private isParentStrong(parentRoot: RootHex): boolean {
|
|
@@ -1818,9 +1808,7 @@ export class ForkChoice implements IForkChoice {
|
|
|
1818
1808
|
committeePercent: this.config.REORG_PARENT_WEIGHT_THRESHOLD,
|
|
1819
1809
|
});
|
|
1820
1810
|
|
|
1821
|
-
|
|
1822
|
-
const parentWeight = isForkPostGloas(this.config.getForkName(node.slot)) ? node.attestationScore : node.weight;
|
|
1823
|
-
return parentWeight > parentThreshold;
|
|
1811
|
+
return node.attestationScore > parentThreshold;
|
|
1824
1812
|
}
|
|
1825
1813
|
|
|
1826
1814
|
/**
|
|
@@ -2226,25 +2214,25 @@ export class ForkChoice implements IForkChoice {
|
|
|
2226
2214
|
|
|
2227
2215
|
/**
|
|
2228
2216
|
* Add a validator's latest message to the tracked votes.
|
|
2229
|
-
*
|
|
2230
|
-
*
|
|
2231
|
-
* Modified for Gloas to accept slot and payloadPresent.
|
|
2232
|
-
* Spec: gloas/fork-choice.md#modified-update_latest_messages
|
|
2217
|
+
* Keep voteCurrentIndices and voteNextIndices the same length, as required by computeDeltas().
|
|
2233
2218
|
*
|
|
2234
|
-
*
|
|
2235
|
-
*
|
|
2236
|
-
*
|
|
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
|
|
2237
2223
|
*/
|
|
2238
2224
|
private addLatestMessage(
|
|
2239
2225
|
validatorIndex: ValidatorIndex,
|
|
2240
2226
|
nextSlot: Slot,
|
|
2241
|
-
nextRoot: RootHex,
|
|
2227
|
+
nextRoot: RootHex | null,
|
|
2242
2228
|
nextPayloadStatus: PayloadStatus
|
|
2243
2229
|
): void {
|
|
2244
|
-
//
|
|
2245
|
-
//
|
|
2246
|
-
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);
|
|
2247
2234
|
if (nextIndex === undefined) {
|
|
2235
|
+
// A supplied root must resolve to the node for the attestation's payload status.
|
|
2248
2236
|
throw new Error(`Could not find proto index for nextRoot ${nextRoot} with payloadStatus ${nextPayloadStatus}`);
|
|
2249
2237
|
}
|
|
2250
2238
|
|
|
@@ -2279,18 +2267,16 @@ export class ForkChoice implements IForkChoice {
|
|
|
2279
2267
|
if (slot < currentSlot) {
|
|
2280
2268
|
this.queuedAttestations.delete(slot);
|
|
2281
2269
|
for (const [blockRoot, validatorVotes] of byRoot.entries()) {
|
|
2282
|
-
const
|
|
2270
|
+
const nextRoot = this.protoArray.hasBlock(blockRoot) ? blockRoot : null;
|
|
2283
2271
|
for (const [validatorIndex, payloadStatus] of validatorVotes.entries()) {
|
|
2284
2272
|
// equivocatingIndices was checked in onAttestation
|
|
2285
|
-
this.addLatestMessage(validatorIndex, slot,
|
|
2273
|
+
this.addLatestMessage(validatorIndex, slot, nextRoot, payloadStatus);
|
|
2286
2274
|
}
|
|
2287
2275
|
|
|
2288
|
-
if (slot === currentSlot - 1) {
|
|
2276
|
+
if (nextRoot !== null && slot === currentSlot - 1) {
|
|
2289
2277
|
this.queuedAttestationsPreviousSlot += validatorVotes.size;
|
|
2290
2278
|
}
|
|
2291
2279
|
}
|
|
2292
|
-
} else {
|
|
2293
|
-
break;
|
|
2294
2280
|
}
|
|
2295
2281
|
}
|
|
2296
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
|
|