@lodestar/fork-choice 1.52.0-dev.b76fc9b708 → 1.52.0-dev.eea81beb7c
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 +6 -1
- package/lib/forkChoice/errors.d.ts.map +1 -1
- package/lib/forkChoice/errors.js +1 -0
- package/lib/forkChoice/errors.js.map +1 -1
- package/lib/forkChoice/forkChoice.d.ts +2 -5
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +17 -23
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +3 -6
- package/lib/forkChoice/interface.d.ts.map +1 -1
- package/lib/forkChoice/interface.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/protoArray/interface.d.ts +33 -2
- package/lib/protoArray/interface.d.ts.map +1 -1
- package/lib/protoArray/interface.js +22 -0
- package/lib/protoArray/interface.js.map +1 -1
- package/lib/protoArray/protoArray.d.ts +11 -14
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +79 -85
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +7 -7
- package/src/forkChoice/errors.ts +3 -1
- package/src/forkChoice/forkChoice.ts +18 -24
- package/src/forkChoice/interface.ts +3 -4
- package/src/index.ts +9 -1
- package/src/protoArray/interface.ts +30 -4
- package/src/protoArray/protoArray.ts +83 -97
|
@@ -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
|
-
|
|
56
|
-
|
|
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,
|
|
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,CAA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AAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,KAAK,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,wBAAwB,EAAE,KAAK,CAAC;IAChC,uBAAuB,EAAE,OAAO,CAAC;IACjC,wBAAwB,EAAE,KAAK,CAAC;IAChC,uBAAuB,EAAE,OAAO,CAAC;IAGjC,UAAU,EAAE,OAAO,CAAC;IAIpB,aAAa,EAAE,OAAO,CAAC;IAGvB,cAAc,EAAE,OAAO,CAAC;IAGxB,aAAa,EAAE,cAAc,CAAC;IAE9B,0EAA0E;IAC1E,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;
|
|
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;AAQD,2GAA2G;AAC3G,MAAM,CAAN,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,2EAA2E;IAC3E,4CAAwB,CAAA;IACxB,yGAAyG;IACzG,kDAA8B,CAAA;AAChC,CAAC,EALW,gBAAgB,KAAhB,gBAAgB,QAK3B;AAYD,MAAM,CAAN,IAAY,mBAYX;AAZD,WAAY,mBAAmB;IAC7B,kEAAkE;IAClE,iDAA0B,CAAA;IAC1B,4CAA4C;IAC5C,yDAAkC,CAAA;IAClC,mEAAmE;IACnE,sDAA+B,CAAA;IAC/B,gHAAgH;IAChH,mDAA4B,CAAA;IAC5B,6FAA6F;IAC7F,oEAA6C,CAAA;IAC7C,sCAAe,CAAA;AACjB,CAAC,EAZW,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 {
|
|
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,20 +270,19 @@ 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 `
|
|
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
|
|
279
|
-
*
|
|
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
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
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
|
|
287
|
-
strict?: boolean;
|
|
288
|
-
}): boolean;
|
|
285
|
+
validateLatestHash(execResponse: LVHExecResponse, currentSlot: Slot): LVHVerdictResult;
|
|
289
286
|
/**
|
|
290
287
|
* Upper bound (exclusive) for invalidating from `fromIndex` when the engine gave no usable LVH: the parent of the
|
|
291
288
|
* last ancestor that still inherits the queried payload. Pre-gloas this is the parent of `fromIndex`. For a gloas
|
|
@@ -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;
|
|
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;AAIrE,OAAO,EAGL,eAAe,EAGf,gBAAgB,EAChB,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;AACnC;;;;GAIG;AACH,KAAK,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvE,KAAK,cAAc,GAAG,o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@@ import { computeEpochAtSlot, computeStartSlotAtEpoch } from "@lodestar/state-tra
|
|
|
4
4
|
import { bitCount, toRootHex } from "@lodestar/utils";
|
|
5
5
|
import { ForkChoiceError, ForkChoiceErrorCode } from "../forkChoice/errors.js";
|
|
6
6
|
import { LVHExecErrorCode, ProtoArrayError, ProtoArrayErrorCode } from "./errors.js";
|
|
7
|
-
import { ExecutionStatus, HEX_ZERO_HASH, PayloadStatus, isGloasBlock, } from "./interface.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;
|
|
@@ -837,18 +836,19 @@ export class ProtoArray {
|
|
|
837
836
|
}
|
|
838
837
|
/**
|
|
839
838
|
* 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 `
|
|
841
|
-
* the LVH node (exclusive), then every descendant. Returns whether any status changed.
|
|
839
|
+
* LVH node. INVALID invalidates the node identified by `invalidateFromBlockRoot/Hash` and its ancestors up to
|
|
840
|
+
* the LVH node (exclusive), then every descendant. Returns whether any status changed, and if not, why.
|
|
842
841
|
*
|
|
843
|
-
* A
|
|
844
|
-
*
|
|
842
|
+
* A verdict never contradicts what fork choice already holds: a node the engine already resolved is never flipped
|
|
843
|
+
* and an INVALID never crosses the justified node. The LVH is unusable when it is null, not an ancestor of the from
|
|
844
|
+
* node, or the walk to it meets such a node.
|
|
845
845
|
*
|
|
846
|
-
*
|
|
847
|
-
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
846
|
+
* An unusable LVH leaves only the claim about the judged payload. With `LVHInvalidJudged.FromBlock` that is the from
|
|
847
|
+
* node: it and the nodes that inherit its payload (gloas PENDING and EMPTY variants) are invalidated, nothing above
|
|
848
|
+
* them. With `LVHInvalidJudged.ChildPayload` the judged payload is not in the tree and the from node is its parent,
|
|
849
|
+
* so the verdict is dropped.
|
|
850
850
|
*/
|
|
851
|
-
validateLatestHash(execResponse, currentSlot
|
|
851
|
+
validateLatestHash(execResponse, currentSlot) {
|
|
852
852
|
// Look reverse because its highly likely node with latestValidExecHash is towards the
|
|
853
853
|
// the leaves of the forkchoice
|
|
854
854
|
//
|
|
@@ -876,28 +876,26 @@ export class ProtoArray {
|
|
|
876
876
|
// We are trying to be as forgiving as possible here because ideally latestValidHashIndex
|
|
877
877
|
// should be found in the forkchoice
|
|
878
878
|
if (latestValidHashIndex < 0) {
|
|
879
|
-
return false;
|
|
879
|
+
return { applied: false, reason: LVHNotAppliedReason.UnknownLVH };
|
|
880
880
|
}
|
|
881
881
|
const { executionStatus } = this.nodes[latestValidHashIndex];
|
|
882
882
|
if (executionStatus === ExecutionStatus.Valid || executionStatus === ExecutionStatus.PreMerge) {
|
|
883
|
-
return false;
|
|
883
|
+
return { applied: false, reason: LVHNotAppliedReason.AlreadyApplied };
|
|
884
884
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
return false;
|
|
895
|
-
}
|
|
896
|
-
nodeIndex = node.parent;
|
|
885
|
+
// The walk up flips every Syncing ancestor, it must not contradict an invalidated one
|
|
886
|
+
let nodeIndex = latestValidHashIndex;
|
|
887
|
+
while (nodeIndex !== undefined) {
|
|
888
|
+
const node = this.nodes[nodeIndex];
|
|
889
|
+
if (node.executionStatus === ExecutionStatus.Valid || node.executionStatus === ExecutionStatus.PreMerge) {
|
|
890
|
+
break;
|
|
891
|
+
}
|
|
892
|
+
if (node.executionStatus === ExecutionStatus.Invalid) {
|
|
893
|
+
return { applied: false, reason: LVHNotAppliedReason.Contradiction };
|
|
897
894
|
}
|
|
895
|
+
nodeIndex = node.parent;
|
|
898
896
|
}
|
|
899
897
|
this.propagateValidExecutionStatusByIndex(latestValidHashIndex);
|
|
900
|
-
return true;
|
|
898
|
+
return { applied: true };
|
|
901
899
|
}
|
|
902
900
|
// In case of invalidation, ideally:
|
|
903
901
|
// i) Find the invalid payload
|
|
@@ -912,44 +910,57 @@ export class ProtoArray {
|
|
|
912
910
|
// Mark chain ii) as Invalid if LVH is found and non null, else only invalidate invalid_payload
|
|
913
911
|
// if its in fcU.
|
|
914
912
|
//
|
|
915
|
-
const {
|
|
916
|
-
const
|
|
917
|
-
if (
|
|
918
|
-
throw Error(`Unable to find
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
|
|
913
|
+
const { invalidateFromBlockRoot, invalidateFromBlockHash, latestValidExecHash, judged } = execResponse;
|
|
914
|
+
const invalidateFromIndex = this.getNodeIndexByRootAndBlockHash(invalidateFromBlockRoot, invalidateFromBlockHash);
|
|
915
|
+
if (invalidateFromIndex === undefined) {
|
|
916
|
+
throw Error(`Unable to find invalidateFromBlockRoot=${invalidateFromBlockRoot} invalidateFromBlockHash=${invalidateFromBlockHash} in forkChoice`);
|
|
917
|
+
}
|
|
918
|
+
const fromStatus = this.nodes[invalidateFromIndex].executionStatus;
|
|
919
|
+
if (fromStatus !== ExecutionStatus.Syncing) {
|
|
920
|
+
return {
|
|
921
|
+
applied: false,
|
|
922
|
+
reason: fromStatus === ExecutionStatus.Invalid
|
|
923
|
+
? LVHNotAppliedReason.AlreadyApplied
|
|
924
|
+
: LVHNotAppliedReason.Contradiction,
|
|
925
|
+
};
|
|
922
926
|
}
|
|
923
|
-
let latestValidHashIndex = latestValidExecHash !== null ? this.getNodeIndexFromLVH(latestValidExecHash,
|
|
927
|
+
let latestValidHashIndex = latestValidExecHash !== null ? this.getNodeIndexFromLVH(latestValidExecHash, invalidateFromIndex) : null;
|
|
924
928
|
if (latestValidHashIndex === null) {
|
|
925
|
-
if (
|
|
926
|
-
|
|
927
|
-
throw Error(`Unable to find latestValidExecHash=${latestValidExecHash} in the forkchoice`);
|
|
929
|
+
if (judged === LVHInvalidJudged.ChildPayload) {
|
|
930
|
+
return { applied: false, reason: LVHNotAppliedReason.UnusableLVH };
|
|
928
931
|
}
|
|
929
|
-
latestValidHashIndex = this.getUnknownLVHIndex(
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
932
|
+
latestValidHashIndex = this.getUnknownLVHIndex(invalidateFromIndex);
|
|
933
|
+
}
|
|
934
|
+
// Never invalidate the justified block, the EMPTY variant sharing its chain, or anything at or below it in
|
|
935
|
+
// the tree. The justified block's own payload (FULL variant) is not part of the checkpoint
|
|
936
|
+
const justifiedIndex = this.getDefaultNodeIndex(this.justifiedRoot) ?? -1;
|
|
937
|
+
let nodeIndex = invalidateFromIndex;
|
|
938
|
+
while (nodeIndex !== undefined && nodeIndex > latestValidHashIndex) {
|
|
939
|
+
const node = this.nodes[nodeIndex];
|
|
940
|
+
const conflict = node.executionStatus !== ExecutionStatus.Syncing;
|
|
941
|
+
const justified = nodeIndex <= justifiedIndex ||
|
|
942
|
+
(node.blockRoot === this.justifiedRoot && node.payloadStatus === PayloadStatus.EMPTY);
|
|
943
|
+
if (conflict || justified) {
|
|
944
|
+
if (judged === LVHInvalidJudged.FromBlock) {
|
|
945
|
+
// The LVH is unusable: fall back to the unknown LVH bound, but never cross this node
|
|
946
|
+
latestValidHashIndex = Math.max(nodeIndex, this.getUnknownLVHIndex(invalidateFromIndex));
|
|
944
947
|
}
|
|
945
|
-
|
|
948
|
+
else if (conflict) {
|
|
949
|
+
return { applied: false, reason: LVHNotAppliedReason.Contradiction };
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
// The LVH is below the justified node, it still covers everything above it
|
|
953
|
+
latestValidHashIndex = nodeIndex;
|
|
954
|
+
}
|
|
955
|
+
break;
|
|
946
956
|
}
|
|
957
|
+
nodeIndex = node.parent;
|
|
947
958
|
}
|
|
948
|
-
if (
|
|
949
|
-
return false;
|
|
959
|
+
if (invalidateFromIndex <= latestValidHashIndex) {
|
|
960
|
+
return { applied: false, reason: LVHNotAppliedReason.NothingToInvalidate };
|
|
950
961
|
}
|
|
951
|
-
this.propagateInValidExecutionStatusByIndex(
|
|
952
|
-
return true;
|
|
962
|
+
this.propagateInValidExecutionStatusByIndex(invalidateFromIndex, latestValidHashIndex, currentSlot);
|
|
963
|
+
return { applied: true };
|
|
953
964
|
}
|
|
954
965
|
/**
|
|
955
966
|
* Upper bound (exclusive) for invalidating from `fromIndex` when the engine gave no usable LVH: the parent of the
|
|
@@ -1013,9 +1024,9 @@ export class ProtoArray {
|
|
|
1013
1024
|
* latestValidHashIndex === -1 implies invalidate all post merge blocks
|
|
1014
1025
|
* latestValidHashIndex >=0 implies invalidate the chain upwards from invalidateTillIndex
|
|
1015
1026
|
*/
|
|
1016
|
-
propagateInValidExecutionStatusByIndex(
|
|
1017
|
-
// Pass 1: mark
|
|
1018
|
-
let invalidateIndex =
|
|
1027
|
+
propagateInValidExecutionStatusByIndex(invalidateFromIndex, latestValidHashIndex, currentSlot) {
|
|
1028
|
+
// Pass 1: mark invalidateFromIndex and its parents invalid
|
|
1029
|
+
let invalidateIndex = invalidateFromIndex;
|
|
1019
1030
|
while (invalidateIndex !== undefined && invalidateIndex > latestValidHashIndex) {
|
|
1020
1031
|
const invalidNode = this.invalidateNodeByIndex(invalidateIndex);
|
|
1021
1032
|
invalidateIndex = invalidNode.parent;
|
|
@@ -1057,24 +1068,16 @@ export class ProtoArray {
|
|
|
1057
1068
|
}
|
|
1058
1069
|
invalidateNodeByIndex(nodeIndex) {
|
|
1059
1070
|
const invalidNode = this.getNodeFromIndex(nodeIndex);
|
|
1060
|
-
//
|
|
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!
|
|
1071
|
+
// validateLatestHash never starts an invalidation that reaches a pre-merge or valid node
|
|
1065
1072
|
if (invalidNode.executionStatus === ExecutionStatus.Valid ||
|
|
1066
1073
|
invalidNode.executionStatus === ExecutionStatus.PreMerge) {
|
|
1067
|
-
const lvhCode = invalidNode.executionStatus === ExecutionStatus.Valid
|
|
1068
|
-
? LVHExecErrorCode.ValidToInvalid
|
|
1069
|
-
: LVHExecErrorCode.PreMergeToInvalid;
|
|
1070
|
-
this.lvhError = {
|
|
1071
|
-
lvhCode,
|
|
1072
|
-
blockRoot: invalidNode.blockRoot,
|
|
1073
|
-
execHash: invalidNode.executionPayloadBlockHash ?? ZERO_HASH_HEX,
|
|
1074
|
-
};
|
|
1075
1074
|
throw new ProtoArrayError({
|
|
1076
1075
|
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1077
|
-
|
|
1076
|
+
lvhCode: invalidNode.executionStatus === ExecutionStatus.Valid
|
|
1077
|
+
? LVHExecErrorCode.ValidToInvalid
|
|
1078
|
+
: LVHExecErrorCode.PreMergeToInvalid,
|
|
1079
|
+
blockRoot: invalidNode.blockRoot,
|
|
1080
|
+
execHash: invalidNode.executionPayloadBlockHash ?? ZERO_HASH_HEX,
|
|
1078
1081
|
});
|
|
1079
1082
|
}
|
|
1080
1083
|
invalidNode.executionStatus = ExecutionStatus.Invalid;
|
|
@@ -1092,14 +1095,11 @@ export class ProtoArray {
|
|
|
1092
1095
|
validateNodeByIndex(nodeIndex) {
|
|
1093
1096
|
const validNode = this.getNodeFromIndex(nodeIndex);
|
|
1094
1097
|
if (validNode.executionStatus === ExecutionStatus.Invalid) {
|
|
1095
|
-
|
|
1098
|
+
throw new ProtoArrayError({
|
|
1099
|
+
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1096
1100
|
lvhCode: LVHExecErrorCode.InvalidToValid,
|
|
1097
1101
|
blockRoot: validNode.blockRoot,
|
|
1098
1102
|
execHash: validNode.executionPayloadBlockHash,
|
|
1099
|
-
};
|
|
1100
|
-
throw new ProtoArrayError({
|
|
1101
|
-
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1102
|
-
...this.lvhError,
|
|
1103
1103
|
});
|
|
1104
1104
|
}
|
|
1105
1105
|
if (validNode.executionStatus === ExecutionStatus.Syncing) {
|
|
@@ -1158,12 +1158,6 @@ export class ProtoArray {
|
|
|
1158
1158
|
* For Gloas, may return PENDING/EMPTY/FULL variants.
|
|
1159
1159
|
*/
|
|
1160
1160
|
findHead(justifiedRoot, currentSlot) {
|
|
1161
|
-
if (this.lvhError) {
|
|
1162
|
-
throw new ProtoArrayError({
|
|
1163
|
-
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1164
|
-
...this.lvhError,
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
1161
|
// Get canonical node: FULL for pre-Gloas, PENDING for Gloas
|
|
1168
1162
|
const justifiedIndex = this.getDefaultNodeIndex(justifiedRoot);
|
|
1169
1163
|
if (justifiedIndex === undefined) {
|