@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.
- package/lib/api/impl/validator/index.js +1 -1
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/blocks/blockInput/types.d.ts +1 -0
- package/lib/chain/blocks/blockInput/types.d.ts.map +1 -1
- package/lib/chain/blocks/blockInput/types.js +1 -0
- package/lib/chain/blocks/blockInput/types.js.map +1 -1
- package/lib/chain/validation/syncCommittee.d.ts +2 -2
- package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
- package/lib/chain/validation/syncCommittee.js +12 -11
- package/lib/chain/validation/syncCommittee.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +12 -4
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +19 -15
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/gossip/encoding.d.ts.map +1 -1
- package/lib/network/gossip/encoding.js +15 -0
- package/lib/network/gossip/encoding.js.map +1 -1
- package/lib/network/interface.d.ts +1 -1
- package/lib/network/interface.d.ts.map +1 -1
- package/lib/network/network.d.ts +1 -1
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +2 -2
- package/lib/network/network.js.map +1 -1
- package/lib/network/processor/extractSlotRootFns.d.ts +1 -1
- package/lib/network/processor/extractSlotRootFns.js +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +9 -7
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/index.d.ts +12 -7
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +99 -78
- package/lib/network/processor/index.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +3 -9
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +8 -41
- package/lib/sync/unknownBlock.js.map +1 -1
- package/package.json +15 -15
- package/src/api/impl/validator/index.ts +1 -1
- package/src/chain/blocks/blockInput/types.ts +1 -0
- package/src/chain/validation/syncCommittee.ts +15 -14
- package/src/metrics/metrics/lodestar.ts +23 -19
- package/src/network/gossip/encoding.ts +16 -0
- package/src/network/interface.ts +1 -1
- package/src/network/network.ts +2 -2
- package/src/network/processor/extractSlotRootFns.ts +1 -1
- package/src/network/processor/gossipHandlers.ts +9 -8
- package/src/network/processor/index.ts +110 -89
- 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,
|
|
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
|
|
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
|
|
94
|
-
// As seen on mainnet,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
162
|
-
private
|
|
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.
|
|
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.
|
|
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
|
-
|
|
237
|
-
|
|
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.
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
//
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
311
|
-
|
|
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
|
-
|
|
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 ===
|
|
339
|
+
if (count === MAX_AWAITING_GOSSIP_OBJECTS_PER_TICK) {
|
|
334
340
|
count = 0;
|
|
335
|
-
await sleep(
|
|
341
|
+
await sleep(AWAITING_GOSSIP_OBJECTS_YIELD_EVERY_MS);
|
|
336
342
|
}
|
|
337
343
|
}
|
|
338
344
|
|
|
339
|
-
|
|
345
|
+
this.awaitingMessagesByBlockRoot.delete(rootHex);
|
|
340
346
|
}
|
|
341
347
|
|
|
342
348
|
private onClockSlot(clockSlot: Slot): void {
|
|
343
349
|
const nowSec = Date.now() / 1000;
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
349
|
-
this.metrics?.
|
|
350
|
-
|
|
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
|
-
//
|
|
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
|
}
|
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -64,7 +64,7 @@ enum FetchResult {
|
|
|
64
64
|
*
|
|
65
65
|
* - publishBlock
|
|
66
66
|
* - gossipHandlers
|
|
67
|
-
* -
|
|
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
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
//
|
|
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
|