@lodestar/beacon-node 1.42.0-dev.1d50253953 → 1.42.0-dev.4118b5b440

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 (48) hide show
  1. package/lib/api/impl/validator/index.js +1 -1
  2. package/lib/api/impl/validator/index.js.map +1 -1
  3. package/lib/chain/blocks/blockInput/types.d.ts +1 -0
  4. package/lib/chain/blocks/blockInput/types.d.ts.map +1 -1
  5. package/lib/chain/blocks/blockInput/types.js +1 -0
  6. package/lib/chain/blocks/blockInput/types.js.map +1 -1
  7. package/lib/chain/validation/syncCommittee.d.ts +2 -2
  8. package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
  9. package/lib/chain/validation/syncCommittee.js +12 -11
  10. package/lib/chain/validation/syncCommittee.js.map +1 -1
  11. package/lib/metrics/metrics/lodestar.d.ts +12 -4
  12. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  13. package/lib/metrics/metrics/lodestar.js +19 -15
  14. package/lib/metrics/metrics/lodestar.js.map +1 -1
  15. package/lib/network/gossip/encoding.d.ts.map +1 -1
  16. package/lib/network/gossip/encoding.js +15 -0
  17. package/lib/network/gossip/encoding.js.map +1 -1
  18. package/lib/network/interface.d.ts +1 -1
  19. package/lib/network/interface.d.ts.map +1 -1
  20. package/lib/network/network.d.ts +1 -1
  21. package/lib/network/network.d.ts.map +1 -1
  22. package/lib/network/network.js +2 -2
  23. package/lib/network/network.js.map +1 -1
  24. package/lib/network/processor/extractSlotRootFns.d.ts +1 -1
  25. package/lib/network/processor/extractSlotRootFns.js +1 -1
  26. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  27. package/lib/network/processor/gossipHandlers.js +9 -7
  28. package/lib/network/processor/gossipHandlers.js.map +1 -1
  29. package/lib/network/processor/index.d.ts +12 -7
  30. package/lib/network/processor/index.d.ts.map +1 -1
  31. package/lib/network/processor/index.js +99 -78
  32. package/lib/network/processor/index.js.map +1 -1
  33. package/lib/sync/unknownBlock.d.ts +3 -9
  34. package/lib/sync/unknownBlock.d.ts.map +1 -1
  35. package/lib/sync/unknownBlock.js +8 -41
  36. package/lib/sync/unknownBlock.js.map +1 -1
  37. package/package.json +15 -15
  38. package/src/api/impl/validator/index.ts +1 -1
  39. package/src/chain/blocks/blockInput/types.ts +1 -0
  40. package/src/chain/validation/syncCommittee.ts +15 -14
  41. package/src/metrics/metrics/lodestar.ts +23 -19
  42. package/src/network/gossip/encoding.ts +16 -0
  43. package/src/network/interface.ts +1 -1
  44. package/src/network/network.ts +2 -2
  45. package/src/network/processor/extractSlotRootFns.ts +1 -1
  46. package/src/network/processor/gossipHandlers.ts +9 -8
  47. package/src/network/processor/index.ts +110 -89
  48. package/src/sync/unknownBlock.ts +10 -50
@@ -2,7 +2,7 @@ import {routes} from "@lodestar/api";
2
2
  import {ForkSeq} from "@lodestar/params";
3
3
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
4
4
  import {RootHex, Slot, SlotRootHex} from "@lodestar/types";
5
- import {Logger, MapDef, mapValues, pruneSetToMax, sleep} from "@lodestar/utils";
5
+ import {Logger, MapDef, mapValues, sleep} from "@lodestar/utils";
6
6
  import {BlockInputSource} from "../../chain/blocks/blockInput/types.js";
7
7
  import {ChainEvent} from "../../chain/emitter.js";
8
8
  import {GossipErrorCode} from "../../chain/errors/gossipValidation.js";
