@lodestar/beacon-node 1.46.0 → 1.47.0-dev.0bcaaaebb5

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 (69) hide show
  1. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  2. package/lib/api/impl/lodestar/index.js +11 -12
  3. package/lib/api/impl/lodestar/index.js.map +1 -1
  4. package/lib/api/impl/validator/index.d.ts.map +1 -1
  5. package/lib/api/impl/validator/index.js +11 -21
  6. package/lib/api/impl/validator/index.js.map +1 -1
  7. package/lib/api/impl/validator/utils.d.ts +5 -0
  8. package/lib/api/impl/validator/utils.d.ts.map +1 -1
  9. package/lib/api/impl/validator/utils.js +18 -12
  10. package/lib/api/impl/validator/utils.js.map +1 -1
  11. package/lib/chain/blocks/importBlock.js +1 -1
  12. package/lib/chain/blocks/importBlock.js.map +1 -1
  13. package/lib/chain/blocks/importExecutionPayload.js +1 -1
  14. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  15. package/lib/chain/blocks/index.d.ts.map +1 -1
  16. package/lib/chain/blocks/index.js +3 -5
  17. package/lib/chain/blocks/index.js.map +1 -1
  18. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  19. package/lib/chain/blocks/verifyBlock.js +11 -16
  20. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  21. package/lib/chain/chain.d.ts +1 -1
  22. package/lib/chain/chain.d.ts.map +1 -1
  23. package/lib/chain/chain.js +8 -2
  24. package/lib/chain/chain.js.map +1 -1
  25. package/lib/chain/errors/blockError.d.ts +1 -0
  26. package/lib/chain/errors/blockError.d.ts.map +1 -1
  27. package/lib/chain/options.d.ts +0 -2
  28. package/lib/chain/options.d.ts.map +1 -1
  29. package/lib/chain/options.js.map +1 -1
  30. package/lib/chain/prepareNextSlot.js +1 -1
  31. package/lib/chain/prepareNextSlot.js.map +1 -1
  32. package/lib/chain/produceBlock/produceBlockBody.d.ts +2 -0
  33. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  34. package/lib/chain/produceBlock/produceBlockBody.js +8 -3
  35. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  36. package/lib/chain/seenCache/seenBlockProposers.d.ts +5 -1
  37. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  38. package/lib/chain/seenCache/seenBlockProposers.js +17 -7
  39. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  40. package/lib/chain/validation/block.d.ts.map +1 -1
  41. package/lib/chain/validation/block.js +21 -7
  42. package/lib/chain/validation/block.js.map +1 -1
  43. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  44. package/lib/network/processor/gossipHandlers.js +25 -3
  45. package/lib/network/processor/gossipHandlers.js.map +1 -1
  46. package/lib/sync/range/batch.js +1 -1
  47. package/lib/sync/range/batch.js.map +1 -1
  48. package/lib/sync/range/utils/hashBlocks.d.ts +16 -4
  49. package/lib/sync/range/utils/hashBlocks.d.ts.map +1 -1
  50. package/lib/sync/range/utils/hashBlocks.js +49 -18
  51. package/lib/sync/range/utils/hashBlocks.js.map +1 -1
  52. package/package.json +16 -16
  53. package/src/api/impl/lodestar/index.ts +11 -12
  54. package/src/api/impl/validator/index.ts +21 -26
  55. package/src/api/impl/validator/utils.ts +30 -15
  56. package/src/chain/blocks/importBlock.ts +1 -1
  57. package/src/chain/blocks/importExecutionPayload.ts +1 -1
  58. package/src/chain/blocks/index.ts +3 -5
  59. package/src/chain/blocks/verifyBlock.ts +21 -25
  60. package/src/chain/chain.ts +8 -1
  61. package/src/chain/errors/blockError.ts +1 -1
  62. package/src/chain/options.ts +0 -2
  63. package/src/chain/prepareNextSlot.ts +1 -1
  64. package/src/chain/produceBlock/produceBlockBody.ts +15 -2
  65. package/src/chain/seenCache/seenBlockProposers.ts +24 -7
  66. package/src/chain/validation/block.ts +21 -7
  67. package/src/network/processor/gossipHandlers.ts +26 -3
  68. package/src/sync/range/batch.ts +1 -1
  69. package/src/sync/range/utils/hashBlocks.ts +56 -21
