@lodestar/beacon-node 1.49.0-dev.73ea27a093 → 1.49.0-dev.90c86b6529

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 (43) hide show
  1. package/lib/api/impl/beacon/pool/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/pool/index.js +4 -2
  3. package/lib/api/impl/beacon/pool/index.js.map +1 -1
  4. package/lib/chain/archiveStore/historicalState/metrics.d.ts.map +1 -1
  5. package/lib/chain/archiveStore/historicalState/metrics.js +4 -0
  6. package/lib/chain/archiveStore/historicalState/metrics.js.map +1 -1
  7. package/lib/chain/errors/payloadAttestation.d.ts +4 -0
  8. package/lib/chain/errors/payloadAttestation.d.ts.map +1 -1
  9. package/lib/chain/errors/payloadAttestation.js +1 -0
  10. package/lib/chain/errors/payloadAttestation.js.map +1 -1
  11. package/lib/chain/options.d.ts +0 -4
  12. package/lib/chain/options.d.ts.map +1 -1
  13. package/lib/chain/options.js +0 -1
  14. package/lib/chain/options.js.map +1 -1
  15. package/lib/chain/validation/payloadAttestationMessage.d.ts.map +1 -1
  16. package/lib/chain/validation/payloadAttestationMessage.js +8 -1
  17. package/lib/chain/validation/payloadAttestationMessage.js.map +1 -1
  18. package/lib/metrics/metrics/lodestar.d.ts +5 -1
  19. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  20. package/lib/metrics/metrics/lodestar.js +10 -0
  21. package/lib/metrics/metrics/lodestar.js.map +1 -1
  22. package/lib/network/processor/index.d.ts +1 -1
  23. package/lib/network/processor/index.d.ts.map +1 -1
  24. package/lib/network/processor/index.js +42 -21
  25. package/lib/network/processor/index.js.map +1 -1
  26. package/lib/sync/types.d.ts +18 -1
  27. package/lib/sync/types.d.ts.map +1 -1
  28. package/lib/sync/types.js +19 -1
  29. package/lib/sync/types.js.map +1 -1
  30. package/lib/sync/unknownBlock.d.ts +19 -0
  31. package/lib/sync/unknownBlock.d.ts.map +1 -1
  32. package/lib/sync/unknownBlock.js +143 -2
  33. package/lib/sync/unknownBlock.js.map +1 -1
  34. package/package.json +14 -14
  35. package/src/api/impl/beacon/pool/index.ts +6 -2
  36. package/src/chain/archiveStore/historicalState/metrics.ts +4 -0
  37. package/src/chain/errors/payloadAttestation.ts +2 -0
  38. package/src/chain/options.ts +0 -5
  39. package/src/chain/validation/payloadAttestationMessage.ts +9 -0
  40. package/src/metrics/metrics/lodestar.ts +17 -1
  41. package/src/network/processor/index.ts +51 -22
  42. package/src/sync/types.ts +19 -1
  43. package/src/sync/unknownBlock.ts +151 -1
@@ -197,6 +197,19 @@ type PreprocessResult =
197
197
  | {action: PreprocessAction.AwaitBlock; root: RootHex}
198
198
  | {action: PreprocessAction.AwaitEnvelope; root: RootHex};
199
199
 
