@lodestar/beacon-node 1.49.0-dev.09a1892a85 → 1.49.0-dev.1fb3469ab7

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 (90) hide show
  1. package/lib/api/impl/beacon/blocks/index.js +2 -2
  2. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  3. package/lib/api/impl/validator/index.js +7 -7
  4. package/lib/api/impl/validator/index.js.map +1 -1
  5. package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
  6. package/lib/chain/archiveStore/utils/pruneHistory.js +10 -2
  7. package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
  8. package/lib/chain/blocks/index.js +2 -2
  9. package/lib/chain/blocks/index.js.map +1 -1
  10. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts +1 -1
  11. package/lib/chain/blocks/payloadEnvelopeInput/types.d.ts.map +1 -1
  12. package/lib/chain/emitter.d.ts +10 -0
  13. package/lib/chain/emitter.d.ts.map +1 -1
  14. package/lib/chain/emitter.js +4 -0
  15. package/lib/chain/emitter.js.map +1 -1
  16. package/lib/chain/errors/attesterSlashingError.d.ts +4 -1
  17. package/lib/chain/errors/attesterSlashingError.d.ts.map +1 -1
  18. package/lib/chain/errors/attesterSlashingError.js +1 -0
  19. package/lib/chain/errors/attesterSlashingError.js.map +1 -1
  20. package/lib/chain/errors/proposerSlashingError.d.ts +4 -1
  21. package/lib/chain/errors/proposerSlashingError.d.ts.map +1 -1
  22. package/lib/chain/errors/proposerSlashingError.js +1 -0
  23. package/lib/chain/errors/proposerSlashingError.js.map +1 -1
  24. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  25. package/lib/chain/produceBlock/produceBlockBody.js +6 -6
  26. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  27. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts +2 -1
  28. package/lib/chain/seenCache/seenPayloadEnvelopeInput.d.ts.map +1 -1
  29. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js +3 -2
  30. package/lib/chain/seenCache/seenPayloadEnvelopeInput.js.map +1 -1
  31. package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
  32. package/lib/chain/validation/attesterSlashing.js +1 -2
  33. package/lib/chain/validation/attesterSlashing.js.map +1 -1
  34. package/lib/chain/validation/proposerSlashing.js +1 -2
  35. package/lib/chain/validation/proposerSlashing.js.map +1 -1
  36. package/lib/chain/validatorMonitor.d.ts.map +1 -1
  37. package/lib/chain/validatorMonitor.js +2 -2
  38. package/lib/chain/validatorMonitor.js.map +1 -1
  39. package/lib/db/repositories/blockArchive.d.ts +5 -0
  40. package/lib/db/repositories/blockArchive.d.ts.map +1 -1
  41. package/lib/db/repositories/blockArchive.js +36 -1
  42. package/lib/db/repositories/blockArchive.js.map +1 -1
  43. package/lib/network/gossip/gossipsub.d.ts.map +1 -1
  44. package/lib/network/gossip/gossipsub.js +15 -0
  45. package/lib/network/gossip/gossipsub.js.map +1 -1
  46. package/lib/network/gossip/topic.d.ts +1 -1
  47. package/lib/network/gossip/topic.d.ts.map +1 -1
  48. package/lib/network/gossip/topic.js +1 -1
  49. package/lib/network/gossip/topic.js.map +1 -1
  50. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  51. package/lib/network/processor/gossipHandlers.js +16 -5
  52. package/lib/network/processor/gossipHandlers.js.map +1 -1
  53. package/lib/network/processor/gossipValidatorFn.d.ts +2 -0
  54. package/lib/network/processor/gossipValidatorFn.d.ts.map +1 -1
  55. package/lib/network/processor/gossipValidatorFn.js +88 -7
  56. package/lib/network/processor/gossipValidatorFn.js.map +1 -1
  57. package/lib/network/processor/index.d.ts +6 -2
  58. package/lib/network/processor/index.d.ts.map +1 -1
  59. package/lib/network/processor/index.js +26 -9
  60. package/lib/network/processor/index.js.map +1 -1
  61. package/lib/sync/types.d.ts +4 -0
  62. package/lib/sync/types.d.ts.map +1 -1
  63. package/lib/sync/types.js +4 -0
  64. package/lib/sync/types.js.map +1 -1
  65. package/lib/sync/unknownBlock.d.ts +1 -0
  66. package/lib/sync/unknownBlock.d.ts.map +1 -1
  67. package/lib/sync/unknownBlock.js +15 -0
  68. package/lib/sync/unknownBlock.js.map +1 -1
  69. package/package.json +14 -14
  70. package/src/api/impl/beacon/blocks/index.ts +2 -2
  71. package/src/api/impl/validator/index.ts +7 -7
  72. package/src/chain/archiveStore/utils/pruneHistory.ts +10 -3
  73. package/src/chain/blocks/index.ts +2 -2
  74. package/src/chain/blocks/payloadEnvelopeInput/types.ts +1 -1
  75. package/src/chain/emitter.ts +7 -2
  76. package/src/chain/errors/attesterSlashingError.ts +3 -1
  77. package/src/chain/errors/proposerSlashingError.ts +3 -1
  78. package/src/chain/produceBlock/produceBlockBody.ts +17 -6
  79. package/src/chain/seenCache/seenPayloadEnvelopeInput.ts +3 -2
  80. package/src/chain/validation/attesterSlashing.ts +1 -2
  81. package/src/chain/validation/proposerSlashing.ts +1 -2
  82. package/src/chain/validatorMonitor.ts +12 -2
  83. package/src/db/repositories/blockArchive.ts +38 -1
  84. package/src/network/gossip/gossipsub.ts +18 -1
  85. package/src/network/gossip/topic.ts +2 -2
  86. package/src/network/processor/gossipHandlers.ts +18 -5
  87. package/src/network/processor/gossipValidatorFn.ts +111 -7
  88. package/src/network/processor/index.ts +37 -9
  89. package/src/sync/types.ts +6 -3
  90. package/src/sync/unknownBlock.ts +15 -0