@@ -1,23 +1,54 @@
1
- import { toRootHex } from "@lodestar/utils";
1
+ import { digest } from "@chainsafe/as-sha256";
2
+ import { ssz } from "@lodestar/types";
3
+ import { fromHex, toRootHex } from "@lodestar/utils";
4
+ const ROOT_SIZE = 32;
5
+ const SIGNATURE_SIZE = 96;
6
+ /** Every block and every payload envelope contributes a fixed-size (root, signature) entry */
7
+ const ENTRY_SIZE = ROOT_SIZE + SIGNATURE_SIZE;
8
+ /** uint32 LE counts of block and envelope entries, so the variable-length sections are self-describing */
9
+ const COUNT_SIZE = 4;
10
+ const HEADER_SIZE = COUNT_SIZE * 2;
2
11
  /**
3
- * String to uniquely identify block segments. Used for peer scoring and to compare if batches are equivalent.
12
+ * Root uniquely identifying a batch attempt (its blocks AND payloads). Used for peer scoring and to
13
+ * compare if two attempts are equivalent.
14
+ *
15
+ * Signatures are part of the id for BOTH blocks and payload envelopes, not just their message roots:
16
+ * a peer serving a correct message with a garbage signature would otherwise produce the same id as
17
+ * the honest attempt and escape scoring in `SyncChain.advanceChain`. Signatures are not verified at
18
+ * download time, only during processChainSegment (block signatures in verifyBlocksSignatures,
19
+ * envelope signatures in importExecutionPayload).
20
+ *
21
+ * Entries are written as raw bytes into a single exactly-sized buffer and digested once, so an
22
+ * `Attempt` retains 32 bytes rather than the ~16 KB a full 32-slot gloas batch would need if the
23
+ * roots and signatures were concatenated as hex. sha256 (not a 64-bit hash) because a peer that
24
+ * could force a collision with the winning attempt would escape peer scoring.
4
25
  */