@@ -87,27 +87,27 @@ const executeGossipWorkOrder = Object.keys(executeGossipWorkOrderObj) as (keyof
87
87
  // TODO: Arbitrary constant, check metrics
88
88
  const MAX_JOBS_SUBMITTED_PER_TICK = 128;
89
89
 
90
- // How many attestations (aggregate + unaggregate) we keep before new ones get dropped.
90
+ // How many gossip messages we keep before new ones get dropped.
91
91
  const MAX_QUEUED_UNKNOWN_BLOCK_GOSSIP_OBJECTS = 16_384;
92
92
 
93
- // We don't want to process too many attestations in a single tick
94
- // As seen on mainnet, attestation concurrency metric ranges from 1000 to 2000
93
+ // We don't want to process too many gossip messages in a single tick
94
+ // As seen on mainnet, gossip messages concurrency metric ranges from 1000 to 2000
95
95
  // so make this constant a little bit conservative
96
- const MAX_UNKNOWN_BLOCK_GOSSIP_OBJECTS_PER_TICK = 1024;
96
+ const MAX_AWAITING_GOSSIP_OBJECTS_PER_TICK = 1024;
97
97
 
98
98
  // Same motivation to JobItemQueue, we don't want to block the event loop
99
- const PROCESS_UNKNOWN_BLOCK_GOSSIP_OBJECTS_YIELD_EVERY_MS = 50;
99
+ const AWAITING_GOSSIP_OBJECTS_YIELD_EVERY_MS = 50;
100
100
 
101
101
  /**
102
102
  * Reprocess reject reason for metrics
103
103
  */
104
104
  export enum ReprocessRejectReason {
105
105
  /**
106
- * There are too many attestations that have unknown block root.
106
+ * There are too many gossip messages that have unknown block root.
107
107
  */
108
108
  reached_limit = "reached_limit",
109
109
  /**
110
- * The awaiting attestation is pruned per clock slot.
110
+ * The awaiting gossip message is pruned per clock slot.
111
111
  */
112
112
  expired = "expired",
113
113
  }
@@ -137,7 +137,7 @@ export enum CannotAcceptWorkReason {
137
137
  *
138
138
  * ### PendingGossipsubMessage beacon_attestation example
139
139
  *
140
- * For attestations, processing the message includes the steps:
140
+ * For gossip messages, processing the message includes the steps:
141
141
  * 1. Pre shuffling sync validation
142
142
  * 2. Retrieve shuffling: async + goes into the regen queue and can be expensive
143
143
  * 3. Pre sig validation sync validation
@@ -156,11 +156,10 @@ export class NetworkProcessor {
156
156
  private readonly gossipQueues: ReturnType<typeof createGossipQueues>;
157
157
  private readonly gossipTopicConcurrency: {[K in GossipType]: number};
158
158
  private readonly extractBlockSlotRootFns = createExtractBlockSlotRootFns();
159
- // we may not receive the block for Attestation and SignedAggregateAndProof messages, in that case PendingGossipsubMessage needs
159
+ // we may not receive the block for messages like Attestation and SignedAggregateAndProof messages, in that case PendingGossipsubMessage needs
160
160
  // to be stored in this Map and reprocessed once the block comes
161
- private readonly awaitingGossipsubMessagesByRootBySlot: MapDef<Slot, MapDef<RootHex, Set<PendingGossipsubMessage>>>;
162
- private unknownBlockGossipsubMessagesCount = 0;
163
- private unknownRootsBySlot = new MapDef<Slot, Set<RootHex>>(() => new Set());
161
+ private readonly awaitingMessagesByBlockRoot: MapDef<RootHex, Set<PendingGossipsubMessage>>;
162
+ private unknownBlocksBySlot = new MapDef<Slot, Set<RootHex>>(() => new Set());
164
163
 
165
164
  constructor(
166
165
  modules: NetworkProcessorModules,
@@ -184,9 +183,7 @@ export class NetworkProcessor {
184
183
  this.chain.emitter.on(routes.events.EventType.block, this.onBlockProcessed.bind(this));
185
184
  this.chain.clock.on(ClockEvent.slot, this.onClockSlot.bind(this));
186
185
 
187
- this.awaitingGossipsubMessagesByRootBySlot = new MapDef(
188
- () => new MapDef<RootHex, Set<PendingGossipsubMessage>>(() => new Set())
189
- );
186
+ this.awaitingMessagesByBlockRoot = new MapDef<RootHex, Set<PendingGossipsubMessage>>(() => new Set());
190
187
 
191
188
  // TODO: Implement queues and priorization for ReqResp incoming requests
192
189
  // Listens to NetworkEvent.reqRespIncomingRequest event
@@ -198,7 +195,7 @@ export class NetworkProcessor {
198
195
  metrics.gossipValidationQueue.keySize.set({topic}, this.gossipQueues[topic].keySize);
199
196
  metrics.gossipValidationQueue.concurrency.set({topic}, this.gossipTopicConcurrency[topic]);
200
197
  }
201
- metrics.reprocessGossipAttestations.countPerSlot.set(this.unknownBlockGossipsubMessagesCount);
198
+ metrics.awaitingBlockGossipMessages.countPerSlot.set(this.unknownBlockGossipsubMessagesCount);
202
199
  // specific metric for beacon_attestation topic
203
200
  metrics.gossipValidationQueue.keyAge.reset();
204
201
  for (const ageMs of this.gossipQueues.beacon_attestation.getDataAgeMs()) {
@@ -233,64 +230,77 @@ export class NetworkProcessor {
233
230
  return queue.getAll();
234
231
  }
235
232
 
236
- searchUnknownSlotRoot({slot, root}: SlotRootHex, source: BlockInputSource, peer?: PeerIdStr): void {
237
- if (this.chain.seenBlock(root) || this.unknownRootsBySlot.getOrDefault(slot).has(root)) {
233
+ /**
234
+ * Search block via `ChainEvent.unknownBlockRoot` event
235
+ * Note that slot is not necessarily the same to the block's slot but it can be used for a good prune strategy.
236
+ * In the rare case, if 2 messages on 2 slots search for the same root (for example beacon_attestation) we may emit the same root twice but BlockInputSync should handle it well.
237
+ */
238
+ searchUnknownBlock({slot, root}: SlotRootHex, source: BlockInputSource, peer?: PeerIdStr): void {
239
+ if (
240
+ this.chain.seenBlock(root) ||
241
+ this.awaitingMessagesByBlockRoot.has(root) ||
242
+ this.unknownBlocksBySlot.getOrDefault(slot).has(root)
243
+ ) {
238
244
  return;
239
245
  }
240
246
  // Search for the unknown block
241
- this.unknownRootsBySlot.getOrDefault(slot).add(root);
247
+ this.unknownBlocksBySlot.getOrDefault(slot).add(root);
242
248
  this.chain.emitter.emit(ChainEvent.unknownBlockRoot, {rootHex: root, peer, source});
243
249
  }
244
250
 
245
251
  private onPendingGossipsubMessage(message: PendingGossipsubMessage): void {
246
252
  const topicType = message.topic.type;
247
253
  const extractBlockSlotRootFn = this.extractBlockSlotRootFns[topicType];
248
- // check block root of Attestation and SignedAggregateAndProof messages
249
- if (extractBlockSlotRootFn) {
250
- const slotRoot = extractBlockSlotRootFn(message.msg.data, message.topic.boundary.fork);
251
- // if slotRoot is null, it means the msg.data is invalid
252
- // in that case message will be rejected when deserializing data in later phase (gossipValidatorFn)
253
- if (slotRoot) {
254
- // DOS protection: avoid processing messages that are too old
255
- const {slot, root} = slotRoot;
256
- const clockSlot = this.chain.clock.currentSlot;
257
- const {fork} = message.topic.boundary;
258
- let earliestPermissableSlot = clockSlot - DEFAULT_EARLIEST_PERMISSIBLE_SLOT_DISTANCE;
259
- if (ForkSeq[fork] >= ForkSeq.deneb && topicType === GossipType.beacon_attestation) {
260
- // post deneb, the attestations could be in current or previous epoch
261
- earliestPermissableSlot = computeStartSlotAtEpoch(this.chain.clock.currentEpoch - 1);
262
- }
263
- if (slot < earliestPermissableSlot) {
264
- // TODO: Should report the dropped job to gossip? It will be eventually pruned from the mcache
265
- this.metrics?.networkProcessor.gossipValidationError.inc({
266
- topic: topicType,
267
- error: GossipErrorCode.PAST_SLOT,
268
- });
269
- return;
270
- }
271
- message.msgSlot = slot;
272
- // check if we processed a block with this root
273
- // no need to check if root is a descendant of the current finalized block, it will be checked once we validate the message if needed
274
- if (root && !this.chain.forkChoice.hasBlockHexUnsafe(root)) {
275
- this.searchUnknownSlotRoot({slot, root}, BlockInputSource.gossip, message.propagationSource.toString());
276
-
277
- if (this.unknownBlockGossipsubMessagesCount > MAX_QUEUED_UNKNOWN_BLOCK_GOSSIP_OBJECTS) {
278
- // TODO: Should report the dropped job to gossip? It will be eventually pruned from the mcache
279
- this.metrics?.reprocessGossipAttestations.reject.inc({reason: ReprocessRejectReason.reached_limit});
280
- return;
281
- }
254
+ const slotRoot = extractBlockSlotRootFn
255
+ ? extractBlockSlotRootFn(message.msg.data, message.topic.boundary.fork)
256
+ : null;
257
+ if (slotRoot === null) {
258
+ // some messages don't have slot and root
259
+ // if the msg.data is invalid, message will be rejected when deserializing data in later phase (gossipValidatorFn)
260
+ this.pushPendingGossipsubMessageToQueue(message);
261
+ return;
262
+ }
282
263
 
283
- this.metrics?.reprocessGossipAttestations.total.inc();
284
- const awaitingGossipsubMessagesByRoot = this.awaitingGossipsubMessagesByRootBySlot.getOrDefault(slot);
285
- const awaitingGossipsubMessages = awaitingGossipsubMessagesByRoot.getOrDefault(root);
286
- awaitingGossipsubMessages.add(message);
287
- this.unknownBlockGossipsubMessagesCount++;
288
- return;
289
- }
264
+ // common check for all topics
265
+ // DOS protection: avoid processing messages that are too old
266
+ const {slot, root} = slotRoot;
267
+ const clockSlot = this.chain.clock.currentSlot;
268
+ const {fork} = message.topic.boundary;
269
+ let earliestPermissableSlot = clockSlot - DEFAULT_EARLIEST_PERMISSIBLE_SLOT_DISTANCE;
270
+ if (ForkSeq[fork] >= ForkSeq.deneb && topicType === GossipType.beacon_attestation) {
271
+ // post deneb, the attestations could be in current or previous epoch
272
+ earliestPermissableSlot = computeStartSlotAtEpoch(this.chain.clock.currentEpoch - 1);
273
+ }
274
+ if (slot < earliestPermissableSlot) {
275
+ // No need to report the dropped job to gossip. It will be eventually pruned from the mcache
276
+ this.metrics?.networkProcessor.gossipValidationError.inc({
277
+ topic: topicType,
278
+ error: GossipErrorCode.PAST_SLOT,
279
+ });
280
+ return;
281
+ }
282
+
283
+ message.msgSlot = slot;
284
+
285
+ // no need to check if root is a descendant of the current finalized block, it will be checked once we validate the message if needed
286
+ if (root && !this.chain.forkChoice.hasBlockHexUnsafe(root)) {
287
+ this.searchUnknownBlock({slot, root}, BlockInputSource.network_processor, message.propagationSource.toString());
288
+
289
+ if (this.unknownBlockGossipsubMessagesCount > MAX_QUEUED_UNKNOWN_BLOCK_GOSSIP_OBJECTS) {
290
+ // No need to report the dropped job to gossip. It will be eventually pruned from the mcache
291
+ this.metrics?.awaitingBlockGossipMessages.reject.inc({
292
+ reason: ReprocessRejectReason.reached_limit,
293
+ topic: topicType,
294
+ });
295
+ return;
290
296
  }
297
+
298
+ this.metrics?.awaitingBlockGossipMessages.queue.inc({topic: topicType});
299
+ const awaitingGossipsubMessages = this.awaitingMessagesByBlockRoot.getOrDefault(root);
300
+ awaitingGossipsubMessages.add(message);
301
+ return;
291
302
  }
292
303
 
293
- // bypass the check for other messages
294
304
  this.pushPendingGossipsubMessageToQueue(message);
295
305
  }
296
306
 
@@ -298,7 +308,7 @@ export class NetworkProcessor {
298
308
  const topicType = message.topic.type;
299
309
  const droppedCount = this.gossipQueues[topicType].add(message);
300
310
  if (droppedCount) {
301
- // TODO: Should report the dropped job to gossip? It will be eventually pruned from the mcache
311
+ // No need to report the dropped job to gossip. It will be eventually pruned from the mcache
302
312
  this.metrics?.gossipValidationQueue.droppedJobs.inc({topic: message.topic.type}, droppedCount);
303
313
  }
304
314
 
@@ -306,58 +316,61 @@ export class NetworkProcessor {
306
316
  this.executeWork();
307
317
  }
308
318
 
309
- private async onBlockProcessed({
310
- slot,
311
- block: rootHex,
312
- }: {
313
- slot: Slot;
314
- block: string;
315
- executionOptimistic: boolean;
316
- }): Promise<void> {
317
- const byRootGossipsubMessages = this.awaitingGossipsubMessagesByRootBySlot.getOrDefault(slot);
318
- const waitingGossipsubMessages = byRootGossipsubMessages.getOrDefault(rootHex);
319
- if (waitingGossipsubMessages.size === 0) {
319
+ private async onBlockProcessed({block: rootHex}: {block: string; executionOptimistic: boolean}): Promise<void> {
320
+ const waitingGossipsubMessages = this.awaitingMessagesByBlockRoot.get(rootHex);
321
+ if (!waitingGossipsubMessages || waitingGossipsubMessages.size === 0) {
320
322
  return;
321
323
  }
322
324
 
323
- this.metrics?.reprocessGossipAttestations.resolve.inc(waitingGossipsubMessages.size);
324
325
  const nowSec = Date.now() / 1000;
325
326
  let count = 0;
326
327
  // TODO: we can group attestations to process in batches but since we have the SeenAttestationDatas
327
328
  // cache, it may not be necessary at this time
328
329
  for (const message of waitingGossipsubMessages) {
329
- this.metrics?.reprocessGossipAttestations.waitSecBeforeResolve.set(nowSec - message.seenTimestampSec);
330
+ const topicType = message.topic.type;
331
+ this.metrics?.awaitingBlockGossipMessages.waitSecBeforeResolve.set(
332
+ {topic: topicType},
333
+ nowSec - message.seenTimestampSec
334
+ );
335
+ this.metrics?.awaitingBlockGossipMessages.resolve.inc({topic: topicType});
330
336
  this.pushPendingGossipsubMessageToQueue(message);
331
337
  count++;
332
338
  // don't want to block the event loop, worse case it'd wait for 16_084 / 1024 * 50ms = 800ms which is not a big deal
333
- if (count === MAX_UNKNOWN_BLOCK_GOSSIP_OBJECTS_PER_TICK) {
339
+ if (count === MAX_AWAITING_GOSSIP_OBJECTS_PER_TICK) {
334
340
  count = 0;
335
- await sleep(PROCESS_UNKNOWN_BLOCK_GOSSIP_OBJECTS_YIELD_EVERY_MS);
341
+ await sleep(AWAITING_GOSSIP_OBJECTS_YIELD_EVERY_MS);
336
342
  }
337
343
  }
338
344
 
339
- byRootGossipsubMessages.delete(rootHex);
345
+ this.awaitingMessagesByBlockRoot.delete(rootHex);
340
346
  }
341
347
 
342
348
  private onClockSlot(clockSlot: Slot): void {
343
349
  const nowSec = Date.now() / 1000;
344
- for (const [slot, gossipMessagesByRoot] of this.awaitingGossipsubMessagesByRootBySlot.entries()) {
345
- if (slot < clockSlot) {
346
- for (const gossipMessages of gossipMessagesByRoot.values()) {
350
+ const minSlot = clockSlot - MAX_UNKNOWN_ROOTS_SLOT_CACHE_SIZE;
351
+
352
+ for (const [slot, roots] of this.unknownBlocksBySlot) {
353
+ if (slot > minSlot) continue;
354
+ for (const rootHex of roots) {
355
+ const gossipMessages = this.awaitingMessagesByBlockRoot.get(rootHex);
356
+ if (gossipMessages !== undefined) {
347
357
  for (const message of gossipMessages) {
348
- this.metrics?.reprocessGossipAttestations.reject.inc({reason: ReprocessRejectReason.expired});
349
- this.metrics?.reprocessGossipAttestations.waitSecBeforeReject.set(
350
- {reason: ReprocessRejectReason.expired},
358
+ const topicType = message.topic.type;
359
+ this.metrics?.awaitingBlockGossipMessages.reject.inc({
360
+ topic: topicType,
361
+ reason: ReprocessRejectReason.expired,
362
+ });
363
+ this.metrics?.awaitingBlockGossipMessages.waitSecBeforeReject.set(
364
+ {topic: topicType, reason: ReprocessRejectReason.expired},
351
365
  nowSec - message.seenTimestampSec
352
366
  );
353
- // TODO: Should report the dropped job to gossip? It will be eventually pruned from the mcache
367
+ // No need to report the dropped job to gossip. It will be eventually pruned from the mcache
354
368
  }
369
+ this.awaitingMessagesByBlockRoot.delete(rootHex);
355
370
  }
356
- this.awaitingGossipsubMessagesByRootBySlot.delete(slot);
357
371
  }
372
+ this.unknownBlocksBySlot.delete(slot);
358
373
  }
359
- pruneSetToMax(this.unknownRootsBySlot, MAX_UNKNOWN_ROOTS_SLOT_CACHE_SIZE);
360
- this.unknownBlockGossipsubMessagesCount = 0;
361
374
  }
362
375
 
363
376
  private executeWork(): void {
@@ -496,4 +509,12 @@ export class NetworkProcessor {
496
509
 
497
510
  return null;
498
511
  }
512
+
513
+ private get unknownBlockGossipsubMessagesCount(): number {
514
+ let count = 0;
515
+ for (const messages of this.awaitingMessagesByBlockRoot.values()) {
516
+ count += messages.size;
517
+ }
518
+ return count;
519
+ }
499
520
  }
@@ -64,7 +64,7 @@ enum FetchResult {
64
64
  *
65
65
  * - publishBlock
66
66
  * - gossipHandlers
67
- * - searchUnknownSlotRoot
67
+ * - searchUnknownBlock
68
68
  * = produceSyncCommitteeContribution
69
69
  * = validateGossipFnRetryUnknownRoot
70
70
  * * submitPoolAttestationsV2
@@ -481,7 +481,7 @@ export class BlockInputSync {
481
481
  * From a set of shuffled peers:
482
482
  * - fetch the block
483
483
  * - from deneb, fetch all missing blobs
484
- * - from peerDAS, fetch sampled colmns
484
+ * - from peerDAS, fetch sampled columns
485
485
  * TODO: this means we only have block root, and nothing else. Consider to reflect this in the function name
486
486
  * prefulu, will attempt a max of `MAX_ATTEMPTS_PER_BLOCK` on different peers, postfulu we may attempt more as defined in `getMaxDownloadAttempts()` function
487
487
  * Also verifies the received block root + returns the peer that provided the block for future downscoring.
@@ -489,10 +489,7 @@ export class BlockInputSync {
489
489
  private async fetchBlockInput(cacheItem: BlockInputSyncCacheItem): Promise<PendingBlockInput> {
490
490
  const rootHex = getBlockInputSyncCacheItemRootHex(cacheItem);
491
491
  const excludedPeers = new Set<PeerIdStr>();
492
- const defaultPendingColumns =
493
- this.config.getForkSeq(this.chain.clock.currentSlot) >= ForkSeq.fulu
494
- ? new Set(this.network.custodyConfig.sampledColumns)
495
- : null;
492
+ const defaultPendingColumns = new Set(this.network.custodyConfig.sampledColumns);
496
493
 
497
494
  const fetchStartSec = Date.now() / 1000;
498
495
  let slot = isPendingBlockInput(cacheItem) ? cacheItem.blockInput.slot : undefined;
@@ -506,14 +503,10 @@ export class BlockInputSync {
506
503
  isPendingBlockInput(cacheItem) && isBlockInputColumns(cacheItem.blockInput)
507
504
  ? new Set(cacheItem.blockInput.getMissingSampledColumnMeta().missing)
508
505
  : defaultPendingColumns;
509
- // pendingDataColumns is null pre-fulu
510
506
  const peerMeta = this.peerBalancer.bestPeerForPendingColumns(pendingColumns, excludedPeers);
511
507
  if (peerMeta === null) {
512
508
  // no more peer with needed columns to try, throw error
513
- let message = `Error fetching UnknownBlockRoot slot=${slot} root=${rootHex} after ${i}: cannot find peer`;
514
- if (pendingColumns) {
515
- message += ` with needed columns=${prettyPrintIndices(Array.from(pendingColumns))}`;
516
- }
509
+ const message = `Error fetching UnknownBlockRoot slot=${slot} root=${rootHex} after ${i}: cannot find peer with needed columns=${prettyPrintIndices(Array.from(pendingColumns))}`;
517
510
  this.metrics?.blockInputSync.fetchTimeSec.observe(
518
511
  {result: FetchResult.FailureTriedAllPeers},
519
512
  Date.now() / 1000 - fetchStartSec
@@ -650,7 +643,7 @@ export class BlockInputSync {
650
643
  // TODO(fulu): why is this commented out here?
651
644
  //
652
645
  // this.knownBadBlocks.add(block.blockRootHex);
653
- // for (const peerIdStr of block.peerIdStrs) {
646
+ // for (const peerIdStr of block.peerIdStrings) {
654
647
  // // TODO: Refactor peerRpcScores to work with peerIdStr only
655
648
  // this.network.reportPeer(peerIdStr, PeerAction.LowToleranceError, "BadBlockByRoot");
656
649
  // }
@@ -729,11 +722,11 @@ export class UnknownBlockPeerBalancer {
729
722
  }
730
723
 
731
724
  /**
732
- * called from fetchUnknownBlockRoot() where we only have block root and nothing else
725
+ * called from fetchBlockInput() where we only have block root and nothing else
733
726
  * excludedPeers are the peers that we requested already so we don't want to try again
734
727
  * pendingColumns is empty for prefulu, or the 1st time we we download a block by root
735
728
  */
736
- bestPeerForPendingColumns(pendingColumns: Set<number> | null, excludedPeers: Set<PeerIdStr>): PeerSyncMeta | null {
729
+ bestPeerForPendingColumns(pendingColumns: Set<number>, excludedPeers: Set<PeerIdStr>): PeerSyncMeta | null {
737
730
  const eligiblePeers = this.filterPeers(pendingColumns, excludedPeers);
738
731
  if (eligiblePeers.length === 0) {
739
732
  return null;
@@ -750,37 +743,6 @@ export class UnknownBlockPeerBalancer {
750
743
  return this.peersMeta.get(bestPeerId) ?? null;
751
744
  }
752
745
 
753
- /**
754
- * called from fetchUnavailableBlockInput() where we have either BlockInput or NullBlockInput
755
- * excludedPeers are the peers that we requested already so we don't want to try again
756
- */
757
- bestPeerForBlockInput(blockInput: IBlockInput, excludedPeers: Set<PeerIdStr>): PeerSyncMeta | null {
758
- const eligiblePeers: PeerIdStr[] = [];
759
-
760
- if (isBlockInputColumns(blockInput)) {
761
- const pendingDataColumns: Set<number> = new Set(blockInput.getMissingSampledColumnMeta().missing);
762
- // there could be no pending column in case when block is still missing
763
- eligiblePeers.push(...this.filterPeers(pendingDataColumns, excludedPeers));
764
- } else {
765
- // prefulu
766
- eligiblePeers.push(...this.filterPeers(null, excludedPeers));
767
- }
768
-
769
- if (eligiblePeers.length === 0) {
770
- return null;
771
- }
772
-
773
- const sortedEligiblePeers = sortBy(
774
- shuffle(eligiblePeers),
775
- // prefer peers with least active req
776
- (peerId) => this.activeRequests.get(peerId) ?? 0
777
- );
778
-
779
- const bestPeerId = sortedEligiblePeers[0];
780
- this.onRequest(bestPeerId);
781
- return this.peersMeta.get(bestPeerId) ?? null;
782
- }
783
-
784
746
  /**
785
747
  * Consumers don't need to call this method directly, it is called internally by bestPeer*() methods
786
748
  * make this public for testing
@@ -804,8 +766,7 @@ export class UnknownBlockPeerBalancer {
804
766
  return totalActiveRequests;
805
767
  }
806
768
 
807
- // pendingDataColumns could be null for prefulu
808
- private filterPeers(pendingDataColumns: Set<number> | null, excludedPeers: Set<PeerIdStr>): PeerIdStr[] {
769
+ private filterPeers(pendingDataColumns: Set<number>, excludedPeers: Set<PeerIdStr>): PeerIdStr[] {
809
770
  let maxColumnCount = 0;
810
771
  const considerPeers: {peerId: PeerIdStr; columnCount: number}[] = [];
811
772
  for (const [peerId, syncMeta] of this.peersMeta.entries()) {
@@ -820,13 +781,12 @@ export class UnknownBlockPeerBalancer {
820
781
  continue;
821
782
  }
822
783
 
823
- if (pendingDataColumns === null || pendingDataColumns.size === 0) {
824
- // prefulu, no pending columns
784
+ if (pendingDataColumns.size === 0) {
825
785
  considerPeers.push({peerId, columnCount: 0});
826
786
  continue;
827
787
  }
828
788
 
829
- // postfulu, find peers that have custody columns that we need
789
+ // find peers that have custody columns that we need
830
790
  const {custodyColumns: peerColumns} = syncMeta;
831
791
  // check if the peer has all needed columns
832
792
  // get match