@lodestar/beacon-node 1.49.0-dev.fa4ae94ccc → 1.49.0-rc.0

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 (131) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +13 -4
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
  5. package/lib/chain/archiveStore/archiveStore.js +5 -3
  6. package/lib/chain/archiveStore/archiveStore.js.map +1 -1
  7. package/lib/chain/archiveStore/historicalState/metrics.d.ts.map +1 -1
  8. package/lib/chain/archiveStore/historicalState/metrics.js +2 -1
  9. package/lib/chain/archiveStore/historicalState/metrics.js.map +1 -1
  10. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts +11 -2
  11. package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
  12. package/lib/chain/archiveStore/utils/archiveBlocks.js +46 -28
  13. package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
  14. package/lib/chain/archiveStore/utils/pruneHistory.d.ts +2 -2
  15. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  16. package/lib/chain/archiveStore/utils/pruneHistory.js +1 -0
  17. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  18. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  19. package/lib/chain/blocks/importExecutionPayload.js +13 -0
  20. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  21. package/lib/chain/chain.d.ts +10 -0
  22. package/lib/chain/chain.d.ts.map +1 -1
  23. package/lib/chain/chain.js +85 -16
  24. package/lib/chain/chain.js.map +1 -1
  25. package/lib/chain/errors/envelopeReconstructionError.d.ts +23 -0
  26. package/lib/chain/errors/envelopeReconstructionError.d.ts.map +1 -0
  27. package/lib/chain/errors/envelopeReconstructionError.js +13 -0
  28. package/lib/chain/errors/envelopeReconstructionError.js.map +1 -0
  29. package/lib/chain/errors/index.d.ts +1 -0
  30. package/lib/chain/errors/index.d.ts.map +1 -1
  31. package/lib/chain/errors/index.js +1 -0
  32. package/lib/chain/errors/index.js.map +1 -1
  33. package/lib/chain/interface.d.ts +6 -1
  34. package/lib/chain/interface.d.ts.map +1 -1
  35. package/lib/chain/interface.js.map +1 -1
  36. package/lib/chain/options.d.ts +2 -0
  37. package/lib/chain/options.d.ts.map +1 -1
  38. package/lib/chain/options.js +1 -0
  39. package/lib/chain/options.js.map +1 -1
  40. package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts +21 -9
  41. package/lib/db/repositories/executionPayloadEnvelopeArchive.d.ts.map +1 -1
  42. package/lib/db/repositories/executionPayloadEnvelopeArchive.js +32 -12
  43. package/lib/db/repositories/executionPayloadEnvelopeArchive.js.map +1 -1
  44. package/lib/db/repositories/index.d.ts +1 -1
  45. package/lib/db/repositories/index.d.ts.map +1 -1
  46. package/lib/db/repositories/index.js +1 -1
  47. package/lib/db/repositories/index.js.map +1 -1
  48. package/lib/execution/engine/disabled.d.ts +1 -0
  49. package/lib/execution/engine/disabled.d.ts.map +1 -1
  50. package/lib/execution/engine/disabled.js +3 -0
  51. package/lib/execution/engine/disabled.js.map +1 -1
  52. package/lib/execution/engine/http.d.ts +2 -1
  53. package/lib/execution/engine/http.d.ts.map +1 -1
  54. package/lib/execution/engine/http.js +7 -1
  55. package/lib/execution/engine/http.js.map +1 -1
  56. package/lib/execution/engine/interface.d.ts +3 -1
  57. package/lib/execution/engine/interface.d.ts.map +1 -1
  58. package/lib/execution/engine/mock.d.ts +1 -0
  59. package/lib/execution/engine/mock.d.ts.map +1 -1
  60. package/lib/execution/engine/mock.js +14 -2
  61. package/lib/execution/engine/mock.js.map +1 -1
  62. package/lib/execution/engine/types.d.ts +11 -0
  63. package/lib/execution/engine/types.d.ts.map +1 -1
  64. package/lib/execution/engine/types.js +10 -0
  65. package/lib/execution/engine/types.js.map +1 -1
  66. package/lib/metrics/metrics/beacon.d.ts +9 -0
  67. package/lib/metrics/metrics/beacon.d.ts.map +1 -1
  68. package/lib/metrics/metrics/beacon.js +16 -0
  69. package/lib/metrics/metrics/beacon.js.map +1 -1
  70. package/lib/metrics/metrics/lodestar.d.ts +12 -0
  71. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  72. package/lib/metrics/metrics/lodestar.js +30 -0
  73. package/lib/metrics/metrics/lodestar.js.map +1 -1
  74. package/lib/metrics/metrics.d.ts +3 -1
  75. package/lib/metrics/metrics.d.ts.map +1 -1
  76. package/lib/metrics/metrics.js +2 -2
  77. package/lib/metrics/metrics.js.map +1 -1
  78. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.d.ts.map +1 -1
  79. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js +47 -34
  80. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRange.js.map +1 -1
  81. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.d.ts.map +1 -1
  82. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js +23 -4
  83. package/lib/network/reqresp/handlers/executionPayloadEnvelopesByRoot.js.map +1 -1
  84. package/lib/network/reqresp/handlers/index.d.ts.map +1 -1
  85. package/lib/network/reqresp/handlers/index.js +20 -4
  86. package/lib/network/reqresp/handlers/index.js.map +1 -1
  87. package/lib/sync/types.d.ts +0 -2
  88. package/lib/sync/types.d.ts.map +1 -1
  89. package/lib/sync/types.js +0 -2
  90. package/lib/sync/types.js.map +1 -1
  91. package/lib/sync/unknownBlock.d.ts.map +1 -1
  92. package/lib/sync/unknownBlock.js +41 -13
  93. package/lib/sync/unknownBlock.js.map +1 -1
  94. package/lib/util/execution.d.ts +42 -0
  95. package/lib/util/execution.d.ts.map +1 -1
  96. package/lib/util/execution.js +123 -2
  97. package/lib/util/execution.js.map +1 -1
  98. package/lib/util/headerEnvelope.d.ts +17 -0
  99. package/lib/util/headerEnvelope.d.ts.map +1 -0
  100. package/lib/util/headerEnvelope.js +43 -0
  101. package/lib/util/headerEnvelope.js.map +1 -0
  102. package/package.json +16 -16
  103. package/src/api/impl/beacon/blocks/index.ts +16 -3
  104. package/src/chain/archiveStore/archiveStore.ts +6 -3
  105. package/src/chain/archiveStore/historicalState/metrics.ts +3 -2
  106. package/src/chain/archiveStore/utils/archiveBlocks.ts +54 -32
  107. package/src/chain/archiveStore/utils/pruneHistory.ts +4 -2
  108. package/src/chain/blocks/importExecutionPayload.ts +14 -0
  109. package/src/chain/chain.ts +96 -20
  110. package/src/chain/errors/envelopeReconstructionError.ts +22 -0
  111. package/src/chain/errors/index.ts +1 -0
  112. package/src/chain/interface.ts +6 -1
  113. package/src/chain/options.ts +3 -0
  114. package/src/db/buckets.ts +1 -1
  115. package/src/db/repositories/executionPayloadEnvelopeArchive.ts +43 -13
  116. package/src/db/repositories/index.ts +6 -1
  117. package/src/execution/engine/disabled.ts +4 -0
  118. package/src/execution/engine/http.ts +12 -0
  119. package/src/execution/engine/interface.ts +4 -1
  120. package/src/execution/engine/mock.ts +22 -2
  121. package/src/execution/engine/types.ts +25 -0
  122. package/src/metrics/metrics/beacon.ts +16 -0
  123. package/src/metrics/metrics/lodestar.ts +31 -0
  124. package/src/metrics/metrics.ts +7 -2
  125. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts +57 -39
  126. package/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts +27 -5
  127. package/src/network/reqresp/handlers/index.ts +49 -5
  128. package/src/sync/types.ts +0 -2
  129. package/src/sync/unknownBlock.ts +41 -13
  130. package/src/util/execution.ts +175 -2
  131. package/src/util/headerEnvelope.ts +76 -0
