@lodestar/beacon-node 1.52.0-dev.dad8e3af98 → 1.52.0-dev.e33126114e

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 (75) hide show
  1. package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
  2. package/lib/chain/archiveStore/historicalState/getHistoricalState.js +7 -0
  3. package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
  4. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  5. package/lib/chain/archiveStore/utils/pruneHistory.js +8 -4
  6. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  7. package/lib/chain/lightClient/index.d.ts +13 -6
  8. package/lib/chain/lightClient/index.d.ts.map +1 -1
  9. package/lib/chain/lightClient/index.js +95 -115
  10. package/lib/chain/lightClient/index.js.map +1 -1
  11. package/lib/execution/engine/http.d.ts +2 -2
  12. package/lib/execution/engine/http.d.ts.map +1 -1
  13. package/lib/execution/engine/http.js +11 -5
  14. package/lib/execution/engine/http.js.map +1 -1
  15. package/lib/execution/engine/interface.d.ts +2 -2
  16. package/lib/execution/engine/interface.d.ts.map +1 -1
  17. package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -0
  18. package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
  19. package/lib/execution/engine/jsonRpcHttpClient.js +14 -6
  20. package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
  21. package/lib/execution/engine/jsonRpcTransport.d.ts +2 -2
  22. package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -1
  23. package/lib/execution/engine/jsonRpcTransport.js +4 -4
  24. package/lib/execution/engine/jsonRpcTransport.js.map +1 -1
  25. package/lib/execution/engine/restHttpClient.d.ts.map +1 -1
  26. package/lib/execution/engine/restHttpClient.js +9 -5
  27. package/lib/execution/engine/restHttpClient.js.map +1 -1
  28. package/lib/execution/engine/restTransport.d.ts +2 -2
  29. package/lib/execution/engine/restTransport.d.ts.map +1 -1
  30. package/lib/execution/engine/restTransport.js +4 -4
  31. package/lib/execution/engine/restTransport.js.map +1 -1
  32. package/lib/execution/engine/signal.d.ts +6 -0
  33. package/lib/execution/engine/signal.d.ts.map +1 -0
  34. package/lib/execution/engine/signal.js +24 -0
  35. package/lib/execution/engine/signal.js.map +1 -0
  36. package/lib/execution/engine/transport.d.ts +2 -2
  37. package/lib/execution/engine/transport.d.ts.map +1 -1
  38. package/lib/network/gossip/gossipsub.d.ts +1 -0
  39. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  40. package/lib/network/gossip/gossipsub.js +3 -0
  41. package/lib/network/gossip/gossipsub.js.map +1 -1
  42. package/lib/network/network.d.ts.map +1 -1
  43. package/lib/network/network.js +6 -1
  44. package/lib/network/network.js.map +1 -1
  45. package/lib/network/peers/peerManager.d.ts.map +1 -1
  46. package/lib/network/peers/peerManager.js +22 -2
  47. package/lib/network/peers/peerManager.js.map +1 -1
  48. package/lib/network/peers/utils/prioritizePeers.d.ts +2 -0
  49. package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
  50. package/lib/network/peers/utils/prioritizePeers.js +11 -2
  51. package/lib/network/peers/utils/prioritizePeers.js.map +1 -1
  52. package/lib/sync/unknownBlock.d.ts.map +1 -1
  53. package/lib/sync/unknownBlock.js +63 -3
  54. package/lib/sync/unknownBlock.js.map +1 -1
  55. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  56. package/lib/sync/utils/downloadByRoot.js +5 -4
  57. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  58. package/package.json +25 -25
  59. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
  60. package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
  61. package/src/chain/lightClient/index.ts +108 -142
  62. package/src/execution/engine/http.ts +15 -9
  63. package/src/execution/engine/interface.ts +4 -2
  64. package/src/execution/engine/jsonRpcHttpClient.ts +26 -14
  65. package/src/execution/engine/jsonRpcTransport.ts +8 -4
  66. package/src/execution/engine/restHttpClient.ts +17 -11
  67. package/src/execution/engine/restTransport.ts +5 -4
  68. package/src/execution/engine/signal.ts +28 -0
  69. package/src/execution/engine/transport.ts +3 -2
  70. package/src/network/gossip/gossipsub.ts +4 -0
  71. package/src/network/network.ts +6 -2
  72. package/src/network/peers/peerManager.ts +26 -2
  73. package/src/network/peers/utils/prioritizePeers.ts +14 -1
  74. package/src/sync/unknownBlock.ts +68 -2
  75. package/src/sync/utils/downloadByRoot.ts +7 -5
