@lodestar/fork-choice 1.46.0-dev.20101a8cc1 → 1.46.0-dev.20c6ad786e
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 +4 -6
- package/lib/forkChoice/errors.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/data.d.ts +1 -1
- package/lib/forkChoice/fastConfirmation/data.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts +4 -4
- package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/fastConfirmationRule.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/index.d.ts +3 -3
- package/lib/forkChoice/fastConfirmation/metrics.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/metrics.js +1 -2
- package/lib/forkChoice/fastConfirmation/metrics.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/rules.d.ts +1 -1
- package/lib/forkChoice/fastConfirmation/rules.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/types.d.ts +3 -3
- package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -1
- package/lib/forkChoice/fastConfirmation/types.js +1 -2
- package/lib/forkChoice/fastConfirmation/types.js.map +1 -1
- package/lib/forkChoice/fastConfirmation/utils.d.ts +3 -3
- package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
- package/lib/forkChoice/forkChoice.d.ts +5 -3
- package/lib/forkChoice/forkChoice.d.ts.map +1 -1
- package/lib/forkChoice/forkChoice.js +12 -3
- package/lib/forkChoice/forkChoice.js.map +1 -1
- package/lib/forkChoice/interface.d.ts +5 -2
- package/lib/forkChoice/interface.d.ts.map +1 -1
- package/lib/forkChoice/interface.js +3 -6
- package/lib/forkChoice/interface.js.map +1 -1
- package/lib/forkChoice/safeBlocks.d.ts +14 -9
- package/lib/forkChoice/safeBlocks.d.ts.map +1 -1
- package/lib/forkChoice/safeBlocks.js +46 -21
- package/lib/forkChoice/safeBlocks.js.map +1 -1
- package/lib/forkChoice/store.d.ts +6 -6
- package/lib/forkChoice/store.d.ts.map +1 -1
- package/lib/forkChoice/store.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/metrics.d.ts +2 -2
- package/lib/metrics.d.ts.map +1 -1
- package/lib/metrics.js.map +1 -1
- package/lib/protoArray/computeDeltas.js.map +1 -1
- package/lib/protoArray/errors.js +2 -4
- package/lib/protoArray/errors.js.map +1 -1
- package/lib/protoArray/interface.d.ts +3 -1
- package/lib/protoArray/interface.d.ts.map +1 -1
- package/lib/protoArray/interface.js +2 -4
- package/lib/protoArray/interface.js.map +1 -1
- package/lib/protoArray/protoArray.d.ts +3 -3
- package/lib/protoArray/protoArray.d.ts.map +1 -1
- package/lib/protoArray/protoArray.js +1 -1
- package/lib/protoArray/protoArray.js.map +1 -1
- package/package.json +9 -9
- package/src/forkChoice/errors.ts +3 -1
- package/src/forkChoice/fastConfirmation/data.ts +2 -2
- package/src/forkChoice/fastConfirmation/fastConfirmationRule.ts +6 -6
- package/src/forkChoice/fastConfirmation/index.ts +3 -3
- package/src/forkChoice/fastConfirmation/rules.ts +3 -3
- package/src/forkChoice/fastConfirmation/types.ts +3 -3
- package/src/forkChoice/fastConfirmation/utils.ts +3 -3
- package/src/forkChoice/forkChoice.ts +14 -2
- package/src/forkChoice/interface.ts +4 -1
- package/src/forkChoice/safeBlocks.ts +54 -22
- package/src/forkChoice/store.ts +1 -1
- package/src/index.ts +1 -1
- package/src/metrics.ts +1 -1
- package/src/protoArray/interface.ts +1 -1
- package/src/protoArray/protoArray.ts +1 -1
|
@@ -1,35 +1,67 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import {GENESIS_SLOT} from "@lodestar/params";
|
|
2
|
+
import {RootHex} from "@lodestar/types";
|
|
3
|
+
import {LogLevel, Logger} from "@lodestar/utils";
|
|
4
|
+
import {ExecutionStatus, HEX_ZERO_HASH, ProtoBlock, isGloasBlock} from "../protoArray/interface.js";
|
|
5
|
+
import {ForkChoiceError, ForkChoiceErrorCode} from "./errors.js";
|
|
4
6
|
import {IForkChoice} from "./interface.js";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
8
|
-
* that is safe from re-orgs. Normally this block is pretty close to the head of canonical
|
|
9
|
-
* chain which makes it valuable to expose a safe block to users.
|
|
9
|
+
* Get execution payload hash to report as `safeBlockHash` in `engine_forkchoiceUpdated`.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* Pre-Gloas: the confirmed block's own payload hash.
|
|
12
|
+
* Post-Gloas: the confirmed block's bid `parent_block_hash` — under ePBS the block's own
|
|
13
|
+
* payload may not yet be confirmed canonical, so we report the parent EL block which has
|
|
14
|
+
* been (the bid commits to extending it).
|
|
15
|
+
*
|
|
16
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.13/specs/bellatrix/fast-confirmation.md#new-get_safe_execution_block_hash
|
|
12
17
|
*/
|
|
13
|
-
export function
|
|
14
|
-
const confirmedRoot =
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
export function getSafeExecutionBlockHash(forkChoice: IForkChoice, logger?: Pick<Logger, LogLevel.debug>): RootHex {
|
|
19
|
+
const confirmedRoot = forkChoice.getConfirmedRoot();
|
|
20
|
+
const confirmedBlock = forkChoice.getConfirmedBlock();
|
|
21
|
+
if (confirmedBlock === null) {
|
|
22
|
+
throw new ForkChoiceError({code: ForkChoiceErrorCode.MISSING_PROTO_ARRAY_BLOCK, root: confirmedRoot});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (confirmedBlock.blockRoot === forkChoice.getFinalizedBlock().blockRoot) {
|
|
26
|
+
logger?.debug("Confirmed block is the finalized block", {
|
|
27
|
+
blockRoot: confirmedBlock.blockRoot,
|
|
28
|
+
slot: confirmedBlock.slot,
|
|
29
|
+
});
|
|
17
30
|
}
|
|
18
|
-
|
|
31
|
+
|
|
32
|
+
return getExecutionBlockHash(confirmedBlock);
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
/**
|
|
22
|
-
* Get execution payload hash
|
|
36
|
+
* Get execution payload hash to report as `finalizedBlockHash` in `engine_forkchoiceUpdated`.
|
|
37
|
+
* Mirrors `getSafeExecutionBlockHash`: post-Gloas returns the bid `parent_block_hash`.
|
|
23
38
|
*
|
|
24
|
-
* https://github.com/ethereum/consensus-specs/blob/
|
|
39
|
+
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.13/specs/gloas/fork-choice.md#notify_forkchoice_updated
|
|
25
40
|
*/
|
|
26
|
-
export function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
export function getFinalizedExecutionBlockHash(forkChoice: IForkChoice): RootHex {
|
|
42
|
+
return getExecutionBlockHash(forkChoice.getFinalizedBlock());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getExecutionBlockHash(block: ProtoBlock): RootHex {
|
|
46
|
+
if (isGloasBlock(block)) {
|
|
47
|
+
return block.parentBlockHash;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The genesis block body carries a default execution payload, so it is not an execution block
|
|
51
|
+
// per the spec (`is_execution_block`); its proto-array payload hash comes from the anchor
|
|
52
|
+
// state header instead of a block body and must not be reported as safe.
|
|
53
|
+
if (block.slot === GENESIS_SLOT) {
|
|
54
|
+
return HEX_ZERO_HASH;
|
|
33
55
|
}
|
|
34
|
-
|
|
56
|
+
|
|
57
|
+
const {blockRoot, slot} = block;
|
|
58
|
+
if (block.executionPayloadBlockHash === null && block.executionStatus !== ExecutionStatus.PreMerge) {
|
|
59
|
+
throw new ForkChoiceError({
|
|
60
|
+
code: ForkChoiceErrorCode.MISSING_EXECUTION_PAYLOAD_BLOCK_HASH,
|
|
61
|
+
root: blockRoot,
|
|
62
|
+
slot,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return block.executionPayloadBlockHash ?? HEX_ZERO_HASH;
|
|
35
67
|
}
|
package/src/forkChoice/store.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {EffectiveBalanceIncrements, IBeaconStateView} from "@lodestar/state-transition";
|
|
2
2
|
import {RootHex, Slot, ValidatorIndex, phase0} from "@lodestar/types";
|
|
3
3
|
import {toRootHex} from "@lodestar/utils";
|
|
4
|
-
import {ForkChoiceStateGetter, IFastConfirmationStore} from "./fastConfirmation/types.
|
|
4
|
+
import {ForkChoiceStateGetter, IFastConfirmationStore} from "./fastConfirmation/types.js";
|
|
5
5
|
import {CheckpointWithBalance, CheckpointWithTotalBalance} from "./interface.js";
|
|
6
6
|
|
|
7
7
|
/**
|
package/src/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ export {
|
|
|
16
16
|
type IFastConfirmationRule,
|
|
17
17
|
type IFastConfirmationStore,
|
|
18
18
|
getFastConfirmationMetrics,
|
|
19
|
-
} from "./forkChoice/fastConfirmation/fastConfirmationRule.
|
|
19
|
+
} from "./forkChoice/fastConfirmation/fastConfirmationRule.js";
|
|
20
20
|
export {ForkChoice, type ForkChoiceOpts, UpdateHeadOpt, getCommitteeFraction} from "./forkChoice/forkChoice.js";
|
|
21
21
|
export {
|
|
22
22
|
type AncestorResult,
|
package/src/metrics.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {MetricsRegisterExtra} from "@lodestar/utils";
|
|
2
|
-
import {FastConfirmationMetrics, getFastConfirmationMetrics} from "./forkChoice/fastConfirmation/metrics.
|
|
2
|
+
import {FastConfirmationMetrics, getFastConfirmationMetrics} from "./forkChoice/fastConfirmation/metrics.js";
|
|
3
3
|
import {UpdateHeadOpt} from "./forkChoice/forkChoice.js";
|
|
4
4
|
import {NotReorgedReason} from "./forkChoice/interface.js";
|
|
5
5
|
|
|
@@ -48,7 +48,7 @@ export enum PayloadStatus {
|
|
|
48
48
|
/**
|
|
49
49
|
* Check if a block is in the Gloas fork (ePBS enabled)
|
|
50
50
|
*/
|
|
51
|
-
export function isGloasBlock(block: ProtoBlock):
|
|
51
|
+
export function isGloasBlock(block: ProtoBlock): block is ProtoBlock & {parentBlockHash: RootHex} {
|
|
52
52
|
return block.parentBlockHash !== null;
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -855,7 +855,7 @@ export class ProtoArray {
|
|
|
855
855
|
}
|
|
856
856
|
|
|
857
857
|
/**
|
|
858
|
-
* Spec: should_build_on_full(store, head)
|
|
858
|
+
* Spec: should_build_on_full(store, head, slot)
|
|
859
859
|
*
|
|
860
860
|
* The proposer is forced to build on the EMPTY variant (effectively reorging)
|
|
861
861
|
* when the PTC majority voted that the blob data is not available or that the
|