@lodestar/beacon-node 1.52.0-dev.b59a889970 → 1.52.0-dev.b9e2dc8d93

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 (91) hide show
  1. package/lib/api/impl/validator/index.d.ts.map +1 -1
  2. package/lib/api/impl/validator/index.js +2 -4
  3. package/lib/api/impl/validator/index.js.map +1 -1
  4. package/lib/chain/errors/executionPayloadBid.d.ts +6 -1
  5. package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
  6. package/lib/chain/errors/executionPayloadBid.js +1 -0
  7. package/lib/chain/errors/executionPayloadBid.js.map +1 -1
  8. package/lib/chain/errors/executionPayloadEnvelope.d.ts +7 -0
  9. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  10. package/lib/chain/errors/executionPayloadEnvelope.js +1 -0
  11. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  12. package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
  13. package/lib/chain/validation/executionPayloadBid.js +17 -2
  14. package/lib/chain/validation/executionPayloadBid.js.map +1 -1
  15. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  16. package/lib/chain/validation/executionPayloadEnvelope.js +21 -5
  17. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  18. package/lib/execution/engine/blockHash.d.ts +12 -0
  19. package/lib/execution/engine/blockHash.d.ts.map +1 -0
  20. package/lib/execution/engine/blockHash.js +17 -0
  21. package/lib/execution/engine/blockHash.js.map +1 -0
  22. package/lib/execution/engine/http.d.ts +2 -2
  23. package/lib/execution/engine/http.d.ts.map +1 -1
  24. package/lib/execution/engine/http.js +13 -7
  25. package/lib/execution/engine/http.js.map +1 -1
  26. package/lib/execution/engine/interface.d.ts +16 -3
  27. package/lib/execution/engine/interface.d.ts.map +1 -1
  28. package/lib/execution/engine/interface.js +11 -0
  29. package/lib/execution/engine/interface.js.map +1 -1
  30. package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -0
  31. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
  32. package/lib/execution/engine/jsonRpcHttpClient.js +14 -6
  33. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
  34. package/lib/execution/engine/jsonRpcTransport.d.ts +2 -2
  35. package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -1
  36. package/lib/execution/engine/jsonRpcTransport.js +4 -4
  37. package/lib/execution/engine/jsonRpcTransport.js.map +1 -1
  38. package/lib/execution/engine/mock.d.ts.map +1 -1
  39. package/lib/execution/engine/mock.js +6 -6
  40. package/lib/execution/engine/mock.js.map +1 -1
  41. package/lib/execution/engine/restHttpClient.d.ts.map +1 -1
  42. package/lib/execution/engine/restHttpClient.js +9 -5
  43. package/lib/execution/engine/restHttpClient.js.map +1 -1
  44. package/lib/execution/engine/restTransport.d.ts +2 -2
  45. package/lib/execution/engine/restTransport.d.ts.map +1 -1
  46. package/lib/execution/engine/restTransport.js +4 -4
  47. package/lib/execution/engine/restTransport.js.map +1 -1
  48. package/lib/execution/engine/signal.d.ts +6 -0
  49. package/lib/execution/engine/signal.d.ts.map +1 -0
  50. package/lib/execution/engine/signal.js +24 -0
  51. package/lib/execution/engine/signal.js.map +1 -0
  52. package/lib/execution/engine/transport.d.ts +2 -2
  53. package/lib/execution/engine/transport.d.ts.map +1 -1
  54. package/lib/index.d.ts +1 -1
  55. package/lib/index.d.ts.map +1 -1
  56. package/lib/index.js +1 -1
  57. package/lib/index.js.map +1 -1
  58. package/lib/metrics/metrics/lodestar.d.ts +1 -0
  59. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  60. package/lib/metrics/metrics/lodestar.js +5 -0
  61. package/lib/metrics/metrics/lodestar.js.map +1 -1
  62. package/lib/network/peers/peerManager.d.ts.map +1 -1
  63. package/lib/network/peers/peerManager.js +10 -1
  64. package/lib/network/peers/peerManager.js.map +1 -1
  65. package/lib/sync/types.d.ts +2 -0
  66. package/lib/sync/types.d.ts.map +1 -1
  67. package/lib/sync/types.js.map +1 -1
  68. package/lib/sync/unknownBlock.d.ts.map +1 -1
  69. package/lib/sync/unknownBlock.js +60 -19
  70. package/lib/sync/unknownBlock.js.map +1 -1
  71. package/package.json +17 -17
  72. package/src/api/impl/validator/index.ts +2 -4
  73. package/src/chain/errors/executionPayloadBid.ts +6 -0
  74. package/src/chain/errors/executionPayloadEnvelope.ts +8 -0
  75. package/src/chain/validation/executionPayloadBid.ts +20 -2
  76. package/src/chain/validation/executionPayloadEnvelope.ts +28 -5
  77. package/src/execution/engine/blockHash.ts +27 -0
  78. package/src/execution/engine/http.ts +18 -10
  79. package/src/execution/engine/interface.ts +18 -3
  80. package/src/execution/engine/jsonRpcHttpClient.ts +26 -14
  81. package/src/execution/engine/jsonRpcTransport.ts +8 -4
  82. package/src/execution/engine/mock.ts +13 -8
  83. package/src/execution/engine/restHttpClient.ts +17 -11
  84. package/src/execution/engine/restTransport.ts +5 -4
  85. package/src/execution/engine/signal.ts +28 -0
  86. package/src/execution/engine/transport.ts +3 -2
  87. package/src/index.ts +6 -1
  88. package/src/metrics/metrics/lodestar.ts +5 -0
  89. package/src/network/peers/peerManager.ts +14 -1
  90. package/src/sync/types.ts +2 -0
  91. package/src/sync/unknownBlock.ts +65 -21
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.b59a889970",
14
+ "version": "1.52.0-dev.b9e2dc8d93",
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
@@ -126,18 +126,18 @@
126
126
  "@libp2p/prometheus-metrics": "^5.0.31",