@@ -241,7 +241,8 @@ export class RestEngineTransport implements IEngineTransport {
241
241
  headBlockHash: RootHex,
242
242
  safeBlockHash: RootHex,
243
243
  finalizedBlockHash: RootHex,
244
- payloadAttributes?: PayloadAttributes
244
+ payloadAttributes?: PayloadAttributes,
245
+ signal?: AbortSignal
245
246
  ): Promise<ForkchoiceUpdatedResult> {
246
247
  const forkchoiceState = {
247
248
  headBlockHash: fromHex(headBlockHash),
@@ -279,7 +280,7 @@ export class RestEngineTransport implements IEngineTransport {
279
280
 
280
281
  const res = await this.client.request(
281
282
  {method: "POST", path: "/forkchoice", executionFork: toExecutionForkName(fork), body, responseType: "ssz"},
282
- fcUReqOpts
283
+ {...fcUReqOpts, signal}
283
284
  );
284
285
  const {payloadStatus, payloadId} = deserializeResponse(
285
286
  ForkchoiceUpdateResponse,
@@ -293,14 +294,14 @@ export class RestEngineTransport implements IEngineTransport {
293
294
  };
294
295
  }
295
296
 
296
- async getPayload(fork: ForkName, payloadId: PayloadId): Promise<GetPayloadResult> {
297
+ async getPayload(fork: ForkName, payloadId: PayloadId, signal?: AbortSignal): Promise<GetPayloadResult> {
297
298
  if (!PAYLOAD_ID_REGEX.test(payloadId)) {
298
299
  throw Error(`Invalid payloadId=${payloadId}, expected 0x prefixed 8 bytes hex`);
299
300
  }
300
301
 
301
302
  const res = await this.client.request(
302
303
  {method: "GET", path: `/payloads/${payloadId}`, executionFork: toExecutionForkName(fork), responseType: "ssz"},
303
- getPayloadOpts
304
+ {...getPayloadOpts, signal}
304
305
  );
305
306
 
306
307
  if (ForkSeq[fork] >= ForkSeq.gloas) {
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Runs `fn` with a signal that aborts with either the signal of the client or the signal of a single request.
3
+ * Not AbortSignal.any(), Node retains every composite until the long-lived client signal aborts.
4
+ */
5
+ export async function withRequestSignal<T>(
6
+ clientSignal: AbortSignal | undefined,
7
+ requestSignal: AbortSignal | undefined,
8
+ fn: (signal: AbortSignal | undefined) => Promise<T>
9
+ ): Promise<T> {
10
+ if (requestSignal === undefined) {
11
+ return fn(clientSignal);
12
+ }
13
+
14
+ const controller = new AbortController();
15
+ const onAbort = (): void => controller.abort();
16
+ clientSignal?.addEventListener("abort", onAbort, {once: true});
17
+ requestSignal.addEventListener("abort", onAbort, {once: true});
18
+ if (clientSignal?.aborted || requestSignal.aborted) {
19
+ controller.abort();
20
+ }
21
+
22
+ try {
23
+ return await fn(controller.signal);
24
+ } finally {
25
+ clientSignal?.removeEventListener("abort", onAbort);
26
+ requestSignal.removeEventListener("abort", onAbort);
27
+ }
28
+ }
@@ -42,10 +42,11 @@ export interface IEngineTransport {
42
42
  headBlockHash: RootHex,
43
43
  safeBlockHash: RootHex,
44
44
  finalizedBlockHash: RootHex,
45
- payloadAttributes?: PayloadAttributes
45
+ payloadAttributes?: PayloadAttributes,
46
+ signal?: AbortSignal
46
47
  ): Promise<ForkchoiceUpdatedResult>;
47
48
 
48
- getPayload(fork: ForkName, payloadId: PayloadId): Promise<GetPayloadResult>;
49
+ getPayload(fork: ForkName, payloadId: PayloadId, signal?: AbortSignal): Promise<GetPayloadResult>;
49
50
 
50
51
  getPayloadBodiesByHashV2(blockHashes: RootHex[]): Promise<(ExecutionPayloadBodyV2 | null)[]>;
51
52
 
@@ -505,6 +505,10 @@ export class Eth2Gossipsub {
505
505
  getDirectPeers(): string[] {
506
506
  return Array.from(this.gossipsub.direct);
507
507
  }
508
+
509
+ isDirectPeer(peerIdStr: string): boolean {
510
+ return this.gossipsub.direct.has(peerIdStr);
511
+ }
508
512
  }
509
513
 
510
514
  /**
@@ -431,7 +431,7 @@ export class Network implements INetwork {
431
431
  }
432
432
 
433
433
  async publishBlsToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange): Promise<number> {
434
- const publishChanges = [];
434
+ const publishChanges: Promise<number>[] = [];
435
435
  for (const boundary of getActiveForkBoundaries(this.config, this.clock.currentEpoch)) {
436
436
  const fork = ForkSeq[boundary.fork];
437
437
 
@@ -447,7 +447,11 @@ export class Network implements INetwork {
447
447
  if (publishChanges.length === 0) {
448
448
  throw Error("No capella+ fork active yet to publish blsToExecutionChange");
449
449
  }
450
- return Promise.any(publishChanges);
450
+ try {
451
+ return await Promise.any(publishChanges);
452
+ } finally {
453
+ await Promise.allSettled(publishChanges);
454
+ }
451
455
  }
452
456
 
453
457
  async publishProposerSlashing(proposerSlashing: phase0.ProposerSlashing): Promise<number> {
@@ -449,7 +449,8 @@ export class PeerManager {
449
449
  .catch((e) => this.logger.verbose("cannot tag peer", {peerId: peer.toString()}, e as Error));
450
450
  peerData.relevantStatus = RelevantPeerStatus.relevant;
451
451
  }
452
- if (getConnection(this.libp2p, peer.toString())) {
452
+ // A peer rejected on connect is not tracked and may still send a status before its goodbye completes
453
+ if (peerData && getConnection(this.libp2p, peer.toString())) {
453
454
  const nodeId = peerData?.nodeId ?? computeNodeId(peer);
454
455
  // TODO(fulu): Are we sure we've run Metadata before this?
455
456
  const custodyGroupCount = peerData?.metadata?.custodyGroupCount ?? this.config.CUSTODY_REQUIREMENT;
@@ -554,6 +555,11 @@ export class PeerManager {
554
555
  // ban and disconnect peers with bad score, collect rest of healthy peers
555
556
  const connectedHealthyPeers: PeerId[] = [];
556
557
  for (const peer of connectedPeers) {
558
+ // Direct peers are trusted by the operator, a bad score never disconnects them
559
+ if (this.gossipsub.isDirectPeer(peer.toString())) {
560
+ connectedHealthyPeers.push(peer);
561
+ continue;
562
+ }
557
563
  switch (this.peerRpcScores.getScoreState(peer)) {
558
564
  case ScoreState.Banned:
559
565
  this.metrics?.peerManager.peersPruned.inc({reason: "banned"});
@@ -584,9 +590,11 @@ export class PeerManager {
584
590
  const prioritizeTimer = this.metrics?.peerManager.prioritizePeersDuration.startTimer();
585
591
  const {peersToDisconnect, peersToConnect, attnetQueries, syncnetQueries, custodyGroupQueries} = prioritizePeers(
586
592
  connectedHealthyPeers.map((peer) => {
587
- const peerData = this.connectedPeers.get(peer.toString());
593
+ const peerIdStr = peer.toString();
594
+ const peerData = this.connectedPeers.get(peerIdStr);
588
595
  return {
589
596
  id: peer,
597
+ direct: this.gossipsub.isDirectPeer(peerIdStr),
590
598
  direction: peerData?.direction ?? null,
591
599
  status: peerData?.status ?? null,
592
600
  attnets: peerData?.metadata?.attnets ?? null,
@@ -708,6 +716,10 @@ export class PeerManager {
708
716
  private updateGossipsubScores(): void {
709
717
  const gossipsubScores = new Map<string, number>();
710
718
  for (const peerIdStr of this.connectedPeers.keys()) {
719
+ // Direct peers are never disconnected, they must not take the negative score allowance of other peers
720
+ if (this.gossipsub.isDirectPeer(peerIdStr)) {
721
+ continue;
722
+ }
711
723
  gossipsubScores.set(peerIdStr, this.gossipsub.getScore(peerIdStr));
712
724
  }
713
725
 
@@ -786,6 +798,18 @@ export class PeerManager {
786
798
  return false;
787
799
  }
788
800
 
801
+ // The heartbeat only disconnects peers that are already connected, a peer with a bad score
802
+ // could otherwise reconnect right after and stay connected until the next heartbeat
803
+ const scoreState = this.peerRpcScores.getScoreState(remotePeer);
804
+ if (scoreState !== ScoreState.Healthy && !this.gossipsub.isDirectPeer(remotePeerStr)) {
805
+ this.logger.debug("Peer with bad score connected, disconnecting", {peer: remotePeerPrettyStr, scoreState});
806
+ void this.goodbyeAndDisconnect(
807
+ remotePeer,
808
+ scoreState === ScoreState.Banned ? GoodByeReasonCode.BANNED : GoodByeReasonCode.SCORE_TOO_LOW
809
+ );
810
+ return false;
811
+ }
812
+
789
813
  if (!opts.overwriteExisting && this.connectedPeers.has(remotePeerStr)) {
790
814
  return false;
791
815
  }
@@ -98,6 +98,7 @@ function computeStatusScore(ours: Status, theirs: Status | null, opts: Prioritiz
98
98
 
99
99
  type PeerInfo = {
100
100
  id: PeerId;
101
+ direct: boolean;
101
102
  direction: MessageStreamDirection | null;
102
103
  statusScore: StatusScore;
103
104
  attnets: phase0.AttestationSubnets;
@@ -140,6 +141,7 @@ export enum ExcessPeerDisconnectReason {
140
141
  export function prioritizePeers(
141
142
  connectedPeersInfo: {
142
143
  id: PeerId;
144
+ direct?: boolean;
143
145
  direction: MessageStreamDirection | null;
144
146
  status: Status | null;
145
147
  attnets: phase0.AttestationSubnets | null;
@@ -169,6 +171,7 @@ export function prioritizePeers(
169
171
  const connectedPeers = connectedPeersInfo.map(
170
172
  (peer): PeerInfo => ({
171
173
  id: peer.id,
174
+ direct: peer.direct ?? false,
172
175
  direction: peer.direction,
173
176
  statusScore: computeStatusScore(opts.status, peer.status, opts),
174
177
  attnets: peer.attnets ?? attnetsZero,
@@ -365,6 +368,11 @@ function pruneExcessPeers(
365
368
  const peersEligibleForPruning = sortedPeers
366
369
  // Then, iterate from highest score to lowest doing a manual filter for duties and outbound ratio
367
370
  .filter((peer) => {
371
+ // Direct peers are pinned by the operator, they count towards all targets but are never pruned
372
+ if (peer.direct) {
373
+ return false;
374
+ }
375
+
368
376
  // Peers with duties are not eligible for pruning
369
377
  if ((dutiesByPeer.get(peer) ?? 0) > 0) {
370
378
  return false;
@@ -488,11 +496,12 @@ function pruneExcessPeers(
488
496
  // otherwise we'll not able to accept new peer connection to consider better peers
489
497
  // see https://github.com/ChainSafe/lodestar/issues/5198
490
498
  const remainingPeersToDisconnect: PeerId[] = [];
491
- for (const {id} of sortedPeers) {
499
+ for (const {id, direct} of sortedPeers) {
492
500
  if (peersToDisconnectCount >= peersToDisconnectTarget) {
493
501
  break;
494
502
  }
495
503
  if (
504
+ direct ||
496
505
  noLongLivedSubnetPeersToDisconnect.includes(id) ||
497
506
  badScorePeersToDisconnect.includes(id) ||
498
507
  tooGroupedPeersToDisconnect.includes(id)
@@ -568,6 +577,10 @@ function findPeerToRemove(
568
577
  const peersOnSubnet = sortBy(peersOnMostGroupedSubnet, (peer) => peer.attnetsTrueBitIndices.length);
569
578
  let removedPeer: PeerInfo | null = null;
570
579
  for (const candidatePeer of peersOnSubnet) {
580
+ if (candidatePeer.direct) {
581
+ continue;
582
+ }
583
+
571
584
  // new logic of lodestar
572
585
  const attnetIndices = candidatePeer.attnetsTrueBitIndices;
573
586
  if (attnetIndices.length > 0) {
@@ -13,6 +13,8 @@ import {PayloadEnvelopeInput, PayloadEnvelopeInputSource} from "../chain/blocks/
13
13
  import {
14
14
  BlockError,
15
15
  BlockErrorCode,
16
+ DataColumnSidecarErrorCode,
17
+ DataColumnSidecarValidationError,
16
18
  ExecutionPayloadEnvelopeError,
17
19
  ExecutionPayloadEnvelopeErrorCode,
18
20
  } from "../chain/errors/index.js";
@@ -1997,7 +1999,20 @@ export class BlockInputSync {
1997
1999
 
1998
2000
  let i = 0;
1999
2001
  let deferredByRateLimit = false;
2002
+ let requestedWhenReconstructable = false;
2000
2003
  while (i++ < this.getMaxDownloadAttempts()) {
2004
+ const reconstructable =
2005
+ isPendingBlockInput(cacheItem) &&
2006
+ isBlockInputColumns(cacheItem.blockInput) &&
2007
+ cacheItem.blockInput.hasBlockAndAllData();
2008
+ // Reconstruction recovers whole rows however many columns are missing, so only one more request is worth it,
2009
+ // further peers could each hold the import until their response times out
2010
+ if (reconstructable) {
2011
+ if (requestedWhenReconstructable) {
2012
+ break;
2013
+ }
2014
+ requestedWhenReconstructable = true;
2015
+ }
2001
2016
  const pendingColumns =
2002
2017
  isPendingBlockInput(cacheItem) && isBlockInputColumns(cacheItem.blockInput)
2003
2018
  ? new Set(cacheItem.blockInput.getMissingSampledColumnMeta().missing)
@@ -2012,6 +2027,10 @@ export class BlockInputSync {
2012
2027
  now
2013
2028
  );
2014
2029
  if (peerMeta === null) {
2030
+ if (reconstructable) {
2031
+ break;
2032
+ }
2033
+
2015
2034
  const retryAt = this.peerBalancer.getNextRateLimitRetryAt(pendingColumns, excludedPeers, now);
2016
2035
  if (retryAt !== null) {
2017
2036
  throw new UnknownBlockRateLimitedError(
@@ -2056,8 +2075,16 @@ export class BlockInputSync {
2056
2075
  for (const warning of warnings) {
2057
2076
  this.logger.debug("BlockInputSync.fetchBlockInput: downloaded with warning", logCtx, warning);
2058
2077
  this.metrics?.blockInputSync.downloadByRoot.warn.inc({code: warning.type.code, client: peerClient});
2078
+ // A partial response is legal, columns that were not requested are not
2079
+ if (warning.type.code === DownloadByRootErrorCode.EXTRA_SIDECAR_RECEIVED) {
2080
+ this.network.reportPeer(peerId, PeerAction.LowToleranceError, warning.type.code);
2081
+ excludedPeers.add(peerId);
2082
+ }
2083
+ // Not picked again for this block, it would be preferred as a previous source of it
2084
+ if (warning.type.code === DownloadByRootErrorCode.NOT_ENOUGH_SIDECARS_RECEIVED) {
2085
+ excludedPeers.add(peerId);
2086
+ }
2059
2087
  }
2060
- // TODO: penalize peer?
2061
2088
  }
2062
2089
  } catch (e) {
2063
2090
  this.logger.debug(
@@ -2066,7 +2093,6 @@ export class BlockInputSync {
2066
2093
  e as Error
2067
2094
  );
2068
2095
  const downloadByRootMetrics = this.metrics?.blockInputSync.downloadByRoot;
2069
- // TODO: penalize peer?
2070
2096
  if (e instanceof DownloadByRootError) {
2071
2097
  const errorCode = e.type.code;
2072
2098
  downloadByRootMetrics?.error.inc({code: errorCode, client: peerClient});
@@ -2082,6 +2108,22 @@ export class BlockInputSync {
2082
2108
  this.network.reportPeer(peerId, PeerAction.LowToleranceError, errorCode);
2083
2109
  }
2084
2110
  excludedPeers.add(peerId);
2111
+ } else if (e instanceof DataColumnSidecarValidationError) {
2112
+ const errorCode = e.type.code;
2113
+ downloadByRootMetrics?.error.inc({code: errorCode, client: peerClient});
2114
+ // Not PROPOSAL_SIGNATURE_INVALID or INCORRECT_HEADER_ROOT, which compares signatures too: the spec does not
2115
+ // require verifying the header signature of req/resp columns, so honest peers may serve a bad one
2116
+ switch (errorCode) {
2117
+ case DataColumnSidecarErrorCode.INCORRECT_BLOCK:
2118
+ case DataColumnSidecarErrorCode.INVALID_INDEX:
2119
+ case DataColumnSidecarErrorCode.INCORRECT_CELL_COUNT:
2120
+ case DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT:
2121
+ case DataColumnSidecarErrorCode.INCORRECT_KZG_PROOF_COUNT:
2122
+ case DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID:
2123
+ case DataColumnSidecarErrorCode.INVALID_KZG_PROOF_BATCH:
2124
+ this.network.reportPeer(peerId, PeerAction.LowToleranceError, errorCode);
2125
+ }
2126
+ excludedPeers.add(peerId);
2085
2127
  } else if (e instanceof RequestError) {
2086
2128
  // should look into req_resp metrics in this case
2087
2129
  downloadByRootMetrics?.error.inc({code: "req_resp", client: peerClient});
@@ -2133,6 +2175,30 @@ export class BlockInputSync {
2133
2175
 
2134
2176
  const message = `Error fetching BlockInput with slot=${slot} root=${rootHex} after ${i - 1} attempts.`;
2135
2177
 
2178
+ if (
2179
+ isPendingBlockInput(cacheItem) &&
2180
+ isBlockInputColumns(cacheItem.blockInput) &&
2181
+ cacheItem.blockInput.hasBlockAndAllData()
2182
+ ) {
2183
+ // Peers cannot serve the remaining columns now, half of them is enough to reconstruct the rest
2184
+ this.logger.verbose("BlockInputSync.fetchBlockInput: reconstructing columns peers could not serve", {
2185
+ slot,
2186
+ rootHex,
2187
+ missing: cacheItem.blockInput.getMissingSampledColumnMeta().missing.length,
2188
+ });
2189
+ this.chain.columnReconstructionTracker.triggerColumnReconstruction(cacheItem.blockInput);
2190
+ cacheItem = {...cacheItem, status: PendingBlockInputStatus.downloaded, timeSyncedSec: Date.now() / 1000};
2191
+ if (this.pendingBlocks.has(rootHex)) {
2192
+ this.pendingBlocks.set(rootHex, cacheItem);
2193
+ }
2194
+ const result = this.chain.forkChoice.hasBlockHex(cacheItem.blockInput.parentRootHex)
2195
+ ? FetchResult.SuccessResolved
2196
+ : FetchResult.SuccessMissingParent;
2197
+ this.metrics?.blockInputSync.fetchTime.observe({result}, Date.now() / 1000 - fetchStartSec);
2198
+ this.metrics?.blockInputSync.fetchPeers.set({result}, i - 1);
2199
+ return cacheItem;
2200
+ }
2201
+
2136
2202
  const retryAt = deferredByRateLimit ? this.peerBalancer.getNextRateLimitRetryAt() : null;
2137
2203
  if (retryAt !== null) {
2138
2204
  throw new UnknownBlockRateLimitedError(`${message} Peers are rate-limited.`, retryAt);
@@ -115,9 +115,8 @@ export async function downloadByRoot({
115
115
  });
116
116
  }
117
117
 
118
- const hasAllDataPreDownload = blockInput.hasBlockAndAllData();
119
-
120
- if (isBlockInputColumns(blockInput) && !hasAllDataPreDownload) {
118
+ // Like range sync, download every sampled column, half of them only counts as available for reconstruction
119
+ if (isBlockInputColumns(blockInput) && !blockInput.hasComputedAllData()) {
121
120
  // columnSidecars could be undefined if gossip resulted in full block+columns so we don't download any
122
121
  if (!columnSidecars) {
123
122
  throw new DownloadByRootError({
@@ -154,7 +153,10 @@ export async function downloadByRoot({
154
153
 
155
154
  let status: PendingBlockInputStatus;
156
155
  let timeSyncedSec: number | undefined;
157
- if (blockInput.hasBlockAndAllData()) {
156
+ if (
157
+ blockInput.hasBlock() &&
158
+ (isBlockInputColumns(blockInput) ? blockInput.hasComputedAllData() : blockInput.hasAllData())
159
+ ) {
158
160
  status = PendingBlockInputStatus.downloaded;
159
161
  timeSyncedSec = Date.now() / 1000;
160
162
  } else {
@@ -201,7 +203,7 @@ export async function fetchByRoot({
201
203
  }
202
204
 
203
205
  const forkName = config.getForkName(block.message.slot);
204
- if (!cacheItem.blockInput.hasAllData() && isBlockInputColumns(cacheItem.blockInput)) {
206
+ if (isBlockInputColumns(cacheItem.blockInput) && !cacheItem.blockInput.hasComputedAllData()) {
205
207
  columnSidecarResult = await fetchAndValidateColumns({
206
208
  config,
207
209
  chain,