@lodestar/fork-choice 1.52.0-dev.53c3aab4e9 → 1.52.0-dev.5745da1108

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.
Files changed (40) hide show
  1. package/lib/forkChoice/errors.d.ts +6 -1
  2. package/lib/forkChoice/errors.d.ts.map +1 -1
  3. package/lib/forkChoice/errors.js +1 -0
  4. package/lib/forkChoice/errors.js.map +1 -1
  5. package/lib/forkChoice/fastConfirmation/utils.d.ts +12 -12
  6. package/lib/forkChoice/fastConfirmation/utils.d.ts.map +1 -1
  7. package/lib/forkChoice/fastConfirmation/utils.js +48 -61
  8. package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
  9. package/lib/forkChoice/forkChoice.d.ts +5 -6
  10. package/lib/forkChoice/forkChoice.d.ts.map +1 -1
  11. package/lib/forkChoice/forkChoice.js +29 -25
  12. package/lib/forkChoice/forkChoice.js.map +1 -1
  13. package/lib/forkChoice/interface.d.ts +4 -7
  14. package/lib/forkChoice/interface.d.ts.map +1 -1
  15. package/lib/forkChoice/interface.js.map +1 -1
  16. package/lib/index.d.ts +2 -2
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +1 -1
  19. package/lib/index.js.map +1 -1
  20. package/lib/protoArray/errors.d.ts +8 -10
  21. package/lib/protoArray/errors.d.ts.map +1 -1
  22. package/lib/protoArray/errors.js +7 -7
  23. package/lib/protoArray/errors.js.map +1 -1
  24. package/lib/protoArray/interface.d.ts +33 -2
  25. package/lib/protoArray/interface.d.ts.map +1 -1
  26. package/lib/protoArray/interface.js +22 -0
  27. package/lib/protoArray/interface.js.map +1 -1
  28. package/lib/protoArray/protoArray.d.ts +20 -22
  29. package/lib/protoArray/protoArray.d.ts.map +1 -1
  30. package/lib/protoArray/protoArray.js +104 -100
  31. package/lib/protoArray/protoArray.js.map +1 -1
  32. package/package.json +8 -8
  33. package/src/forkChoice/errors.ts +3 -1
  34. package/src/forkChoice/fastConfirmation/utils.ts +84 -94
  35. package/src/forkChoice/forkChoice.ts +29 -26
  36. package/src/forkChoice/interface.ts +4 -5
  37. package/src/index.ts +9 -1
  38. package/src/protoArray/errors.ts +8 -5
  39. package/src/protoArray/interface.ts +30 -4
  40. package/src/protoArray/protoArray.ts +106 -110
@@ -49,13 +49,44 @@ export type LVHValidResponse = {
49
49
  /** Resolves the exact node to validate when several nodes carry the same payload hash (gloas variants) */
50
50
  blockRoot?: RootHex;
51
51
  };
52
+ /** Which payload the execution engine judged INVALID, relative to the node the invalidation starts from */
53
+ export declare enum LVHInvalidJudged {
54
+ /** The from node's own payload, e.g. the head sent in forkchoiceUpdated */
55
+ FromBlock = "from_block",
56
+ /** A payload built on the from node that is not in fork choice, e.g. a payload rejected by newPayload */
57
+ ChildPayload = "child_payload"
58
+ }
52
59
  export type LVHInvalidResponse = {
53
60
  executionStatus: ExecutionStatus.Invalid;
54
61
  latestValidExecHash: RootHex | null;
55
- invalidateFromParentBlockRoot: RootHex;
56
- invalidateFromParentBlockHash: RootHex;
62
+ invalidateFromBlockRoot: RootHex;
63
+ invalidateFromBlockHash: RootHex;
64
+ judged: LVHInvalidJudged;
57
65
  };
58
66
  export type LVHExecResponse = LVHValidResponse | LVHInvalidResponse;
