@lodestar/beacon-node 1.36.0-dev.d42eb95bf0 → 1.36.0-dev.d8afb6dc39

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 (169) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +41 -22
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/lodestar/index.d.ts +5 -0
  5. package/lib/api/impl/lodestar/index.d.ts.map +1 -1
  6. package/lib/api/impl/lodestar/index.js +35 -10
  7. package/lib/api/impl/lodestar/index.js.map +1 -1
  8. package/lib/api/impl/node/utils.js +1 -1
  9. package/lib/api/impl/node/utils.js.map +1 -1
  10. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -1
  11. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js +6 -1
  12. package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js.map +1 -1
  13. package/lib/chain/chain.d.ts +5 -2
  14. package/lib/chain/chain.d.ts.map +1 -1
  15. package/lib/chain/chain.js +32 -16
  16. package/lib/chain/chain.js.map +1 -1
  17. package/lib/chain/errors/dataColumnSidecarError.d.ts +17 -14
  18. package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
  19. package/lib/chain/errors/dataColumnSidecarError.js +4 -0
  20. package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
  21. package/lib/chain/forkChoice/index.d.ts +9 -1
  22. package/lib/chain/forkChoice/index.d.ts.map +1 -1
  23. package/lib/chain/forkChoice/index.js +109 -4
  24. package/lib/chain/forkChoice/index.js.map +1 -1
  25. package/lib/chain/interface.d.ts +2 -0
  26. package/lib/chain/interface.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 +2 -2
  30. package/lib/chain/options.js.map +1 -1
  31. package/lib/chain/stateCache/datastore/db.d.ts +12 -0
  32. package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
  33. package/lib/chain/stateCache/datastore/db.js +70 -0
  34. package/lib/chain/stateCache/datastore/db.js.map +1 -1
  35. package/lib/chain/stateCache/datastore/file.d.ts +1 -0
  36. package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
  37. package/lib/chain/stateCache/datastore/file.js +7 -0
  38. package/lib/chain/stateCache/datastore/file.js.map +1 -1
  39. package/lib/chain/stateCache/datastore/types.d.ts +1 -0
  40. package/lib/chain/stateCache/datastore/types.d.ts.map +1 -1
  41. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +16 -1
  42. package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
  43. package/lib/chain/stateCache/persistentCheckpointsCache.js +31 -1
  44. package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
  45. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  46. package/lib/chain/validation/dataColumnSidecar.js +32 -15
  47. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  48. package/lib/index.d.ts +2 -0
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +2 -0
  51. package/lib/index.js.map +1 -1
  52. package/lib/metrics/metrics/lodestar.js +1 -1
  53. package/lib/metrics/metrics/lodestar.js.map +1 -1
  54. package/lib/network/core/networkCore.d.ts.map +1 -1
  55. package/lib/network/core/networkCore.js +5 -1
  56. package/lib/network/core/networkCore.js.map +1 -1
  57. package/lib/network/core/networkCoreWorker.js +8 -8
  58. package/lib/network/core/networkCoreWorker.js.map +1 -1
  59. package/lib/network/core/networkCoreWorkerHandler.js +1 -1
  60. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  61. package/lib/network/discv5/worker.js +2 -7
  62. package/lib/network/discv5/worker.js.map +1 -1
  63. package/lib/network/events.d.ts +1 -0
  64. package/lib/network/events.d.ts.map +1 -1
  65. package/lib/network/gossip/encoding.js +1 -1
  66. package/lib/network/gossip/encoding.js.map +1 -1
  67. package/lib/network/gossip/snappy_bun.d.ts +3 -0
  68. package/lib/network/gossip/snappy_bun.d.ts.map +1 -0
  69. package/lib/network/gossip/snappy_bun.js +3 -0
  70. package/lib/network/gossip/snappy_bun.js.map +1 -0
  71. package/lib/network/metadata.d.ts +1 -1
  72. package/lib/network/metadata.d.ts.map +1 -1
  73. package/lib/network/metadata.js +1 -0
  74. package/lib/network/metadata.js.map +1 -1
  75. package/lib/network/options.d.ts +0 -1
  76. package/lib/network/options.d.ts.map +1 -1
  77. package/lib/network/options.js.map +1 -1
  78. package/lib/network/peers/discover.js +2 -2
  79. package/lib/network/peers/discover.js.map +1 -1
  80. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  81. package/lib/network/processor/gossipHandlers.js +14 -8
  82. package/lib/network/processor/gossipHandlers.js.map +1 -1
  83. package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -1
  84. package/lib/network/reqresp/ReqRespBeaconNode.js +3 -1
  85. package/lib/network/reqresp/ReqRespBeaconNode.js.map +1 -1
  86. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts +2 -1
  87. package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
  88. package/lib/network/reqresp/handlers/beaconBlocksByRange.js +14 -3
  89. package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
  90. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts +2 -1
  91. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
  92. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +9 -1
  93. package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
  94. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts +2 -1
  95. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
  96. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +9 -1
  97. package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
  98. package/lib/network/reqresp/handlers/index.js +6 -6
  99. package/lib/network/reqresp/handlers/index.js.map +1 -1
  100. package/lib/network/reqresp/types.d.ts +1 -0
  101. package/lib/network/reqresp/types.d.ts.map +1 -1
  102. package/lib/node/nodejs.d.ts +2 -1
  103. package/lib/node/nodejs.d.ts.map +1 -1
  104. package/lib/node/nodejs.js +2 -1
  105. package/lib/node/nodejs.js.map +1 -1
  106. package/lib/sync/range/range.d.ts.map +1 -1
  107. package/lib/sync/range/range.js +2 -1
  108. package/lib/sync/range/range.js.map +1 -1
  109. package/lib/sync/utils/downloadByRange.d.ts +58 -13
  110. package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
  111. package/lib/sync/utils/downloadByRange.js +201 -82
  112. package/lib/sync/utils/downloadByRange.js.map +1 -1
  113. package/lib/sync/utils/remoteSyncType.d.ts +2 -1
  114. package/lib/sync/utils/remoteSyncType.d.ts.map +1 -1
  115. package/lib/sync/utils/remoteSyncType.js +19 -4
  116. package/lib/sync/utils/remoteSyncType.js.map +1 -1
  117. package/lib/util/blobs.d.ts +1 -1
  118. package/lib/util/blobs.d.ts.map +1 -1
  119. package/lib/util/blobs.js +53 -20
  120. package/lib/util/blobs.js.map +1 -1
  121. package/lib/util/profile.d.ts +6 -4
  122. package/lib/util/profile.d.ts.map +1 -1
  123. package/lib/util/profile.js +40 -3
  124. package/lib/util/profile.js.map +1 -1
  125. package/lib/util/sszBytes.d.ts +2 -0
  126. package/lib/util/sszBytes.d.ts.map +1 -1
  127. package/lib/util/sszBytes.js +25 -0
  128. package/lib/util/sszBytes.js.map +1 -1
  129. package/package.json +31 -24
  130. package/src/api/impl/beacon/blocks/index.ts +47 -25
  131. package/src/api/impl/lodestar/index.ts +42 -10
  132. package/src/api/impl/node/utils.ts +1 -1
  133. package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +5 -1
  134. package/src/chain/chain.ts +48 -23
  135. package/src/chain/errors/dataColumnSidecarError.ts +20 -14
  136. package/src/chain/forkChoice/index.ts +178 -2
  137. package/src/chain/interface.ts +2 -0
  138. package/src/chain/options.ts +2 -3
  139. package/src/chain/stateCache/datastore/db.ts +89 -1
  140. package/src/chain/stateCache/datastore/file.ts +8 -0
  141. package/src/chain/stateCache/datastore/types.ts +1 -0
  142. package/src/chain/stateCache/persistentCheckpointsCache.ts +45 -2
  143. package/src/chain/validation/dataColumnSidecar.ts +34 -16
  144. package/src/index.ts +2 -0
  145. package/src/metrics/metrics/lodestar.ts +1 -1
  146. package/src/network/core/networkCore.ts +5 -1
  147. package/src/network/core/networkCoreWorker.ts +9 -9
  148. package/src/network/core/networkCoreWorkerHandler.ts +1 -1
  149. package/src/network/discv5/worker.ts +2 -7
  150. package/src/network/events.ts +1 -1
  151. package/src/network/gossip/encoding.ts +1 -1
  152. package/src/network/gossip/snappy_bun.ts +2 -0
  153. package/src/network/metadata.ts +3 -1
  154. package/src/network/options.ts +0 -1
  155. package/src/network/peers/discover.ts +2 -2
  156. package/src/network/processor/gossipHandlers.ts +16 -7
  157. package/src/network/reqresp/ReqRespBeaconNode.ts +3 -1
  158. package/src/network/reqresp/handlers/beaconBlocksByRange.ts +18 -3
  159. package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +13 -1
  160. package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +13 -1
  161. package/src/network/reqresp/handlers/index.ts +6 -6
  162. package/src/network/reqresp/types.ts +1 -0
  163. package/src/node/nodejs.ts +3 -0
  164. package/src/sync/range/range.ts +2 -1
  165. package/src/sync/utils/downloadByRange.ts +259 -103
  166. package/src/sync/utils/remoteSyncType.ts +23 -4
  167. package/src/util/blobs.ts +64 -20
  168. package/src/util/profile.ts +45 -3
  169. package/src/util/sszBytes.ts +30 -0