@@ -1,25 +1,44 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
- import {BUCKET_LENGTH, Db, Repository, encodeKey as encodeDbKey} from "@lodestar/db";
2
+ import {BUCKET_LENGTH, BinaryRepository, Db, DbBatch, encodeKey as encodeDbKey} from "@lodestar/db";
3
3
  import {Slot, gloas, ssz} from "@lodestar/types";
4
4
  import {bytesToInt} from "@lodestar/utils";
5
5
  import {Bucket, getBucketNameByValue} from "../buckets.js";
6
6
 
7
7
  /**
8
- * Used to store finalized `SignedExecutionPayloadEnvelope`
9
- *
10
- * Indexed by slot for chronological archival
8
+ * Prefix of a header entry. A full `SignedExecutionPayloadEnvelope` starts with the offset of its
9
+ * variable-size `message` field (4 + 96 = 0x64), so a leading 0x00 byte is unambiguous and full
10
+ * entries can be stored as the hot db bytes, untouched.
11
11
  */
12
- export class ExecutionPayloadEnvelopeArchiveRepository extends Repository<Slot, gloas.SignedExecutionPayloadEnvelope> {
12
+ const HEADER_ENVELOPE_PREFIX = 0x00;
13
+
14
+ /** An archive entry as the serving paths need it: full stays bytes, header is deserialized for reconstruction */
15
+ export type ArchivedEnvelope =
16
+ | {headerEnvelope: gloas.SignedExecutionPayloadHeaderEnvelope; envelopeBytes?: undefined}
17
+ | {headerEnvelope?: undefined; envelopeBytes: Uint8Array};
18
+
19
+ export function decodeArchivedEnvelope(bytes: Uint8Array): ArchivedEnvelope {
20
+ return bytes[0] === HEADER_ENVELOPE_PREFIX
21
+ ? {headerEnvelope: ssz.gloas.SignedExecutionPayloadHeaderEnvelope.deserialize(bytes.subarray(1))}
22
+ : {envelopeBytes: bytes};
23
+ }
24
+
25
+ export function encodeArchivedHeaderEnvelope(headerEnvelope: gloas.SignedExecutionPayloadHeaderEnvelope): Uint8Array {
26
+ const value = ssz.gloas.SignedExecutionPayloadHeaderEnvelope.serialize(headerEnvelope);
27
+ const out = new Uint8Array(1 + value.length);
28
+ out[0] = HEADER_ENVELOPE_PREFIX;
29
+ out.set(value, 1);
30
+ return out;
31
+ }
32
+
33
+ /**
34
+ * Finalized envelopes indexed by slot: `SignedExecutionPayloadEnvelope` bytes as-is
35
+ * (`--chain.dedupePayloads=false`, or the block was still optimistic when archived), or a
36
+ * `SignedExecutionPayloadHeaderEnvelope` behind a 0x00 prefix. See {@link decodeArchivedEnvelope}.
37
+ */
38
+ export class ExecutionPayloadEnvelopeArchiveRepository extends BinaryRepository<Slot> {
13
39
  constructor(config: ChainForkConfig, db: Db) {
14
40
  const bucket = Bucket.gloas_executionPayloadEnvelopeArchive;
15
- super(config, db, bucket, ssz.gloas.SignedExecutionPayloadEnvelope, getBucketNameByValue(bucket));
16
- }
17
-
18
- /**
19
- * Id is the slot from the envelope
20
- */
21
- getId(value: gloas.SignedExecutionPayloadEnvelope): Slot {
22
- return value.message.payload.slotNumber;
41
+ super(config, db, bucket, getBucketNameByValue(bucket));
23
42
  }
24
43
 
25
44
  encodeKey(id: Slot): Uint8Array {
@@ -29,4 +48,15 @@ export class ExecutionPayloadEnvelopeArchiveRepository extends Repository<Slot,
29
48
  decodeKey(data: Uint8Array): number {
30
49
  return bytesToInt(data.subarray(BUCKET_LENGTH), "be");
31
50
  }
51
+
52
+ /** Archive entries and delete their hot counterparts (`hotKey` pre-encoded) in one atomic batch */
53
+ async batchArchiveAndDeleteHot(
54
+ entries: {slot: Slot; archivedBytes: Uint8Array; hotKey: Uint8Array}[]
55
+ ): Promise<void> {
56
+ const operations: DbBatch<Uint8Array, Uint8Array> = [];
57
+ for (const {slot, archivedBytes, hotKey} of entries) {
58
+ operations.push({type: "put", key: this.encodeKey(slot), value: archivedBytes}, {type: "del", key: hotKey});
59
+ }
60
+ await this.db.batch(operations, this.dbReqOpts);
61
+ }
32
62
  }
@@ -8,7 +8,12 @@ export {BLSToExecutionChangeRepository} from "./blsToExecutionChange.js";
8
8
  export {DataColumnSidecarRepository} from "./dataColumnSidecar.js";
9
9
  export {DataColumnSidecarArchiveRepository} from "./dataColumnSidecarArchive.js";
10
10
  export {ExecutionPayloadEnvelopeRepository} from "./executionPayloadEnvelope.js";
11
- export {ExecutionPayloadEnvelopeArchiveRepository} from "./executionPayloadEnvelopeArchive.js";
11
+ export {
12
+ type ArchivedEnvelope,
13
+ ExecutionPayloadEnvelopeArchiveRepository,
14
+ decodeArchivedEnvelope,
15
+ encodeArchivedHeaderEnvelope,
16
+ } from "./executionPayloadEnvelopeArchive.js";
12
17
  export {BestLightClientUpdateRepository} from "./lightclientBestUpdate.js";
13
18
  export {CheckpointHeaderRepository} from "./lightclientCheckpointHeader.js";
14
19
  export {SyncCommitteeRepository} from "./lightclientSyncCommittee.js";
@@ -25,6 +25,10 @@ export class ExecutionEngineDisabled implements IExecutionEngine {
25
25
  throw Error("Execution engine disabled");
26
26
  }
27
27
 
28
+ getPayloadBodiesByHashV2(): Promise<never> {
29
+ throw Error("Execution engine disabled");
30
+ }
31
+
28
32
  getPayloadBodiesByRange(): Promise<never> {
29
33
  throw Error("Execution engine disabled");
30
34
  }
@@ -32,11 +32,13 @@ import {
32
32
  EngineApiRpcParamTypes,
33
33
  EngineApiRpcReturnTypes,
34
34
  ExecutionPayloadBody,
35
+ ExecutionPayloadBodyV2,
35
36
  assertReqSizeLimit,
36
37
  deserializeBlobAndProofs,
37
38
  deserializeBlobAndProofsV2,
38
39
  deserializeBlobAndProofsV2IntoBytes,
39
40
  deserializeExecutionPayloadBody,
41
+ deserializeExecutionPayloadBodyV2,
40
42
  parseExecutionPayload,
41
43
  serializeBeaconBlockRoot,
42
44
  serializeExecutionPayload,
@@ -476,6 +478,16 @@ export class ExecutionEngineHttp implements IExecutionEngine {
476
478
  return response.map(deserializeExecutionPayloadBody);
477
479
  }
478
480
 
481
+ async getPayloadBodiesByHashV2(blockHashes: RootHex[]): Promise<(ExecutionPayloadBodyV2 | null)[]> {
482
+ const method = "engine_getPayloadBodiesByHashV2";
483
+ assertReqSizeLimit(blockHashes.length, 32);
484
+ const response = await this.rpc.fetchWithRetries<
485
+ EngineApiRpcReturnTypes[typeof method],
486
+ EngineApiRpcParamTypes[typeof method]
487
+ >({method, params: [blockHashes]}, getPayloadBodiesByHashOpts);
488
+ return response.map(deserializeExecutionPayloadBodyV2);
489
+ }
490
+
479
491
  async getPayloadBodiesByRange(
480
492
  _fork: ForkName,
481
493
  startBlockNumber: number,
@@ -13,7 +13,7 @@ import {BlobsBundle, ExecutionPayload, ExecutionRequests, Root, RootHex, Wei, ca
13
13
  import {BlobAndProof} from "@lodestar/types/deneb";
14
14
  import {BlobAndProofV2} from "@lodestar/types/fulu";
15
15
  import {PayloadId, PayloadIdCache, WithdrawalV1} from "./payloadIdCache.js";
16
- import {ExecutionPayloadBody} from "./types.js";
16
+ import {ExecutionPayloadBody, ExecutionPayloadBodyV2} from "./types.js";
17
17
  import {DATA} from "./utils.js";
18
18
 
19
19
  export {PayloadIdCache, type PayloadId, type WithdrawalV1};
@@ -172,6 +172,9 @@ export interface IExecutionEngine {
172
172
 
173
173
  getPayloadBodiesByHash(fork: ForkName, blockHash: DATA[]): Promise<(ExecutionPayloadBody | null)[]>;
174
174
 
175
+ /** Amsterdam: like V1 but also returns the block access list (null if the EL no longer has it) */
176
+ getPayloadBodiesByHashV2(blockHash: DATA[]): Promise<(ExecutionPayloadBodyV2 | null)[]>;
177
+
175
178
  getPayloadBodiesByRange(fork: ForkName, start: number, count: number): Promise<(ExecutionPayloadBody | null)[]>;
176
179
 
177
180
  getBlobs(
@@ -23,6 +23,7 @@ import {
23
23
  EngineApiRpcParamTypes,
24
24
  EngineApiRpcReturnTypes,
25
25
  ExecutionPayloadBodyRpc,
26
+ ExecutionPayloadBodyV2Rpc,
26
27
  ExecutionPayloadRpc,
27
28
  ExecutionRequestsRpc,
28
29
  PayloadStatus,
@@ -49,6 +50,8 @@ type ExecutionBlock = {
49
50
  blockHash: RootHex;
50
51
  timestamp: number;
51
52
  blockNumber: number;
53
+ /** Bodies as received via newPayload, served back by engine_getPayloadBodiesByHash{V1,V2} */
54
+ body: ExecutionPayloadBodyV2Rpc;
52
55
  };
53
56
 
54
57
  const TX_TYPE_EIP1559 = 2;
@@ -93,6 +96,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
93
96
  blockHash: ZERO_HASH_HEX,
94
97
  timestamp: 0,
95
98
  blockNumber: 0,
99
+ body: {transactions: [], withdrawals: null, blockAccessList: null},
96
100
  });
97
101
 
98
102
  const eth1BlockHash = opts.eth1BlockHash ?? toRootHex(INTEROP_BLOCK_HASH);
@@ -102,6 +106,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
102
106
  blockHash: eth1BlockHash,
103
107
  timestamp: 0,
104
108
  blockNumber: 1,
109
+ body: {transactions: [], withdrawals: null, blockAccessList: null},
105
110
  });
106
111
 
107
112
  const {config} = opts;
@@ -144,6 +149,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
144
149
  engine_getPayloadV5: this.getPayloadV5.bind(this),
145
150
  engine_getPayloadV6: this.getPayloadV5.bind(this),
146
151
  engine_getPayloadBodiesByHashV1: this.getPayloadBodiesByHash.bind(this),
152
+ engine_getPayloadBodiesByHashV2: this.getPayloadBodiesByHashV2.bind(this),
147
153
  engine_getPayloadBodiesByRangeV1: this.getPayloadBodiesByRange.bind(this),
148
154
  engine_getClientVersionV1: this.getClientVersionV1.bind(this),
149
155
  engine_getBlobsV1: this.getBlobs.bind(this),
@@ -152,9 +158,18 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
152
158
  }
153
159
 
154
160
  private getPayloadBodiesByHash(
155
- _blockHex: EngineApiRpcParamTypes["engine_getPayloadBodiesByHashV1"][0]
161
+ blockHashes: EngineApiRpcParamTypes["engine_getPayloadBodiesByHashV1"][0]
156
162
  ): EngineApiRpcReturnTypes["engine_getPayloadBodiesByHashV1"] {
157
- return [] as ExecutionPayloadBodyRpc[];
163
+ return this.getPayloadBodiesByHashV2(blockHashes).map((body) =>
164
+ body ? {transactions: body.transactions, withdrawals: body.withdrawals} : null
165
+ );
166
+ }
167
+
168
+ private getPayloadBodiesByHashV2(
169
+ blockHashes: EngineApiRpcParamTypes["engine_getPayloadBodiesByHashV2"][0]
170
+ ): EngineApiRpcReturnTypes["engine_getPayloadBodiesByHashV2"] {
171
+ // null for unknown blocks, as a real EL does; the genesis/eth1 seed blocks carry no body
172
+ return blockHashes.map((hash) => this.validBlocks.get(hash)?.body ?? null);
158
173
  }
159
174
 
160
175
  private getPayloadBodiesByRange(
@@ -227,6 +242,11 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
227
242
  blockHash,
228
243
  timestamp: quantityToNum(executionPayloadRpc.timestamp),
229
244
  blockNumber: quantityToNum(executionPayloadRpc.blockNumber),
245
+ body: {
246
+ transactions: executionPayloadRpc.transactions,
247
+ withdrawals: executionPayloadRpc.withdrawals ?? null,
248
+ blockAccessList: executionPayloadRpc.blockAccessList ?? null,
249
+ },
230
250
  });
231
251
 
232
252
  // IF the payload has been fully validated while processing the call
@@ -89,6 +89,7 @@ export type EngineApiRpcParamTypes = {
89
89
  * 1. Array of DATA - Array of block_hash field values of the ExecutionPayload structure
90
90
  * */
91
91
  engine_getPayloadBodiesByHashV1: DATA[][];
92
+ engine_getPayloadBodiesByHashV2: DATA[][];
92
93
 
93
94
  /**
94
95
  * 1. start: QUANTITY, 64 bits - Starting block number
@@ -148,6 +149,7 @@ export type EngineApiRpcReturnTypes = {
148
149
  engine_getPayloadV6: ExecutionPayloadResponse;
149
150
 
150
151
  engine_getPayloadBodiesByHashV1: (ExecutionPayloadBodyRpc | null)[];
152
+ engine_getPayloadBodiesByHashV2: (ExecutionPayloadBodyV2Rpc | null)[];
151
153
 
152
154
  engine_getPayloadBodiesByRangeV1: (ExecutionPayloadBodyRpc | null)[];
153
155
 
@@ -177,6 +179,15 @@ export type ExecutionPayloadBody = {
177
179
  withdrawals: capella.Withdrawals | null;
178
180
  };
179
181
 
182
+ /** engine_getPayloadBodiesByHashV2 (Amsterdam): adds the RLP-encoded block access list, or null if the EL has pruned it */
183
+ export type ExecutionPayloadBodyV2Rpc = ExecutionPayloadBodyRpc & {
184
+ blockAccessList?: DATA | null;
185
+ };
186
+
187
+ export type ExecutionPayloadBodyV2 = ExecutionPayloadBody & {
188
+ blockAccessList: Uint8Array | null;
189
+ };
190
+
180
191
  export type ExecutionPayloadRpc = {
181
192
  parentHash: DATA; // 32 bytes
182
193
  feeRecipient: DATA; // 20 bytes
@@ -678,6 +689,20 @@ export function deserializeExecutionPayloadBody(data: ExecutionPayloadBodyRpc |
678
689
  : null;
679
690
  }
680
691
 
692
+ export function deserializeExecutionPayloadBodyV2(
693
+ data: ExecutionPayloadBodyV2Rpc | null
694
+ ): ExecutionPayloadBodyV2 | null {
695
+ const body = deserializeExecutionPayloadBody(data);
696
+ return body
697
+ ? {...body, blockAccessList: data?.blockAccessList ? dataToBytes(data.blockAccessList, null) : null}
698
+ : null;
699
+ }
700
+
701
+ export function serializeExecutionPayloadBodyV2(data: ExecutionPayloadBodyV2 | null): ExecutionPayloadBodyV2Rpc | null {
702
+ const body = serializeExecutionPayloadBody(data);
703
+ return body ? {...body, blockAccessList: data?.blockAccessList ? bytesToData(data.blockAccessList) : null} : null;
704
+ }
705
+
681
706
  export function serializeExecutionPayloadBody(data: ExecutionPayloadBody | null): ExecutionPayloadBodyRpc | null {
682
707
  return data
683
708
  ? {
@@ -215,6 +215,22 @@ export function createBeaconMetrics(register: RegistryMetricCreator) {
215
215
  help: "Number of getBlobsV1 hits where a versioned hash returns blob and the blob is needed so call is useful",
216
216
  }),
217
217
  },
218
+ payloadEnvelopeReconstruction: {
219
+ envelopes: register.counter<{result: "ok" | "unavailable" | "mismatch"}>({
220
+ name: "beacon_payload_envelope_reconstruction_envelopes_total",
221
+ help: "Archived header envelopes rebuilt from EL bodies, by outcome",
222
+ labelNames: ["result"],
223
+ }),
224
+ mismatchByField: register.counter<{field: "transactions" | "withdrawals" | "blockAccessList"}>({
225
+ name: "beacon_payload_envelope_reconstruction_mismatch_total",
226
+ help: "Body root mismatches, by which body differed from the stored root",
227
+ labelNames: ["field"],
228
+ }),
229
+ engineErrors: register.counter({
230
+ name: "beacon_payload_envelope_reconstruction_engine_errors_total",
231
+ help: "engine_getPayloadBodiesByHashV2 round-trips that failed while rebuilding envelopes",
232
+ }),
233
+ },
218
234
 
219
235
  blockInputFetchStats: {
220
236
  // of already available blocks which didn't have to go through blobs pull
@@ -180,6 +180,30 @@ export function createLodestarMetrics(
180
180
  buckets: [0.001, 0.003, 0.01, 0.03, 0.1],
181
181
  }),
182
182
 
183
+ reqRespByRange: {
184
+ requestedSlots: register.histogram<{method: string}>({
185
+ name: "lodestar_reqresp_by_range_requested_slots",
186
+ help: "Histogram of slot count requested per served by_range request",
187
+ labelNames: ["method"],
188
+ buckets: [1, 16, 32, 64, 128],
189
+ }),
190
+ // data_column_sidecars_by_range is the only by_range request carrying columns
191
+ requestedColumns: register.histogram({
192
+ name: "lodestar_reqresp_by_range_requested_columns",
193
+ help: "Histogram of column count requested per served data_column_sidecars_by_range request",
194
+ // 128 is NUMBER_OF_COLUMNS.
195
+ buckets: [1, 4, 8, 32, 128],
196
+ }),
197
+ servedBytes: register.histogram<{method: string}>({
198
+ name: "lodestar_reqresp_by_range_served_bytes",
199
+ help: "Histogram of total serialized bytes served per by_range request",
200
+ labelNames: ["method"],
201
+ // min bucket is roughly a typical mainnet block is 100MB,
202
+ // max bucket is roughly 100 * MAX_PAYLOAD_SIZE
203
+ buckets: [100e3, 1e6, 10e6, 100e6, 1000e6],
204
+ }),
205
+ },
206
+
183
207
  regenQueue: {
184
208
  length: register.gauge({
185
209
  name: "lodestar_regen_queue_length",
@@ -1011,6 +1035,13 @@ export function createLodestarMetrics(
1011
1035
  help: "Count of errors, by error type, while processing execution payload envelopes",
1012
1036
  labelNames: ["error"],
1013
1037
  }),
1038
+ executionPayload: {
1039
+ recvToValidation: register.histogram({
1040
+ name: "lodestar_gossip_execution_payload_envelope_received_to_execution_payload_verification_seconds",
1041
+ help: "Time elapsed between execution payload envelope received and execution payload verification",
1042
+ buckets: [0.05, 0.1, 0.25, 0.5, 1, 2, 3, 4, 6, 8],
1043
+ }),
1044
+ },
1014
1045
  },
1015
1046
  gossipExecutionPayloadBid: {
1016
1047
  elapsedTimeTillReceived: register.histogram<{source: OpSource}>({
@@ -12,7 +12,12 @@ export type Metrics = BeaconMetrics &
12
12
  BeaconStateTransitionMetrics &
13
13
  LodestarMetrics & {register: RegistryMetricCreator; close: () => void};
14
14
 
15
- export function createMetrics(opts: MetricsOptions, genesisTime: number, externalRegistries: Registry[] = []): Metrics {
15
+ export function createMetrics(
16
+ opts: MetricsOptions,
17
+ genesisTime: number,
18
+ externalRegistries: Registry[] = [],
19
+ {collectNodeMetrics = true}: {collectNodeMetrics?: boolean} = {}
20
+ ): Metrics {
16
21
  const register = new RegistryMetricCreator();
17
22
  const beacon = createBeaconMetrics(register);
18
23
  const forkChoice = getForkChoiceMetrics(register);
@@ -24,7 +29,7 @@ export function createMetrics(opts: MetricsOptions, genesisTime: number, externa
24
29
  };
25
30
  process.on("unhandledRejection", onUnhandledRejection);
26
31
 
27
- const nodeJsMetricsClose = collectNodeJSMetrics(register);
32
+ const nodeJsMetricsClose = collectNodeMetrics ? collectNodeJSMetrics(register) : (): void => {};
28
33
  const close = (): void => {
29
34
  process.removeListener("unhandledRejection", onUnhandledRejection);
30
35
  nodeJsMetricsClose();
@@ -5,8 +5,10 @@ import {GENESIS_SLOT} from "@lodestar/params";
5
5
  import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
6
6
  import {computeEpochAtSlot} from "@lodestar/state-transition";
7
7
  import {gloas} from "@lodestar/types";
8
+ import {EnvelopeReconstructionError} from "../../../chain/errors/index.js";
8
9
  import {IBeaconChain} from "../../../chain/index.js";
9
10
  import {IBeaconDb} from "../../../db/index.js";
11
+ import {reconstructExecutionPayloadEnvelopesByRange} from "../../../util/execution.js";
10
12
  import {prettyPrintPeerId} from "../../util.js";
11
13
 
12
14
  export async function* onExecutionPayloadEnvelopesByRange(
@@ -35,58 +37,74 @@ export async function* onExecutionPayloadEnvelopesByRange(
35
37
  );
36
38
  }
37
39
 
38
- const finalized = db.executionPayloadEnvelopeArchive;
39
40
  // Use the finalized block's actual slot as the checkpoint epoch-boundary slot may be skipped
40
41
  const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
41
42
  // The finalized block's envelope stays in the hot db until the next finalization run
42
43
  const archiveMaxSlot = finalizedSlot - 1;
43
44
 
44
- // Finalized range of envelopes
45
- if (startSlot <= archiveMaxSlot) {
46
- for await (const {key, value: envelopeBytes} of finalized.binaryEntriesStream({
47
- gte: startSlot,
48
- lt: Math.min(endSlot, archiveMaxSlot + 1),
49
- })) {
50
- const slot = finalized.decodeKey(key);
51
- yield {
52
- data: envelopeBytes,
53
- boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(slot)),
54
- };
45
+ let yielded = 0;
46
+ try {
47
+ if (startSlot <= archiveMaxSlot) {
48
+ for await (const {slot, envelopeBytes} of reconstructExecutionPayloadEnvelopesByRange(
49
+ db,
50
+ chain.executionEngine,
51
+ chain.logger,
52
+ chain.metrics,
53
+ startSlot,
54
+ Math.min(endSlot, archiveMaxSlot + 1)
55
+ )) {
56
+ yielded++;
57
+ yield {
58
+ data: envelopeBytes,
59
+ boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(slot)),
60
+ };
61
+ }
55
62
  }
56
- }
57
63
 
58
- // Non-finalized range of envelopes
59
- if (endSlot > archiveMaxSlot) {
60
- const headBlock = chain.forkChoice.getHead();
61
- const headRoot = headBlock.blockRoot;
62
- const headChain = chain.forkChoice.getAllAncestorBlocks(headRoot, headBlock.payloadStatus);
64
+ // Non-finalized range of envelopes. The finalized block's own envelope may be archived by a
65
+ // migration that ran since archiveMaxSlot was computed, so this read can reconstruct too.
66
+ if (endSlot > archiveMaxSlot) {
67
+ const headBlock = chain.forkChoice.getHead();
68
+ const headRoot = headBlock.blockRoot;
69
+ const headChain = chain.forkChoice.getAllAncestorBlocks(headRoot, headBlock.payloadStatus);
63
70
 
64
- // Iterate head chain with ascending block numbers
65
- for (let i = headChain.length - 1; i >= 0; i--) {
66
- const block = headChain[i];
71
+ // Iterate head chain with ascending block numbers
72
+ for (let i = headChain.length - 1; i >= 0; i--) {
73
+ const block = headChain[i];
67
74
 
68
- if (block.slot > archiveMaxSlot && block.slot >= startSlot && block.slot < endSlot) {
69
- // Skip EMPTY blocks
70
- if (block.payloadStatus !== PayloadStatus.FULL) {
71
- continue;
72
- }
75
+ if (block.slot > archiveMaxSlot && block.slot >= startSlot && block.slot < endSlot) {
76
+ // Skip EMPTY blocks
77
+ if (block.payloadStatus !== PayloadStatus.FULL) {
78
+ continue;
79
+ }
73
80
 
74
- const envelopeBytes = await chain.getSerializedExecutionPayloadEnvelope(block.slot, block.blockRoot);
75
- if (!envelopeBytes) {
76
- throw new ResponseError(
77
- RespStatus.SERVER_ERROR,
78
- `No envelope for root ${block.blockRoot} slot ${block.slot}, startSlot=${startSlot} endSlot=${endSlot} finalizedSlot=${finalizedSlot}`
79
- );
80
- }
81
+ const envelopeBytes = await chain.getSerializedExecutionPayloadEnvelope(block.slot, block.blockRoot);
82
+ if (!envelopeBytes) {
83
+ throw new ResponseError(
84
+ RespStatus.SERVER_ERROR,
85
+ `No envelope for root ${block.blockRoot} slot ${block.slot}, startSlot=${startSlot} endSlot=${endSlot} finalizedSlot=${finalizedSlot}`
86
+ );
87
+ }
81
88
 
82
- yield {
83
- data: envelopeBytes,
84
- boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(block.slot)),
85
- };
86
- } else if (block.slot >= endSlot) {
87
- break;
89
+ yielded++;
90
+ yield {
91
+ data: envelopeBytes,
92
+ boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(block.slot)),
93
+ };
94
+ } else if (block.slot >= endSlot) {
95
+ break;
96
+ }
88
97
  }
89
98
  }
99
+ } catch (e) {
100
+ if (e instanceof EnvelopeReconstructionError) {
101
+ // An unservable entry or our own EL failing: after some envelopes, end short (spec-legal, the
102
+ // peer fetches the rest elsewhere); with nothing served, RESOURCE_UNAVAILABLE rather than
103
+ // SERVER_ERROR so peers don't downscore us for it
104
+ if (yielded > 0) return;
105
+ throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, `Failed to serve envelopes: ${e.message}`);
106
+ }
107
+ throw e;
90
108
  }
91
109
  }
92
110
 
@@ -1,7 +1,9 @@
1
1
  import {PeerId} from "@libp2p/interface";
2
- import {ResponseOutgoing} from "@lodestar/reqresp";
2
+ import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
3
3
  import {computeEpochAtSlot} from "@lodestar/state-transition";
4
+ import {RootHex, Slot} from "@lodestar/types";
4
5
  import {toRootHex} from "@lodestar/utils";
6
+ import {EnvelopeReconstructionError} from "../../../chain/errors/index.js";
5
7
  import {IBeaconChain} from "../../../chain/index.js";
6
8
  import {IBeaconDb} from "../../../db/index.js";
7
9
  import {ExecutionPayloadEnvelopesByRootRequest} from "../../../util/types.js";
@@ -17,6 +19,8 @@ export async function* onExecutionPayloadEnvelopesByRoot(
17
19
  // The gloas req/resp spec uses MIN_EPOCHS_FOR_BLOCK_REQUESTS to define the minimum range peers MUST serve.
18
20
  // Archival nodes may still serve older retained payloads to allow genesis sync.
19
21
 
22
+ // Resolve slots first so archived header envelopes are rebuilt in one EL batch, not one call per root
23
+ const requests: {blockSlot: Slot; blockRootHex: RootHex}[] = [];
20
24
  for (const root of requestBody) {
21
25
  const rootHex = toRootHex(root);
22
26
  const block = chain.forkChoice.getBlockHexDefaultStatus(rootHex);
@@ -34,17 +38,35 @@ export async function* onExecutionPayloadEnvelopesByRoot(
34
38
  );
35
39
  continue;
36
40
  }
41
+ requests.push({blockSlot: slot, blockRootHex: rootHex});
42
+ }
43
+
44
+ let envelopesBytes: (Uint8Array | null)[];
45
+ try {
46
+ // by-root allows omission, so a mismatched envelope is left out rather than failing the response
47
+ envelopesBytes = await chain.getSerializedExecutionPayloadEnvelopes(requests, "omit");
48
+ } catch (e) {
49
+ if (e instanceof EnvelopeReconstructionError) {
50
+ throw new ResponseError(
51
+ RespStatus.RESOURCE_UNAVAILABLE,
52
+ `Failed to reconstruct archived envelopes: ${e.message}`
53
+ );
54
+ }
55
+ throw e;
56
+ }
37
57
 
38
- const envelopeBytes = await chain.getSerializedExecutionPayloadEnvelope(slot, rootHex);
58
+ for (let i = 0; i < requests.length; i++) {
59
+ const {blockSlot, blockRootHex} = requests[i];
60
+ const envelopeBytes = envelopesBytes[i];
39
61
  if (envelopeBytes) {
40
62
  yield {
41
63
  data: envelopeBytes,
42
- boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(slot)),
64
+ boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(blockSlot)),
43
65
  };
44
66
  } else {
45
67
  chain.logger.debug("Cannot serve ExecutionPayloadEnvelopesByRoot: envelope not found", {
46
- slot,
47
- root: rootHex,
68
+ slot: blockSlot,
69
+ root: blockRootHex,
48
70
  peer: prettyPrintPeerId(peerId),
49
71
  client: peerClient,
50
72
  });
@@ -1,5 +1,5 @@
1
1
  import type {Type} from "@chainsafe/ssz";
2
- import {ProtocolHandler, RespStatus, ResponseError} from "@lodestar/reqresp";
2
+ import {ProtocolHandler, RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
3
3
  import {ssz} from "@lodestar/types";
4
4
  import {IBeaconChain} from "../../../chain/index.js";
5
5
  import {IBeaconDb} from "../../../db/index.js";
@@ -38,6 +38,29 @@ function deserializeRequestBody<T>(type: Type<T>, data: Uint8Array): T {
38
38
  }
39
39
  }
40
40
 
41
+ async function* trackByRangeResponse(
42
+ chain: IBeaconChain,
43
+ method: ReqRespMethod,
44
+ count: number,
45
+ source: AsyncIterable<ResponseOutgoing>,
46
+ columns?: number
47
+ ): AsyncIterable<ResponseOutgoing> {
48
+ chain.metrics?.reqRespByRange.requestedSlots.observe({method}, count);
49
+ if (columns !== undefined) {
50
+ chain.metrics?.reqRespByRange.requestedColumns.observe(columns);
51
+ }
52
+
53
+ let servedBytes = 0;
54
+ try {
55
+ for await (const chunk of source) {
56
+ servedBytes += chunk.data.length;
57
+ yield chunk;
58
+ }
59
+ } finally {
60
+ chain.metrics?.reqRespByRange.servedBytes.observe({method}, servedBytes);
61
+ }
62
+ }
63
+
41
64
  /**
42
65
  * The ReqRespHandler module handles app-level requests / responses from other peers,
43
66
  * fetching state from the chain and database as needed.
@@ -50,7 +73,12 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
50
73
  [ReqRespMethod.Metadata]: notImplemented(ReqRespMethod.Metadata),
51
74
  [ReqRespMethod.BeaconBlocksByRange]: (req, peerId, peerClient) => {
52
75
  const body = deserializeRequestBody(ssz.phase0.BeaconBlocksByRangeRequest, req.data);
53
- return onBeaconBlocksByRange(body, chain, db, peerId, peerClient);
76
+ return trackByRangeResponse(
77
+ chain,
78
+ ReqRespMethod.BeaconBlocksByRange,
79
+ body.count,
80
+ onBeaconBlocksByRange(body, chain, db, peerId, peerClient)
81
+ );
54
82
  },
55
83
  [ReqRespMethod.BeaconBlocksByRoot]: (req) => {
56
84
  const fork = chain.config.getForkName(chain.clock.currentSlot);
@@ -68,11 +96,22 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
68
96
  },
69
97
  [ReqRespMethod.BlobSidecarsByRange]: (req) => {
70
98
  const body = deserializeRequestBody(ssz.deneb.BlobSidecarsByRangeRequest, req.data);
71
- return onBlobSidecarsByRange(body, chain, db);
99
+ return trackByRangeResponse(
100
+ chain,
101
+ ReqRespMethod.BlobSidecarsByRange,
102
+ body.count,
103
+ onBlobSidecarsByRange(body, chain, db)
104
+ );
72
105
  },
73
106
  [ReqRespMethod.DataColumnSidecarsByRange]: (req, peerId, peerClient) => {
74
107
  const body = deserializeRequestBody(ssz.fulu.DataColumnSidecarsByRangeRequest, req.data);
75
- return onDataColumnSidecarsByRange(body, chain, db, peerId, peerClient);
108
+ return trackByRangeResponse(
109
+ chain,
110
+ ReqRespMethod.DataColumnSidecarsByRange,
111
+ body.count,
112
+ onDataColumnSidecarsByRange(body, chain, db, peerId, peerClient),
113
+ body.columns.length
114
+ );
76
115
  },
77
116
  [ReqRespMethod.DataColumnSidecarsByRoot]: (req, peerId, peerClient) => {
78
117
  const body = deserializeRequestBody(DataColumnSidecarsByRootRequestType(chain.config), req.data);
@@ -85,7 +124,12 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
85
124
  },
86
125
  [ReqRespMethod.ExecutionPayloadEnvelopesByRange]: (req, peerId, peerClient) => {
87
126
  const body = deserializeRequestBody(ssz.gloas.ExecutionPayloadEnvelopesByRangeRequest, req.data);
88
- return onExecutionPayloadEnvelopesByRange(body, chain, db, peerId, peerClient);
127
+ return trackByRangeResponse(
128
+ chain,
129
+ ReqRespMethod.ExecutionPayloadEnvelopesByRange,
130
+ body.count,
131
+ onExecutionPayloadEnvelopesByRange(body, chain, db, peerId, peerClient)
132
+ );
89
133
  },
90
134
 
91
135
  [ReqRespMethod.LightClientBootstrap]: (req) => {
package/src/sync/types.ts CHANGED
@@ -105,8 +105,6 @@ export enum DroppedItemReason {
105
105
  invalidEnvelope = "invalid_envelope",
106
106
  /** a payload had an invalid signature (INVALID_SIGNATURE) */
107
107
  invalidSignature = "invalid_signature",
108
- /** a block root was given up on after exhausting download attempts (data could not be fetched) */
109
- unavailable = "unavailable",
110
108
  /** an unexpected / unhandled error code led to removal */
111
109
  unknown = "unknown",
112
110
  }