67
+ export declare enum LVHNotAppliedReason {
68
+ /** VALID verdict whose latest valid hash is not in fork choice */
69
+ UnknownLVH = "unknown_lvh",
70
+ /** Fork choice already holds the verdict */
71
+ AlreadyApplied = "already_applied",
72
+ /** The verdict contradicts a status the engine already resolved */
73
+ Contradiction = "contradiction",
74
+ /** INVALID verdict on a payload that is not in fork choice, with a latest valid hash that is null or unknown */
75
+ UnusableLVH = "unusable_lvh",
76
+ /** INVALID verdict that covers no node above the latest valid hash or the justified block */
77
+ NothingToInvalidate = "nothing_to_invalidate",
78
+ Error = "error"
79
+ }
80
+ export type LVHVerdictResult = {
81
+ applied: true;
82
+ } | {
83
+ applied: false;
84
+ reason: Exclude<LVHNotAppliedReason, LVHNotAppliedReason.Error>;
85
+ } | {
86
+ applied: false;
87
+ reason: LVHNotAppliedReason.Error;
88
+ error: Error;
89
+ };
59
90
  /**
60
91
  * Any execution status that is not definitively invalid.
61
92
  * Valid | Syncing | PreMerge
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/protoArray/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAIhF,eAAO,MAAM,aAAa,uEAAuE,CAAC;AAElG;;;;GAIG;AACH,eAAO,MAAM,eAAe,aAAa,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;;;;;;;;;GAUG;AACH,oBAAY,eAAe;IACzB,KAAK,UAAU;IACf,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,OAAO,YAAY;CACpB;AAED;;;GAGG;AACH,oBAAY,aAAa;IACvB,OAAO,IAAI;IACX,KAAK,IAAI;IACT,IAAI,IAAI;CACT;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,IAAI,UAAU,GAAG;IAAC,eAAe,EAAE,OAAO,CAAA;CAAC,CAEhG;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,EAAE,eAAe,CAAC,KAAK,CAAC;IACvC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,0GAA0G;IAC1G,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,eAAe,CAAC,OAAO,CAAC;IACzC,mBAAmB,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,6BAA6B,EAAE,OAAO,CAAC;IAGvC,6BAA6B,EAAE,OAAO,CAAC;CACxC,CAAC;AACF,MAAM,MA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E,aAAa,EAAE,aAAa,CAAC;IAI7B,eAAe,EAAE,OAAO,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,cAAc,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B,iBAAiB,EAAE,OAAO,GAAG,IAAI,CAAC;CACnC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAC,cAAc,EAAE,iBAAiB,EAAC,EAAE,SAAS,GAAG,OAAO,GAAG,IAAI,CAI5F"}
@@ -41,6 +41,28 @@ export var PayloadStatus;
41
41
  export function isGloasBlock(block) {
42
42
  return block.parentBlockHash !== null;
43
43
  }
44
+ /** Which payload the execution engine judged INVALID, relative to the node the invalidation starts from */
45
+ export var LVHInvalidJudged;
46
+ (function (LVHInvalidJudged) {
47
+ /** The from node's own payload, e.g. the head sent in forkchoiceUpdated */
48
+ LVHInvalidJudged["FromBlock"] = "from_block";
49
+ /** A payload built on the from node that is not in fork choice, e.g. a payload rejected by newPayload */
50
+ LVHInvalidJudged["ChildPayload"] = "child_payload";
51
+ })(LVHInvalidJudged || (LVHInvalidJudged = {}));
52
+ export var LVHNotAppliedReason;
53
+ (function (LVHNotAppliedReason) {
54
+ /** VALID verdict whose latest valid hash is not in fork choice */
55
+ LVHNotAppliedReason["UnknownLVH"] = "unknown_lvh";
56
+ /** Fork choice already holds the verdict */
57
+ LVHNotAppliedReason["AlreadyApplied"] = "already_applied";
58
+ /** The verdict contradicts a status the engine already resolved */
59
+ LVHNotAppliedReason["Contradiction"] = "contradiction";
60
+ /** INVALID verdict on a payload that is not in fork choice, with a latest valid hash that is null or unknown */
61
+ LVHNotAppliedReason["UnusableLVH"] = "unusable_lvh";
62
+ /** INVALID verdict that covers no node above the latest valid hash or the justified block */
63
+ LVHNotAppliedReason["NothingToInvalidate"] = "nothing_to_invalidate";
64
+ LVHNotAppliedReason["Error"] = "error";
65
+ })(LVHNotAppliedReason || (LVHNotAppliedReason = {}));
44
66
  /**
45
67
  * The PTC verdict fork choice acts on: `false` once either field has a majority against the
46
68
  * payload, `true` once both have a majority for it, `null` while undecided. A single majority
@@ -1 +1 @@
1
- {"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/protoArray/interface.ts"],"names":[],"mappings":"AAGA,oCAAoC;AACpC,2CAA2C;AAC3C,MAAM,CAAC,MAAM,aAAa,GAAG,oEAAoE,CAAC;AAElG;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;AAO1C;;;;;;;;;;GAUG;AACH,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,kCAAe,CAAA;IACf,sCAAmB,CAAA;IACnB,wCAAqB,CAAA;IACrB,sCAAmB,CAAA;AACrB,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B;AAED;;;GAGG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,uDAAW,CAAA;IACX,mDAAS,CAAA;IACT,iDAAQ,CAAA;AACV,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC5C,OAAO,KAAK,CAAC,eAAe,KAAK,IAAI,CAAC;AACxC,CAAC;AA8ID;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,EAAC,cAAc,EAAE,iBAAiB,EAAY;IAC1E,IAAI,cAAc,KAAK,KAAK,IAAI,iBAAiB,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC1E,IAAI,cA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ZW,mBAAmB,KAAnB,mBAAmB,QAY9B;AAkID;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,EAAC,cAAc,EAAE,iBAAiB,EAAY;IAC1E,IAAI,cAAc,KAAK,KAAK,IAAI,iBAAiB,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAC1E,IAAI,cAAc,KAAK,IAAI,IAAI,iBAAiB,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACvE,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,8 +1,7 @@
1
1
  import { BitArray } from "@chainsafe/ssz";
2
2
  import { DataAvailabilityStatus } from "@lodestar/state-transition";
3
3
  import { Epoch, RootHex, Slot, ValidatorIndex } from "@lodestar/types";
4
- import { LVHExecError } from "./errors.js";
5
- import { LVHExecResponse, PayloadExecutionStatus, PayloadStatus, ProtoBlock, ProtoNode, PtcQuorum } from "./interface.js";
4
+ import { LVHExecResponse, LVHVerdictResult, PayloadExecutionStatus, PayloadStatus, ProtoBlock, ProtoNode, PtcQuorum } from "./interface.js";
6
5
  /**
7
6
  * popcount(attended AND NOT yes) — explicit False-vote count.
8
7
  * Excludes PTC members who didn't attest (the None state).
@@ -40,7 +39,6 @@ export declare class ProtoArray {
40
39
  * Note: undefined array elements indicate that variant doesn't exist for this block
41
40
  */
