@lodestar/beacon-node 1.52.0-dev.b17bb95924 → 1.52.0-dev.b59a889970

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 (49) 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/errors/executionPayloadEnvelope.d.ts +48 -0
  8. package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
  9. package/lib/chain/errors/executionPayloadEnvelope.js +7 -0
  10. package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
  11. package/lib/chain/lightClient/index.d.ts +13 -6
  12. package/lib/chain/lightClient/index.d.ts.map +1 -1
  13. package/lib/chain/lightClient/index.js +95 -115
  14. package/lib/chain/lightClient/index.js.map +1 -1
  15. package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
  16. package/lib/chain/validation/executionPayloadEnvelope.js +79 -4
  17. package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
  18. package/lib/network/gossip/gossipsub.d.ts +1 -0
  19. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  20. package/lib/network/gossip/gossipsub.js +3 -0
  21. package/lib/network/gossip/gossipsub.js.map +1 -1
  22. package/lib/network/network.d.ts.map +1 -1
  23. package/lib/network/network.js +6 -1
  24. package/lib/network/network.js.map +1 -1
  25. package/lib/network/peers/peerManager.d.ts.map +1 -1
  26. package/lib/network/peers/peerManager.js +12 -1
  27. package/lib/network/peers/peerManager.js.map +1 -1
  28. package/lib/network/peers/utils/prioritizePeers.d.ts +2 -0
  29. package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
  30. package/lib/network/peers/utils/prioritizePeers.js +11 -2
  31. package/lib/network/peers/utils/prioritizePeers.js.map +1 -1
  32. package/lib/sync/unknownBlock.d.ts.map +1 -1
  33. package/lib/sync/unknownBlock.js +63 -3
  34. package/lib/sync/unknownBlock.js.map +1 -1
  35. package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
  36. package/lib/sync/utils/downloadByRoot.js +5 -4
  37. package/lib/sync/utils/downloadByRoot.js.map +1 -1
  38. package/package.json +25 -25
  39. package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
  40. package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
  41. package/src/chain/errors/executionPayloadEnvelope.ts +50 -0
  42. package/src/chain/lightClient/index.ts +108 -142
  43. package/src/chain/validation/executionPayloadEnvelope.ts +87 -3
  44. package/src/network/gossip/gossipsub.ts +4 -0
  45. package/src/network/network.ts +6 -2
  46. package/src/network/peers/peerManager.ts +12 -1
  47. package/src/network/peers/utils/prioritizePeers.ts +14 -1
  48. package/src/sync/unknownBlock.ts +68 -2
  49. package/src/sync/utils/downloadByRoot.ts +7 -5
@@ -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,