@lodestar/fork-choice 1.52.0-dev.1f4a364fc5 → 1.52.0-dev.20cca3c9f1
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/fastConfirmation/data.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/data.js +3 -2
- package/lib/forkChoice/fastConfirmation/data.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/types.d.ts +30 -4
- package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/types.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/utils.d.ts +12 -14
- package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/utils.js +184 -115
- package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
- package/lib/forkChoice/forkChoice.d.ts +4 -2
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +13 -3
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +3 -1
- package/lib/forkChoice/interface.d.ts.map +1 -1
- package/lib/protoArray/errors.d.ts +8 -10
- package/lib/protoArray/errors.d.ts.map +1 -1
- package/lib/protoArray/errors.js +7 -7
- package/lib/protoArray/errors.js.map +1 -1
- package/lib/protoArray/protoArray.d.ts +9 -8
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +33 -23
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +8 -8
- package/src/forkChoice/fastConfirmation/data.ts +3 -2
- package/src/forkChoice/fastConfirmation/types.ts +28 -4
- package/src/forkChoice/fastConfirmation/utils.ts +236 -163
- package/src/forkChoice/forkChoice.ts +13 -7
- package/src/forkChoice/interface.ts +3 -1
- package/src/protoArray/errors.ts +8 -5
- package/src/protoArray/protoArray.ts +32 -22
|
@@ -211,7 +211,7 @@ export interface IForkChoice {
|
|
|
211
211
|
): void;
|
|
212
212
|
/**
|
|
213
213
|
* Notify fork choice that an execution payload has arrived (Gloas fork)
|
|
214
|
-
* Creates the FULL variant of a Gloas block when the payload becomes available
|
|
214
|
+
* Creates the FULL variant of a Gloas block when the payload becomes available and refreshes the cached head
|
|
215
215
|
*
|
|
216
216
|
* ## Specification
|
|
217
217
|
*
|
|
@@ -281,6 +281,8 @@ export interface IForkChoice {
|
|
|
281
281
|
shouldExtendPayload(blockRoot: RootHex): boolean;
|
|
282
282
|
/** Spec: should_build_on_full(store, head, slot) */
|
|
283
283
|
shouldBuildOnFull(head: ProtoBlock, slot: Slot): boolean;
|
|
284
|
+
/** Spec: is_proposer_equivocation(store, root) */
|
|
285
|
+
isProposerEquivocation(block: ProtoBlock): boolean;
|
|
284
286
|
/** Inclusion list verdict for the payload of `blockRoot`, as reported by the execution engine. True if it changed */
|
|
285
287
|
recordPayloadInclusionListSatisfaction(blockRoot: RootHex, satisfied: boolean): boolean;
|
|
286
288
|
/** True once the payload is delivered and not recorded unsatisfied */
|
package/src/protoArray/errors.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {Epoch, RootHex} from "@lodestar/types";
|
|
2
2
|
import {LodestarError} from "@lodestar/utils";
|
|
3
3
|
|
|
4
|
-
export enum
|
|
4
|
+
export enum ExecutionStatusTransition {
|
|
5
5
|
PreMergeToInvalid = "PreMergeToInvalid",
|
|
6
6
|
ValidToInvalid = "ValidToInvalid",
|
|
7
7
|
InvalidToValid = "InvalidToValid",
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export type LVHExecError = {lvhCode: LVHExecErrorCode; blockRoot: RootHex; execHash: RootHex};
|
|
11
|
-
|
|
12
10
|
export enum ProtoArrayErrorCode {
|
|
13
11
|
FINALIZED_NODE_UNKNOWN = "PROTO_ARRAY_ERROR_FINALIZED_NODE_UNKNOWN",
|
|
14
12
|
JUSTIFIED_NODE_UNKNOWN = "PROTO_ARRAY_ERROR_JUSTIFIED_NODE_UNKNOWN",
|
|
@@ -28,7 +26,7 @@ export enum ProtoArrayErrorCode {
|
|
|
28
26
|
INVALID_BEST_NODE = "PROTO_ARRAY_ERROR_INVALID_BEST_NODE",
|
|
29
27
|
INVALID_BLOCK_EXECUTION_STATUS = "PROTO_ARRAY_INVALID_BLOCK_EXECUTION_STATUS",
|
|
30
28
|
INVALID_JUSTIFIED_EXECUTION_STATUS = "PROTO_ARRAY_INVALID_JUSTIFIED_EXECUTION_STATUS",
|
|
31
|
-
|
|
29
|
+
INVALID_EXECUTION_STATUS_TRANSITION = "PROTO_ARRAY_ERROR_INVALID_EXECUTION_STATUS_TRANSITION",
|
|
32
30
|
PRE_GLOAS_BLOCK = "PROTO_ARRAY_ERROR_PRE_GLOAS_BLOCK",
|
|
33
31
|
}
|
|
34
32
|
|
|
@@ -59,7 +57,12 @@ export type ProtoArrayErrorType =
|
|
|
59
57
|
}
|
|
60
58
|
| {code: ProtoArrayErrorCode.INVALID_BLOCK_EXECUTION_STATUS; root: RootHex}
|
|
61
59
|
| {code: ProtoArrayErrorCode.INVALID_JUSTIFIED_EXECUTION_STATUS; root: RootHex}
|
|
62
|
-
|
|
|
60
|
+
| {
|
|
61
|
+
code: ProtoArrayErrorCode.INVALID_EXECUTION_STATUS_TRANSITION;
|
|
62
|
+
transition: ExecutionStatusTransition;
|
|
63
|
+
blockRoot: RootHex;
|
|
64
|
+
execHash: RootHex;
|
|
65
|
+
}
|
|
63
66
|
| {code: ProtoArrayErrorCode.PRE_GLOAS_BLOCK; root: RootHex};
|
|
64
67
|
|
|
65
68
|
export class ProtoArrayError extends LodestarError<ProtoArrayErrorType> {}
|
|
@@ -4,7 +4,7 @@ import {DataAvailabilityStatus, computeEpochAtSlot, computeStartSlotAtEpoch} fro
|
|
|
4
4
|
import {Epoch, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
|
|
5
5
|
import {bitCount, toRootHex} from "@lodestar/utils";
|
|
6
6
|
import {ForkChoiceError, ForkChoiceErrorCode} from "../forkChoice/errors.js";
|
|
7
|
-
import {
|
|
7
|
+
import {ExecutionStatusTransition, ProtoArrayError, ProtoArrayErrorCode} from "./errors.js";
|
|
8
8
|
import {
|
|
9
9
|
ExecutionStatus,
|
|
10
10
|
HEX_ZERO_HASH,
|
|
@@ -711,8 +711,14 @@ export class ProtoArray {
|
|
|
711
711
|
this.propagateValidExecutionStatusByIndex(pendingIndex);
|
|
712
712
|
}
|
|
713
713
|
|
|
714
|
-
//
|
|
715
|
-
|
|
714
|
+
// A zero-weight leaf only changes best child and descendant links on its path to the root
|
|
715
|
+
let childIndex = fullIndex;
|
|
716
|
+
let parentIndex: number | undefined = pendingIndex;
|
|
717
|
+
while (parentIndex !== undefined) {
|
|
718
|
+
this.maybeUpdateBestChildAndDescendant(parentIndex, childIndex, currentSlot, proposerBoostRoot);
|
|
719
|
+
childIndex = parentIndex;
|
|
720
|
+
parentIndex = this.nodes[childIndex].parent;
|
|
721
|
+
}
|
|
716
722
|
}
|
|
717
723
|
|
|
718
724
|
/** Count blocks selected as FULL or EMPTY by the supplied head chain in the inclusive slot range. */
|
|
@@ -1123,7 +1129,7 @@ export class ProtoArray {
|
|
|
1123
1129
|
if (judged === LVHInvalidJudged.ChildPayload) {
|
|
1124
1130
|
return {applied: false, reason: LVHNotAppliedReason.UnusableLVH};
|
|
1125
1131
|
}
|
|
1126
|
-
latestValidHashIndex = this.
|
|
1132
|
+
latestValidHashIndex = this.getParentPayloadIndex(invalidateFromIndex);
|
|
1127
1133
|
}
|
|
1128
1134
|
|
|
1129
1135
|
// Never invalidate the justified block, the EMPTY variant sharing its chain, or anything at or below it in
|
|
@@ -1138,8 +1144,8 @@ export class ProtoArray {
|
|
|
1138
1144
|
(node.blockRoot === this.justifiedRoot && node.payloadStatus === PayloadStatus.EMPTY);
|
|
1139
1145
|
if (conflict || justified) {
|
|
1140
1146
|
if (judged === LVHInvalidJudged.FromBlock) {
|
|
1141
|
-
// The LVH is unusable:
|
|
1142
|
-
latestValidHashIndex = Math.max(nodeIndex, this.
|
|
1147
|
+
// The LVH is unusable: invalidate only the judged payload, but never cross this node
|
|
1148
|
+
latestValidHashIndex = Math.max(nodeIndex, this.getParentPayloadIndex(invalidateFromIndex));
|
|
1143
1149
|
} else if (conflict) {
|
|
1144
1150
|
return {applied: false, reason: LVHNotAppliedReason.Contradiction};
|
|
1145
1151
|
} else {
|
|
@@ -1160,11 +1166,11 @@ export class ProtoArray {
|
|
|
1160
1166
|
}
|
|
1161
1167
|
|
|
1162
1168
|
/**
|
|
1163
|
-
*
|
|
1164
|
-
*
|
|
1165
|
-
*
|
|
1169
|
+
* Index of the nearest ancestor carrying a different payload than `fromIndex`, i.e. the node holding its parent
|
|
1170
|
+
* payload. Pre-gloas this is the parent of `fromIndex`. For a gloas EMPTY or PENDING node it skips past the FULL
|
|
1171
|
+
* node that owns the payload. -1 when the chain reaches the root.
|
|
1166
1172
|
*/
|
|
1167
|
-
private
|
|
1173
|
+
private getParentPayloadIndex(fromIndex: number): number {
|
|
1168
1174
|
const payloadBlockHash = this.nodes[fromIndex].executionPayloadBlockHash;
|
|
1169
1175
|
let nodeIndex = fromIndex;
|
|
1170
1176
|
let parentIndex = this.nodes[nodeIndex].parent;
|
|
@@ -1198,19 +1204,23 @@ export class ProtoArray {
|
|
|
1198
1204
|
}
|
|
1199
1205
|
|
|
1200
1206
|
/**
|
|
1201
|
-
*
|
|
1202
|
-
*
|
|
1203
|
-
*
|
|
1204
|
-
*
|
|
1207
|
+
* A node's execution status is that of the payload in its `executionPayloadBlockHash`: its own for FULL, the
|
|
1208
|
+
* inherited parent payload for gloas PENDING and EMPTY. Once that payload is VALID every node carrying it is, not
|
|
1209
|
+
* only the chain the validation walked up (e.g. siblings, blocks on a sibling's EMPTY variant, or an equivocating
|
|
1210
|
+
* block with the same payload). A node is only flipped below a Valid parent, otherwise a later INVALID for the
|
|
1211
|
+
* parent would reach it. A parent has a lower index than its children, so the scan updates it first.
|
|
1205
1212
|
*/
|
|
1206
1213
|
private validatePayloadDependents(payloadHashes: Set<RootHex>): void {
|
|
1207
1214
|
for (let nodeIndex = 0; nodeIndex < this.nodes.length; nodeIndex++) {
|
|
1208
1215
|
const node = this.nodes[nodeIndex];
|
|
1216
|
+
const parentStatus = node.parent !== undefined ? this.nodes[node.parent].executionStatus : undefined;
|
|
1209
1217
|
if (
|
|
1210
|
-
node.payloadStatus === PayloadStatus.PENDING &&
|
|
1211
1218
|
node.executionStatus === ExecutionStatus.Syncing &&
|
|
1212
1219
|
node.executionPayloadBlockHash !== null &&
|
|
1213
|
-
payloadHashes.has(node.executionPayloadBlockHash)
|
|
1220
|
+
payloadHashes.has(node.executionPayloadBlockHash) &&
|
|
1221
|
+
(parentStatus === undefined ||
|
|
1222
|
+
parentStatus === ExecutionStatus.Valid ||
|
|
1223
|
+
parentStatus === ExecutionStatus.PreMerge)
|
|
1214
1224
|
) {
|
|
1215
1225
|
// Also flips the sibling EMPTY variant
|
|
1216
1226
|
this.validateNodeByIndex(nodeIndex);
|
|
@@ -1289,11 +1299,11 @@ export class ProtoArray {
|
|
|
1289
1299
|
invalidNode.executionStatus === ExecutionStatus.PreMerge
|
|
1290
1300
|
) {
|
|
1291
1301
|
throw new ProtoArrayError({
|
|
1292
|
-
code: ProtoArrayErrorCode.
|
|
1293
|
-
|
|
1302
|
+
code: ProtoArrayErrorCode.INVALID_EXECUTION_STATUS_TRANSITION,
|
|
1303
|
+
transition:
|
|
1294
1304
|
invalidNode.executionStatus === ExecutionStatus.Valid
|
|
1295
|
-
?
|
|
1296
|
-
:
|
|
1305
|
+
? ExecutionStatusTransition.ValidToInvalid
|
|
1306
|
+
: ExecutionStatusTransition.PreMergeToInvalid,
|
|
1297
1307
|
blockRoot: invalidNode.blockRoot,
|
|
1298
1308
|
execHash: invalidNode.executionPayloadBlockHash ?? ZERO_HASH_HEX,
|
|
1299
1309
|
});
|
|
@@ -1317,8 +1327,8 @@ export class ProtoArray {
|
|
|
1317
1327
|
const validNode = this.getNodeFromIndex(nodeIndex);
|
|
1318
1328
|
if (validNode.executionStatus === ExecutionStatus.Invalid) {
|
|
1319
1329
|
throw new ProtoArrayError({
|
|
1320
|
-
code: ProtoArrayErrorCode.
|
|
1321
|
-
|
|
1330
|
+
code: ProtoArrayErrorCode.INVALID_EXECUTION_STATUS_TRANSITION,
|
|
1331
|
+
transition: ExecutionStatusTransition.InvalidToValid,
|
|
1322
1332
|
blockRoot: validNode.blockRoot,
|
|
1323
1333
|
execHash: validNode.executionPayloadBlockHash,
|
|
1324
1334
|
});
|