42
41
  indices: Map<string, VariantIndices>;
43
- lvhError?: LVHExecError;
44
42
  private previousProposerBoost;
45
43
  /** Root read by shouldExtendPayload(), set even while the boost weight is withheld */
46
44
  private proposerBoostRoot;
@@ -272,32 +270,32 @@ export declare class ProtoArray {
272
270
  shouldExtendPayload(blockRoot: RootHex, proposerBoostRoot: RootHex | null): boolean;
273
271
  /**
274
272
  * Apply an execution engine verdict with a latest valid hash (LVH) to the tree. VALID flips Syncing nodes up to the
275
- * LVH node. INVALID invalidates the node identified by `invalidateFromParentBlockRoot/Hash` and its ancestors up to
276
- * the LVH node (exclusive), then every descendant. Returns whether any status changed.
273
+ * LVH node. INVALID invalidates the node identified by `invalidateFromBlockRoot/Hash` and its ancestors up to
274
+ * the LVH node (exclusive), then every descendant. Returns whether any status changed, and if not, why.
277
275
  *
278
- * A null or unknown LVH means the engine only vouches for the queried payload being invalid: the queried node and
279
- * the nodes that inherit that payload (gloas PENDING and EMPTY variants) are invalidated, nothing above them.
276
+ * A verdict never contradicts what fork choice already holds: a node the engine already resolved is never flipped
277
+ * and an INVALID never crosses the justified node. The LVH is unusable when it is null, not an ancestor of the from
278
+ * node, or the walk to it meets such a node.
280
279
  *
281
- * `strict` keeps the consensus failure semantics for verdicts about a payload the engine just processed: a VALID
282
- * or PreMerge node on the invalidated chain poisons the tree. Verdicts from forkchoiceUpdated or about an ancestor
283
- * chain are applied with `strict: false`: a node the engine already validated is never invalidated and the justified
284
- * node is never crossed. If the walk to the LVH meets either, the LVH is treated as unknown.
280
+ * An unusable LVH leaves only the claim about the judged payload. With `LVHInvalidJudged.FromBlock` that is the from
281
+ * node: it and the nodes that inherit its payload (gloas PENDING and EMPTY variants) are invalidated, nothing above
282
+ * them. With `LVHInvalidJudged.ChildPayload` the judged payload is not in the tree and the from node is its parent,
283
+ * so the verdict is dropped.
285
284
  */
286
- validateLatestHash(execResponse: LVHExecResponse, currentSlot: Slot, { strict }?: {
287
- strict?: boolean;
288
- }): boolean;
285
+ validateLatestHash(execResponse: LVHExecResponse, currentSlot: Slot): LVHVerdictResult;
289
286
  /**
290
- * Upper bound (exclusive) for invalidating from `fromIndex` when the engine gave no usable LVH: the parent of the
291
- * last ancestor that still inherits the queried payload. Pre-gloas this is the parent of `fromIndex`. For a gloas
292
- * EMPTY or PENDING node it reaches up to the FULL node that owns the payload. -1 when the chain reaches the root.
287
+ * Index of the nearest ancestor carrying a different payload than `fromIndex`, i.e. the node holding its parent
288
+ * payload. Pre-gloas this is the parent of `fromIndex`. For a gloas EMPTY or PENDING node it skips past the FULL
289
+ * node that owns the payload. -1 when the chain reaches the root.
293
290
  */
294
- private getUnknownLVHIndex;
291
+ private getParentPayloadIndex;
295
292
  private propagateValidExecutionStatusByIndex;
296
293
  /**
297
- * Gloas PENDING and EMPTY variants have no payload of their own, they inherit the execution status of
298
- * the payload they build on, which is their `executionPayloadBlockHash`. Once that payload is VALID, all
299
- * of them are, not only the ones on the chain the validation walked up (e.g. siblings, or blocks
300
- * building on a sibling's EMPTY variant).
294
+ * A node's execution status is that of the payload in its `executionPayloadBlockHash`: its own for FULL, the
295
+ * inherited parent payload for gloas PENDING and EMPTY. Once that payload is VALID every node carrying it is, not
296
+ * only the chain the validation walked up (e.g. siblings, blocks on a sibling's EMPTY variant, or an equivocating
297
+ * block with the same payload). A node is only flipped below a Valid parent, otherwise a later INVALID for the
298
+ * parent would reach it. A parent has a lower index than its children, so the scan updates it first.
301
299
  */
302
300
  private validatePayloadDependents;
303
301
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"protoArray.d.ts","sourceRoot":"","sources":["../../src/protoArray/protoArray.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAC,sBAAsB,EAA8C,MAAM,4BAA4B,CAAC;AAC/G,OAAO,EAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAGrE,OAAO,EAAC,YAAY,EAAyD,MAAM,aAAa,CAAC;AACjG,OAAO,EAGL,eAAe,EACf,sBAAsB,EACtB,aAAa,EACb,UAAU,EACV,SAAS,EACT,SAAS,EAEV,MAAM,gBAAgB,CAAC;AAoBxB;;;GAGG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,GAAG,MAAM,CAYtE;AAQD,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,KAAK,aAAa,GAAG;IAAC,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC;AAIpD,yEAAyE;AACzE,KAAK,oBAAoB,GAAG,MAAM,CAAC;AAC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2CrD;IAED;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAEpC;IAED;;;OAGG;IACH,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAItC;IAED;;;;;;;;;OASG;IACH,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,GAAG,SAAS,GAAG,SAAS,CAM/E;IAED;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAM9D;IAED;;;;;;;OAOG;IACH,oBAAoB,CAClB,aAAa,EAAE,cAAc,EAC7B,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,OAAO,EACpB,aAAa,EAAE,OAAO,GACrB,OAAO,CAoBT;IAED;;;;;;;;;OASG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,GAAG,UAAU,GAAG,SAAS,CAQjF;IAED;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,GAAG,UAAU,CAM7E;IAED;;;;;;;;;OASG;IACH,YAAY,CACV,YAAY,EAAE,OAAO,EACrB,qBAAqB,EAAE,aAAa,EACpC,cAAc,EAAE,OAAO,EACvB,uBAAuB,EAAE,aAAa,GACrC,OAAO,CAwBT;IAED;;OAEG;IACH,iBAAiB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAmCtE;IAED,MAAM,IAAI,MAAM,CAEf;IAED,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,eAAe;CAcxB"}
@@ -3,8 +3,8 @@ import { EFFECTIVE_BALANCE_INCREMENT, GENESIS_EPOCH, GENESIS_SLOT, PTC_SIZE } fr
3
3
  import { computeEpochAtSlot, computeStartSlotAtEpoch } from "@lodestar/state-transition";
4
4
  import { bitCount, toRootHex } from "@lodestar/utils";
5
5
  import { ForkChoiceError, ForkChoiceErrorCode } from "../forkChoice/errors.js";
6
- import { LVHExecErrorCode, ProtoArrayError, ProtoArrayErrorCode } from "./errors.js";
7
- import { ExecutionStatus, HEX_ZERO_HASH, PayloadStatus, isGloasBlock, } from "./interface.js";
6
+ import { ExecutionStatusTransition, ProtoArrayError, ProtoArrayErrorCode } from "./errors.js";
7
+ import { ExecutionStatus, HEX_ZERO_HASH, LVHInvalidJudged, LVHNotAppliedReason, PayloadStatus, isGloasBlock, } from "./interface.js";
8
8
  /**
9
9
  * Threshold for payload timeliness (>50% of PTC must vote)
10
10
  * Spec: gloas/fork-choice.md (PAYLOAD_TIMELY_THRESHOLD = PTC_SIZE // 2)
@@ -67,7 +67,6 @@ export class ProtoArray {
67
67
  * Note: undefined array elements indicate that variant doesn't exist for this block
68
68
  */
69
69
  indices = new Map();
70
- lvhError;
71
70
  previousProposerBoost = null;
72
71
  /** Root read by shouldExtendPayload(), set even while the boost weight is withheld */
73
72
  proposerBoostRoot = null;
@@ -569,8 +568,14 @@ export class ProtoArray {
569
568
  // immediately if we start at FULL. Same pattern as pre-gloas onBlock at line ~533.
570
569
  this.propagateValidExecutionStatusByIndex(pendingIndex);
571
570
  }
572
- // Update bestChild for PENDING node (may now prefer FULL over EMPTY)
573
- this.maybeUpdateBestChildAndDescendant(pendingIndex, fullIndex, currentSlot, proposerBoostRoot);
571
+ // A zero-weight leaf only changes best child and descendant links on its path to the root
572
+ let childIndex = fullIndex;
573
+ let parentIndex = pendingIndex;
574
+ while (parentIndex !== undefined) {
575
+ this.maybeUpdateBestChildAndDescendant(parentIndex, childIndex, currentSlot, proposerBoostRoot);
576
+ childIndex = parentIndex;
577
+ parentIndex = this.nodes[childIndex].parent;
578
+ }
574
579
  }