127
127
  "@libp2p/tcp": "^11.0.30",
128
128
  "@libp2p/utils": "^7.4.6",
129
- "@lodestar/api": "^1.52.0-dev.b59a889970",
130
- "@lodestar/config": "^1.52.0-dev.b59a889970",
131
- "@lodestar/db": "^1.52.0-dev.b59a889970",
132
- "@lodestar/fork-choice": "^1.52.0-dev.b59a889970",
133
- "@lodestar/logger": "^1.52.0-dev.b59a889970",
134
- "@lodestar/native": "^1.52.0-dev.b59a889970",
135
- "@lodestar/params": "^1.52.0-dev.b59a889970",
136
- "@lodestar/reqresp": "^1.52.0-dev.b59a889970",
137
- "@lodestar/state-transition": "^1.52.0-dev.b59a889970",
138
- "@lodestar/types": "^1.52.0-dev.b59a889970",
139
- "@lodestar/utils": "^1.52.0-dev.b59a889970",
140
- "@lodestar/validator": "^1.52.0-dev.b59a889970",
129
+ "@lodestar/api": "^1.52.0-dev.b9e2dc8d93",
130
+ "@lodestar/config": "^1.52.0-dev.b9e2dc8d93",
131
+ "@lodestar/db": "^1.52.0-dev.b9e2dc8d93",
132
+ "@lodestar/fork-choice": "^1.52.0-dev.b9e2dc8d93",
133
+ "@lodestar/logger": "^1.52.0-dev.b9e2dc8d93",
134
+ "@lodestar/native": "^1.52.0-dev.b9e2dc8d93",
135
+ "@lodestar/params": "^1.52.0-dev.b9e2dc8d93",
136
+ "@lodestar/reqresp": "^1.52.0-dev.b9e2dc8d93",
137
+ "@lodestar/state-transition": "^1.52.0-dev.b9e2dc8d93",
138
+ "@lodestar/types": "^1.52.0-dev.b9e2dc8d93",
139
+ "@lodestar/utils": "^1.52.0-dev.b9e2dc8d93",
140
+ "@lodestar/validator": "^1.52.0-dev.b9e2dc8d93",
141
141
  "@multiformats/multiaddr": "^13.0.1",
142
142
  "datastore-core": "^12.0.1",
143
143
  "datastore-level": "^13.0.1",
@@ -156,11 +156,11 @@
156
156
  "xxhash-wasm": "1.0.2"
157
157
  },
158
158
  "devDependencies": {
159
- "@ethereumjs/rlp": "^4.0.1",
159
+ "@ethereumjs/rlp": "^10.1.3",
160
160
  "@libp2p/interface-internal": "^3.2.3",
161
161
  "@libp2p/logger": "^6.2.16",
162
- "@lodestar/spec-test-util": "^1.52.0-dev.b59a889970",
163
- "@lodestar/test-utils": "^1.52.0-dev.b59a889970",
162
+ "@lodestar/spec-test-util": "^1.52.0-dev.b9e2dc8d93",
163
+ "@lodestar/test-utils": "^1.52.0-dev.b9e2dc8d93",
164
164
  "@types/js-yaml": "^4.0.5",
165
165
  "@types/qs": "^6.9.7",
166
166
  "@types/tmp": "^0.2.3",
@@ -174,5 +174,5 @@
174
174
  "beacon",
175
175
  "blockchain"
176
176
  ],
177
- "gitHead": "f2199fafd868c2fcf80f958b2d77c2a57c3ab68d"
177
+ "gitHead": "6d901399fdf22f08aae5e078f4e4c083cbcb3ce3"
178
178
  }
@@ -132,8 +132,6 @@ const BLOCK_PRODUCTION_RACE_CUTOFF_BPS = 1667;
132
132
  * TODO GLOAS: revisit, the block propagates faster as it only commits to a bid and the attestation deadline changed
133
133
  */
134
134
  export const BLOCK_PRODUCTION_RACE_CUTOFF_GLOAS_BPS = 1667;
135
- /** Rejection message of the bid block branch when there is no viable bid to commit to */
136
- const NO_BID_AVAILABLE = "No builder bid available";
137
135
 
138
136
  type BidCandidate = {
139
137
  signedBid: gloas.SignedExecutionPayloadBid;
@@ -1156,7 +1154,7 @@ export function getValidatorApi(
1156
1154
  });