@@ -35,7 +35,7 @@ import {
35
35
  isSignedExecutionPayloadEnvelopeContents,
36
36
  sszTypesFor,
37
37
  } from "@lodestar/types";
38
- import {fromHex, sleep, toHex, toRootHex} from "@lodestar/utils";
38
+ import {fromHex, prettyGweiToEth, sleep, toHex, toRootHex} from "@lodestar/utils";
39
39
  import {BlockInputSource, isBlockInputBlobs, isBlockInputColumns} from "../../../../chain/blocks/blockInput/index.js";
40
40
  import {PayloadEnvelopeInputSource} from "../../../../chain/blocks/payloadEnvelopeInput/index.js";
41
41
  import {ImportBlockOpts} from "../../../../chain/blocks/types.js";
@@ -1089,7 +1089,7 @@ export function getBeaconBlockApi({
1089
1089
  builderIndex: bid.builderIndex,
1090
1090
  blockHash: toRootHex(bid.blockHash),
1091
1091
  parentBlockHash: toRootHex(bid.parentBlockHash),
1092
- value: bid.value,
1092
+ value: prettyGweiToEth(bid.value),
1093
1093
  sentPeers,
1094
1094
  });
1095
1095
  },
@@ -481,8 +481,8 @@ export function getValidatorApi(
481
481
  metrics?.blockProductionExecutionPayloadValue.observe({source}, Number(formatWeiToEth(executionPayloadValue)));
482
482
  logger.verbose("Produced blinded block", {
483
483
  slot,
484
- executionPayloadValue,
485
- consensusBlockValue,
484
+ executionPayloadValue: prettyWeiToEth(executionPayloadValue),
485
+ consensusBlockValue: prettyWeiToEth(consensusBlockValue),
486
486
  root: toRootHex(config.getPostBellatrixForkTypes(slot).BlindedBeaconBlock.hashTreeRoot(block)),
487
487
  });
488
488
 
@@ -540,8 +540,8 @@ export function getValidatorApi(
540
540
  const blockRoot = toRootHex(config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block));
541
541
  logger.verbose("Produced execution block", {
542
542
  slot,
543
- executionPayloadValue,
544
- consensusBlockValue,
543
+ executionPayloadValue: prettyWeiToEth(executionPayloadValue),
544
+ consensusBlockValue: prettyWeiToEth(consensusBlockValue),
545
545
  root: blockRoot,
546
546
  });
547
547
  if (chain.opts.persistProducedBlocks) {
@@ -1247,8 +1247,8 @@ export function getValidatorApi(
1247
1247
  const blockRoot = toRootHex(config.getForkTypes(slot).BeaconBlock.hashTreeRoot(block));
1248
1248
  logger.verbose("Produced block", {
1249
1249
  ...logCtx,
1250
- executionPayloadValue,
1251
- consensusBlockValue,
1250
+ executionPayloadValue: prettyWeiToEth(executionPayloadValue),
1251
+ consensusBlockValue: prettyWeiToEth(consensusBlockValue),
1252
1252
  root: blockRoot,
1253
1253
  });
1254
1254
  if (chain.opts.persistProducedBlocks) {
@@ -2104,7 +2104,7 @@ export function getValidatorApi(
2104
2104
  auth: entry.auth,
2105
2105
  });
2106
2106
  } catch (e) {
2107
- failures.push({index: i, message: (e as Error).message});
2107
+ failures.push({index: i, message: `${builder}: ${(e as Error).message}`});
2108
2108
  logger.verbose(
2109
2109
  `Error on submitBuilderPreferences [${i}]`,
2110
2110
  {slot: entry.auth.message.slot, builder},
@@ -1,7 +1,7 @@
1
1
  import {ChainConfig} from "@lodestar/config";
2
2
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
3
3
  import {Epoch} from "@lodestar/types";
4
- import {Logger} from "@lodestar/utils";
4
+ import {Logger, prettyPrintIndices} from "@lodestar/utils";
5
5
  import {IBeaconDb} from "../../../db/interface.js";
6
6
  import {Metrics} from "../../../metrics/index.js";
7
7
 
@@ -20,18 +20,22 @@ export async function pruneHistory(
20
20
  finalizedEpoch
21
21
  );
22
22
  const blockCutoffSlot = computeStartSlotAtEpoch(blockCutoffEpoch);
23
+ // The latest archived state is the anchor on restart and can trail finalization by a few epochs
24
+ const lastArchivedStateSlot = (await db.stateArchive.lastKey()) ?? 0;
25
+ const stateCutoffSlot = Math.min(computeStartSlotAtEpoch(finalizedEpoch), lastArchivedStateSlot);
23
26
 
24
27
  logger.debug("Preparing to prune history", {
25
28
  currentEpoch,
26
29
  finalizedEpoch,
27
30
  blockCutoffEpoch,
31
+ stateCutoffSlot,
28
32
  });
29
33
 
30
34
  const step0 = metrics?.pruneHistory.fetchKeys.startTimer();
31
35
  const [blocks, envelopes, states] = await Promise.all([
32
36
  db.blockArchive.keys({gte: 0, lt: blockCutoffSlot}),
33
37
  db.executionPayloadEnvelopeArchive.keys({gte: 0, lt: blockCutoffSlot}),
34
- db.stateArchive.keys({gte: 0, lt: finalizedEpoch}),
38
+ db.stateArchive.keys({gte: 0, lt: stateCutoffSlot}),
35
39
  ]);
36
40
  step0?.();
37
41
 
@@ -40,12 +44,15 @@ export async function pruneHistory(
40
44
  blocksToPrune: blocks.length,
41
45
  envelopesToPrune: envelopes.length,
42
46
  statesToPrune: states.length,
47
+ blockSlots: prettyPrintIndices(blocks),
48
+ envelopeSlots: prettyPrintIndices(envelopes),
49
+ stateSlots: prettyPrintIndices(states),
43
50
  });
44
51
 
45
52
  const step1 = metrics?.pruneHistory.pruneKeys.startTimer();
46
53
  await Promise.all([
47
54
  // ->
48
- db.blockArchive.batchDelete(blocks),
55
+ db.blockArchive.batchDeleteRange(blocks),
49
56
  db.executionPayloadEnvelopeArchive.batchDelete(envelopes),
50
57
  db.stateArchive.batchDelete(states),
51
58
  ]);
@@ -104,7 +104,7 @@ export async function processBlocks(
104
104
  payloadEnvelopesToImport.delete(orphaned.slot);
105
105
  // never validated, drop it from the shared cache so it is not served to peers, by-root sync reloads the
106
106
  // entry from db if the payload is ever needed
107
- this.seenPayloadEnvelopeInputCache.prune(orphaned.payloadEnvelopeInput.blockRootHex);
107
+ this.seenPayloadEnvelopeInputCache.remove(orphaned.payloadEnvelopeInput.blockRootHex);
108
108
  }
109
109
  }
110
110
 
@@ -278,7 +278,7 @@ async function importPayloadEnvelopesOfKnownBlocks(
278
278
  this.forkChoice.isDescendant(blockRootHex, PayloadStatus.EMPTY, head.blockRoot, head.payloadStatus)
279
279
  ) {
280
280
  // never validated, see processBlocks()
281
- this.seenPayloadEnvelopeInputCache.prune(blockRootHex);
281
+ this.seenPayloadEnvelopeInputCache.remove(blockRootHex);
282
282
  orphaned.push({slot, payloadEnvelopeInput: payloadInput});
283
283
  continue;
284
284
  }
@@ -23,7 +23,7 @@ export enum PayloadEnvelopeInputSource {
23
23
  * - prune: explicit prune by root
24
24
  * - cap: insertion-order backstop cap (MAX_PAYLOAD_ENVELOPE_INPUT_CACHE_SIZE)
25
25
  */
26
- export type PayloadEnvelopeInputPruneReason = "belowParent" | "finalized" | "prune" | "cap";
26
+ export type PayloadEnvelopeInputPruneReason = "belowParent" | "finalized" | "remove" | "cap";
27
27
 
28
28
  export type SourceMeta = {
29
29
  source: PayloadEnvelopeInputSource;
@@ -72,6 +72,10 @@ export enum ChainEvent {
72
72
  * Trigger BlockInputSync to find a SignedExecutionPayloadEnvelope with specified block root.
73
73
  */
74
74
  unknownEnvelopeBlockRoot = "unknownEnvelopeBlockRoot",
75
+ /**
76
+ * Same as unknownEnvelopeBlockRoot, but with slot
77
+ */
78
+ unknownEnvelopeBlockRootSlot = "unknownEnvelopeBlockRootSlot",
75
79
  /**
76
80
  * Trigger BlockInputSync for blocks that are partially received via gossip but are not complete by time the
77
81
  * cut-off window passes for waiting on gossip
@@ -99,8 +103,8 @@ export type ChainEventData = {
99
103
  peer: PeerIdStr;
100
104
  source: BlockInputSource;
101
105
  };
102
- // slot is the message slot, not necessarily the envelope's slot, but useful as a logging/prune hint
103
- [ChainEvent.unknownEnvelopeBlockRoot]: {rootHex: RootHex; slot: Slot; peer?: PeerIdStr; source: BlockInputSource};
106
+ [ChainEvent.unknownEnvelopeBlockRoot]: {rootHex: RootHex; peer?: PeerIdStr; source: BlockInputSource};
107
+ [ChainEvent.unknownEnvelopeBlockRootSlot]: {rootHex: RootHex; slot: Slot; peer?: PeerIdStr; source: BlockInputSource};
104
108
  };
105
109
 
106
110
  export type IChainEvents = ApiEvents & {
@@ -126,6 +130,7 @@ export type IChainEvents = ApiEvents & {
126
130
  [ChainEvent.incompleteBlockInput]: (data: ChainEventData[ChainEvent.incompleteBlockInput]) => void;
127
131
  [ChainEvent.incompletePayloadEnvelope]: (data: ChainEventData[ChainEvent.incompletePayloadEnvelope]) => void;
128
132
  [ChainEvent.unknownEnvelopeBlockRoot]: (data: ChainEventData[ChainEvent.unknownEnvelopeBlockRoot]) => void;
133
+ [ChainEvent.unknownEnvelopeBlockRootSlot]: (data: ChainEventData[ChainEvent.unknownEnvelopeBlockRootSlot]) => void;
129
134
  };
130
135
 
131
136
  /**
@@ -3,9 +3,11 @@ import {GossipActionError} from "./gossipValidation.js";
3
3
  export enum AttesterSlashingErrorCode {
4
4
  ALREADY_EXISTS = "ATTESTATION_SLASHING_ERROR_ALREADY_EXISTS",
5
5
  INVALID = "ATTESTATION_SLASHING_ERROR_INVALID",
6
+ INVALID_SIGNATURE = "ATTESTATION_SLASHING_ERROR_INVALID_SIGNATURE",
6
7
  }
7
8
  export type AttesterSlashingErrorType =
8
9
  | {code: AttesterSlashingErrorCode.ALREADY_EXISTS}
9
- | {code: AttesterSlashingErrorCode.INVALID; error: Error};
10
+ | {code: AttesterSlashingErrorCode.INVALID; error: Error}
11
+ | {code: AttesterSlashingErrorCode.INVALID_SIGNATURE};
10
12
 
11
13
  export class AttesterSlashingError extends GossipActionError<AttesterSlashingErrorType> {}
@@ -3,9 +3,11 @@ import {GossipActionError} from "./gossipValidation.js";
3
3
  export enum ProposerSlashingErrorCode {
4
4
  ALREADY_EXISTS = "PROPOSER_SLASHING_ERROR_ALREADY_EXISTS",
5
5
  INVALID = "PROPOSER_SLASHING_ERROR_INVALID",
6
+ INVALID_SIGNATURE = "PROPOSER_SLASHING_ERROR_INVALID_SIGNATURE",
6
7
  }
7
8
  export type ProposerSlashingErrorType =
8
9
  | {code: ProposerSlashingErrorCode.ALREADY_EXISTS}
9
- | {code: ProposerSlashingErrorCode.INVALID; error: Error};
10
+ | {code: ProposerSlashingErrorCode.INVALID; error: Error}
11
+ | {code: ProposerSlashingErrorCode.INVALID_SIGNATURE};
10
12
 
11
13
  export class ProposerSlashingError extends GossipActionError<ProposerSlashingErrorType> {}
@@ -59,7 +59,18 @@ import {
59
59
  heze,
60
60
  ssz,
61
61
  } from "@lodestar/types";
62
- import {GWEI_TO_WEI, Logger, byteArrayEquals, fromHex, sleep, toHex, toPubkeyHex, toRootHex} from "@lodestar/utils";
62
+ import {
63
+ GWEI_TO_WEI,
64
+ Logger,
65
+ byteArrayEquals,
66
+ fromHex,
67
+ prettyGweiToEth,
68
+ prettyWeiToEth,
69
+ sleep,
70
+ toHex,
71
+ toPubkeyHex,
72
+ toRootHex,
73
+ } from "@lodestar/utils";
63
74
  import {ZERO_HASH_HEX} from "../../constants/index.js";
64
75
  import {numToQuantity} from "../../execution/engine/utils.js";
65
76
  import {IExecutionBuilder, IExecutionEngine, PayloadAttributes, PayloadId} from "../../execution/index.js";
@@ -259,7 +270,7 @@ export async function produceBlockBody<T extends BlockType>(
259
270
  this.logger.verbose("Produced block with builder bid", {
260
271
  slot: blockSlot,
261
272
  builderIndex: builderBid.message.builderIndex,
262
- bidValue: builderBid.message.value,
273
+ bidValue: prettyGweiToEth(builderBid.message.value),
263
274
  parentBlockHash: toRootHex(builderBid.message.parentBlockHash),
264
275
  parentBlockRoot: toRootHex(builderBid.message.parentBlockRoot),
265
276
  blockHash: toRootHex(builderBid.message.blockHash),
@@ -410,7 +421,7 @@ export async function produceBlockBody<T extends BlockType>(
410
421
  this.metrics?.blockPayload.payloadFetchedTime.observe({prepType}, fetchedTime);
411
422
  this.logger.verbose("Produced block with self-build bid", {
412
423
  slot: blockSlot,
413
- executionPayloadValue,
424
+ executionPayloadValue: prettyWeiToEth(executionPayloadValue),
414
425
  prepType,
415
426
  payloadId,
416
427
  fetchedTime,
@@ -490,7 +501,7 @@ export async function produceBlockBody<T extends BlockType>(
490
501
  this.metrics?.blockPayload.payloadFetchedTime.observe({prepType}, fetchedTime);
491
502
  this.logger.verbose("Fetched execution payload header from builder", {
492
503
  slot: blockSlot,
493
- executionPayloadValue,
504
+ executionPayloadValue: prettyWeiToEth(executionPayloadValue),
494
505
  prepType,
495
506
  fetchedTime,
496
507
  });
@@ -607,7 +618,7 @@ export async function produceBlockBody<T extends BlockType>(
607
618
  this.metrics?.blockPayload.payloadFetchedTime.observe({prepType}, fetchedTime);
608
619
  this.logger.verbose("Fetched execution payload from engine", {
609
620
  slot: blockSlot,
610
- executionPayloadValue,
621
+ executionPayloadValue: prettyWeiToEth(executionPayloadValue),
611
622
  prepType,
612
623
  payloadId,
613
624
  fetchedTime,
@@ -708,7 +719,7 @@ export async function produceBlockBody<T extends BlockType>(
708
719
  }
709
720
  }
710
721
 
711
- Object.assign(logMeta, {executionPayloadValue});
722
+ Object.assign(logMeta, {executionPayloadValue: prettyWeiToEth(executionPayloadValue)});
712
723
  this.logger.verbose("Produced beacon block body", logMeta);
713
724
 
714
725
  return {body: blockBody as AssembledBodyType<T>, produceResult, executionPayloadValue, shouldOverrideBuilder};
@@ -256,10 +256,11 @@ export class SeenPayloadEnvelopeInput {
256
256
  return this.payloadInputs.size;
257
257
  }
258
258
 
259
- prune(blockRootHex: RootHex): void {
259
+ /** Removes the single PayloadEnvelopeInput from the cache */
260
+ remove(blockRootHex: RootHex): void {
260
261
  const input = this.payloadInputs.get(blockRootHex);
261
262
  if (input) {
262
- this.evictPayloadInput(input, "prune");
263
+ this.evictPayloadInput(input, "remove");
263
264
  }
264
265
  }
265
266
 
@@ -63,8 +63,7 @@ export async function validateAttesterSlashing(
63
63
  const signatureSets = getAttesterSlashingSignatureSets(chain.config, state.slot, attesterSlashing);
64
64
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
65
65
  throw new AttesterSlashingError(GossipAction.REJECT, {
66
- code: AttesterSlashingErrorCode.INVALID,
67
- error: Error("Invalid signature"),
66
+ code: AttesterSlashingErrorCode.INVALID_SIGNATURE,
68
67
  });
69
68
  }
70
69
  }
@@ -48,8 +48,7 @@ async function validateProposerSlashing(
48
48
  const signatureSets = getProposerSlashingSignatureSets(chain.config, state.slot, proposerSlashing);
49
49
  if (!(await chain.bls.verifySignatureSets(signatureSets, {batchable: true, priority: prioritizeBls}))) {
50
50
  throw new ProposerSlashingError(GossipAction.REJECT, {
51
- code: ProposerSlashingErrorCode.INVALID,
52
- error: Error("Invalid signature"),
51
+ code: ProposerSlashingErrorCode.INVALID_SIGNATURE,
53
52
  });
54
53
  }
55
54
  }
@@ -24,7 +24,17 @@ import {
24
24
  deneb,
25
25
  gloas,
26
26
  } from "@lodestar/types";
27
- import {LogData, LogHandler, LogLevel, Logger, MapDef, MapDefMax, prettyPrintIndices, toRootHex} from "@lodestar/utils";
27
+ import {
28
+ LogData,
29
+ LogHandler,
30
+ LogLevel,
31
+ Logger,
32
+ MapDef,
33
+ MapDefMax,
34
+ prettyGweiToEth,
35
+ prettyPrintIndices,
36
+ toRootHex,
37
+ } from "@lodestar/utils";
28
38
  import {GENESIS_SLOT} from "../constants/constants.js";
29
39
  import {RegistryMetricCreator} from "../metrics/index.js";
30
40
 
@@ -470,7 +480,7 @@ export function createValidatorMonitor(
470
480
  src,
471
481
  builderIndex: bid.builderIndex,
472
482
  gasLimit: Number(bid.gasLimit),
473
- value: bid.value.toString(),
483
+ value: prettyGweiToEth(bid.value),
474
484
  parentBlockRoot: toRootHex(bid.parentBlockRoot),
475
485
  parentBlockHash: toRootHex(bid.parentBlockHash),
476
486
  blockHash: toRootHex(bid.blockHash),
@@ -1,8 +1,9 @@
1
1
  import {ChainForkConfig} from "@lodestar/config";
2
2
  import {Db, DbBatch, FilterOptions, KeyValue, Repository} from "@lodestar/db";
3
3
  import {Root, SignedBeaconBlock, Slot, ssz} from "@lodestar/types";
4
- import {bytesToInt, intToBytes} from "@lodestar/utils";
4
+ import {bytesToInt, fromHex, intToBytes} from "@lodestar/utils";
5
5
  import {getSignedBlockTypeFromBytes} from "../../util/multifork.js";
6
+ import {getParentRootFromSignedBeaconBlockSerialized} from "../../util/sszBytes.js";
6
7
  import {Bucket, getBucketNameByValue} from "../buckets.js";
7
8
  import {
8
9
  deleteParentRootIndex,
@@ -24,6 +25,10 @@ export type BlockArchiveBatchPutBinaryItem = KeyValue<Slot, Uint8Array> & {
24
25
  parentRoot: Root;
25
26
  };
26
27
 
28
+ // The initial prune can span millions of slots. This bounds the slot index reads in flight and keeps each
29
+ // delete batch at a few thousand keys, both tiny next to the block value batches in archiveBlocks
30
+ const DELETE_RANGE_CHUNK_SIZE = 1000;
31
+
27
32
  /**
28
33
  * Stores finalized blocks. Block slot is identifier.
29
34
  */
@@ -103,6 +108,38 @@ export class BlockArchiveRepository extends Repository<Slot, SignedBeaconBlock>
103
108
  );
104
109
  }
105
110
 
111
+ /**
112
+ * Delete a contiguous range of archived blocks together with their index entries.
113
+ * `slots` must be every archived slot in the range, so the parent of each block is the entry before it.
114
+ */
115
+ async batchDeleteRange(slots: Slot[]): Promise<void> {
116
+ const sorted = [...slots].sort((a, b) => a - b);
117
+ let prevRoot: Root | null = null;
118
+
119
+ for (let i = 0; i < sorted.length; i += DELETE_RANGE_CHUNK_SIZE) {
120
+ const chunk = sorted.slice(i, i + DELETE_RANGE_CHUNK_SIZE);
121
+ const roots = await Promise.all(chunk.map((slot) => this.getRootBySlot(slot)));
122
+
123
+ const keys: Uint8Array[] = [];
124
+ for (let j = 0; j < chunk.length; j++) {
125
+ keys.push(this.encodeKey(chunk[j]), getSlotIndexKey(chunk[j]));
126
+ const root = roots[j];
127
+ if (root) keys.push(getRootIndexKey(root));
128
+ // The parent index entry pointing at this block is keyed by its parent root, which is the
129
+ // previous block's root unless that block is unindexed, then it is read from the block itself
130
+ let parentRoot = prevRoot;
131
+ if (parentRoot === null) {
132
+ const block = await this.getBinary(chunk[j]);
133
+ const parentRootHex = block ? getParentRootFromSignedBeaconBlockSerialized(block) : null;
134
+ parentRoot = parentRootHex ? fromHex(parentRootHex) : null;
135
+ }
136
+ if (parentRoot) keys.push(getParentRootIndexKey(parentRoot));
137
+ prevRoot = root;
138
+ }
139
+ await this.db.batchDelete(keys, this.dbReqOpts);
140
+ }
141
+ }
142
+
106
143
  async batch(operations: DbBatch<Slot, SignedBeaconBlock>): Promise<void> {
107
144
  await this.batchBinary(
108
145
  operations.map((operation) =>
@@ -14,7 +14,7 @@ import {peerIdFromString} from "@libp2p/peer-id";
14
14
  import {type Multiaddr, multiaddr} from "@multiformats/multiaddr";
15
15
  import {ENR} from "@chainsafe/enr";
16
16
  import {routes} from "@lodestar/api";
17
- import {BeaconConfig, ForkBoundary} from "@lodestar/config";
17
+ import {BeaconConfig, ChainConfig, ForkBoundary} from "@lodestar/config";
18
18
  import {
19
19
  ATTESTATION_SUBNET_COUNT,
20
20
  MAX_SIGNED_AGGREGATE_AND_PROOF_SIZE,
@@ -47,6 +47,22 @@ const GOSSIPSUB_HEARTBEAT_INTERVAL = 0.7 * 1000;
47
47
 
48
48
  const MAX_OUTBOUND_BUFFER_SIZE = 2 ** 24; // 16MB
49
49
 
50
+ /**
51
+ * Snappy worst-case compressed length for a payload of `n` bytes
52
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.0/specs/phase0/p2p-interface.md#max_compressed_len
53
+ */
54
+ function maxCompressedLen(n: number): number {
55
+ return 32 + n + Math.floor(n / 6);
56
+ }
57
+
58
+ /**
59
+ * Max size of an inbound gossipsub RPC frame, including all bundled messages and control
60
+ * https://github.com/ethereum/consensus-specs/blob/v1.7.0-beta.0/specs/phase0/p2p-interface.md#max_message_size
61
+ */
62
+ function getMaxInboundDataLength(config: Pick<ChainConfig, "MAX_PAYLOAD_SIZE">): number {
63
+ return Math.max(maxCompressedLen(config.MAX_PAYLOAD_SIZE) + 1024, 1024 * 1024);
64
+ }
65
+
50
66
  export type Eth2Context = {
51
67
  activeValidatorCount: number;
52
68
  currentSlot: number;
@@ -176,6 +192,7 @@ export class Eth2Gossipsub {
176
192
  asyncValidation: true,
177
193
 
178
194
  maxOutboundBufferSize: MAX_OUTBOUND_BUFFER_SIZE,
195
+ maxInboundDataLength: getMaxInboundDataLength(config),
179
196
  // serialize message once and send to all peers when publishing
180
197
  batchPublish: true,
181
198
  // if this is false, only publish to mesh peers. If there is not enough GOSSIP_D mesh peers,
@@ -150,8 +150,8 @@ export function getGossipSSZType(topic: GossipTopic) {
150
150
  /**
151
151
  * Return the maximum uncompressed SSZ byte length allowed by the type and configured network bounds.
152
152
  */
153
- export function getGossipSSZMaxSize(topic: GossipTopic, config: ChainForkConfig, sszType?: CompositeTypeAny): number {
154
- const maxSize = Math.min((sszType ?? getGossipSSZType(topic)).maxSize, config.MAX_PAYLOAD_SIZE);
153
+ export function getGossipSSZMaxSize(topic: GossipTopic, config: ChainForkConfig, sszType: CompositeTypeAny): number {
154
+ const maxSize = Math.min(sszType.maxSize, config.MAX_PAYLOAD_SIZE);
155
155
  if (isForkPostGloas(topic.boundary.fork) && topic.type === GossipType.data_column_sidecar) {
156
156
  return Math.min(maxSize, computeMaxGloasDataColumnSidecarSize(config));
157
157
  }
@@ -244,8 +244,20 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
244
244
 
245
245
  // IGNORE means the block is acceptable (e.g. FUTURE_SLOT, ALREADY_KNOWN), just not propagated.
246
246
  // Keep the optimistically-added cache entries; they are pruned on finalization. Only REJECT
247
- // (provably invalid) and unexpected errors prune below.
247
+ // (provably invalid), unexpected errors and repeat proposals that are not imported prune.
248
248
  if (e.action === GossipAction.IGNORE) {
249
+ // Only a signature-verified sibling is imported by the beacon_block handler, any other repeat proposal
250
+ // is dropped from the caches and re-downloaded by sync if it ever becomes relevant. Its signature was not
251
+ // verified, so only its own entry is removed, never its claimed ancestors
252
+ if (
253
+ e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
254
+ !chain.seenBlockProposers.hasBlockRoot(slot, signedBlock.message.proposerIndex, blockRootHex)
255
+ ) {
256
+ chain.seenBlockInputCache.remove(blockRootHex);
257
+ if (isForkPostGloas(fork)) {
258
+ chain.seenPayloadEnvelopeInputCache.remove(blockRootHex);
259
+ }
260
+ }
249
261
  throw e;
250
262
  }
251
263
 
@@ -258,10 +270,10 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
258
270
  }
259
271
 
260
272
  // REJECT or unexpected (non-BlockGossipError) error: drop the optimistically-added entries from
261
- // both caches, keeping them consistent.
262
- chain.seenBlockInputCache.prune(blockRootHex);
273
+ // both caches, keeping them consistent. The block may carry any parent root, so only its own entry is removed
274
+ chain.seenBlockInputCache.remove(blockRootHex);
263
275
  if (isForkPostGloas(fork)) {
264
- chain.seenPayloadEnvelopeInputCache.prune(blockRootHex);
276
+ chain.seenPayloadEnvelopeInputCache.remove(blockRootHex);
265
277
  }
266
278
  throw e;
267
279
  } finally {
@@ -738,7 +750,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
738
750
  if (
739
751
  e instanceof BlockGossipError &&
740
752
  e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
741
- // this is make sure the block's proposer signature was verified, it should be true anyway
753
+ // Only a signature-verified sibling recorded in the seen cache is imported. The cache holds at most two
754
+ // roots per proposer and slot, which bounds full imports over gossip to one alternate
742
755
  chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root)
743
756
  ) {
744
757
  // blockInput was optimistically seeded in validateBeaconBlock and retained on IGNORE