@lodestar/fork-choice 1.52.0-dev.a9e15e2b94 → 1.52.0-dev.f3cc451977
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/forkChoice.d.ts +4 -2
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +10 -5
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +5 -3
- 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 +2 -33
- package/lib/protoArray/interface.d.ts.map +1 -1
- package/lib/protoArray/interface.js +0 -22
- package/lib/protoArray/interface.js.map +1 -1
- package/lib/protoArray/protoArray.d.ts +14 -11
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +85 -79
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +7 -7
- package/src/forkChoice/forkChoice.ts +11 -6
- package/src/forkChoice/interface.ts +2 -3
- package/src/index.ts +1 -9
- package/src/protoArray/interface.ts +4 -30
- package/src/protoArray/protoArray.ts +97 -83
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"bugs": {
|
|
12
12
|
"url": "https://github.com/ChainSafe/lodestar/issues"
|
|
13
13
|
},
|
|
14
|
-
"version": "1.52.0-dev.
|
|
14
|
+
"version": "1.52.0-dev.f3cc451977",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"exports": {
|
|
17
17
|
".": {
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@chainsafe/ssz": "^1.9.0",
|
|
43
|
-
"@lodestar/config": "^1.52.0-dev.
|
|
44
|
-
"@lodestar/params": "^1.52.0-dev.
|
|
45
|
-
"@lodestar/state-transition": "^1.52.0-dev.
|
|
46
|
-
"@lodestar/types": "^1.52.0-dev.
|
|
47
|
-
"@lodestar/utils": "^1.52.0-dev.
|
|
43
|
+
"@lodestar/config": "^1.52.0-dev.f3cc451977",
|
|
44
|
+
"@lodestar/params": "^1.52.0-dev.f3cc451977",
|
|
45
|
+
"@lodestar/state-transition": "^1.52.0-dev.f3cc451977",
|
|
46
|
+
"@lodestar/types": "^1.52.0-dev.f3cc451977",
|
|
47
|
+
"@lodestar/utils": "^1.52.0-dev.f3cc451977"
|
|
48
48
|
},
|
|
49
49
|
"keywords": [
|
|
50
50
|
"ethereum",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"beacon",
|
|
53
53
|
"blockchain"
|
|
54
54
|
],
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "196c223d6714436e5cb8dd279538bc82f70c37a3"
|
|
56
56
|
}
|
|
@@ -40,8 +40,6 @@ import {
|
|
|
40
40
|
ExecutionStatus,
|
|
41
41
|
HEX_ZERO_HASH,
|
|
42
42
|
LVHExecResponse,
|
|
43
|
-
LVHNotAppliedReason,
|
|
44
|
-
LVHVerdictResult,
|
|
45
43
|
NULL_VOTE_INDEX,
|
|
46
44
|
PayloadExecutionStatus,
|
|
47
45
|
PayloadStatus,
|
|
@@ -700,7 +698,11 @@ export class ForkChoice implements IForkChoice {
|
|
|
700
698
|
head = this.protoArray.findHead(this.fcStore.justified.checkpoint.rootHex, currentSlot);
|
|
701
699
|
} catch (e) {
|
|
702
700
|
// A poisoned tree never recovers, shut the node down instead of failing every head computation
|
|
703
|
-
if (
|
|
701
|
+
if (
|
|
702
|
+
e instanceof ProtoArrayError &&
|
|
703
|
+
(e.type.code === ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE ||
|
|
704
|
+
e.type.code === ProtoArrayErrorCode.INVALID_JUSTIFIED_EXECUTION_STATUS)
|
|
705
|
+
) {
|
|
704
706
|
this.irrecoverableError = e;
|
|
705
707
|
}
|
|
706
708
|
throw e;
|
|
@@ -1631,11 +1633,14 @@ export class ForkChoice implements IForkChoice {
|
|
|
1631
1633
|
* justified's status as well as validate the terminal conditions if terminal block
|
|
1632
1634
|
* becomes valid
|
|
1633
1635
|
*/
|
|
1634
|
-
validateLatestHash(execResponse: LVHExecResponse):
|
|
1636
|
+
validateLatestHash(execResponse: LVHExecResponse, opts?: {strict?: boolean}): boolean {
|
|
1635
1637
|
try {
|
|
1636
|
-
return this.protoArray.validateLatestHash(execResponse, this.fcStore.currentSlot);
|
|
1638
|
+
return this.protoArray.validateLatestHash(execResponse, this.fcStore.currentSlot, opts);
|
|
1637
1639
|
} catch (e) {
|
|
1638
|
-
|
|
1640
|
+
if (e instanceof ProtoArrayError && e.type.code === ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE) {
|
|
1641
|
+
this.irrecoverableError = e;
|
|
1642
|
+
}
|
|
1643
|
+
return false;
|
|
1639
1644
|
}
|
|
1640
1645
|
}
|
|
1641
1646
|
|
|
@@ -3,7 +3,6 @@ import {AttesterSlashing, BeaconBlock, Epoch, IndexedAttestation, Root, RootHex,
|
|
|
3
3
|
import {
|
|
4
4
|
BlockExecutionStatus,
|
|
5
5
|
LVHExecResponse,
|
|
6
|
-
LVHVerdictResult,
|
|
7
6
|
PayloadExecutionStatus,
|
|
8
7
|
PayloadStatus,
|
|
9
8
|
ProtoBlock,
|
|
@@ -362,9 +361,9 @@ export interface IForkChoice {
|
|
|
362
361
|
getCommonAncestorDepth(prevBlock: ProtoBlock, newBlock: ProtoBlock): AncestorResult;
|
|
363
362
|
/**
|
|
364
363
|
* Apply an execution engine verdict with a latest valid hash, see `ProtoArray.validateLatestHash`.
|
|
365
|
-
* Returns whether any execution status changed
|
|
364
|
+
* Returns whether any execution status changed. A consensus failure is recorded in `irrecoverableError`.
|
|
366
365
|
*/
|
|
367
|
-
validateLatestHash(execResponse: LVHExecResponse):
|
|
366
|
+
validateLatestHash(execResponse: LVHExecResponse, opts?: {strict?: boolean}): boolean;
|
|
368
367
|
|
|
369
368
|
/**
|
|
370
369
|
* A dependent root is the block root of the last block before the state transition that decided a specific shuffling
|
package/src/index.ts
CHANGED
|
@@ -41,18 +41,10 @@ export type {
|
|
|
41
41
|
BlockExtraMeta,
|
|
42
42
|
LVHInvalidResponse,
|
|
43
43
|
LVHValidResponse,
|
|
44
|
-
LVHVerdictResult,
|
|
45
44
|
PayloadExecutionStatus,
|
|
46
45
|
ProtoBlock,
|
|
47
46
|
ProtoNode,
|
|
48
47
|
PtcQuorum,
|
|
49
48
|
} from "./protoArray/interface.js";
|
|
50
|
-
export {
|
|
51
|
-
ExecutionStatus,
|
|
52
|
-
LVHInvalidJudged,
|
|
53
|
-
LVHNotAppliedReason,
|
|
54
|
-
PayloadStatus,
|
|
55
|
-
getPtcVerdict,
|
|
56
|
-
isGloasBlock,
|
|
57
|
-
} from "./protoArray/interface.js";
|
|
49
|
+
export {ExecutionStatus, PayloadStatus, getPtcVerdict, isGloasBlock} from "./protoArray/interface.js";
|
|
58
50
|
export {ProtoArray} from "./protoArray/protoArray.js";
|
|
@@ -58,42 +58,16 @@ export type LVHValidResponse = {
|
|
|
58
58
|
/** Resolves the exact node to validate when several nodes carry the same payload hash (gloas variants) */
|
|
59
59
|
blockRoot?: RootHex;
|
|
60
60
|
};
|
|
61
|
-
/** Which payload the execution engine judged INVALID, relative to the node the invalidation starts from */
|
|
62
|
-
export enum LVHInvalidJudged {
|
|
63
|
-
/** The from node's own payload, e.g. the head sent in forkchoiceUpdated */
|
|
64
|
-
FromBlock = "from_block",
|
|
65
|
-
/** A payload built on the from node that is not in fork choice, e.g. a payload rejected by newPayload */
|
|
66
|
-
ChildPayload = "child_payload",
|
|
67
|
-
}
|
|
68
61
|
export type LVHInvalidResponse = {
|
|
69
62
|
executionStatus: ExecutionStatus.Invalid;
|
|
70
63
|
latestValidExecHash: RootHex | null;
|
|
71
|
-
|
|
72
|
-
// EL block hash
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
judged: LVHInvalidJudged;
|
|
64
|
+
invalidateFromParentBlockRoot: RootHex;
|
|
65
|
+
// EL block hash from invalid block's bid (gloas) or payload's parentHash (pre-gloas).
|
|
66
|
+
// Disambiguates which variant of the parent (FULL vs EMPTY) to invalidate from.
|
|
67
|
+
invalidateFromParentBlockHash: RootHex;
|
|
76
68
|
};
|
|
77
69
|
export type LVHExecResponse = LVHValidResponse | LVHInvalidResponse;
|
|
78
70
|
|
|
79
|
-
export enum LVHNotAppliedReason {
|
|
80
|
-
/** VALID verdict whose latest valid hash is not in fork choice */
|
|
81
|
-
UnknownLVH = "unknown_lvh",
|
|
82
|
-
/** Fork choice already holds the verdict */
|
|
83
|
-
AlreadyApplied = "already_applied",
|
|
84
|
-
/** The verdict contradicts a status the engine already resolved */
|
|
85
|
-
Contradiction = "contradiction",
|
|
86
|
-
/** INVALID verdict on a payload that is not in fork choice, with a latest valid hash that is null or unknown */
|
|
87
|
-
UnusableLVH = "unusable_lvh",
|
|
88
|
-
/** INVALID verdict that covers no node above the latest valid hash or the justified block */
|
|
89
|
-
NothingToInvalidate = "nothing_to_invalidate",
|
|
90
|
-
Error = "error",
|
|
91
|
-
}
|
|
92
|
-
export type LVHVerdictResult =
|
|
93
|
-
| {applied: true}
|
|
94
|
-
| {applied: false; reason: Exclude<LVHNotAppliedReason, LVHNotAppliedReason.Error>}
|
|
95
|
-
| {applied: false; reason: LVHNotAppliedReason.Error; error: Error};
|
|
96
|
-
|
|
97
71
|
/**
|
|
98
72
|
* Any execution status that is not definitively invalid.
|
|
99
73
|
* Valid | Syncing | PreMerge
|
|
@@ -4,14 +4,11 @@ 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 {LVHExecErrorCode, ProtoArrayError, ProtoArrayErrorCode} from "./errors.js";
|
|
7
|
+
import {LVHExecError, LVHExecErrorCode, ProtoArrayError, ProtoArrayErrorCode} from "./errors.js";
|
|
8
8
|
import {
|
|
9
9
|
ExecutionStatus,
|
|
10
10
|
HEX_ZERO_HASH,
|
|
11
11
|
LVHExecResponse,
|
|
12
|
-
LVHInvalidJudged,
|
|
13
|
-
LVHNotAppliedReason,
|
|
14
|
-
LVHVerdictResult,
|
|
15
12
|
PayloadExecutionStatus,
|
|
16
13
|
PayloadStatus,
|
|
17
14
|
ProtoBlock,
|
|
@@ -97,6 +94,7 @@ export class ProtoArray {
|
|
|
97
94
|
* Note: undefined array elements indicate that variant doesn't exist for this block
|
|
98
95
|
*/
|
|
99
96
|
indices = new Map<RootHex, VariantIndices>();
|
|
97
|
+
lvhError?: LVHExecError;
|
|
100
98
|
|
|
101
99
|
private previousProposerBoost: ProposerBoost | null = null;
|
|
102
100
|
/** Root read by shouldExtendPayload(), set even while the boost weight is withheld */
|
|
@@ -1022,19 +1020,22 @@ export class ProtoArray {
|
|
|
1022
1020
|
|
|
1023
1021
|
/**
|
|
1024
1022
|
* Apply an execution engine verdict with a latest valid hash (LVH) to the tree. VALID flips Syncing nodes up to the
|
|
1025
|
-
* LVH node. INVALID invalidates the node identified by `
|
|
1026
|
-
* the LVH node (exclusive), then every descendant. Returns whether any status changed
|
|
1023
|
+
* LVH node. INVALID invalidates the node identified by `invalidateFromParentBlockRoot/Hash` and its ancestors up to
|
|
1024
|
+
* the LVH node (exclusive), then every descendant. Returns whether any status changed.
|
|
1027
1025
|
*
|
|
1028
|
-
* A
|
|
1029
|
-
*
|
|
1030
|
-
* node, or the walk to it meets such a node.
|
|
1026
|
+
* A null or unknown LVH means the engine only vouches for the queried payload being invalid: the queried node and
|
|
1027
|
+
* the nodes that inherit that payload (gloas PENDING and EMPTY variants) are invalidated, nothing above them.
|
|
1031
1028
|
*
|
|
1032
|
-
*
|
|
1033
|
-
* node
|
|
1034
|
-
*
|
|
1035
|
-
*
|
|
1029
|
+
* `strict` keeps the consensus failure semantics for verdicts about a payload the engine just processed: a VALID
|
|
1030
|
+
* or PreMerge node on the invalidated chain poisons the tree. Verdicts from forkchoiceUpdated or about an ancestor
|
|
1031
|
+
* chain are applied with `strict: false`: a node the engine already validated is never invalidated and the justified
|
|
1032
|
+
* node is never crossed. If the walk to the LVH meets either, the LVH is treated as unknown.
|
|
1036
1033
|
*/
|
|
1037
|
-
validateLatestHash(
|
|
1034
|
+
validateLatestHash(
|
|
1035
|
+
execResponse: LVHExecResponse,
|
|
1036
|
+
currentSlot: Slot,
|
|
1037
|
+
{strict = true}: {strict?: boolean} = {}
|
|
1038
|
+
): boolean {
|
|
1038
1039
|
// Look reverse because its highly likely node with latestValidExecHash is towards the
|
|
1039
1040
|
// the leaves of the forkchoice
|
|
1040
1041
|
//
|
|
@@ -1064,26 +1065,28 @@ export class ProtoArray {
|
|
|
1064
1065
|
// We are trying to be as forgiving as possible here because ideally latestValidHashIndex
|
|
1065
1066
|
// should be found in the forkchoice
|
|
1066
1067
|
if (latestValidHashIndex < 0) {
|
|
1067
|
-
return
|
|
1068
|
+
return false;
|
|
1068
1069
|
}
|
|
1069
1070
|
const {executionStatus} = this.nodes[latestValidHashIndex];
|
|
1070
1071
|
if (executionStatus === ExecutionStatus.Valid || executionStatus === ExecutionStatus.PreMerge) {
|
|
1071
|
-
return
|
|
1072
|
+
return false;
|
|
1072
1073
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1074
|
+
if (!strict) {
|
|
1075
|
+
// The walk up flips every Syncing ancestor, a lenient verdict must not contradict an invalidated one
|
|
1076
|
+
let nodeIndex: number | undefined = latestValidHashIndex;
|
|
1077
|
+
while (nodeIndex !== undefined) {
|
|
1078
|
+
const node: ProtoNode = this.nodes[nodeIndex];
|
|
1079
|
+
if (node.executionStatus === ExecutionStatus.Valid || node.executionStatus === ExecutionStatus.PreMerge) {
|
|
1080
|
+
break;
|
|
1081
|
+
}
|
|
1082
|
+
if (node.executionStatus === ExecutionStatus.Invalid) {
|
|
1083
|
+
return false;
|
|
1084
|
+
}
|
|
1085
|
+
nodeIndex = node.parent;
|
|
1082
1086
|
}
|
|
1083
|
-
nodeIndex = node.parent;
|
|
1084
1087
|
}
|
|
1085
1088
|
this.propagateValidExecutionStatusByIndex(latestValidHashIndex);
|
|
1086
|
-
return
|
|
1089
|
+
return true;
|
|
1087
1090
|
}
|
|
1088
1091
|
|
|
1089
1092
|
// In case of invalidation, ideally:
|
|
@@ -1099,64 +1102,56 @@ export class ProtoArray {
|
|
|
1099
1102
|
// Mark chain ii) as Invalid if LVH is found and non null, else only invalidate invalid_payload
|
|
1100
1103
|
// if its in fcU.
|
|
1101
1104
|
//
|
|
1102
|
-
const {
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1105
|
+
const {invalidateFromParentBlockRoot, invalidateFromParentBlockHash, latestValidExecHash} = execResponse;
|
|
1106
|
+
const invalidateFromParentIndex = this.getNodeIndexByRootAndBlockHash(
|
|
1107
|
+
invalidateFromParentBlockRoot,
|
|
1108
|
+
invalidateFromParentBlockHash
|
|
1109
|
+
);
|
|
1110
|
+
if (invalidateFromParentIndex === undefined) {
|
|
1105
1111
|
throw Error(
|
|
1106
|
-
`Unable to find
|
|
1112
|
+
`Unable to find invalidateFromParentBlockRoot=${invalidateFromParentBlockRoot} invalidateFromParentBlockHash=${invalidateFromParentBlockHash} in forkChoice`
|
|
1107
1113
|
);
|
|
1108
1114
|
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
return {
|
|
1112
|
-
applied: false,
|
|
1113
|
-
reason:
|
|
1114
|
-
fromStatus === ExecutionStatus.Invalid
|
|
1115
|
-
? LVHNotAppliedReason.AlreadyApplied
|
|
1116
|
-
: LVHNotAppliedReason.Contradiction,
|
|
1117
|
-
};
|
|
1115
|
+
if (!strict && this.nodes[invalidateFromParentIndex].executionStatus !== ExecutionStatus.Syncing) {
|
|
1116
|
+
return false;
|
|
1118
1117
|
}
|
|
1119
1118
|
|
|
1120
1119
|
let latestValidHashIndex =
|
|
1121
|
-
latestValidExecHash !== null ? this.getNodeIndexFromLVH(latestValidExecHash,
|
|
1120
|
+
latestValidExecHash !== null ? this.getNodeIndexFromLVH(latestValidExecHash, invalidateFromParentIndex) : null;
|
|
1122
1121
|
if (latestValidHashIndex === null) {
|
|
1123
|
-
if (
|
|
1124
|
-
|
|
1122
|
+
if (strict) {
|
|
1123
|
+
// The strict from node is the parent of the rejected payload and may be valid, never guess here
|
|
1124
|
+
throw Error(`Unable to find latestValidExecHash=${latestValidExecHash} in the forkchoice`);
|
|
1125
1125
|
}
|
|
1126
|
-
latestValidHashIndex = this.getUnknownLVHIndex(
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
//
|
|
1142
|
-
latestValidHashIndex = Math.max(nodeIndex, this.getUnknownLVHIndex(
|
|
1143
|
-
|
|
1144
|
-
return {applied: false, reason: LVHNotAppliedReason.Contradiction};
|
|
1145
|
-
} else {
|
|
1146
|
-
// The LVH is below the justified node, it still covers everything above it
|
|
1147
|
-
latestValidHashIndex = nodeIndex;
|
|
1126
|
+
latestValidHashIndex = this.getUnknownLVHIndex(invalidateFromParentIndex);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
if (!strict) {
|
|
1130
|
+
// Never invalidate the justified block, the EMPTY variant sharing its chain, or anything at or below it in
|
|
1131
|
+
// the tree. The justified block's own payload (FULL variant) is not part of the checkpoint
|
|
1132
|
+
const justifiedIndex = this.getDefaultNodeIndex(this.justifiedRoot) ?? -1;
|
|
1133
|
+
let nodeIndex: number | undefined = invalidateFromParentIndex;
|
|
1134
|
+
while (nodeIndex !== undefined && nodeIndex > latestValidHashIndex) {
|
|
1135
|
+
const node: ProtoNode = this.nodes[nodeIndex];
|
|
1136
|
+
if (
|
|
1137
|
+
node.executionStatus !== ExecutionStatus.Syncing ||
|
|
1138
|
+
nodeIndex <= justifiedIndex ||
|
|
1139
|
+
(node.blockRoot === this.justifiedRoot && node.payloadStatus === PayloadStatus.EMPTY)
|
|
1140
|
+
) {
|
|
1141
|
+
// Conflicting LVH: fall back to the unknown LVH bound, but never cross this node
|
|
1142
|
+
latestValidHashIndex = Math.max(nodeIndex, this.getUnknownLVHIndex(invalidateFromParentIndex));
|
|
1143
|
+
break;
|
|
1148
1144
|
}
|
|
1149
|
-
|
|
1145
|
+
nodeIndex = node.parent;
|
|
1150
1146
|
}
|
|
1151
|
-
nodeIndex = node.parent;
|
|
1152
1147
|
}
|
|
1153
1148
|
|
|
1154
|
-
if (
|
|
1155
|
-
return
|
|
1149
|
+
if (invalidateFromParentIndex <= latestValidHashIndex) {
|
|
1150
|
+
return false;
|
|
1156
1151
|
}
|
|
1157
1152
|
|
|
1158
|
-
this.propagateInValidExecutionStatusByIndex(
|
|
1159
|
-
return
|
|
1153
|
+
this.propagateInValidExecutionStatusByIndex(invalidateFromParentIndex, latestValidHashIndex, currentSlot);
|
|
1154
|
+
return true;
|
|
1160
1155
|
}
|
|
1161
1156
|
|
|
1162
1157
|
/**
|
|
@@ -1229,12 +1224,12 @@ export class ProtoArray {
|
|
|
1229
1224
|
*/
|
|
1230
1225
|
|
|
1231
1226
|
private propagateInValidExecutionStatusByIndex(
|
|
1232
|
-
|
|
1227
|
+
invalidateFromParentIndex: number,
|
|
1233
1228
|
latestValidHashIndex: number,
|
|
1234
1229
|
currentSlot: Slot
|
|
1235
1230
|
): void {
|
|
1236
|
-
// Pass 1: mark
|
|
1237
|
-
let invalidateIndex: number | undefined =
|
|
1231
|
+
// Pass 1: mark invalidateFromParentIndex and its parents invalid
|
|
1232
|
+
let invalidateIndex: number | undefined = invalidateFromParentIndex;
|
|
1238
1233
|
while (invalidateIndex !== undefined && invalidateIndex > latestValidHashIndex) {
|
|
1239
1234
|
const invalidNode = this.invalidateNodeByIndex(invalidateIndex);
|
|
1240
1235
|
invalidateIndex = invalidNode.parent;
|
|
@@ -1283,19 +1278,28 @@ export class ProtoArray {
|
|
|
1283
1278
|
private invalidateNodeByIndex(nodeIndex: number): ProtoNode {
|
|
1284
1279
|
const invalidNode = this.getNodeFromIndex(nodeIndex);
|
|
1285
1280
|
|
|
1286
|
-
//
|
|
1281
|
+
// If node to be invalidated is pre-merge or valid,it is a catastrophe,
|
|
1282
|
+
// and indicates consensus failure and a non recoverable damage.
|
|
1283
|
+
//
|
|
1284
|
+
// There is no further processing that can be done.
|
|
1285
|
+
// Just assign error for marking proto-array perma damaged and throw!
|
|
1287
1286
|
if (
|
|
1288
1287
|
invalidNode.executionStatus === ExecutionStatus.Valid ||
|
|
1289
1288
|
invalidNode.executionStatus === ExecutionStatus.PreMerge
|
|
1290
1289
|
) {
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1290
|
+
const lvhCode =
|
|
1291
|
+
invalidNode.executionStatus === ExecutionStatus.Valid
|
|
1292
|
+
? LVHExecErrorCode.ValidToInvalid
|
|
1293
|
+
: LVHExecErrorCode.PreMergeToInvalid;
|
|
1294
|
+
|
|
1295
|
+
this.lvhError = {
|
|
1296
|
+
lvhCode,
|
|
1297
1297
|
blockRoot: invalidNode.blockRoot,
|
|
1298
1298
|
execHash: invalidNode.executionPayloadBlockHash ?? ZERO_HASH_HEX,
|
|
1299
|
+
};
|
|
1300
|
+
throw new ProtoArrayError({
|
|
1301
|
+
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1302
|
+
...this.lvhError,
|
|
1299
1303
|
});
|
|
1300
1304
|
}
|
|
1301
1305
|
|
|
@@ -1316,11 +1320,14 @@ export class ProtoArray {
|
|
|
1316
1320
|
private validateNodeByIndex(nodeIndex: number): ProtoNode {
|
|
1317
1321
|
const validNode = this.getNodeFromIndex(nodeIndex);
|
|
1318
1322
|
if (validNode.executionStatus === ExecutionStatus.Invalid) {
|
|
1319
|
-
|
|
1320
|
-
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1323
|
+
this.lvhError = {
|
|
1321
1324
|
lvhCode: LVHExecErrorCode.InvalidToValid,
|
|
1322
1325
|
blockRoot: validNode.blockRoot,
|
|
1323
1326
|
execHash: validNode.executionPayloadBlockHash,
|
|
1327
|
+
};
|
|
1328
|
+
throw new ProtoArrayError({
|
|
1329
|
+
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1330
|
+
...this.lvhError,
|
|
1324
1331
|
});
|
|
1325
1332
|
}
|
|
1326
1333
|
|
|
@@ -1386,6 +1393,13 @@ export class ProtoArray {
|
|
|
1386
1393
|
* For Gloas, may return PENDING/EMPTY/FULL variants.
|
|
1387
1394
|
*/
|
|
1388
1395
|
findHead(justifiedRoot: RootHex, currentSlot: Slot): ProtoNode {
|
|
1396
|
+
if (this.lvhError) {
|
|
1397
|
+
throw new ProtoArrayError({
|
|
1398
|
+
code: ProtoArrayErrorCode.INVALID_LVH_EXECUTION_RESPONSE,
|
|
1399
|
+
...this.lvhError,
|
|
1400
|
+
});
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1389
1403
|
// Get canonical node: FULL for pre-Gloas, PENDING for Gloas
|
|
1390
1404
|
const justifiedIndex = this.getDefaultNodeIndex(justifiedRoot);
|
|
1391
1405
|
if (justifiedIndex === undefined) {
|