1157
1155
  const bidBlockPromise: ReturnType<typeof chain.produceBlock> = bestBidPromise.then((candidate) => {
1158
1156
  if (candidate === null) {
1159
- throw new Error(NO_BID_AVAILABLE);
1157
+ throw new NoBidReceived();
1160
1158
  }
1161
1159
  metrics?.blockProductionRequests.inc({source: ProducedBlockSource.builder});
1162
1160
  return timed(ProducedBlockSource.builder, () =>
@@ -1270,7 +1268,7 @@ export function getValidatorApi(
1270
1268
  source = ProducedBlockSource.engine;
1271
1269
  bestResult = engineResult;
1272
1270
  const reason =
1273
- bidBlockResult.status === "rejected" && (bidBlockResult.reason as Error).message === NO_BID_AVAILABLE
1271
+ bidBlockResult.status === "rejected" && bidBlockResult.reason instanceof NoBidReceived
1274
1272
  ? EngineBlockSelectionReason.BuilderNoBid
1275
1273
  : bidBlockResult.status === "pending"
1276
1274
  ? EngineBlockSelectionReason.BuilderPending
@@ -23,6 +23,7 @@ export enum ExecutionPayloadBidErrorCode {
23
23
  PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH = "EXECUTION_PAYLOAD_BID_ERROR_PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH",
24
24
  INCLUSION_LIST_BITS_NOT_INCLUSIVE = "EXECUTION_PAYLOAD_BID_ERROR_INCLUSION_LIST_BITS_NOT_INCLUSIVE",
25
25
  BEFORE_INCLUSION_LIST_DEADLINE = "EXECUTION_PAYLOAD_BID_ERROR_BEFORE_INCLUSION_LIST_DEADLINE",
26
+ BEFORE_PAYLOAD_ATTESTATION_DEADLINE = "EXECUTION_PAYLOAD_BID_ERROR_BEFORE_PAYLOAD_ATTESTATION_DEADLINE",
26
27
  }
27
28
 
28
29
  export type ExecutionPayloadBidErrorType =
@@ -99,6 +100,11 @@ export type ExecutionPayloadBidErrorType =
99
100
  builderIndex: BuilderIndex;
100
101
  slot: Slot;
101
102
  }
103
+ | {
104
+ code: ExecutionPayloadBidErrorCode.BEFORE_PAYLOAD_ATTESTATION_DEADLINE;
105
+ builderIndex: BuilderIndex;
106
+ slot: Slot;
107
+ }
102
108
  | {
103
109
  code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH;
104
110
  builderIndex: BuilderIndex;
@@ -20,6 +20,7 @@ export enum ExecutionPayloadEnvelopeErrorCode {
20
20
  INCORRECT_TIMESTAMP = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INCORRECT_TIMESTAMP",
21
21
  EMPTY_TRANSACTION = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_EMPTY_TRANSACTION",
22
22
  WITHDRAWALS_MISMATCH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_WITHDRAWALS_MISMATCH",
23
+ INVALID_BLOCK_HASH = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INVALID_BLOCK_HASH",
23
24
  INVALID_SIGNATURE = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_INVALID_SIGNATURE",
24
25
  PAYLOAD_ENVELOPE_INPUT_MISSING = "EXECUTION_PAYLOAD_ENVELOPE_ERROR_PAYLOAD_ENVELOPE_INPUT_MISSING",
25
26
  }
@@ -112,6 +113,13 @@ export type ExecutionPayloadEnvelopeErrorType =
112
113
  envelopeWithdrawalsRoot: RootHex;
113
114
  expectedWithdrawalsRoot: RootHex;
114
115
  }
116
+ | {
117
+ code: ExecutionPayloadEnvelopeErrorCode.INVALID_BLOCK_HASH;
118
+ slot: Slot;
119
+ root: RootHex;
120
+ blockHash: RootHex;
121
+ computedBlockHash: RootHex;
122
+ }
115
123
  | {code: ExecutionPayloadEnvelopeErrorCode.INVALID_SIGNATURE; slot: Slot; root: RootHex}
116
124
  | {code: ExecutionPayloadEnvelopeErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING; blockRoot: RootHex};
117
125
 
@@ -19,8 +19,9 @@ import {RegenCaller} from "../regen/index.js";
19
19
  /**
20
20
  * Check whether a bid builds on one of the paths compatible with the local head branch.
21
21
  *
22
- * Building directly on the parent is allowed for proposer-boost reorgs, including at epoch
23
- * boundaries when the head is weak enough that a reorg onto the strong parent is predicted.
22
+ * Building directly on the parent is allowed for the slot after the head if the head was late or
23
+ * its proposer equivocated, the conditions under which a proposer may re-org the head. At epoch
24
+ * boundaries the parent must also be the predicted proposer head.
24
25
  * Otherwise the bid must build on the local head's full or empty payload variant, as selected for its slot.
25
26
  */
26
27
  function isBidCompatibleWithHead(
@@ -34,6 +35,11 @@ function isBidCompatibleWithHead(
34
35
  const buildsOnParentPayload = bidParentBlockHash === head.parentBlockHash;
35
36
 
36
37
  if (buildsOnParentBlock && buildsOnParentPayload) {
38
+ const bidSlotOk = head.slot + 1 === bidSlot;
39
+ const headLate = !head.timeliness;
40
+ if (!bidSlotOk || !(headLate || chain.forkChoice.isProposerEquivocation(head))) {
41
+ return false;
42
+ }
37
43
  if (!isStartSlotOfEpoch(bidSlot)) {
38
44
  return true;
39
45
  }
@@ -114,6 +120,18 @@ async function validateExecutionPayloadBid(
114
120
  });
115
121
  }
116
122
 
123
+ // [IGNORE] The bid is received after the payload attestation deadline of `bid.slot - 1`
124
+ if (
125
+ chain.clock.msFromSlot(bid.slot - 1) <
126
+ chain.config.getPayloadAttestationDueMs(chain.config.getForkName(bid.slot - 1))
127
+ ) {
128
+ throw new ExecutionPayloadBidError(GossipAction.IGNORE, {
129
+ code: ExecutionPayloadBidErrorCode.BEFORE_PAYLOAD_ATTESTATION_DEADLINE,
130
+ builderIndex: bid.builderIndex,
131
+ slot: bid.slot,
132
+ });
133
+ }
134
+
117
135
  // [IGNORE] The bid is received after the inclusion list deadline of `bid.slot - 1`
118
136
  if (
119
137
  isForkPostHeze(chain.config.getForkName(bid.slot)) &&
@@ -7,6 +7,7 @@ import {
7
7
  } from "@lodestar/state-transition";
8
8
  import {gloas, ssz} from "@lodestar/types";
9
9
  import {byteArrayEquals, toRootHex} from "@lodestar/utils";
10
+ import {computeExecutionBlockHash} from "../../execution/engine/blockHash.js";
10
11
  import {
11
12
  getBeaconBlockRootFromExecutionPayloadEnvelopeSerialized,
12
13
  getSlotFromExecutionPayloadEnvelopeSerialized,
@@ -55,7 +56,7 @@ export function validateGossipExecutionPayloadEnvelopeSerialized(
55
56
 
56
57
  const maxTransactionCount = getMaxTransactionCount(chain, block, payloadInput);
57
58
  if (BigInt(transactionCount) > maxTransactionCount) {
58
- throw new ExecutionPayloadEnvelopeError(GossipAction.IGNORE, {
59
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
59
60
  code: ExecutionPayloadEnvelopeErrorCode.TOO_MANY_TRANSACTIONS,
60
61
  slot,
61
62
  root: blockRootHex,
@@ -199,12 +200,13 @@ async function validateExecutionPayloadEnvelope(
199
200
  });
200
201
  }
201
202
 
202
- // [IGNORE] The number of transactions is within the limit implied by the parent payload's gas limit
203
- // TODO GLOAS: [REJECT] once https://github.com/ethereum/consensus-specs/pull/5802 is released,
204
- // also in validateGossipExecutionPayloadEnvelopeSerialized
203
+ // Execution request and withdrawal count limits are enforced by the SSZ list limits on decode
204
+
205
+ // [REJECT] The number of transactions is within the limit implied by the parent payload's gas limit,
206
+ // also checked before deserialization in validateGossipExecutionPayloadEnvelopeSerialized
205
207
  const maxTransactionCount = getMaxTransactionCount(chain, block, payloadInput);
206
208
  if (BigInt(payload.transactions.length) > maxTransactionCount) {
207
- throw new ExecutionPayloadEnvelopeError(GossipAction.IGNORE, {
209
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
208
210
  code: ExecutionPayloadEnvelopeErrorCode.TOO_MANY_TRANSACTIONS,
209
211
  slot: payload.slotNumber,
210
212
  root: blockRootHex,
@@ -251,6 +253,8 @@ async function validateExecutionPayloadEnvelope(
251
253
  }
252
254
 
253
255
  // [REJECT] The payload contains no empty transactions
256
+ // An empty transaction is a deletion in the transactions trie, so trailing empty transactions would not change
257
+ // the block hash. The EL rejects such a payload, as `verify_and_notify_new_payload` does before hashing.
254
258
  for (let i = 0; i < payload.transactions.length; i++) {
255
259
  if (payload.transactions.getSize(i) === 0) {
256
260
  throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
@@ -275,6 +279,25 @@ async function validateExecutionPayloadEnvelope(
275
279
  });
276
280
  }
277
281
 
282
+ // [REJECT] The payload's block hash is computed correctly
283
+ const timer = chain.metrics?.gossipExecutionPayloadEnvelope.blockHashTime.startTimer();
284
+ const computedBlockHash = computeExecutionBlockHash(
285
+ blockState.forkName,
286
+ payload,
287
+ envelope.parentBeaconBlockRoot,
288
+ envelope.executionRequests
289
+ );
290
+ timer?.();
291
+ if (!byteArrayEquals(computedBlockHash, payload.blockHash)) {
292
+ throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
293
+ code: ExecutionPayloadEnvelopeErrorCode.INVALID_BLOCK_HASH,
294
+ slot: payload.slotNumber,
295
+ root: blockRootHex,
296
+ blockHash: toRootHex(payload.blockHash),
297
+ computedBlockHash: toRootHex(computedBlockHash),
298
+ });
299
+ }
300
+
278
301
  // [REJECT] `signed_execution_payload_envelope.signature` is valid as verified
279
302
  // by `verify_execution_payload_envelope_signature`.
280
303
  const signatureSet = getExecutionPayloadEnvelopeSignatureSet(
@@ -0,0 +1,27 @@
1
+ import {computeExecutionBlockHash as computeExecutionBlockHashNative} from "@lodestar/native/execution-block-hash";
2
+ import {ForkPostBellatrix, ForkSeq, isForkPostElectra} from "@lodestar/params";
3
+ import {ExecutionPayload, ExecutionRequests, Root, sszTypesFor} from "@lodestar/types";
4
+
5
+ /**
6
+ * Compute the execution block hash of `payload`: keccak256 of the RLP-encoded execution block header,
7
+ * with the header fields laid out as in execution-specs for the execution fork paired with `fork`.
8
+ *
9
+ * `parentBeaconBlockRoot` is required from deneb and `executionRequests` from electra.
10
+ *
11
+ * Throws if a transaction is empty. It would be a deletion in the transactions trie and not change the hash.
12
+ */
13
+ export function computeExecutionBlockHash(
14
+ fork: ForkPostBellatrix,
15
+ payload: ExecutionPayload,
16
+ parentBeaconBlockRoot: Root | null,
17
+ executionRequests: ExecutionRequests | null
18
+ ): Uint8Array {
19
+ return computeExecutionBlockHashNative(
20
+ ForkSeq[fork],
21
+ sszTypesFor(fork).ExecutionPayload.serialize(payload),
22
+ parentBeaconBlockRoot ?? undefined,
23
+ executionRequests !== null && isForkPostElectra(fork)
24
+ ? sszTypesFor(fork).ExecutionRequests.serialize(executionRequests)
25
+ : undefined
26
+ );
27
+ }
@@ -2,7 +2,7 @@ import {Logger} from "@lodestar/logger";
2
2
  import {ForkName, ForkPostFulu, ForkSeq, SLOTS_PER_EPOCH, isForkPostBellatrix} from "@lodestar/params";
3
3
  import {BlobsBundle, ExecutionPayload, ExecutionRequests, Root, RootHex, Wei, bellatrix} from "@lodestar/types";
4
4
  import {BlobAndProofV2} from "@lodestar/types/fulu";
5
- import {isErrorAborted} from "@lodestar/utils";
5
+ import {ErrorAborted, isErrorAborted} from "@lodestar/utils";
6
6
  import {Metrics} from "../../metrics/index.js";
7
7
  import {EPOCHS_PER_BATCH} from "../../sync/constants.js";
8
8
  import {getLodestarClientVersion} from "../../util/metadata.js";
@@ -11,6 +11,8 @@ import {JobItemQueue} from "../../util/queue/index.js";
11
11
  import {
12
12
  ClientVersion,
13
13
  ExecutePayloadResponse,
14
+ ExecutionEngineError,
15
+ ExecutionEngineErrorCode,
14
16
  ExecutionEngineState,
15
17
  ExecutionPayloadStatus,
16
18
  ForkchoiceUpdatedResult,
@@ -334,13 +336,18 @@ export class ExecutionEngineHttp implements IExecutionEngine {
334
336
  headBlockHash: RootHex,
335
337
  safeBlockHash: RootHex,
336
338
  finalizedBlockHash: RootHex,
337
- payloadAttributes?: PayloadAttributes
339
+ payloadAttributes?: PayloadAttributes,
340
+ signal?: AbortSignal
338
341
  ): Promise<ForkchoiceUpdatedResult> {
339
- const result = await this.enqueue(() =>
340
- this.withTransport(fork, undefined, (transport) =>
341
- transport.forkchoiceUpdated(fork, headBlockHash, safeBlockHash, finalizedBlockHash, payloadAttributes)
342
- )
343
- );
342
+ const result = await this.enqueue(() => {
343
+ // Aborted while waiting in the queue, do not select a transport and sign a request that is not sent
344
+ if (signal?.aborted) {
345
+ throw new ErrorAborted("notifyForkchoiceUpdate");
346
+ }
347
+ return this.withTransport(fork, undefined, (transport) =>
348
+ transport.forkchoiceUpdated(fork, headBlockHash, safeBlockHash, finalizedBlockHash, payloadAttributes, signal)
349
+ );
350
+ });
344
351
  const {
345
352
  payloadStatus: {status},
346
353
  payloadId,
@@ -373,7 +380,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
373
380
  case ExecutionPayloadStatus.SYNCING:
374
381
  // Throw error on syncing if requested to produce a block, else silently ignore
375
382
  if (payloadAttributes) {
376
- throw Error("Execution Layer Syncing");
383
+ throw new ExecutionEngineError({code: ExecutionEngineErrorCode.SYNCING}, "Execution Layer Syncing");
377
384
  }
378
385
  return result;
379
386
 
@@ -394,7 +401,8 @@ export class ExecutionEngineHttp implements IExecutionEngine {
394
401
  */
395
402
  async getPayload(
396
403
  fork: ForkName,
397
- payloadId: PayloadId
404
+ payloadId: PayloadId,
405
+ signal?: AbortSignal
398
406
  ): Promise<{
399
407
  executionPayload: ExecutionPayload;
400
408
  executionPayloadValue: Wei;
@@ -402,7 +410,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
402
410
  executionRequests?: ExecutionRequests;
403
411
  shouldOverrideBuilder?: boolean;
404
412
  }> {
405
- return this.withTransport(fork, undefined, (transport) => transport.getPayload(fork, payloadId));
413
+ return this.withTransport(fork, undefined, (transport) => transport.getPayload(fork, payloadId, signal));
406
414
  }
407
415
 
408
416
  async prunePayloadIdCache(): Promise<void> {
@@ -19,6 +19,7 @@ import {
19
19
  capella,
20
20
  } from "@lodestar/types";
21
21
  import {BlobAndProofV2} from "@lodestar/types/fulu";
22
+ import {LodestarError} from "@lodestar/utils";
22
23
  import {PayloadId, PayloadIdCache, WithdrawalV1} from "./payloadIdCache.js";
23
24
  import {ExecutionPayloadBodyV2} from "./types.js";
24
25
  import {DATA} from "./utils.js";
@@ -131,6 +132,18 @@ export type PayloadAttributes = {
131
132
 
132
133
  export type VersionedHashes = Uint8Array[];
133
134
 
135
+ export enum ExecutionEngineErrorCode {
136
+ /**
137
+ * `notifyForkchoiceUpdate` requested a payload while the execution client is syncing, the head block is not
138
+ * available to build on yet
139
+ */
140
+ SYNCING = "EXECUTION_ENGINE_ERROR_SYNCING",
141
+ }
142
+
143
+ export type ExecutionEngineErrorType = {code: ExecutionEngineErrorCode.SYNCING};
144
+
145
+ export class ExecutionEngineError extends LodestarError<ExecutionEngineErrorType> {}
146
+
134
147
  /**
135
148
  * Execution engine represents an abstract protocol to interact with execution clients. Potential transports include:
136
149
  * - JSON RPC over network
@@ -180,14 +193,15 @@ export interface IExecutionEngine {
180
193
  * Should be called in response to fork-choice head and finalized events.
181
194
  *
182
195
  * An INVALID verdict is returned, not thrown: the caller feeds it back into fork choice together with the
183
- * `latestValidHash`. Only SYNCING while building a payload is an error.
196
+ * `latestValidHash`. Only SYNCING while building a payload is an error, thrown as `ExecutionEngineError` with code `SYNCING`.
184
197
  */
185
198
  notifyForkchoiceUpdate(
186
199
  fork: ForkName,
187
200
  headBlockHash: RootHex,
188
201
  safeBlockHash: RootHex,
189
202
  finalizedBlockHash: RootHex,
190
- payloadAttributes?: PayloadAttributes
203
+ payloadAttributes?: PayloadAttributes,
204
+ signal?: AbortSignal
191
205
  ): Promise<ForkchoiceUpdatedResult>;
192
206
 
193
207
  /**
@@ -199,7 +213,8 @@ export interface IExecutionEngine {
199
213
  */
200
214
  getPayload(
201
215
  fork: ForkName,
202
- payloadId: PayloadId
216
+ payloadId: PayloadId,
217
+ signal?: AbortSignal
203
218
  ): Promise<{
204
219
  executionPayload: ExecutionPayload;
205
220
  executionPayloadValue: Wei;
@@ -2,6 +2,7 @@ import {EventEmitter} from "node:events";
2
2
  import {StrictEventEmitter} from "strict-event-emitter-types";
3
3
  import {ErrorAborted, Gauge, Histogram, TimeoutError, fetch, isValidHttpUrl, retry} from "@lodestar/utils";
4
4
  import {JwtClaim, encodeJwtToken} from "./jwt.js";
5
+ import {withRequestSignal} from "./signal.js";
5
6
  import {EngineTransportMetrics} from "./transportMetrics.js";
6
7
  import {IJson, RpcPayload} from "./utils.js";
7
8
 
@@ -54,6 +55,8 @@ export type ReqOpts = {
54
55
  retries?: number;
55
56
  retryDelay?: number;
56
57
  shouldRetry?: (lastError: Error) => boolean;
58
+ /** Aborts this request only, in addition to the signal of the client */
59
+ signal?: AbortSignal;
57
60
  };
58
61
 
59
62
  export type JsonRpcHttpClientMetrics = EngineTransportMetrics & {
@@ -157,19 +160,23 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
157
160
  return this.wrapWithEvents(async () => {
158
161
  const routeId = opts?.routeId ?? "unknown";
159
162
 
160
- const res = await retry<RpcResponse<R>>(
161
- async (_attempt) => {
162
- return this.fetchJson({jsonrpc: "2.0", id: this.id++, ...payload}, opts);
163
- },
164
- {
165
- retries: opts?.retries ?? this.opts?.retries ?? 0,
166
- retryDelay: opts?.retryDelay ?? this.opts?.retryDelay,
167
- shouldRetry: opts?.shouldRetry,
168
- signal: this.opts?.signal,
169
- onRetry: () => {
170
- this.opts?.metrics?.retryCount.inc({routeId});
163
+ // The delay between retries has to end with the request signal as well
164
+ const res = await withRequestSignal(this.opts?.signal, opts?.signal, (signal) =>
165
+ retry<RpcResponse<R>>(
166
+ async (_attempt) => {
167
+ return this.fetchJson({jsonrpc: "2.0", id: this.id++, ...payload}, opts);
171
168
  },
172
- }
169
+ {
170
+ retries: opts?.retries ?? this.opts?.retries ?? 0,
171
+ retryDelay: opts?.retryDelay ?? this.opts?.retryDelay,
172
+ // An aborted request is no longer of interest to its caller
173
+ shouldRetry: (lastError) => !opts?.signal?.aborted && (opts?.shouldRetry?.(lastError) ?? true),
174
+ signal,
175
+ onRetry: () => {
176
+ this.opts?.metrics?.retryCount.inc({routeId});
177
+ },
178
+ }
179
+ )
173
180
  );
174
181
  return parseRpcResponse(res, payload);
175
182
  }, payload);
@@ -244,6 +251,10 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
244
251
 
245
252
  const onParentSignalAbort = (): void => controller.abort();
246
253
  this.opts?.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
254
+ opts?.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
255
+ if (opts?.signal?.aborted) {
256
+ controller.abort();
257
+ }
247
258
 
248
259
  // Default to "unknown" to prevent mixing metrics with others.
249
260
  const routeId = opts?.routeId ?? "unknown";
@@ -306,8 +317,8 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
306
317
  } catch (e) {
307
318
  this.metrics?.requestErrors.inc({routeId});
308
319
  if (controller.signal.aborted) {
309
- // controller will abort on both parent signal abort + timeout of this specific request
310
- if (this.opts?.signal?.aborted) {
320
+ // controller will abort on parent signal abort, request signal abort + timeout of this specific request
321
+ if (this.opts?.signal?.aborted || opts?.signal?.aborted) {
311
322
  throw new ErrorAborted("request");
312
323
  }
313
324
  throw new TimeoutError("request");
@@ -319,6 +330,7 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
319
330
 
320
331
  clearTimeout(timeout);
321
332
  this.opts?.signal?.removeEventListener("abort", onParentSignalAbort);
333
+ opts?.signal?.removeEventListener("abort", onParentSignalAbort);
322
334
  }
323
335
  }
324
336
  }
@@ -141,7 +141,8 @@ export class JsonRpcEngineTransport implements IEngineTransport {
141
141
  headBlockHash: RootHex,
142
142
  safeBlockHash: RootHex,
143
143
  finalizedBlockHash: RootHex,
144
- payloadAttributes?: PayloadAttributes
144
+ payloadAttributes?: PayloadAttributes,
145
+ signal?: AbortSignal
145
146
  ): Promise<ForkchoiceUpdatedResult> {
146
147
  const method =
147
148
  ForkSeq[fork] >= ForkSeq.heze
@@ -161,12 +162,15 @@ export class JsonRpcEngineTransport implements IEngineTransport {
161
162
  const {payloadStatus, payloadId} = await this.rpc.fetchWithRetries<
162
163
  EngineApiRpcReturnTypes[typeof method],
163
164
  EngineApiRpcParamTypes[typeof method]
164
- >({method, params: [{headBlockHash, safeBlockHash, finalizedBlockHash}, payloadAttributesRpc]}, fcUReqOpts);
165
+ >(
166
+ {method, params: [{headBlockHash, safeBlockHash, finalizedBlockHash}, payloadAttributesRpc]},
167
+ {...fcUReqOpts, signal}
168
+ );
165
169
 
166
170
  return {payloadStatus, payloadId: payloadId && payloadId !== "0x" ? payloadId : null};
167
171
  }
168
172
 
169
- async getPayload(fork: ForkName, payloadId: PayloadId): Promise<GetPayloadResult> {
173
+ async getPayload(fork: ForkName, payloadId: PayloadId, signal?: AbortSignal): Promise<GetPayloadResult> {
170
174
  let method: keyof EngineApiRpcReturnTypes;
171
175
  switch (fork) {
172
176
  case ForkName.phase0:
@@ -193,7 +197,7 @@ export class JsonRpcEngineTransport implements IEngineTransport {
193
197
  const payloadResponse = await this.rpc.fetchWithRetries<
194
198
  EngineApiRpcReturnTypes[typeof method],
195
199
  EngineApiRpcParamTypes[typeof method]
196
- >({method, params: [payloadId]}, getPayloadOpts);
200
+ >({method, params: [payloadId]}, {...getPayloadOpts, signal});
197
201
  return parseExecutionPayload(fork, payloadResponse);
198
202
  }
199
203
 
@@ -10,14 +10,16 @@ import {
10
10
  ForkPostCapella,
11
11
  ForkSeq,
12
12
  SLOTS_PER_EPOCH,
13
+ isForkPostElectra,
13
14
  } from "@lodestar/params";
14
15
  import {computeTimeAtSlot} from "@lodestar/state-transition";
15
- import {ExecutionPayload, RootHex, bellatrix, deneb, gloas, ssz} from "@lodestar/types";
16
+ import {ExecutionPayload, RootHex, bellatrix, deneb, gloas, ssz, sszTypesFor} from "@lodestar/types";
16
17
  import {fromHex, toRootHex} from "@lodestar/utils";
17
18
  import {ZERO_HASH_HEX} from "../../constants/index.js";
18
19
  import {INTEROP_BLOCK_HASH} from "../../node/utils/interop/state.js";
19
20
  import {kzgCommitmentToVersionedHash} from "../../util/blobs.js";
20
21
  import {kzg} from "../../util/kzg.js";
22
+ import {computeExecutionBlockHash} from "./blockHash.js";
21
23
  import {ClientCode, ExecutionPayloadStatus, PayloadIdCache} from "./interface.js";
22
24
  import {
23
25
  BlobsBundleRpc,
@@ -351,7 +353,6 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
351
353
  executionPayload.gasLimit = INTEROP_GAS_LIMIT;
352
354
  executionPayload.gasUsed = Math.floor(0.5 * INTEROP_GAS_LIMIT);
353
355
  executionPayload.timestamp = payloadAttributes.timestamp;
354
- executionPayload.blockHash = crypto.randomBytes(32);
355
356
  const transactions: Uint8Array[] = [];
356
357
 
357
358
  // Between 0 and 4 transactions for all forks
@@ -401,6 +402,15 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
401
402
  (executionPayload as gloas.ExecutionPayload).slotNumber = payloadAttributes.slotNumber;
402
403
  }
403
404
 
405
+ const executionRequests = isForkPostElectra(fork) ? sszTypesFor(fork).ExecutionRequests.defaultValue() : null;
406
+
407
+ executionPayload.blockHash = computeExecutionBlockHash(
408
+ fork,
409
+ executionPayload,
410
+ payloadAttributes.parentBeaconBlockRoot ?? null,
411
+ executionRequests
412
+ );
413
+
404
414
  this.preparingPayloads.set(payloadId, {
405
415
  executionPayload: serializeExecutionPayload(fork, executionPayload),
406
416
  blobsBundle: serializeBlobsBundle({
@@ -408,12 +418,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
408
418
  blobs,
409
419
  proofs,
410
420
  }),
411
- executionRequests: serializeExecutionRequests(
412
- fork,
413
- ForkSeq[fork] >= ForkSeq.gloas
414
- ? ssz.gloas.ExecutionRequests.defaultValue()
415
- : ssz.electra.ExecutionRequests.defaultValue()
416
- ),
421
+ executionRequests: executionRequests !== null ? serializeExecutionRequests(fork, executionRequests) : [],
417
422
  });
418
423
 
419
424
  // IF the payload is deemed VALID and the build process has begun
@@ -6,6 +6,7 @@ import {
6
6
  ReqOpts,
7
7
  } from "./jsonRpcHttpClient.js";
8
8
  import {JwtClaim, encodeJwtToken} from "./jwt.js";
9
+ import {withRequestSignal} from "./signal.js";
9
10
  import {ExecutionForkName} from "./sszTypes.js";
10
11
 
11
12
  export const ENGINE_REST_BASE_PATH = "/engine/v1";
@@ -115,15 +116,18 @@ export class EngineRestHttpClient {
115
116
  /** Perform request with retries without emitting events, used to probe support for the REST API */
116
117
  async requestWithRetries(req: EngineRestRequest, opts?: ReqOpts): Promise<EngineRestResponse> {
117
118
  const routeId = opts?.routeId ?? "unknown";
118
- return retry(() => this.requestAnyUrl(req, opts), {
119
- retries: opts?.retries ?? this.opts.retries ?? 0,
120
- retryDelay: opts?.retryDelay ?? this.opts.retryDelay,
121
- shouldRetry: opts?.shouldRetry ?? isRetryableEngineRestError,
122
- signal: this.opts.signal,
123
- onRetry: () => {
124
- this.metrics?.retryCount.inc({routeId});
125
- },
126
- });
119
+ // The delay between retries has to end with the request signal as well
120
+ return withRequestSignal(this.opts.signal, opts?.signal, (signal) =>
121
+ retry(() => this.requestAnyUrl(req, opts), {
122
+ retries: opts?.retries ?? this.opts.retries ?? 0,
123
+ retryDelay: opts?.retryDelay ?? this.opts.retryDelay,
124
+ shouldRetry: opts?.shouldRetry ?? isRetryableEngineRestError,
125
+ signal,
126
+ onRetry: () => {
127
+ this.metrics?.retryCount.inc({routeId});
128
+ },
129
+ })
130
+ );
127
131
  }
128
132
 
129
133
  private async requestAnyUrl(req: EngineRestRequest, opts?: ReqOpts): Promise<EngineRestResponse> {
@@ -154,7 +158,8 @@ export class EngineRestHttpClient {
154
158
  // Not AbortSignal.any(), Node retains every composite until the long-lived parent signal aborts
155
159
  const onParentSignalAbort = (): void => controller.abort();
156
160
  this.opts.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
157
- if (this.opts.signal?.aborted) {
161
+ opts?.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
162
+ if (this.opts.signal?.aborted || opts?.signal?.aborted) {
158
163
  controller.abort();
159
164
  }
160
165
 
@@ -223,7 +228,7 @@ export class EngineRestHttpClient {
223
228
  } catch (e) {
224
229
  this.metrics?.requestErrors.inc({routeId});
225
230
  if (controller.signal.aborted) {
226
- if (this.opts.signal?.aborted) {
231
+ if (this.opts.signal?.aborted || opts?.signal?.aborted) {
227
232
  throw new ErrorAborted("request");
228
233
  }
229
234
  throw new TimeoutError("request");
@@ -235,6 +240,7 @@ export class EngineRestHttpClient {
235
240
 
236
241
  clearTimeout(timeout);
237
242
  this.opts.signal?.removeEventListener("abort", onParentSignalAbort);
243
+ opts?.signal?.removeEventListener("abort", onParentSignalAbort);
238
244
  }
239
245
  }
240
246
  }