200
+ enum SearchTarget {
201
+ Block,
202
+ PayloadEnvelope,
203
+ }
204
+
205
+ type SearchUnknownRootTarget =
206
+ | {target: SearchTarget.Block}
207
+ | {
208
+ target: SearchTarget.PayloadEnvelope;
209
+ /** The message slot is the payload's slot, so it can be used for UnknownBlockInput search */
210
+ slotIsPayloadSlot: boolean;
211
+ };
212
+
200
213
  /**
201
214
  * Network processor handles the gossip queues and throtles processing to not overload the main thread
202
215
  * - Decides when to process work and what to process
@@ -450,7 +463,7 @@ export class NetworkProcessor {
450
463
  // 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
451
464
  if (root && !this.chain.forkChoice.hasBlockHexUnsafe(root)) {
452
465
  // starting from GLOAS, unknown root from data_column_sidecar also falls into this case
453
- this.searchUnknownRoot({slot, root}, true, false, peerId);
466
+ this.searchUnknownRoot({slot, root}, peerId, {target: SearchTarget.Block});
454
467
  // for beacon_attestation and beacon_aggregate_and_proof messages, this is only temporary.
455
468
  // if "index = 1" we need to await for the Envelope instead
456
469
  preprocessResult = {action: PreprocessAction.AwaitBlock, root};
@@ -465,27 +478,28 @@ export class NetworkProcessor {
465
478
  if (topicType === GossipType.beacon_block) {
466
479
  const parentRoot = getParentRootFromSignedBeaconBlockSerialized(message.msg.data);
467
480
  if (parentRoot) {
468
- let searchParentBlock = false;
469
- let searchParentEnvelope = false;
481
+ let search: SearchUnknownRootTarget | null = null;
470
482
  if (ForkSeq[fork] >= ForkSeq.gloas) {
471
483
  // GLOAS: also check parent envelope, same logic as execution_payload_bid
472
484
  const parentBlockHash = getParentBlockHashFromGloasSignedBeaconBlockSerialized(message.msg.data);
473
485
  if (parentBlockHash && !this.chain.forkChoice.getBlockHexAndBlockHash(parentRoot, parentBlockHash)) {
474
486
  const protoBlock = this.chain.forkChoice.getBlockHexDefaultStatus(parentRoot);
475
487
  if (protoBlock === null) {
476
- searchParentBlock = true;
488
+ search = {target: SearchTarget.Block};
477
489
  } else if (
478
490
  protoBlock.executionPayloadBlockHash &&
479
491
  protoBlock.executionPayloadBlockHash !== parentBlockHash
480
492
  ) {
481
493
  // only search for the envelope by block root if we're sure there is one. Otherwise UnknownBlockSync will penalize the peer.
482
- searchParentEnvelope = true;
494
+ search = {target: SearchTarget.PayloadEnvelope, slotIsPayloadSlot: false};
483
495
  }
484
496
  }
485
497
  } else if (!this.chain.forkChoice.hasBlockHexUnsafe(parentRoot)) {
486
- searchParentBlock = true;
498
+ search = {target: SearchTarget.Block};
499
+ }
500
+ if (search !== null) {
501
+ this.searchUnknownRoot({slot, root: parentRoot}, peerId, search);
487
502
  }
488
- this.searchUnknownRoot({slot, root: parentRoot}, searchParentBlock, searchParentEnvelope, peerId);
489
503
  }
490
504
  preprocessResult = {action: PreprocessAction.PushToQueue};
491
505
  }
@@ -504,7 +518,10 @@ export class NetworkProcessor {
504
518
  : getDataIndexFromSignedAggregateAndProofSerialized(message.msg.data);
505
519
  if (attIndex === 1 && !this.chain.forkChoice.hasPayloadHexUnsafe(root)) {
506
520
  // attestation votes that the payload is available but it is not yet known
507
- this.searchUnknownRoot({slot, root}, false, true, peerId);
521
+ this.searchUnknownRoot({slot, root}, peerId, {
522
+ target: SearchTarget.PayloadEnvelope,
523
+ slotIsPayloadSlot: false,
524
+ });
508
525
  preprocessResult = {action: PreprocessAction.AwaitEnvelope, root};
509
526
  }
510
527
  break;
@@ -514,8 +531,12 @@ export class NetworkProcessor {
514
531
  const payloadPresent = getPayloadPresentFromPayloadAttestationMessageSerialized(message.msg.data);
515
532
  if (payloadPresent && !this.chain.forkChoice.hasPayloadHexUnsafe(root)) {
516
533
  // payload attestation votes that the payload is available but it is not yet known.
534
+ // this is optimistic search, the peer may not have the payload (only the ptc committee had).
517
535
  // the PTC vote's slot is the payload's slot
518
- this.searchUnknownRoot({slot, root}, false, true, peerId, true);
536
+ this.searchUnknownRoot({slot, root}, undefined, {
537
+ target: SearchTarget.PayloadEnvelope,
538
+ slotIsPayloadSlot: true,
539
+ });
519
540
  // do not await the envelope, payload attestation processing only requires that the block is known
520
541
  // also do not reset preprocessResult, we may already await for the block
521
542
  }
@@ -524,8 +545,12 @@ export class NetworkProcessor {
524
545
  case GossipType.data_column_sidecar: {
525
546
  if (root == null) break;
526
547
  if (!this.chain.forkChoice.hasPayloadHexUnsafe(root)) {
548
+ // this is optimistic search, the peer may not have the payload.
527
549
  // the sidecar's slot is the block's (and so the payload's) slot
528
- this.searchUnknownRoot({slot, root}, false, true, peerId, true);
550
+ this.searchUnknownRoot({slot, root}, undefined, {
551
+ target: SearchTarget.PayloadEnvelope,
552
+ slotIsPayloadSlot: true,
553
+ });
529
554
  // do not await the envelope, we can do gossip validation
530
555
  // also do not reset preprocessResult, we may already await for the block
531
556
  }
@@ -536,7 +561,7 @@ export class NetworkProcessor {
536
561
  // Extract beacon_block_root directly
537
562
  const blockRoot = getBeaconBlockRootFromExecutionPayloadEnvelopeSerialized(message.msg.data);
538
563
  if (blockRoot && !this.chain.forkChoice.hasBlockHexUnsafe(blockRoot)) {
539
- this.searchUnknownRoot({slot, root: blockRoot}, true, false, peerId);
564
+ this.searchUnknownRoot({slot, root: blockRoot}, peerId, {target: SearchTarget.Block});
540
565
  // We always want to await the block
541
566
  // This allows us to properly forward the payload envelope
542
567
  preprocessResult = {action: PreprocessAction.AwaitBlock, root: blockRoot};
@@ -555,13 +580,16 @@ export class NetworkProcessor {
555
580
  ) {
556
581
  const protoBlock = this.chain.forkChoice.getBlockHexDefaultStatus(parentBlockRoot);
557
582
  if (protoBlock === null) {
558
- this.searchUnknownRoot({slot, root: parentBlockRoot}, true, false, peerId);
583
+ this.searchUnknownRoot({slot, root: parentBlockRoot}, peerId, {target: SearchTarget.Block});
559
584
  preprocessResult = {action: PreprocessAction.AwaitBlock, root: parentBlockRoot};
560
585
  } else if (
561
586
  protoBlock.executionPayloadBlockHash &&
562
587
  protoBlock.executionPayloadBlockHash !== parentBlockHash
563
588
  ) {
564
- this.searchUnknownRoot({slot, root: parentBlockRoot}, false, true, peerId);
589
+ this.searchUnknownRoot({slot, root: parentBlockRoot}, peerId, {
590
+ target: SearchTarget.PayloadEnvelope,
591
+ slotIsPayloadSlot: false,
592
+ });
565
593
  preprocessResult = {action: PreprocessAction.AwaitEnvelope, root: parentBlockRoot};
566
594
  }
567
595
  }
@@ -664,20 +692,21 @@ export class NetworkProcessor {
664
692
 
665
693
  /**
666
694
  * Search block/envelope given a SlotRootHex
667
- * envelopeSlotIsPayloadSlot: the message slot is the payload's slot or not
695
+ * undefined peer id means optimistic search
668
696
  */
