@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.
Files changed (67) 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 +4 -6
  4. package/lib/forkChoice/errors.js.map +1 -1
  5. package/lib/forkChoice/fastConfirmation/data.d.ts +1 -1
  6. package/lib/forkChoice/fastConfirmation/data.js.map +1 -1
  7. package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts +4 -4
  8. package/lib/forkChoice/fastConfirmation/fastConfirmationRule.d.ts.map +1 -1
  9. package/lib/forkChoice/fastConfirmation/fastConfirmationRule.js.map +1 -1
  10. package/lib/forkChoice/fastConfirmation/index.d.ts +3 -3
  11. package/lib/forkChoice/fastConfirmation/metrics.d.ts.map +1 -1
  12. package/lib/forkChoice/fastConfirmation/metrics.js +1 -2
  13. package/lib/forkChoice/fastConfirmation/metrics.js.map +1 -1
  14. package/lib/forkChoice/fastConfirmation/rules.d.ts +1 -1
  15. package/lib/forkChoice/fastConfirmation/rules.js.map +1 -1
  16. package/lib/forkChoice/fastConfirmation/types.d.ts +3 -3
  17. package/lib/forkChoice/fastConfirmation/types.d.ts.map +1 -1
  18. package/lib/forkChoice/fastConfirmation/types.js +1 -2
  19. package/lib/forkChoice/fastConfirmation/types.js.map +1 -1
  20. package/lib/forkChoice/fastConfirmation/utils.d.ts +3 -3
  21. package/lib/forkChoice/fastConfirmation/utils.js.map +1 -1
  22. package/lib/forkChoice/forkChoice.d.ts +5 -3
  23. package/lib/forkChoice/forkChoice.d.ts.map +1 -1
  24. package/lib/forkChoice/forkChoice.js +12 -3
  25. package/lib/forkChoice/forkChoice.js.map +1 -1
  26. package/lib/forkChoice/interface.d.ts +5 -2
  27. package/lib/forkChoice/interface.d.ts.map +1 -1
  28. package/lib/forkChoice/interface.js +3 -6
  29. package/lib/forkChoice/interface.js.map +1 -1
  30. package/lib/forkChoice/safeBlocks.d.ts +14 -9
  31. package/lib/forkChoice/safeBlocks.d.ts.map +1 -1
  32. package/lib/forkChoice/safeBlocks.js +46 -21
  33. package/lib/forkChoice/safeBlocks.js.map +1 -1
  34. package/lib/forkChoice/store.d.ts +6 -6
  35. package/lib/forkChoice/store.d.ts.map +1 -1
  36. package/lib/forkChoice/store.js.map +1 -1
  37. package/lib/index.d.ts +1 -1
  38. package/lib/metrics.d.ts +2 -2
  39. package/lib/metrics.d.ts.map +1 -1
  40. package/lib/metrics.js.map +1 -1
  41. package/lib/protoArray/computeDeltas.js.map +1 -1
  42. package/lib/protoArray/errors.js +2 -4
  43. package/lib/protoArray/errors.js.map +1 -1
  44. package/lib/protoArray/interface.d.ts +3 -1
  45. package/lib/protoArray/interface.d.ts.map +1 -1
  46. package/lib/protoArray/interface.js +2 -4
  47. package/lib/protoArray/interface.js.map +1 -1
  48. package/lib/protoArray/protoArray.d.ts +3 -3
  49. package/lib/protoArray/protoArray.d.ts.map +1 -1
  50. package/lib/protoArray/protoArray.js +1 -1
  51. package/lib/protoArray/protoArray.js.map +1 -1
  52. package/package.json +9 -9
  53. package/src/forkChoice/errors.ts +3 -1
  54. package/src/forkChoice/fastConfirmation/data.ts +2 -2
  55. package/src/forkChoice/fastConfirmation/fastConfirmationRule.ts +6 -6
  56. package/src/forkChoice/fastConfirmation/index.ts +3 -3
  57. package/src/forkChoice/fastConfirmation/rules.ts +3 -3
  58. package/src/forkChoice/fastConfirmation/types.ts +3 -3
  59. package/src/forkChoice/fastConfirmation/utils.ts +3 -3
  60. package/src/forkChoice/forkChoice.ts +14 -2
  61. package/src/forkChoice/interface.ts +4 -1
  62. package/src/forkChoice/safeBlocks.ts +54 -22
  63. package/src/forkChoice/store.ts +1 -1
  64. package/src/index.ts +1 -1
  65. package/src/metrics.ts +1 -1
  66. package/src/protoArray/interface.ts +1 -1
  67. package/src/protoArray/protoArray.ts +1 -1
@@ -1,35 +1,67 @@
1
- import {ZERO_HASH_HEX} from "@lodestar/params";
2
- import {Root, RootHex} from "@lodestar/types";
3
- import {fromHex} from "@lodestar/utils";
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
- * Under honest majority and certain network synchronicity assumptions there exists a block
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
- * @deprecated The merged fast-confirmation spec only defines `get_safe_execution_block_hash`.
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 getSafeBeaconBlockRoot(fc: IForkChoice): Root {
14
- const confirmedRoot = fc.getConfirmedRoot();
15
- if (confirmedRoot && fc.hasBlockHex(confirmedRoot)) {
16
- return fromHex(confirmedRoot);
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
- return fc.getJustifiedCheckpoint().root;
31
+
32
+ return getExecutionBlockHash(confirmedBlock);
19
33
  }
20
34
 
21
35
  /**
22
- * Get execution payload hash for the safe block
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/master/fork_choice/safe-block.md#get_safe_execution_block_hash
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 getSafeExecutionBlockHash(forkChoice: IForkChoice): RootHex {
27
- const confirmedRoot = forkChoice.getConfirmedRoot();
28
- if (confirmedRoot) {
29
- const confirmedBlock = forkChoice.getBlockHexDefaultStatus(confirmedRoot);
30
- if (confirmedBlock?.executionPayloadBlockHash) {
31
- return confirmedBlock.executionPayloadBlockHash;
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
- return ZERO_HASH_HEX;
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
  }
@@ -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.ts";
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.ts";
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.ts";
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): boolean {
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