575
580
  /** Count blocks selected as FULL or EMPTY by the supplied head chain in the inclusive slot range. */
576
581
  getCanonicalPayloadCounts(fromSlot, toSlot, headRoot, headPayloadStatus) {
@@ -837,18 +842,19 @@ export class ProtoArray {
837
842
  }
838
843
  /**
839
844
  * Apply an execution engine verdict with a latest valid hash (LVH) to the tree. VALID flips Syncing nodes up to the
840
- * LVH node. INVALID invalidates the node identified by `invalidateFromParentBlockRoot/Hash` and its ancestors up to
841
- * the LVH node (exclusive), then every descendant. Returns whether any status changed.
845
+ * LVH node. INVALID invalidates the node identified by `invalidateFromBlockRoot/Hash` and its ancestors up to
846
+ * the LVH node (exclusive), then every descendant. Returns whether any status changed, and if not, why.
842
847
  *
843
- * A null or unknown LVH means the engine only vouches for the queried payload being invalid: the queried node and
844
- * the nodes that inherit that payload (gloas PENDING and EMPTY variants) are invalidated, nothing above them.
848
+ * A verdict never contradicts what fork choice already holds: a node the engine already resolved is never flipped
849
+ * and an INVALID never crosses the justified node. The LVH is unusable when it is null, not an ancestor of the from
850
+ * node, or the walk to it meets such a node.
845
851
  *
846
- * `strict` keeps the consensus failure semantics for verdicts about a payload the engine just processed: a VALID
847
- * or PreMerge node on the invalidated chain poisons the tree. Verdicts from forkchoiceUpdated or about an ancestor
848
- * chain are applied with `strict: false`: a node the engine already validated is never invalidated and the justified
849
- * node is never crossed. If the walk to the LVH meets either, the LVH is treated as unknown.
852
+ * An unusable LVH leaves only the claim about the judged payload. With `LVHInvalidJudged.FromBlock` that is the from
853
+ * node: it and the nodes that inherit its payload (gloas PENDING and EMPTY variants) are invalidated, nothing above
854
+ * them. With `LVHInvalidJudged.ChildPayload` the judged payload is not in the tree and the from node is its parent,
855
+ * so the verdict is dropped.
850
856
  */
851
- validateLatestHash(execResponse, currentSlot, { strict = true } = {}) {
857
+ validateLatestHash(execResponse, currentSlot) {
852
858
  // Look reverse because its highly likely node with latestValidExecHash is towards the
853
859
  // the leaves of the forkchoice
854
860
  //
@@ -876,28 +882,26 @@ export class ProtoArray {
876
882
  // We are trying to be as forgiving as possible here because ideally latestValidHashIndex
877
883
  // should be found in the forkchoice
878
884
  if (latestValidHashIndex < 0) {
879
- return false;
885
+ return { applied: false, reason: LVHNotAppliedReason.UnknownLVH };
880
886
  }
881
887
  const { executionStatus } = this.nodes[latestValidHashIndex];
882
888
  if (executionStatus === ExecutionStatus.Valid || executionStatus === ExecutionStatus.PreMerge) {
883
- return false;
889
+ return { applied: false, reason: LVHNotAppliedReason.AlreadyApplied };
884
890
  }
885
- if (!strict) {
886
- // The walk up flips every Syncing ancestor, a lenient verdict must not contradict an invalidated one
887
- let nodeIndex = latestValidHashIndex;
888
- while (nodeIndex !== undefined) {
889
- const node = this.nodes[nodeIndex];
890
- if (node.executionStatus === ExecutionStatus.Valid || node.executionStatus === ExecutionStatus.PreMerge) {
891
- break;
892
- }
893
- if (node.executionStatus === ExecutionStatus.Invalid) {
894
- return false;
895
- }
896
- nodeIndex = node.parent;
891
+ // The walk up flips every Syncing ancestor, it must not contradict an invalidated one
892
+ let nodeIndex = latestValidHashIndex;
893
+ while (nodeIndex !== undefined) {
894
+ const node = this.nodes[nodeIndex];
895
+ if (node.executionStatus === ExecutionStatus.Valid || node.executionStatus === ExecutionStatus.PreMerge) {
896
+ break;
897
+ }
898
+ if (node.executionStatus === ExecutionStatus.Invalid) {
899
+ return { applied: false, reason: LVHNotAppliedReason.Contradiction };
897
900
  }
901
+ nodeIndex = node.parent;
898
902
  }
899
903
  this.propagateValidExecutionStatusByIndex(latestValidHashIndex);
900
- return true;
904
+ return { applied: true };
901
905
  }
902
906
  // In case of invalidation, ideally:
903
907
  // i) Find the invalid payload
@@ -912,51 +916,64 @@ export class ProtoArray {
912
916
  // Mark chain ii) as Invalid if LVH is found and non null, else only invalidate invalid_payload
913
917
  // if its in fcU.
914
918
  //
915
- const { invalidateFromParentBlockRoot, invalidateFromParentBlockHash, latestValidExecHash } = execResponse;
916
- const invalidateFromParentIndex = this.getNodeIndexByRootAndBlockHash(invalidateFromParentBlockRoot, invalidateFromParentBlockHash);
917
- if (invalidateFromParentIndex === undefined) {
918
- throw Error(`Unable to find invalidateFromParentBlockRoot=${invalidateFromParentBlockRoot} invalidateFromParentBlockHash=${invalidateFromParentBlockHash} in forkChoice`);
919
- }
920
- if (!strict && this.nodes[invalidateFromParentIndex].executionStatus !== ExecutionStatus.Syncing) {
921
- return false;
919
+ const { invalidateFromBlockRoot, invalidateFromBlockHash, latestValidExecHash, judged } = execResponse;
920
+ const invalidateFromIndex = this.getNodeIndexByRootAndBlockHash(invalidateFromBlockRoot, invalidateFromBlockHash);
921
+ if (invalidateFromIndex === undefined) {
922
+ throw Error(`Unable to find invalidateFromBlockRoot=${invalidateFromBlockRoot} invalidateFromBlockHash=${invalidateFromBlockHash} in forkChoice`);
923
+ }
924
+ const fromStatus = this.nodes[invalidateFromIndex].executionStatus;
925
+ if (fromStatus !== ExecutionStatus.Syncing) {
926
+ return {
927
+ applied: false,
928
+ reason: fromStatus === ExecutionStatus.Invalid
929
+ ? LVHNotAppliedReason.AlreadyApplied
930
+ : LVHNotAppliedReason.Contradiction,
931
+ };
922
932
  }
923
- let latestValidHashIndex = latestValidExecHash !== null ? this.getNodeIndexFromLVH(latestValidExecHash, invalidateFromParentIndex) : null;
933
+ let latestValidHashIndex = latestValidExecHash !== null ? this.getNodeIndexFromLVH(latestValidExecHash, invalidateFromIndex) : null;
924
934
  if (latestValidHashIndex === null) {
925
- if (strict) {
926
- // The strict from node is the parent of the rejected payload and may be valid, never guess here
927
- throw Error(`Unable to find latestValidExecHash=${latestValidExecHash} in the forkchoice`);
935
+ if (judged === LVHInvalidJudged.ChildPayload) {
936
+ return { applied: false, reason: LVHNotAppliedReason.UnusableLVH };
928
937
  }
929
- latestValidHashIndex = this.getUnknownLVHIndex(invalidateFromParentIndex);
930
- }
931
- if (!strict) {
932
- // Never invalidate the justified block, the EMPTY variant sharing its chain, or anything at or below it in
933
- // the tree. The justified block's own payload (FULL variant) is not part of the checkpoint
934
- const justifiedIndex = this.getDefaultNodeIndex(this.justifiedRoot) ?? -1;
935
- let nodeIndex = invalidateFromParentIndex;
936
- while (nodeIndex !== undefined && nodeIndex > latestValidHashIndex) {
937
- const node = this.nodes[nodeIndex];
938
- if (node.executionStatus !== ExecutionStatus.Syncing ||
939
- nodeIndex <= justifiedIndex ||
940
- (node.blockRoot === this.justifiedRoot && node.payloadStatus === PayloadStatus.EMPTY)) {
941
- // Conflicting LVH: fall back to the unknown LVH bound, but never cross this node
942
- latestValidHashIndex = Math.max(nodeIndex, this.getUnknownLVHIndex(invalidateFromParentIndex));
943
- break;
938
+ latestValidHashIndex = this.getParentPayloadIndex(invalidateFromIndex);
939
+ }
940
+ // Never invalidate the justified block, the EMPTY variant sharing its chain, or anything at or below it in
941
+ // the tree. The justified block's own payload (FULL variant) is not part of the checkpoint
942
+ const justifiedIndex = this.getDefaultNodeIndex(this.justifiedRoot) ?? -1;
943
+ let nodeIndex = invalidateFromIndex;
944
+ while (nodeIndex !== undefined && nodeIndex > latestValidHashIndex) {
945
+ const node = this.nodes[nodeIndex];
946
+ const conflict = node.executionStatus !== ExecutionStatus.Syncing;
947
+ const justified = nodeIndex <= justifiedIndex ||
948
+ (node.blockRoot === this.justifiedRoot && node.payloadStatus === PayloadStatus.EMPTY);
949
+ if (conflict || justified) {
950
+ if (judged === LVHInvalidJudged.FromBlock) {
951
+ // The LVH is unusable: invalidate only the judged payload, but never cross this node
952
+ latestValidHashIndex = Math.max(nodeIndex, this.getParentPayloadIndex(invalidateFromIndex));
944
953
  }
945
- nodeIndex = node.parent;
954
+ else if (conflict) {
955
+ return { applied: false, reason: LVHNotAppliedReason.Contradiction };
956
+ }
957
+ else {
958
+ // The LVH is below the justified node, it still covers everything above it
959
+ latestValidHashIndex = nodeIndex;
960
+ }
961
+ break;
946
962
  }
963
+ nodeIndex = node.parent;
947
964
  }
948
- if (invalidateFromParentIndex <= latestValidHashIndex) {
949
- return false;
965
+ if (invalidateFromIndex <= latestValidHashIndex) {
966
+ return { applied: false, reason: LVHNotAppliedReason.NothingToInvalidate };
950
967
  }
951
- this.propagateInValidExecutionStatusByIndex(invalidateFromParentIndex, latestValidHashIndex, currentSlot);
952
- return true;
968
+ this.propagateInValidExecutionStatusByIndex(invalidateFromIndex, latestValidHashIndex, currentSlot);
969
+ return { applied: true };
953
970
  }
954
971
  /**
955
- * Upper bound (exclusive) for invalidating from `fromIndex` when the engine gave no usable LVH: the parent of the
956
- * last ancestor that still inherits the queried payload. Pre-gloas this is the parent of `fromIndex`. For a gloas
957
- * EMPTY or PENDING node it reaches up to the FULL node that owns the payload. -1 when the chain reaches the root.
972
+ * Index of the nearest ancestor carrying a different payload than `fromIndex`, i.e. the node holding its parent
973
+ * payload. Pre-gloas this is the parent of `fromIndex`. For a gloas EMPTY or PENDING node it skips past the FULL
974
+ * node that owns the payload. -1 when the chain reaches the root.
958
975
  */
959
- getUnknownLVHIndex(fromIndex) {
976
+ getParentPayloadIndex(fromIndex) {
960
977
  const payloadBlockHash = this.nodes[fromIndex].executionPayloadBlockHash;
961
978
  let nodeIndex = fromIndex;
962
979
  let parentIndex = this.nodes[nodeIndex].parent;
@@ -987,18 +1004,22 @@ export class ProtoArray {
987
1004
  }
988
1005
  }
989
1006
  /**
990
- * Gloas PENDING and EMPTY variants have no payload of their own, they inherit the execution status of
991
- * the payload they build on, which is their `executionPayloadBlockHash`. Once that payload is VALID, all
992
- * of them are, not only the ones on the chain the validation walked up (e.g. siblings, or blocks
993
- * building on a sibling's EMPTY variant).
1007
+ * A node's execution status is that of the payload in its `executionPayloadBlockHash`: its own for FULL, the
1008
+ * inherited parent payload for gloas PENDING and EMPTY. Once that payload is VALID every node carrying it is, not
1009
+ * only the chain the validation walked up (e.g. siblings, blocks on a sibling's EMPTY variant, or an equivocating
1010
+ * block with the same payload). A node is only flipped below a Valid parent, otherwise a later INVALID for the
1011
+ * parent would reach it. A parent has a lower index than its children, so the scan updates it first.
994
1012
  */
995
1013
  validatePayloadDependents(payloadHashes) {
996
1014
  for (let nodeIndex = 0; nodeIndex < this.nodes.length; nodeIndex++) {
997
1015
  const node = this.nodes[nodeIndex];
998
- if (node.payloadStatus === PayloadStatus.PENDING &&
999
- node.executionStatus === ExecutionStatus.Syncing &&
1016
+ const parentStatus = node.parent !== undefined ? this.nodes[node.parent].executionStatus : undefined;
1017
+ if (node.executionStatus === ExecutionStatus.Syncing &&
1000
1018
  node.executionPayloadBlockHash !== null &&
1001
- payloadHashes.has(node.executionPayloadBlockHash)) {
1019
+ payloadHashes.has(node.executionPayloadBlockHash) &&
1020
+ (parentStatus === undefined ||
1021
+ parentStatus === ExecutionStatus.Valid ||
1022
+ parentStatus === ExecutionStatus.PreMerge)) {
1002
1023
  // Also flips the sibling EMPTY variant
1003
1024
  this.validateNodeByIndex(nodeIndex);
1004
1025
  }
@@ -1013,9 +1034,9 @@ export class ProtoArray {
1013
1034
  * latestValidHashIndex === -1 implies invalidate all post merge blocks
1014
1035
  * latestValidHashIndex >=0 implies invalidate the chain upwards from invalidateTillIndex
1015
1036
  */
1016
- propagateInValidExecutionStatusByIndex(invalidateFromParentIndex, latestValidHashIndex, currentSlot) {
1017
- // Pass 1: mark invalidateFromParentIndex and its parents invalid
1018
- let invalidateIndex = invalidateFromParentIndex;
1037
+ propagateInValidExecutionStatusByIndex(invalidateFromIndex, latestValidHashIndex, currentSlot) {
1038
+ // Pass 1: mark invalidateFromIndex and its parents invalid
1039
+ let invalidateIndex = invalidateFromIndex;
1019
1040
  while (invalidateIndex !== undefined && invalidateIndex > latestValidHashIndex) {
1020
1041
  const invalidNode = this.invalidateNodeByIndex(invalidateIndex);
1021
1042
  invalidateIndex = invalidNode.parent;
@@ -1057,24 +1078,16 @@ export class ProtoArray {
1057
1078
  }
1058
1079
  invalidateNodeByIndex(nodeIndex) {
1059
1080
  const invalidNode = this.getNodeFromIndex(nodeIndex);
1060
- // If node to be invalidated is pre-merge or valid,it is a catastrophe,
1061
- // and indicates consensus failure and a non recoverable damage.
1062
- //
1063
- // There is no further processing that can be done.
1064
- // Just assign error for marking proto-array perma damaged and throw!
1081
+ // validateLatestHash never starts an invalidation that reaches a pre-merge or valid node
1065
1082
  if (invalidNode.executionStatus === ExecutionStatus.Valid ||
1066
1083
  invalidNode.executionStatus === ExecutionStatus.PreMerge) {
1067
- const lvhCode = invalidNode.executionStatus === ExecutionStatus.Valid
1068
- ? LVHExecErrorCode.ValidToInvalid
1069
- : LVHExecErrorCode.PreMergeToInvalid;
1070
- this.lvhError = {
1071
- lvhCode,
1084
+ throw new ProtoArrayError({
1085
+ code: ProtoArrayErrorCode.INVALID_EXECUTION_STATUS_TRANSITION,
1086
+ transition: invalidNode.executionStatus === ExecutionStatus.Valid
1087
+ ? ExecutionStatusTransition.ValidToInvalid
1088
+ : ExecutionStatusTransition.PreMergeToInvalid,
1072
1089
  blockRoot: invalidNode.blockRoot,
1073
1090
  execHash: invalidNode.executionPayloadBlockHash ?? ZERO_HASH_HEX,
1074
- };
1075
- throw new ProtoArrayError({
1076
- code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
1077
- ...this.lvhError,
1078
1091
  });
1079
1092
  }
1080
1093
  invalidNode.executionStatus = ExecutionStatus.Invalid;
@@ -1092,14 +1105,11 @@ export class ProtoArray {
1092
1105
  validateNodeByIndex(nodeIndex) {
1093
1106
  const validNode = this.getNodeFromIndex(nodeIndex);
1094
1107
  if (validNode.executionStatus === ExecutionStatus.Invalid) {
1095
- this.lvhError = {
1096
- lvhCode: LVHExecErrorCode.InvalidToValid,
1108
+ throw new ProtoArrayError({
1109
+ code: ProtoArrayErrorCode.INVALID_EXECUTION_STATUS_TRANSITION,
1110
+ transition: ExecutionStatusTransition.InvalidToValid,
1097
1111
  blockRoot: validNode.blockRoot,
1098
1112
  execHash: validNode.executionPayloadBlockHash,
1099
- };
1100
- throw new ProtoArrayError({
1101
- code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
1102
- ...this.lvhError,
1103
1113
  });
1104
1114
  }
1105
1115
  if (validNode.executionStatus === ExecutionStatus.Syncing) {
@@ -1158,12 +1168,6 @@ export class ProtoArray {
1158
1168
  * For Gloas, may return PENDING/EMPTY/FULL variants.
1159
1169
  */
1160
1170
  findHead(justifiedRoot, currentSlot) {
1161
- if (this.lvhError) {
1162
- throw new ProtoArrayError({
1163
- code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
1164
- ...this.lvhError,
1165
- });
1166
- }
1167
1171
  // Get canonical node: FULL for pre-Gloas, PENDING for Gloas
1168
1172
  const justifiedIndex = this.getDefaultNodeIndex(justifiedRoot);
1169
1173
  if (justifiedIndex === undefined) {