669
697
  private searchUnknownRoot(
670
698
  slotRoot: SlotRootHex,
671
- searchBlock: boolean,
672
- searchEnvelope: boolean,
673
- peerId: PeerIdStr,
674
- envelopeSlotIsPayloadSlot = false
699
+ peerId: PeerIdStr | undefined,
700
+ search: SearchUnknownRootTarget
675
701
  ): void {
676
- if (!searchBlock && !searchEnvelope) return;
677
702
  if (this.tooManySearchedRoots(slotRoot.slot, slotRoot.root)) return;
678
- if (searchBlock) this.searchUnknownBlock(slotRoot, BlockInputSource.network_processor, peerId);
679
- if (searchEnvelope) {
680
- this.searchUnknownEnvelope(slotRoot, BlockInputSource.network_processor, peerId, envelopeSlotIsPayloadSlot);
703
+ switch (search.target) {
704
+ case SearchTarget.Block:
705
+ this.searchUnknownBlock(slotRoot, BlockInputSource.network_processor, peerId);
706
+ break;
707
+ case SearchTarget.PayloadEnvelope:
708
+ this.searchUnknownEnvelope(slotRoot, BlockInputSource.network_processor, peerId, search.slotIsPayloadSlot);
709
+ break;
681
710
  }
682
711
  }
683
712
 
package/src/sync/types.ts CHANGED
@@ -24,9 +24,13 @@ export enum PendingBlockType {
24
24
  */
25
25
  UNKNOWN_PAYLOAD_BLOCK_ROOT = "unknown_payload_block_root",
26
26
  /**
27
- * Same as UNKNOWN_PAYLOAD_BLOCK_ROOT, but the trigger also carries the payload's slot.
27
+ * Same as UNKNOWN_PAYLOAD_BLOCK_ROOT, but the trigger also carries the payload's slot
28
28
  */
29
29
  UNKNOWN_PAYLOAD_BLOCK_ROOT_SLOT = "unknown_payload_block_root_slot",
30
+ /**
31
+ * Same as UNKNOWN_PAYLOAD_BLOCK_ROOT_SLOT for the current slot
32
+ */
33
+ DEFERRED_PAYLOAD_BLOCK_ROOT = "deferred_payload_block_root",
30
34
  /**
31
35
  * Payload analog of INCOMPLETE_BLOCK_INPUT: we have a partial payload input that did not complete in time.
32
36
  */
@@ -53,6 +57,20 @@ export enum FetchResult {
53
57
  FailureMaxAttempts = "failure_max_attempts",
54
58
  }
55
59
 
60
+ /**
61
+ * Outcome of a slot's deferred optimistic payload searches, recorded once when its poll loop ends.
62
+ */
63
+ export enum DeferredPayloadResult {
64
+ /** gossip delivered every watched payload before PAYLOAD_DUE, no search was needed */
65
+ ImportedBeforeSearch = "imported_before_search",
66
+ /** at least one was missing at PAYLOAD_DUE, we searched, and all were imported afterwards */
67
+ ImportedAfterSearch = "imported_after_search",
68
+ /** something was still not in fork choice when the slot ended */
69
+ Unresolved = "unresolved",
70
+ /** the slot had no optimistic search and no payload import at all, eg a skipped slot */
71
+ ResolvedNoRoot = "resolved_no_root",
72
+ }
73
+
56
74
  export enum PendingBlockInputStatus {
57
75
  pending = "pending",
58
76
  fetching = "fetching",
@@ -5,7 +5,7 @@ import {ForkSeq, SLOTS_PER_EPOCH, isForkPostGloas} from "@lodestar/params";
5
5
  import {RequestError, RequestErrorCode} from "@lodestar/reqresp";
6
6
  import {computeTimeAtSlot} from "@lodestar/state-transition";
7
7
  import {RootHex, Slot, gloas} from "@lodestar/types";
8
- import {Logger, fromHex, prettyPrintIndices, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
8
+ import {Logger, fromHex, isErrorAborted, prettyPrintIndices, pruneSetToMax, sleep, toRootHex} from "@lodestar/utils";
9
9
  import {isBlockInputBlobs, isBlockInputColumns} from "../chain/blocks/blockInput/blockInput.js";
10
10
  import {BlockInputSource, IBlockInput} from "../chain/blocks/blockInput/types.js";
11
11
  import {PayloadError, PayloadErrorCode} from "../chain/blocks/importExecutionPayload.js";
@@ -18,6 +18,7 @@ import {Metrics} from "../metrics/index.js";
18
18
  import {INetwork, NetworkEvent, NetworkEventData, prettyPrintPeerIdStr} from "../network/index.js";
19
19
  import {PeerSyncMeta} from "../network/peers/peersData.js";
20
20
  import {MAX_PEERS_PER_ROOT} from "../network/processor/constants.js";
21
+ import {ClockEvent} from "../util/clock.js";
21
22
  import {PeerIdStr} from "../util/peerId.js";
22
23
  import {shuffle} from "../util/shuffle.js";
23
24
  import {sortBy} from "../util/sortBy.js";
@@ -26,6 +27,7 @@ import {MAX_CONCURRENT_REQUESTS} from "./constants.js";
26
27
  import {SyncOptions} from "./options.js";
27
28
  import {
28
29
  BlockInputSyncCacheItem,
30
+ DeferredPayloadResult,
29
31
  DownloadResult,
30
32
  DroppedItemReason,
31
33
  FetchResult,
@@ -57,6 +59,11 @@ const MAX_PENDING_BLOCKS = 100;
57
59
  */
58
60
  const PRUNE_UNRESOLVED_SLOT_EPOCHS = 2;
59
61
 
62
+ /**
63
+ * Poll pending payloads of the current slot this often, between PAYLOAD_DUE and the end of the slot.
64
+ */
65
+ export const PAYLOAD_POLL_INTERVAL_MS = 1_000;
66
+
60
67
  type AdvancePendingBlockResult =
61
68
  | "ready"
62
69
  | "queued_block"
@@ -116,6 +123,11 @@ export class BlockInputSync {
116
123
  private subscribedToNetworkEvents = false;
117
124
  private peerBalancer: UnknownBlockPeerBalancer;
118
125
  private rateLimitBackoffTimeout: NodeJS.Timeout | undefined;
126
+ /**
127
+ * Search unknown payload starting at PAYLOAD_DUE_BPS.
128
+ */
129
+ private readonly deferredPayloadRoots = new Map<RootHex, {slot: Slot; source: BlockInputSource; peer?: PeerIdStr}>();
130
+ private payloadPollAbortController: AbortController | undefined;
119
131
 
120
132
  constructor(
121
133
  private readonly config: ChainForkConfig,
@@ -161,6 +173,7 @@ export class BlockInputSync {
161
173
  this.chain.emitter.on(routes.events.EventType.executionPayload, this.onPayloadImported);
162
174
  this.network.events.on(NetworkEvent.peerConnected, this.onPeerConnected);
163
175
  this.network.events.on(NetworkEvent.peerDisconnected, this.onPeerDisconnected);
176
+ this.chain.clock.on(ClockEvent.slot, this.startPayloadPollAtSlot);
164
177
 
165
178
  // Seed the balancer with peers that connected before we subscribed
166
179
  for (const peerId of this.network.getConnectedPeers()) {
@@ -172,12 +185,19 @@ export class BlockInputSync {
172
185
  }
173
186
 
174
187
  this.subscribedToNetworkEvents = true;
188
+ // we subscribe mid-slot, and a root can be deferred at any point in the slot, so start this
189
+ // slot's loop now instead of waiting for the next ClockEvent.slot
190
+ this.startPayloadPollAtSlot(this.chain.clock.currentSlot);
175
191
  }
176
192
  }
177
193
 
178
194
  unsubscribeFromNetwork(): void {
179
195
  this.logger.verbose("BlockInputSync disabled.");
180
196
  this.clearRateLimitBackoffTimer();
197
+ this.chain.clock.off(ClockEvent.slot, this.startPayloadPollAtSlot);
198
+ this.payloadPollAbortController?.abort();
199
+ this.payloadPollAbortController = undefined;
200
+ this.deferredPayloadRoots.clear();
181
201
  this.chain.emitter.off(ChainEvent.unknownBlockRoot, this.onUnknownBlockRoot);
182
202
  this.chain.emitter.off(ChainEvent.unknownEnvelopeBlockRoot, this.onUnknownEnvelopeBlockRoot);
183
203
  this.chain.emitter.off(ChainEvent.unknownEnvelopeBlockRootSlot, this.onUnknownEnvelopeBlockRootSlot);
@@ -246,6 +266,20 @@ export class BlockInputSync {
246
266
 
247
267
  private onUnknownEnvelopeBlockRootSlot = (data: ChainEventData[ChainEvent.unknownEnvelopeBlockRootSlot]): void => {
248
268
  try {
269
+ if (data.slot === this.chain.clock.currentSlot) {
270
+ // we receive the optimistic search, the poll loop searches it at PAYLOAD_DUE or on its next
271
+ // tick. If that loop already returned - every root it watched was imported - this root waits
272
+ // for the next slot, where startPayloadPollAtSlot moves it to pendingPayloads. That is not the normal
273
+ // scenario, and in a forking condition it only delays the search of the extra root
274
+ const deferred = this.deferredPayloadRoots.get(data.rootHex);
275
+ if (deferred === undefined) {
276
+ this.deferredPayloadRoots.set(data.rootHex, {slot: data.slot, source: data.source, peer: data.peer});
277
+ } else if (deferred.peer === undefined) {
278
+ deferred.peer = data.peer;
279
+ }
280
+ return;
281
+ }
282
+
249
283
  const isNewRoot = this.addByPayloadRootHex(data.rootHex, data.peer, data.slot);
250
284
  if (isNewRoot) {
251
285
  this.triggerUnknownBlockSearch();
@@ -800,6 +834,122 @@ export class BlockInputSync {
800
834
  }
801
835
  }
802
836
 
837
+ /**
838
+ * Start this slot's payload poll: end the previous slot's loop, move roots it never got to
839
+ * into pendingPayloads, then poll from PAYLOAD_DUE to the end of the slot.
840
+ */
841
+ private startPayloadPollAtSlot = (slot: Slot): void => {
842
+ if (!isForkPostGloas(this.config.getForkName(slot))) {
843
+ return;
844
+ }
845
+ // end the previous slot's loop, wherever it is: its sleep is bound to this same controller
846
+ this.payloadPollAbortController?.abort();
847
+ this.payloadPollAbortController = new AbortController();
848
+ // entries from an earlier slot is not polled
849
+ for (const [rootHex, {slot: deferredSlot, source, peer}] of this.deferredPayloadRoots) {
850
+ if (deferredSlot < slot) {
851
+ if (!this.chain.forkChoice.hasPayloadHexUnsafe(rootHex)) {
852
+ this.addDeferredPayloadRoot(rootHex, deferredSlot, source, peer);
853
+ }
854
+ this.deferredPayloadRoots.delete(rootHex);
855
+ }
856
+ }
857
+ this.pollPayloadsAtSlot(slot, this.payloadPollAbortController.signal).catch((e) => {
858
+ if (!isErrorAborted(e)) {
859
+ this.logger.debug("Error polling payloads", {slot}, e as Error);
860
+ }
861
+ });
862
+ };
863
+
864
+ /**
865
+ * Poll unknown payloads of the current slot.
866
+ */
867
+ private async pollPayloadsAtSlot(slot: Slot, signal: AbortSignal): Promise<void> {
868
+ // fixed tick count so the loop cannot outlive its slot: for mainnet, it's 6 ticks
869
+ const tickCount = Math.floor(
870
+ (this.config.SLOT_DURATION_MS - this.config.getPayloadDueMs()) / PAYLOAD_POLL_INTERVAL_MS
871
+ );
872
+ // a root still missing on several ticks is searched on each of them, recorded once
873
+ const searchedRoots = new Set<RootHex>();
874
+ let polls = 0;
875
+
876
+ try {
877
+ await sleep(Math.max(0, this.config.getPayloadDueMs() - this.chain.clock.msFromSlot(slot)), signal);
878
+
879
+ for (polls = 0; polls < tickCount; polls++) {
880
+ let importedCount = 0;
881
+ for (const [rootHex, {slot: deferredSlot, source, peer}] of this.deferredPayloadRoots) {
882
+ if (this.chain.forkChoice.hasPayloadHexUnsafe(rootHex)) {
883
+ importedCount++;
884
+ continue;
885
+ }
886
+ // copy to the regular pendingPayloads so that we can search
887
+ this.addDeferredPayloadRoot(rootHex, deferredSlot, source, peer);
888
+ searchedRoots.add(rootHex);
889
+ }
890
+
891
+ // an empty deferredPayloadRoots means there is no optimistic search comes before PAYLOAD_DUE
892
+ // we have to poll until the payload of current slot is imported or slot end
893
+ if (this.deferredPayloadRoots.size > 0 && importedCount === this.deferredPayloadRoots.size) {
894
+ if (searchedRoots.size > 0) {
895
+ // the backup search was needed
896
+ this.metrics?.blockInputSync.deferredPayloadResult.inc({
897
+ result: DeferredPayloadResult.ImportedAfterSearch,
898
+ });
899
+ this.metrics?.blockInputSync.deferredPayloadPolls.observe(polls);
900
+ this.logger.verbose("Payload imported after unknown sync search", {
901
+ slot,
902
+ roots: Array.from(searchedRoots).join(","),
903
+ polls,
904
+ });
905
+ } else {
906
+ // this happens most of the time on devnet
907
+ // gossip delivered everything before PAYLOAD_DUE
908
+ this.metrics?.blockInputSync.deferredPayloadResult.inc({
909
+ result: DeferredPayloadResult.ImportedBeforeSearch,
910
+ });
911
+ }
912
+ return;
913
+ }
914
+
915
+ this.triggerUnknownBlockSearch();
916
+ if (polls < tickCount - 1) {
917
+ // no sleep after the last tick: the loop would otherwise end right at the slot boundary,
918
+ // where startPayloadPollAtSlot aborts it
919
+ await sleep(PAYLOAD_POLL_INTERVAL_MS, signal);
920
+ }
921
+ }
922
+
923
+ // reaching here means the early return never fired
924
+ if (this.deferredPayloadRoots.size > 0) {
925
+ this.metrics?.blockInputSync.deferredPayloadResult.inc({result: DeferredPayloadResult.Unresolved});
926
+ this.logger.debug("Deferred payloads still missing at end of slot", {
927
+ slot,
928
+ roots: Array.from(this.deferredPayloadRoots.keys()).join(","),
929
+ });
930
+ } else {
931
+ // no optimistic search and no payload import ended the loop, eg a skipped slot
932
+ this.metrics?.blockInputSync.deferredPayloadResult.inc({result: DeferredPayloadResult.ResolvedNoRoot});
933
+ this.logger.debug("No deferred payloads at slot", {
934
+ slot,
935
+ });
936
+ }
937
+ } catch (e) {
938
+ if (!isErrorAborted(e)) {
939
+ throw e;
940
+ }
941
+ this.logger.verbose("Payload poll aborted", {slot, polls, msIntoSlot: this.chain.clock.msFromSlot(slot)});
942
+ }
943
+ }
944
+
945
+ private addDeferredPayloadRoot(rootHex: RootHex, slot: Slot, source: BlockInputSource, peer?: PeerIdStr): void {
946
+ const isNewRoot = this.addByPayloadRootHex(rootHex, peer, slot);
947
+ if (isNewRoot) {
948
+ this.metrics?.blockInputSync.requests.inc({type: PendingBlockType.DEFERRED_PAYLOAD_BLOCK_ROOT});
949
+ this.metrics?.blockInputSync.payloadSource.inc({source});
950
+ }
951
+ }
952
+
803
953
  private async downloadBlock(block: BlockInputSyncCacheItem): Promise<void> {
804
954
  if (block.status !== PendingBlockInputStatus.pending) {
805
955
  return;