@@ -1,5 +1,3 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
1
  import worker from "node:worker_threads";
4
2
  import {privateKeyFromProtobuf} from "@libp2p/crypto/keys";
5
3
  import {peerIdFromPrivateKey} from "@libp2p/peer-id";
@@ -11,7 +9,7 @@ import {RegistryMetricCreator, collectNodeJSMetrics} from "../../metrics/index.j
11
9
  import {AsyncIterableBridgeCaller, AsyncIterableBridgeHandler} from "../../util/asyncIterableToEvents.js";
12
10
  import {Clock} from "../../util/clock.js";
13
11
  import {peerIdToString} from "../../util/peerId.js";
14
- import {profileNodeJS, writeHeapSnapshot} from "../../util/profile.js";
12
+ import {ProfileThread, profileThread, writeHeapSnapshot} from "../../util/profile.js";
15
13
  import {wireEventsOnWorkerThread} from "../../util/workerEvents.js";
16
14
  import {NetworkEventBus, NetworkEventData, networkEventDirection} from "../events.js";
17
15
  import {
@@ -100,8 +98,13 @@ const core = await NetworkCore.init({
100
98
  metricsRegistry: metricsRegister,
101
99
  events,
102
100
  clock,
103
- getReqRespHandler: (method) => (req, peerId) =>
104
- reqRespBridgeRespCaller.getAsyncIterable({method, req, peerId: peerIdToString(peerId)}),
101
+ getReqRespHandler: (method) => (req, peerId, peerClient) =>
102
+ reqRespBridgeRespCaller.getAsyncIterable({
103
+ method,
104
+ req,
105
+ peerId: peerIdToString(peerId),
106
+ peerClient,
107
+ }),
105
108
  activeValidatorCount: workerData.activeValidatorCount,
106
109
  initialStatus: workerData.initialStatus,
107
110
  initialCustodyGroupCount: workerData.initialCustodyGroupCount,
@@ -157,10 +160,7 @@ const libp2pWorkerApi: NetworkWorkerApi = {
157
160
  dumpDiscv5KadValues: () => core.dumpDiscv5KadValues(),
158
161
  dumpMeshPeers: () => core.dumpMeshPeers(),
159
162
  writeProfile: async (durationMs: number, dirpath: string) => {
160
- const profile = await profileNodeJS(durationMs);
161
- const filePath = path.join(dirpath, `network_thread_${new Date().toISOString()}.cpuprofile`);
162
- fs.writeFileSync(filePath, profile);
163
- return filePath;
163
+ return profileThread(ProfileThread.NETWORK, durationMs, dirpath);
164
164
  },
165
165
  writeDiscv5Profile: async (durationMs: number, dirpath: string) => {
166
166
  return core.writeDiscv5Profile(durationMs, dirpath);
@@ -73,7 +73,7 @@ export class WorkerNetworkCore implements INetworkCore {
73
73
  // Handles ReqResp response from worker and calls async generator in main thread
74
74
  this.reqRespBridgeRespHandler = new AsyncIterableBridgeHandler(
75
75
  getReqRespBridgeRespEvents(this.reqRespBridgeEventBus),
76
- (data) => modules.getReqRespHandler(data.method)(data.req, peerIdFromString(data.peerId))
76
+ (data) => modules.getReqRespHandler(data.method)(data.req, peerIdFromString(data.peerId), data.peerClient)
77
77
  );
78
78
 
79
79
  wireEventsOnMainThread<NetworkEventData>(
@@ -1,5 +1,3 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
1
  import worker from "node:worker_threads";
4
2
  import {privateKeyFromProtobuf} from "@libp2p/crypto/keys";
5
3
  import {peerIdFromPrivateKey} from "@libp2p/peer-id";
@@ -14,7 +12,7 @@ import {Gauge} from "@lodestar/utils";
14
12
  import {RegistryMetricCreator} from "../../metrics/index.js";
15
13
  import {collectNodeJSMetrics} from "../../metrics/nodeJsMetrics.js";
16
14
  import {Clock} from "../../util/clock.js";
17
- import {profileNodeJS, writeHeapSnapshot} from "../../util/profile.js";
15
+ import {ProfileThread, profileThread, writeHeapSnapshot} from "../../util/profile.js";
18
16
  import {Discv5WorkerApi, Discv5WorkerData} from "./types.js";
19
17
  import {ENRRelevance, enrRelevance} from "./utils.js";
20
18
 
@@ -108,10 +106,7 @@ const module: Discv5WorkerApi = {
108
106
  return (await metricsRegistry?.metrics()) ?? "";
109
107
  },
110
108
  writeProfile: async (durationMs: number, dirpath: string) => {
111
- const profile = await profileNodeJS(durationMs);
112
- const filePath = path.join(dirpath, `discv5_thread_${new Date().toISOString()}.cpuprofile`);
113
- fs.writeFileSync(filePath, profile);
114
- return filePath;
109
+ return profileThread(ProfileThread.DISC5, durationMs, dirpath);
115
110
  },
116
111
  writeHeapSnapshot: async (prefix: string, dirpath: string) => {
117
112
  return writeHeapSnapshot(prefix, dirpath);
@@ -29,7 +29,7 @@ export type NetworkEventData = {
29
29
  clientAgent: string;
30
30
  };
31
31
  [NetworkEvent.peerDisconnected]: {peer: PeerIdStr};
32
- [NetworkEvent.reqRespRequest]: {request: RequestTypedContainer; peer: PeerId};
32
+ [NetworkEvent.reqRespRequest]: {request: RequestTypedContainer; peer: PeerId; peerClient: string};
33
33
  [NetworkEvent.pendingGossipsubMessage]: PendingGossipsubMessage;
34
34
  [NetworkEvent.gossipMessageValidationResult]: {
35
35
  msgId: string;
@@ -1,6 +1,6 @@
1
1
  import {Message} from "@libp2p/interface";
2
- import {compress, uncompress} from "snappyjs";
3
2
  import xxhashFactory from "xxhash-wasm";
3
+ import {compress, uncompress} from "#snappy";
4
4
  import {digest} from "@chainsafe/as-sha256";
5
5
  import {RPC} from "@chainsafe/libp2p-gossipsub/message";
6
6
  import {DataTransform} from "@chainsafe/libp2p-gossipsub/types";
@@ -0,0 +1,2 @@
1
+ import {snappy} from "@lodestar/bun";
2
+ export const {compress, uncompress} = snappy;
@@ -126,7 +126,7 @@ export class MetadataController {
126
126
  * 2. Network MUST call this method on fork transition.
127
127
  * Current Clock implementation ensures no race conditions, epoch is correct if re-fetched
128
128
  */
129
- updateEth2Field(epoch: Epoch): void {
129
+ updateEth2Field(epoch: Epoch): phase0.ENRForkID {
130
130
  const config = this.networkConfig.config;
131
131
  const enrForkId = getENRForkID(config, epoch);
132
132
  const {forkDigest, nextForkVersion, nextForkEpoch} = enrForkId;
@@ -143,6 +143,8 @@ export class MetadataController {
143
143
  : ssz.ForkDigest.defaultValue();
144
144
  this.onSetValue(ENRKey.nfd, nextForkDigest);
145
145
  this.logger.debug("Updated nfd field in ENR", {nextForkDigest: toHex(nextForkDigest)});
146
+
147
+ return enrForkId;
146
148
  }
147
149
  }
148
150
 
@@ -23,7 +23,6 @@ export interface NetworkOptions
23
23
  useWorker?: boolean;
24
24
  maxYoungGenerationSizeMb?: number;
25
25
  disableLightClientServer?: boolean;
26
- supernode?: boolean;
27
26
 
28
27
  /**
29
28
  * During E2E tests observe a lot of following `missing stream`:
@@ -391,8 +391,8 @@ export class PeerDiscovery {
391
391
  // tcp multiaddr is known to be be present, checked inside the worker
392
392
  const multiaddrTCP = enr.getLocationMultiaddr(ENRKey.tcp);
393
393
  if (!multiaddrTCP) {
394
- this.logger.error("Discv5 worker sent enr without tcp multiaddr", {enr: enr.encodeTxt()});
395
- this.metrics?.discovery.discoveredStatus.inc({status: DiscoveredPeerStatus.error});
394
+ this.logger.warn("Discv5 worker sent enr without tcp multiaddr", {enr: enr.encodeTxt()});
395
+ this.metrics?.discovery.discoveredStatus.inc({status: DiscoveredPeerStatus.no_multiaddrs});
396
396
  return;
397
397
  }
398
398
  // Are this fields mandatory?
@@ -39,6 +39,7 @@ import {
39
39
  BlockError,
40
40
  BlockErrorCode,
41
41
  BlockGossipError,
42
+ DataColumnSidecarErrorCode,
42
43
  DataColumnSidecarGossipError,
43
44
  GossipAction,
44
45
  GossipActionError,
@@ -304,7 +305,11 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
304
305
  ...blockInput.getLogMeta(),
305
306
  index: dataColumnSidecar.index,
306
307
  });
307
- return blockInput;
308
+ throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
309
+ code: DataColumnSidecarErrorCode.ALREADY_KNOWN,
310
+ columnIndex: dataColumnSidecar.index,
311
+ slot,
312
+ });
308
313
  }
309
314
  }
310
315
 
@@ -556,6 +561,16 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
556
561
  metrics?.dataColumns.elapsedTimeTillReceived.observe({receivedOrder: receivedColumns}, delaySec);
557
562
  break;
558
563
  }
564
+
565
+ if (!blockInput.hasAllData()) {
566
+ // immediately attempt fetch of data columns from execution engine
567
+ chain.getBlobsTracker.triggerGetBlobs(blockInput);
568
+ // if we've received at least half of the columns, trigger reconstruction of the rest
569
+ if (blockInput.columnCount >= NUMBER_OF_COLUMNS / 2) {
570
+ chain.columnReconstructionTracker.triggerColumnReconstruction(blockInput);
571
+ }
572
+ }
573
+
559
574
  if (!blockInput.hasBlockAndAllData()) {
560
575
  const cutoffTimeMs = getCutoffTimeMs(chain, dataColumnSlot, BLOCK_AVAILABILITY_CUTOFF_MS);
561
576
  chain.logger.debug("Received gossip data column, waiting for full data availability", {
@@ -578,12 +593,6 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
578
593
  source: BlockInputSource.gossip,
579
594
  });
580
595
  });
581
- // immediately attempt fetch of data columns from execution engine
582
- chain.getBlobsTracker.triggerGetBlobs(blockInput);
583
- // if we've received at least half of the columns, trigger reconstruction of the rest
584
- if (blockInput.columnCount >= NUMBER_OF_COLUMNS / 2) {
585
- chain.columnReconstructionTracker.triggerColumnReconstruction(blockInput);
586
- }
587
596
  }
588
597
  },
589
598
 
@@ -19,6 +19,7 @@ import {callInNextEventLoop} from "../../util/eventLoop.js";
19
19
  import {NetworkCoreMetrics} from "../core/metrics.js";
20
20
  import {INetworkEventBus, NetworkEvent} from "../events.js";
21
21
  import {MetadataController} from "../metadata.js";
22
+ import {ClientKind} from "../peers/client.ts";
22
23
  import {PeersData} from "../peers/peersData.js";
23
24
  import {IPeerRpcScoreStore, PeerAction} from "../peers/score/index.js";
24
25
  import {StatusCache} from "../statusCache.js";
@@ -300,10 +301,11 @@ export class ReqRespBeaconNode extends ReqResp {
300
301
  }
301
302
 
302
303
  protected onIncomingRequestBody(request: RequestTypedContainer, peer: PeerId): void {
304
+ const peerClient = this.peersData.getPeerKind(peer.toString()) ?? ClientKind.Unknown;
303
305
  // Allow onRequest to return and close the stream
304
306
  // For Goodbye there may be a race condition where the listener of `receivedGoodbye`
305
307
  // disconnects in the same synchronous call, preventing the stream from ending cleanly
306
- callInNextEventLoop(() => this.networkEventBus.emit(NetworkEvent.reqRespRequest, {request, peer}));
308
+ callInNextEventLoop(() => this.networkEventBus.emit(NetworkEvent.reqRespRequest, {request, peer, peerClient}));
307
309
  }
308
310
 
309
311
  protected onIncomingRequest(peerId: PeerId, protocol: ProtocolDescriptor): void {
@@ -1,25 +1,40 @@
1
+ import {PeerId} from "@libp2p/interface";
1
2
  import {BeaconConfig} from "@lodestar/config";
2
- import {GENESIS_SLOT, isForkPostDeneb} from "@lodestar/params";
3
+ import {GENESIS_SLOT, isForkPostDeneb, isForkPostFulu} from "@lodestar/params";
3
4
  import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
4
5
  import {computeEpochAtSlot} from "@lodestar/state-transition";
5
6
  import {deneb, phase0} from "@lodestar/types";
6
7
  import {fromHex} from "@lodestar/utils";
7
8
  import {IBeaconChain} from "../../../chain/index.js";
8
9
  import {IBeaconDb} from "../../../db/index.js";
10
+ import {prettyPrintPeerId} from "../../util.ts";
9
11
 
10
12
  // TODO: Unit test
11
13
 
12
14
  export async function* onBeaconBlocksByRange(
13
15
  request: phase0.BeaconBlocksByRangeRequest,
14
16
  chain: IBeaconChain,
15
- db: IBeaconDb
17
+ db: IBeaconDb,
18
+ peerId: PeerId,
19
+ peerClient: string
16
20
  ): AsyncIterable<ResponseOutgoing> {
17
21
  const {startSlot, count} = validateBeaconBlocksByRangeRequest(chain.config, request);
18
22
  const endSlot = startSlot + count;
19
23
 
20
24
  const finalized = db.blockArchive;
21
25
  const unfinalized = db.block;
22
- const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
26
+ // in the case of initializing from a non-finalized state, we don't have the finalized block so this api does not work
27
+ // chain.forkChoice.getFinalizeBlock().slot
28
+ const finalizedSlot = chain.forkChoice.getFinalizedCheckpointSlot();
29
+
30
+ const forkName = chain.config.getForkName(startSlot);
31
+ if (isForkPostFulu(forkName) && startSlot < chain.earliestAvailableSlot) {
32
+ chain.logger.verbose("Peer did not respect earliestAvailableSlot for BeaconBlocksByRange", {
33
+ peer: prettyPrintPeerId(peerId),
34
+ client: peerClient,
35
+ });
36
+ return;
37
+ }
23
38
 
24
39
  // Finalized range of blocks
25
40
  if (startSlot <= finalizedSlot) {
@@ -1,3 +1,4 @@
1
+ import {PeerId} from "@libp2p/interface";
1
2
  import {ChainConfig} from "@lodestar/config";
2
3
  import {GENESIS_SLOT} from "@lodestar/params";
3
4
  import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp";
@@ -6,6 +7,7 @@ import {ColumnIndex, fulu} from "@lodestar/types";
6
7
  import {fromHex} from "@lodestar/utils";
7
8
  import {IBeaconChain} from "../../../chain/index.js";
8
9
  import {IBeaconDb} from "../../../db/index.js";
10
+ import {prettyPrintPeerId} from "../../util.ts";
9
11
  import {
10
12
  handleColumnSidecarUnavailability,
11
13
  validateRequestedDataColumns,
@@ -14,7 +16,9 @@ import {
14
16
  export async function* onDataColumnSidecarsByRange(
15
17
  request: fulu.DataColumnSidecarsByRangeRequest,
16
18
  chain: IBeaconChain,
17
- db: IBeaconDb
19
+ db: IBeaconDb,
20
+ peerId: PeerId,
21
+ peerClient: string
18
22
  ): AsyncIterable<ResponseOutgoing> {
19
23
  // Non-finalized range of columns
20
24
  const {startSlot, count, columns: requestedColumns} = validateDataColumnSidecarsByRangeRequest(chain.config, request);
@@ -25,6 +29,14 @@ export async function* onDataColumnSidecarsByRange(
25
29
  return;
26
30
  }
27
31
 
32
+ if (startSlot < chain.earliestAvailableSlot) {
33
+ chain.logger.verbose("Peer did not respect earliestAvailableSlot for DataColumnSidecarsByRange", {
34
+ peer: prettyPrintPeerId(peerId),
35
+ client: peerClient,
36
+ });
37
+ return;
38
+ }
39
+
28
40
  const finalized = db.dataColumnSidecarArchive;
29
41
  const unfinalized = db.dataColumnSidecar;
30
42
  const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
@@ -1,3 +1,4 @@
1
+ import {PeerId} from "@libp2p/interface";
1
2
  import {ResponseOutgoing} from "@lodestar/reqresp";
2
3
  import {computeEpochAtSlot} from "@lodestar/state-transition";
3
4
  import {ColumnIndex} from "@lodestar/types";
@@ -5,6 +6,7 @@ import {toRootHex} from "@lodestar/utils";
5
6
  import {IBeaconChain} from "../../../chain/index.js";
6
7
  import {IBeaconDb} from "../../../db/index.js";
7
8
  import {DataColumnSidecarsByRootRequest} from "../../../util/types.js";
9
+ import {prettyPrintPeerId} from "../../util.ts";
8
10
  import {
9
11
  handleColumnSidecarUnavailability,
10
12
  validateRequestedDataColumns,
@@ -13,7 +15,9 @@ import {
13
15
  export async function* onDataColumnSidecarsByRoot(
14
16
  requestBody: DataColumnSidecarsByRootRequest,
15
17
  chain: IBeaconChain,
16
- db: IBeaconDb
18
+ db: IBeaconDb,
19
+ peerId: PeerId,
20
+ peerClient: string
17
21
  ): AsyncIterable<ResponseOutgoing> {
18
22
  // SPEC: minimum_request_epoch = max(current_epoch - MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS, FULU_FORK_EPOCH)
19
23
  const currentEpoch = chain.clock.currentEpoch;
@@ -39,6 +43,14 @@ export async function* onDataColumnSidecarsByRoot(
39
43
  continue;
40
44
  }
41
45
 
46
+ if (slot < chain.earliestAvailableSlot) {
47
+ chain.logger.verbose("Peer did not respect earliestAvailableSlot for DataColumnSidecarsByRoot", {
48
+ peer: prettyPrintPeerId(peerId),
49
+ client: peerClient,
50
+ });
51
+ continue;
52
+ }
53
+
42
54
  const requestedEpoch = computeEpochAtSlot(slot);
43
55
 
44
56
  // SPEC: Clients MUST support requesting sidecars since minimum_request_epoch.
@@ -35,9 +35,9 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
35
35
  [ReqRespMethod.Goodbye]: notImplemented(ReqRespMethod.Goodbye),
36
36
  [ReqRespMethod.Ping]: notImplemented(ReqRespMethod.Ping),
37
37
  [ReqRespMethod.Metadata]: notImplemented(ReqRespMethod.Metadata),
38
- [ReqRespMethod.BeaconBlocksByRange]: (req) => {
38
+ [ReqRespMethod.BeaconBlocksByRange]: (req, peerId, peerClient) => {
39
39
  const body = ssz.phase0.BeaconBlocksByRangeRequest.deserialize(req.data);
40
- return onBeaconBlocksByRange(body, chain, db);
40
+ return onBeaconBlocksByRange(body, chain, db, peerId, peerClient);
41
41
  },
42
42
  [ReqRespMethod.BeaconBlocksByRoot]: (req) => {
43
43
  const fork = chain.config.getForkName(chain.clock.currentSlot);
@@ -53,13 +53,13 @@ export function getReqRespHandlers({db, chain}: {db: IBeaconDb; chain: IBeaconCh
53
53
  const body = ssz.deneb.BlobSidecarsByRangeRequest.deserialize(req.data);
54
54
  return onBlobSidecarsByRange(body, chain, db);
55
55
  },
56
- [ReqRespMethod.DataColumnSidecarsByRange]: (req) => {
56
+ [ReqRespMethod.DataColumnSidecarsByRange]: (req, peerId, peerClient) => {
57
57
  const body = ssz.fulu.DataColumnSidecarsByRangeRequest.deserialize(req.data);
58
- return onDataColumnSidecarsByRange(body, chain, db);
58
+ return onDataColumnSidecarsByRange(body, chain, db, peerId, peerClient);
59
59
  },
60
- [ReqRespMethod.DataColumnSidecarsByRoot]: (req) => {
60
+ [ReqRespMethod.DataColumnSidecarsByRoot]: (req, peerId, peerClient) => {
61
61
  const body = DataColumnSidecarsByRootRequestType(chain.config).deserialize(req.data);
62
- return onDataColumnSidecarsByRoot(body, chain, db);
62
+ return onDataColumnSidecarsByRoot(body, chain, db, peerId, peerClient);
63
63
  },
64
64
 
65
65
  [ReqRespMethod.LightClientBootstrap]: (req) => {
@@ -169,6 +169,7 @@ export type IncomingRequestArgs = {
169
169
  method: ReqRespMethod;
170
170
  req: ReqRespRequest;
171
171
  peerId: string;
172
+ peerClient: string;
172
173
  };
173
174
 
174
175
  export type GetReqRespHandlerFn = (method: ReqRespMethod) => ProtocolHandler;
@@ -53,6 +53,7 @@ export type BeaconNodeInitModules = {
53
53
  dataDir: string;
54
54
  peerStoreDir?: string;
55
55
  anchorState: BeaconStateAllForks;
56
+ isAnchorStateFinalized: boolean;
56
57
  wsCheckpoint?: phase0.Checkpoint;
57
58
  metricsRegistries?: Registry[];
58
59
  };
@@ -154,6 +155,7 @@ export class BeaconNode {
154
155
  dataDir,
155
156
  peerStoreDir,
156
157
  anchorState,
158
+ isAnchorStateFinalized,
157
159
  wsCheckpoint,
158
160
  metricsRegistries = [],
159
161
  }: BeaconNodeInitModules): Promise<T> {
@@ -217,6 +219,7 @@ export class BeaconNode {
217
219
  metrics,
218
220
  validatorMonitor,
219
221
  anchorState,
222
+ isAnchorStateFinalized,
220
223
  eth1: initializeEth1ForBlockProduction(opts.eth1, {
221
224
  config,
222
225
  db,
@@ -114,13 +114,14 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
114
114
  */
115
115
  addPeer(peerId: PeerIdStr, localStatus: Status, peerStatus: Status): void {
116
116
  // Compute if we should do a Finalized or Head sync with this peer
117
- const {syncType, startEpoch, target} = getRangeSyncTarget(localStatus, peerStatus, this.chain.forkChoice);
117
+ const {syncType, startEpoch, target} = getRangeSyncTarget(localStatus, peerStatus, this.chain);
118
118
  this.logger.debug("Sync peer joined", {
119
119
  peer: peerId,
120
120
  syncType,
121
121
  startEpoch,
122
122
  targetSlot: target.slot,
123
123
  targetRoot: toRootHex(target.root),
124
+ localHeadSlot: localStatus.headSlot,
124
125
  earliestAvailableSlot: (peerStatus as fulu.Status).earliestAvailableSlot ?? Infinity,
125
126
  });
126
127