5
- export function hashBlocks(blocks, config) {
6
- switch (blocks.length) {
7
- case 0:
8
- return "0x";
9
- case 1: {
10
- const block0 = blocks[0].getBlock();
11
- return toRootHex(config.getForkTypes(block0.message.slot).SignedBeaconBlock.hashTreeRoot(block0));
12
- }
13
- default: {
14
- const block0 = blocks[0].getBlock();
15
- const blockN = blocks.at(-1)?.getBlock();
16
- return (
17
- // TODO(fulu): should we be doing checks for presence to make sure these do not blow up?
18
- toRootHex(config.getForkTypes(block0.message.slot).SignedBeaconBlock.hashTreeRoot(block0)) +
19
- toRootHex(config.getForkTypes(blockN.message.slot).SignedBeaconBlock.hashTreeRoot(blockN)));
20
- }
26
+ export function hashBlocks(blocks, payloadEnvelopes) {
27
+ // Envelopes without a payload carry no attributable data, so they are skipped entirely. A `null`
28
+ // map and a map whose entries all lack a payload are therefore equivalent, which is intended.
29
+ const envelopes = payloadEnvelopes && payloadEnvelopes.size > 0
30
+ ? Array.from(payloadEnvelopes.entries())
31
+ .filter(([, envelope]) => envelope.hasPayloadEnvelope())
32
+ .sort(([slotA], [slotB]) => slotA - slotB)
33
+ : [];
34
+ const buf = Buffer.allocUnsafe(HEADER_SIZE + (blocks.length + envelopes.length) * ENTRY_SIZE);
35
+ buf.writeUInt32LE(blocks.length, 0);
36
+ buf.writeUInt32LE(envelopes.length, COUNT_SIZE);
37
+ let offset = HEADER_SIZE;
38
+ for (const block of blocks) {
39
+ buf.set(fromHex(block.blockRootHex), offset);
40
+ offset += ROOT_SIZE;
41
+ buf.set(block.getBlock().signature, offset);
42
+ offset += SIGNATURE_SIZE;
21
43
  }
44
+ for (const [, envelope] of envelopes) {
45
+ const signedEnvelope = envelope.getPayloadEnvelope();
46
+ // envelope's root is cached thanks to cachePermanentRootStruct, so this avoids re-hashing
47
+ buf.set(ssz.gloas.ExecutionPayloadEnvelope.hashTreeRoot(signedEnvelope.message), offset);
48
+ offset += ROOT_SIZE;
49
+ buf.set(signedEnvelope.signature, offset);
50
+ offset += SIGNATURE_SIZE;
51
+ }
52
+ return toRootHex(digest(buf));
22
53
  }
23
54
  //# sourceMappingURL=hashBlocks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hashBlocks.js","sourceRoot":"","sources":["../../../../src/sync/range/utils/hashBlocks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAG1C;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAAqB,EAAE,MAAuB;IACvE,QAAQ,MAAM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AAM,CAAC,EAAE,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC;QACrC,MAAM,cAAc,GAAG,QAAQ,CAAC,kBAAkB,EAAE,CAAC;QACrD,0FAA0F;QAC1F,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,wBAAwB,CAAC,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;QACzF,MAAM,IAAI,SAAS,CAAC;QACpB,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC1C,MAAM,IAAI,cAAc,CAAC;IAC3B,CAAC;IAED,OAAO,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAChC,CAAC"}
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.46.0",
14
+ "version": "1.47.0-dev.0bcaaaebb5",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -102,8 +102,8 @@
102
102
  "dependencies": {
103
103
  "@chainsafe/as-sha256": "^1.2.4",
104
104
  "@chainsafe/blst": "^2.2.0",
105
- "@chainsafe/discv5": "^12.0.1",
106
- "@chainsafe/enr": "^6.0.1",
105
+ "@chainsafe/discv5": "^12.0.2",
106
+ "@chainsafe/enr": "^6.0.2",
107
107
  "@chainsafe/libp2p-noise": "^17.0.0",
108
108
  "@chainsafe/libp2p-quic": "^2.1.3",
109
109
  "@chainsafe/persistent-merkle-tree": "^1.3.0",
@@ -126,17 +126,17 @@
126
126
  "@libp2p/peer-id": "^6.0.4",
127
127
  "@libp2p/prometheus-metrics": "^5.0.14",
128
128
  "@libp2p/tcp": "^11.0.13",
129
- "@lodestar/api": "^1.46.0",
130
- "@lodestar/config": "^1.46.0",
131
- "@lodestar/db": "^1.46.0",
132
- "@lodestar/fork-choice": "^1.46.0",
133
- "@lodestar/logger": "^1.46.0",
134
- "@lodestar/params": "^1.46.0",
135
- "@lodestar/reqresp": "^1.46.0",
136
- "@lodestar/state-transition": "^1.46.0",
137
- "@lodestar/types": "^1.46.0",
138
- "@lodestar/utils": "^1.46.0",
139
- "@lodestar/validator": "^1.46.0",
129
+ "@lodestar/api": "^1.47.0-dev.0bcaaaebb5",
130
+ "@lodestar/config": "^1.47.0-dev.0bcaaaebb5",
131
+ "@lodestar/db": "^1.47.0-dev.0bcaaaebb5",
132
+ "@lodestar/fork-choice": "^1.47.0-dev.0bcaaaebb5",
133
+ "@lodestar/logger": "^1.47.0-dev.0bcaaaebb5",
134
+ "@lodestar/params": "^1.47.0-dev.0bcaaaebb5",
135
+ "@lodestar/reqresp": "^1.47.0-dev.0bcaaaebb5",
136
+ "@lodestar/state-transition": "^1.47.0-dev.0bcaaaebb5",
137
+ "@lodestar/types": "^1.47.0-dev.0bcaaaebb5",
138
+ "@lodestar/utils": "^1.47.0-dev.0bcaaaebb5",
139
+ "@lodestar/validator": "^1.47.0-dev.0bcaaaebb5",
140
140
  "@multiformats/multiaddr": "^13.0.1",
141
141
  "datastore-core": "^11.0.2",
142
142
  "datastore-level": "^12.0.2",
@@ -158,7 +158,7 @@
158
158
  "@libp2p/interface-internal": "^3.0.13",
159
159
  "@libp2p/logger": "^6.2.2",
160
160
  "@libp2p/utils": "^7.0.13",
161
- "@lodestar/spec-test-util": "^1.46.0",
161
+ "@lodestar/spec-test-util": "^1.47.0-dev.0bcaaaebb5",
162
162
  "@types/js-yaml": "^4.0.5",
163
163
  "@types/qs": "^6.9.7",
164
164
  "@types/tmp": "^0.2.3",
@@ -175,5 +175,5 @@
175
175
  "beacon",
176
176
  "blockchain"
177
177
  ],
178
- "gitHead": "3873dd5b032d0ad82581fc3416e9628b4f6f2642"
178
+ "gitHead": "27331d862c72b51db6acde433f3aa446f27aa28f"
179
179
  }
@@ -280,7 +280,7 @@ export function getLodestarApi({
280
280
  },
281
281
 
282
282
  async getFastConfirmationInfo() {
283
- const confirmedRoot = chain.forkChoice.getConfirmedRoot();
283
+ const fcrStore = chain.forkChoice.getFastConfirmationStore();
284
284
  const confirmedBlock = chain.forkChoice.getConfirmedBlock();
285
285
  const justifiedCheckpoint = chain.forkChoice.getJustifiedCheckpoint();
286
286
  const finalizedCheckpoint = chain.forkChoice.getFinalizedCheckpoint();
@@ -290,21 +290,20 @@ export function getLodestarApi({
290
290
  return {
291
291
  data: {
292
292
  confirmed: {
293
- rootHex: confirmedRoot,
294
- slot: confirmedBlock?.slot ?? null,
293
+ root: fromHex(fcrStore.confirmedRoot),
294
+ slot: confirmedBlock?.slot ?? 0,
295
295
  },
296
296
  head: {
297
- rootHex: headRoot,
297
+ root: fromHex(headRoot),
298
298
  slot: head.slot,
299
299
  },
300
- justifiedCheckpoint: {
301
- rootHex: justifiedCheckpoint.rootHex,
302
- epoch: justifiedCheckpoint.epoch,
303
- },
304
- finalizedCheckpoint: {
305
- rootHex: finalizedCheckpoint.rootHex,
306
- epoch: finalizedCheckpoint.epoch,
307
- },
300
+ justifiedCheckpoint,
301
+ finalizedCheckpoint,
302
+ previousEpochObservedJustifiedCheckpoint: fcrStore.previousEpochObservedJustifiedCheckpoint,
303
+ currentEpochObservedJustifiedCheckpoint: fcrStore.currentEpochObservedJustifiedCheckpoint,
304
+ previousEpochGreatestUnrealizedCheckpoint: fcrStore.previousEpochGreatestUnrealizedCheckpoint,
305
+ previousSlotHead: fromHex(fcrStore.previousSlotHead),
306
+ currentSlotHead: fromHex(fcrStore.currentSlotHead),
308
307
  },
309
308
  };
310
309
  },
@@ -92,7 +92,12 @@ import {getStateResponseWithRegen} from "../beacon/state/utils.js";
92
92
  import {ApiError, FailureList, IndexedError, NodeIsSyncing, OnlySupportedByDVT} from "../errors.js";
93
93
  import {ApiModules} from "../types.js";
94
94
  import {notWhileSyncing} from "../utils.js";
95
- import {computeSubnetForCommitteesAtSlot, getPubkeysForIndices, selectBlockProductionSource} from "./utils.js";
95
+ import {
96
+ computeSubnetForCommitteesAtSlot,
97
+ getPubkeysForIndices,
98
+ selectBlockProductionSource,
99
+ selectBlockProductionSourceByBoostFactor,
100
+ } from "./utils.js";
96
101
 
97
102
  /**
98
103
  * Cutoff time to wait from start of the slot for execution and builder block production apis to resolve.
@@ -577,8 +582,7 @@ export function getValidatorApi(
577
582
  builderSelection,
578
583
  isBuilderEnabled,
579
584
  strictFeeRecipientCheck,
580
- // winston logger doesn't like bigint
581
- builderBoostFactor: `${builderBoostFactor}`,
585
+ builderBoostFactor,
582
586
  };
583
587
 
584
588
  logger.verbose("Assembling block with produceEngineOrBuilderBlock", loggerContext);
@@ -851,8 +855,8 @@ export function getValidatorApi(
851
855
  randaoReveal,
852
856
  graffiti,
853
857
  feeRecipient,
858
+ strictFeeRecipientCheck,
854
859
  includePayload,
855
- builderSelection,
856
860
  builderBoostFactor,
857
861
  }) {
858
862
  const fork = config.getForkName(slot);
@@ -861,11 +865,6 @@ export function getValidatorApi(
861
865
  throw new ApiError(400, `produceBlockV4 not supported for pre-gloas fork=${fork}`);
862
866
  }
863
867
 
864
- builderSelection = builderSelection ?? routes.validator.BuilderSelection.MaxProfit;
865
- if (builderSelection === routes.validator.BuilderSelection.BuilderOnly) {
866
- logger.warn("Builder selection builderonly is no longer supported, treating as builderalways");
867
- builderSelection = routes.validator.BuilderSelection.BuilderAlways;
868
- }
869
868
  builderBoostFactor = builderBoostFactor ?? BigInt(100);
870
869
  if (builderBoostFactor > MAX_BUILDER_BOOST_FACTOR) {
871
870
  throw new ApiError(400, `Invalid builderBoostFactor=${builderBoostFactor} > MAX_BUILDER_BOOST_FACTOR`);
@@ -896,14 +895,11 @@ export function getValidatorApi(
896
895
  // TODO GLOAS: add external builder api support when it is implemented
897
896
  const isBuildingOnFull = chain.forkChoice.shouldBuildOnFull(parentBlock, slot);
898
897
  const bidParentBlockHash = isBuildingOnFull ? parentBlock.executionPayloadBlockHash : parentBlock.parentBlockHash;
899
- // Bids are only skipped entirely with executiononly or while the circuit breaker is active,
900
- // other engine-preferring selections still build a block with the best bid as fallback in
901
- // case local production fails
902
898
  const circuitBreakerActive = chain.builderCircuitBreaker.isActive(slot);
903
- const builderBid =
904
- builderSelection === routes.validator.BuilderSelection.ExecutionOnly || circuitBreakerActive
905
- ? null
906
- : chain.executionPayloadBidPool.getBestBid(slot, bidParentBlockHash, parentBlockRootHex);
899
+ // Keep a builder bid as fallback unless the circuit breaker is active
900
+ const builderBid = circuitBreakerActive
901
+ ? null
902
+ : chain.executionPayloadBidPool.getBestBid(slot, bidParentBlockHash, parentBlockRootHex);
907
903
 
908
904
  const logCtx = {
909
905
  slot,
@@ -911,8 +907,8 @@ export function getValidatorApi(
911
907
  parentBlockRoot: parentBlockRootHex,
912
908
  parentBlockHash: parentBlock.executionPayloadBlockHash,
913
909
  fork,
914
- builderSelection,
915
910
  builderBoostFactor,
911
+ strictFeeRecipientCheck,
916
912
  circuitBreakerActive,
917
913
  ...(builderBid !== null
918
914
  ? {
@@ -936,6 +932,7 @@ export function getValidatorApi(
936
932
  randaoReveal,
937
933
  graffiti: graffitiBytes,
938
934
  feeRecipient,
935
+ strictFeeRecipientCheck,
939
936
  commonBlockBodyPromise,
940
937
  };
941
938
 
@@ -960,12 +957,8 @@ export function getValidatorApi(
960
957
  chain.produceBlock(baseAttrs)
961
958
  ).then((engineBlock) => {
962
959
  // No need to wait for the bid block if the engine block will always be selected due to
963
- // suspected builder censorship, a builder boost factor of 0 or executionalways selection
964
- if (
965
- engineBlock.shouldOverrideBuilder ||
966
- builderBoostFactor === BigInt(0) ||
967
- builderSelection === routes.validator.BuilderSelection.ExecutionAlways
968
- ) {
960
+ // suspected builder censorship or a builder boost factor of 0
961
+ if (engineBlock.shouldOverrideBuilder || builderBoostFactor === BigInt(0)) {
969
962
  controller.abort();
970
963
  }
971
964
  return engineBlock;
@@ -994,8 +987,7 @@ export function getValidatorApi(
994
987
  });
995
988
  logger.warn("Selected local block: censorship suspected in builder bid", logCtx);
996
989
  } else if (engineResult.status === "fulfilled" && bidResult.status === "fulfilled") {
997
- const result = selectBlockProductionSource({
998
- builderSelection,
990
+ const result = selectBlockProductionSourceByBoostFactor({
999
991
  builderBoostFactor,
1000
992
  engineExecutionPayloadValue: engineResult.value.executionPayloadValue,
1001
993
  // The bid value is the payment to the proposer, in Gwei
@@ -1061,7 +1053,10 @@ export function getValidatorApi(
1061
1053
  root: blockRoot,
1062
1054
  });
1063
1055
  if (chain.opts.persistProducedBlocks) {
1064
- void chain.persistBlock(block, "produced_engine_block");
1056
+ void chain.persistBlock(
1057
+ block,
1058
+ source === ProducedBlockSource.builder ? "produced_builder_block" : "produced_engine_block"
1059
+ );
1065
1060
  }
1066
1061
 
1067
1062
  // Include the payload for self-builds unless disabled (stateless flow)
@@ -59,24 +59,39 @@ export function selectBlockProductionSource({
59
59
  return {source: ProducedBlockSource.engine, reason: EngineBlockSelectionReason.EnginePreferred};
60
60
 
61
61
  case routes.validator.BuilderSelection.Default:
62
- case routes.validator.BuilderSelection.MaxProfit: {
63
- if (builderBoostFactor === BigInt(0)) {
64
- return {source: ProducedBlockSource.engine, reason: EngineBlockSelectionReason.EnginePreferred};
65
- }
66
-
67
- if (builderBoostFactor === MAX_BUILDER_BOOST_FACTOR) {
68
- return {source: ProducedBlockSource.builder, reason: BuilderBlockSelectionReason.BuilderPreferred};
69
- }
70
-
71
- if (engineExecutionPayloadValue >= (builderExecutionPayloadValue * builderBoostFactor) / BigInt(100)) {
72
- return {source: ProducedBlockSource.engine, reason: EngineBlockSelectionReason.BlockValue};
73
- }
74
-
75
- return {source: ProducedBlockSource.builder, reason: BuilderBlockSelectionReason.BlockValue};
76
- }
62
+ case routes.validator.BuilderSelection.MaxProfit:
63
+ return selectBlockProductionSourceByBoostFactor({
64
+ engineExecutionPayloadValue,
65
+ builderExecutionPayloadValue,
66
+ builderBoostFactor,
67
+ });
77
68
 
78
69
  case routes.validator.BuilderSelection.BuilderAlways:
79
70
  case routes.validator.BuilderSelection.BuilderOnly:
80
71
  return {source: ProducedBlockSource.builder, reason: BuilderBlockSelectionReason.BuilderPreferred};
81
72
  }
82
73
  }
74
+
75
+ export function selectBlockProductionSourceByBoostFactor({
76
+ engineExecutionPayloadValue,
77
+ builderExecutionPayloadValue,
78
+ builderBoostFactor,
79
+ }: {
80
+ engineExecutionPayloadValue: bigint;
81
+ builderExecutionPayloadValue: bigint;
82
+ builderBoostFactor: bigint;
83
+ }): BlockSelectionResult {
84
+ if (builderBoostFactor === BigInt(0)) {
85
+ return {source: ProducedBlockSource.engine, reason: EngineBlockSelectionReason.EnginePreferred};
86
+ }
87
+
88
+ if (builderBoostFactor === MAX_BUILDER_BOOST_FACTOR) {
89
+ return {source: ProducedBlockSource.builder, reason: BuilderBlockSelectionReason.BuilderPreferred};
90
+ }
91
+
92
+ if (engineExecutionPayloadValue >= (builderExecutionPayloadValue * builderBoostFactor) / BigInt(100)) {
93
+ return {source: ProducedBlockSource.engine, reason: EngineBlockSelectionReason.BlockValue};
94
+ }
95
+
96
+ return {source: ProducedBlockSource.builder, reason: BuilderBlockSelectionReason.BlockValue};
97
+ }
@@ -445,7 +445,7 @@ export async function importBlock(
445
445
  * zero block hash (pre TTD)
446
446
  */
447
447
  const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
448
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
448
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice);
449
449
  if (headBlockHash !== ZERO_HASH_HEX) {
450
450
  this.executionEngine
451
451
  .notifyForkchoiceUpdate(
@@ -250,7 +250,7 @@ export async function importExecutionPayload(
250
250
  const head = this.forkChoice.getHead();
251
251
  if (!this.opts.disableImportExecutionFcU && blockRootHex === head.blockRoot) {
252
252
  const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
253
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
253
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice);
254
254
  this.executionEngine.notifyForkchoiceUpdate(fork, blockHashHex, safeBlockHash, finalizedBlockHash).catch((e) => {
255
255
  if (!isErrorAborted(e) && !isQueueErrorAborted(e)) {
256
256
  this.logger.error("Error pushing notifyForkchoiceUpdate()", {blockHashHex, finalizedBlockHash}, e);
@@ -108,11 +108,9 @@ export async function processBlocks(
108
108
  throw segmentExecStatus.execAborted.execError;
109
109
  }
110
110
 
111
- if (opts.skipVerifyBlockSignatures !== true) {
112
- for (const blockInput of relevantBlocks) {
113
- const block = blockInput.getBlock().message;
114
- this.seenBlockProposers.add(block.slot, block.proposerIndex);
115
- }
111
+ for (const blockInput of relevantBlocks) {
112
+ const block = blockInput.getBlock().message;
113
+ this.seenBlockProposers.add(block.slot, block.proposerIndex, blockInput.blockRootHex);
116
114
  }
117
115
 
118
116
  const {executionStatuses} = segmentExecStatus;
@@ -6,9 +6,9 @@ import {
6
6
  computeEpochAtSlot,
7
7
  signedBlockToSignedHeader,
8
8
  } from "@lodestar/state-transition";
9
- import {IndexedAttestation, Slot, deneb, ssz} from "@lodestar/types";
10
- import {toRootHex} from "@lodestar/utils";
9
+ import {IndexedAttestation, Slot, deneb} from "@lodestar/types";
11
10
  import {getBlobKzgCommitments} from "../../util/dataColumns.js";
11
+ import {callInNextEventLoop} from "../../util/eventLoop.js";
12
12
  import type {BeaconChain} from "../chain.js";
13
13
  import {BlockError, BlockErrorCode} from "../errors/index.js";
14
14
  import {BlockProcessOpts} from "../options.js";
@@ -193,34 +193,30 @@ export async function verifyBlocksInEpoch(
193
193
  ),
194
194
 
195
195
  // All signatures at once
196
- opts.skipVerifyBlockSignatures !== true
197
- ? verifyBlocksSignatures(
198
- this.config,
199
- this.bls,
200
- this.logger,
201
- this.metrics,
202
- preState0,
203
- blocks,
204
- indexedAttestationsByBlock,
205
- opts
206
- )
207
- : Promise.resolve({verifySignaturesTime: Date.now()}),
196
+ verifyBlocksSignatures(
197
+ this.config,
198
+ this.bls,
199
+ this.logger,
200
+ this.metrics,
201
+ preState0,
202
+ blocks,
203
+ indexedAttestationsByBlock,
204
+ opts
205
+ ),
208
206
 
209
207
  // TODO GLOAS: can verify payload signatures in batch too
210
208
  // maybe chain with the above verifyBlocksSignatures()
211
209
  ]);
212
210
 
213
- if (opts.skipVerifyBlockSignatures !== true) {
214
- for (const block of blocks) {
215
- const {slot, proposerIndex} = block.message;
216
- const signedBlockHeader = signedBlockToSignedHeader(this.config, block);
217
- const blockRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(signedBlockHeader.message));
218
- this.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockRoot, signedBlockHeader);
219
- // Only produce a slashing while importing the block. A block that is verified before it is published
220
- // must not be treated as equivocation evidence since it may never be seen by the network
221
- if (opts.verifyOnly !== true && this.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
222
- this.processProposerEquivocation(slot, proposerIndex);
223
- }
211
+ for (const blockInput of blockInputs) {
212
+ const block = blockInput.getBlock();
213
+ const {slot, proposerIndex} = block.message;
214
+ const signedBlockHeader = signedBlockToSignedHeader(this.config, block);
215
+ this.seenBlockProposers.observeBlockRoot(slot, proposerIndex, blockInput.blockRootHex, signedBlockHeader);
216
+ // Only produce a slashing while importing the block. A block that is verified before it is published
217
+ // must not be treated as equivocation evidence since it may never be seen by the network
218
+ if (opts.verifyOnly !== true && this.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
219
+ callInNextEventLoop(() => this.processProposerEquivocation(slot, proposerIndex));
224
220
  }
225
221
  }
226
222
 
@@ -1072,6 +1072,7 @@ export class BeaconChain implements IBeaconChain {
1072
1072
  graffiti,
1073
1073
  slot,
1074
1074
  feeRecipient,
1075
+ strictFeeRecipientCheck,
1075
1076
  commonBlockBodyPromise,
1076
1077
  parentBlock,
1077
1078
  builderBid,
@@ -1100,6 +1101,7 @@ export class BeaconChain implements IBeaconChain {
1100
1101
  graffiti,
1101
1102
  slot,
1102
1103
  feeRecipient,
1104
+ strictFeeRecipientCheck,
1103
1105
  parentBlock,
1104
1106
  proposerIndex,
1105
1107
  proposerPubKey,
@@ -1217,7 +1219,12 @@ export class BeaconChain implements IBeaconChain {
1217
1219
  this.emitter.emit(routes.events.EventType.proposerSlashing, proposerSlashing);
1218
1220
  this.emitter.emit(ChainEvent.publishProposerSlashing, proposerSlashing);
1219
1221
  this.metrics?.opPool.proposerSlashingsProduced.inc();
1220
- this.logger.info("Produced proposer slashing from observed equivocation", {slot: blockSlot, proposerIndex});
1222
+ this.logger.info("Produced proposer slashing from observed equivocation", {
1223
+ slot: blockSlot,
1224
+ proposerIndex,
1225
+ header1Root: toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(header1.message)),
1226
+ header2Root: toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(header2.message)),
1227
+ });
1221
1228
  } finally {
1222
1229
  this.producingProposerSlashing.delete(proposerIndex);
1223
1230
  }
@@ -118,7 +118,7 @@ export type BlockErrorType =
118
118
  | {code: BlockErrorCode.GENESIS_BLOCK}
119
119
  | {code: BlockErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
120
120
  | {code: BlockErrorCode.ALREADY_KNOWN; root: RootHex}
121
- | {code: BlockErrorCode.REPEAT_PROPOSAL; proposerIndex: ValidatorIndex}
121
+ | {code: BlockErrorCode.REPEAT_PROPOSAL; proposerIndex: ValidatorIndex; root: RootHex}
122
122
  | {code: BlockErrorCode.BLOCK_SLOT_LIMIT_REACHED}
123
123
  | {code: BlockErrorCode.INCORRECT_PROPOSER; proposerIndex: ValidatorIndex}
124
124
  | {code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID; blockSlot: Slot}
@@ -86,8 +86,6 @@ export type BlockProcessOpts = {
86
86
  verifyOnly?: boolean;
87
87
  /** Used to specify to skip execution payload validation */
88
88
  skipVerifyExecutionPayload?: boolean;
89
- /** Used to specify to skip block signatures validation */
90
- skipVerifyBlockSignatures?: boolean;
91
89
  };
92
90
 
93
91
  export type PoolOpts = {
@@ -224,7 +224,7 @@ export class PrepareNextSlotScheduler {
224
224
  this.metrics?.blockPayload.payloadAdvancePrepTime.observe(preparationTime);
225
225
 
226
226
  const safeBlockHash = getSafeExecutionBlockHash(this.chain.forkChoice, this.logger);
227
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.chain.forkChoice, this.logger);
227
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.chain.forkChoice);
228
228
 
229
229
  // awaiting here instead of throwing an async call because there is no other task
230
230
  // left for scheduler and this gives nice semantics to catch and log errors in the
@@ -100,6 +100,8 @@ export type BlockAttributes = {
100
100
  slot: Slot;
101
101
  parentBlock: ProtoBlock;
102
102
  feeRecipient?: string;
103
+ /** Verify that a locally produced execution payload uses `feeRecipient`. */
104
+ strictFeeRecipientCheck?: boolean;
103
105
  /** When provided, build block with this builder bid instead of a self-build bid */
104
106
  builderBid?: gloas.SignedExecutionPayloadBid;
105
107
  };
@@ -201,6 +203,7 @@ export async function produceBlockBody<T extends BlockType>(
201
203
  const {
202
204
  slot: blockSlot,
203
205
  feeRecipient: requestedFeeRecipient,
206
+ strictFeeRecipientCheck,
204
207
  parentBlock,
205
208
  proposerIndex,
206
209
  proposerPubKey,
@@ -271,7 +274,7 @@ export async function produceBlockBody<T extends BlockType>(
271
274
  // full and blinded no longer makes sense in gloas, it might be a good idea to move
272
275
  // this into a completely separate function and have pre/post gloas more separated
273
276
  const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
274
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
277
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice);
275
278
  // TODO GLOAS: post-Gloas, proposer feeRecipient is also carried (signed) in
276
279
  // ProposerPreferencesPool. Consider using this unified cache instead
277
280
  // see https://github.com/ChainSafe/lodestar/issues/9379
@@ -334,6 +337,16 @@ export async function produceBlockBody<T extends BlockType>(
334
337
  executionPayloadValue = payloadRes.executionPayloadValue;
335
338
  shouldOverrideBuilder = payloadRes.shouldOverrideBuilder;
336
339
 
340
+ if (
341
+ strictFeeRecipientCheck &&
342
+ requestedFeeRecipient &&
343
+ !byteArrayEquals(executionPayload.feeRecipient, fromHex(requestedFeeRecipient))
344
+ ) {
345
+ throw Error(
346
+ `Invalid feeRecipient set in engine payload expected=${requestedFeeRecipient} actual=${toHex(executionPayload.feeRecipient)}`
347
+ );
348
+ }
349
+
337
350
  if (blobsBundle === undefined) {
338
351
  throw Error(`Missing blobsBundle response from getPayload at fork=${fork}`);
339
352
  }
@@ -417,7 +430,7 @@ export async function produceBlockBody<T extends BlockType>(
417
430
  }
418
431
 
419
432
  const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
420
- const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
433
+ const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice);
421
434
  const feeRecipient = requestedFeeRecipient ?? this.beaconProposerCache.getOrDefault(proposerIndex);
422
435
  const feeRecipientType = requestedFeeRecipient
423
436
  ? "requested"