@lodestar/beacon-node 1.46.0-dev.281a8ee194 → 1.46.0-dev.3d8f7cf440

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 (66) hide show
  1. package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
  2. package/lib/api/impl/beacon/blocks/index.js +37 -15
  3. package/lib/api/impl/beacon/blocks/index.js.map +1 -1
  4. package/lib/api/impl/validator/index.d.ts.map +1 -1
  5. package/lib/api/impl/validator/index.js +15 -6
  6. package/lib/api/impl/validator/index.js.map +1 -1
  7. package/lib/chain/blocks/importBlock.d.ts.map +1 -1
  8. package/lib/chain/blocks/importBlock.js +3 -3
  9. package/lib/chain/blocks/importBlock.js.map +1 -1
  10. package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
  11. package/lib/chain/blocks/importExecutionPayload.js +3 -4
  12. package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
  13. package/lib/chain/blocks/index.d.ts.map +1 -1
  14. package/lib/chain/blocks/index.js +6 -0
  15. package/lib/chain/blocks/index.js.map +1 -1
  16. package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -1
  17. package/lib/chain/blocks/utils/chainSegment.js +31 -25
  18. package/lib/chain/blocks/utils/chainSegment.js.map +1 -1
  19. package/lib/chain/blocks/utils/polarBearBanner.d.ts +2 -0
  20. package/lib/chain/blocks/utils/polarBearBanner.d.ts.map +1 -0
  21. package/lib/chain/blocks/utils/polarBearBanner.js +51 -0
  22. package/lib/chain/blocks/utils/polarBearBanner.js.map +1 -0
  23. package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
  24. package/lib/chain/blocks/verifyBlock.js +12 -0
  25. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  26. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  27. package/lib/chain/prepareNextSlot.js +74 -6
  28. package/lib/chain/prepareNextSlot.js.map +1 -1
  29. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  30. package/lib/chain/produceBlock/produceBlockBody.js +5 -5
  31. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  32. package/lib/chain/seenCache/seenBlockProposers.d.ts +15 -4
  33. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  34. package/lib/chain/seenCache/seenBlockProposers.js +35 -2
  35. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  36. package/lib/chain/validation/block.d.ts +4 -1
  37. package/lib/chain/validation/block.d.ts.map +1 -1
  38. package/lib/chain/validation/block.js +26 -15
  39. package/lib/chain/validation/block.js.map +1 -1
  40. package/lib/metrics/metrics/lodestar.d.ts +13 -0
  41. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  42. package/lib/metrics/metrics/lodestar.js +34 -0
  43. package/lib/metrics/metrics/lodestar.js.map +1 -1
  44. package/lib/network/reqresp/score.d.ts.map +1 -1
  45. package/lib/network/reqresp/score.js +20 -3
  46. package/lib/network/reqresp/score.js.map +1 -1
  47. package/lib/util/clock.d.ts +2 -7
  48. package/lib/util/clock.d.ts.map +1 -1
  49. package/lib/util/clock.js +2 -7
  50. package/lib/util/clock.js.map +1 -1
  51. package/package.json +15 -15
  52. package/src/api/impl/beacon/blocks/index.ts +60 -16
  53. package/src/api/impl/validator/index.ts +19 -6
  54. package/src/chain/blocks/importBlock.ts +3 -2
  55. package/src/chain/blocks/importExecutionPayload.ts +8 -4
  56. package/src/chain/blocks/index.ts +7 -0
  57. package/src/chain/blocks/utils/chainSegment.ts +35 -28
  58. package/src/chain/blocks/utils/polarBearBanner.ts +50 -0
  59. package/src/chain/blocks/verifyBlock.ts +16 -0
  60. package/src/chain/prepareNextSlot.ts +82 -6
  61. package/src/chain/produceBlock/produceBlockBody.ts +10 -5
  62. package/src/chain/seenCache/seenBlockProposers.ts +46 -5
  63. package/src/chain/validation/block.ts +36 -18
  64. package/src/metrics/metrics/lodestar.ts +35 -0
  65. package/src/network/reqresp/score.ts +22 -3
  66. package/src/util/clock.ts +2 -7
@@ -1,21 +1,57 @@
1
1
  import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
2
- import {Epoch, Slot, ValidatorIndex} from "@lodestar/types";
2
+ import {Epoch, RootHex, Slot, ValidatorIndex} from "@lodestar/types";
3
3
  import {MapDef} from "@lodestar/utils";
4
4
 
5
+ /** Two distinct block roots signed by the same proposer for the same slot are sufficient to establish an equivocation */
6
+ const MAX_BLOCK_ROOTS_PER_PROPOSAL = 2;
7
+
5
8
  /**
6
9
  * Keeps a cache to filter block proposals from the same validator in the same slot.
7
10
  *
8
- * This cache is not bounded and for extremely long periods of non-finality it can grow a lot. However it's practically
9
- * limited by the possible shufflings in those epochs, and the stored data is very cheap
11
+ * Block roots with a signature verified against the block's proposer index are tracked separately from proposals
12
+ * accepted by gossip validation or block import. A root from a block signed by its declared proposer is potential
13
+ * equivocation evidence, but the block may still fail other validation. Such a block must not mark the proposal as
14
+ * known, since that would cause a later valid block for the same slot and proposer to be ignored as a repeat proposal.
15
+ *
16
+ * The cache is pruned on finalization and bounds the number of roots stored per proposer and slot
10
17
  */
11
18
  export class SeenBlockProposers {
12
19
  private readonly proposerIndexesBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set<ValidatorIndex>());
13
- private finalizedSlot: Epoch = 0;
20
+ private readonly blockRootsBySlot = new MapDef<Slot, MapDef<ValidatorIndex, Set<RootHex>>>(
21
+ () => new MapDef<ValidatorIndex, Set<RootHex>>(() => new Set<RootHex>())
22
+ );
23
+ private finalizedSlot: Slot = 0;
14
24
 
15
25
  isKnown(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
16
26
  return this.proposerIndexesBySlot.get(blockSlot)?.has(proposerIndex) === true;
17
27
  }
18
28
 
29
+ hasBlockRoot(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): boolean {
30
+ return this.blockRootsBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
31
+ }
32
+
33
+ isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
34
+ return (this.blockRootsBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >= MAX_BLOCK_ROOTS_PER_PROPOSAL;
35
+ }
36
+
37
+ getConflictingBlockRoots(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): RootHex[] {
38
+ const roots = this.blockRootsBySlot.get(blockSlot)?.get(proposerIndex);
39
+ return roots === undefined ? [] : Array.from(roots).filter((root) => root !== blockRoot);
40
+ }
41
+
42
+ /** Record a block only after its proposer signature has been verified */
43
+ observeBlockRoot(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): void {
44
+ if (blockSlot < this.finalizedSlot) {
45
+ throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
46
+ }
47
+
48
+ const blockRoots = this.blockRootsBySlot.getOrDefault(blockSlot).getOrDefault(proposerIndex);
49
+ if (blockRoots.size < MAX_BLOCK_ROOTS_PER_PROPOSAL) {
50
+ blockRoots.add(blockRoot);
51
+ }
52
+ }
53
+
54
+ /** Mark a block as known from gossip or another block import path */
19
55
  add(blockSlot: Slot, proposerIndex: ValidatorIndex): void {
20
56
  if (blockSlot < this.finalizedSlot) {
21
57
  throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
@@ -31,9 +67,14 @@ export class SeenBlockProposers {
31
67
  this.proposerIndexesBySlot.delete(slot);
32
68
  }
33
69
  }
70
+ for (const slot of this.blockRootsBySlot.keys()) {
71
+ if (slot < finalizedSlot) {
72
+ this.blockRootsBySlot.delete(slot);
73
+ }
74
+ }
34
75
  }
35
76
 
36
- seenAtEpoch(epoch: Slot, index: ValidatorIndex): boolean {
77
+ seenAtEpoch(epoch: Epoch, index: ValidatorIndex): boolean {
37
78
  const fromSlot = computeStartSlotAtEpoch(epoch);
38
79
  const toSlot = computeStartSlotAtEpoch(epoch + 1);
39
80
 
@@ -24,7 +24,7 @@ import {
24
24
  isExecutionBlockBodyType,
25
25
  isStatePostBellatrix,
26
26
  } from "@lodestar/state-transition";
27
- import {SignedBeaconBlock, deneb, gloas, isGloasBeaconBlock} from "@lodestar/types";
27
+ import {RootHex, SignedBeaconBlock, deneb, gloas, isGloasBeaconBlock} from "@lodestar/types";
28
28
  import {byteArrayEquals, sleep, toRootHex} from "@lodestar/utils";
29
29
  import {BlockErrorCode, BlockGossipError, GossipAction} from "../errors/index.js";
30
30
  import {IBeaconChain} from "../interface.js";
@@ -85,7 +85,12 @@ export async function validateGossipBlock(
85
85
 
86
86
  // [IGNORE] The block is the first block with valid signature received for the proposer for the slot, signed_beacon_block.message.slot.
87
87
  const proposerIndex = block.proposerIndex;
88
+ const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
88
89
  if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
90
+ if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
91
+ await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
92
+ chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot);
93
+ }
89
94
  throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
90
95
  }
91
96
 
@@ -270,18 +275,8 @@ export async function validateGossipBlock(
270
275
  }
271
276
 
272
277
  // [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
273
- if (!chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature)) {
274
- const signatureSet = getBlockProposerSignatureSet(chain.config, signedBlock);
275
- // Don't batch so verification is not delayed
276
- if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
277
- throw new BlockGossipError(GossipAction.REJECT, {
278
- code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
279
- blockSlot,
280
- });
281
- }
282
-
283
- chain.seenBlockInputCache.markVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature);
284
- }
278
+ await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
279
+ chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot);
285
280
 
286
281
  // [REJECT] The block is proposed by the expected proposer_index for the block's slot in the context of the current
287
282
  // shuffling (defined by parent_root/slot). If the proposer_index cannot immediately be verified against the expected
@@ -291,11 +286,6 @@ export async function validateGossipBlock(
291
286
  throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.INCORRECT_PROPOSER, proposerIndex});
292
287
  }
293
288
 
294
- // Check again in case there two blocks are processed concurrently
295
- if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
296
- throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
297
- }
298
-
299
289
  // Simple implementation of a pending block queue. Keeping the block here recycles the queue logic, and keeps the
300
290
  // gossip validation promise without any extra infrastructure.
301
291
  // Do the sleep at the end, since regen and signature validation can already take longer than `msToBlockSlot`.
@@ -305,7 +295,35 @@ export async function validateGossipBlock(
305
295
  await sleep(msToBlockSlot);
306
296
  }
307
297
 
298
+ // Check again after all async validation and the early-block delay so concurrent proposals cannot both pass
299
+ if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
300
+ throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
301
+ }
302
+
308
303
  chain.seenBlockProposers.add(blockSlot, proposerIndex);
309
304
 
310
305
  return {skippedSlots};
311
306
  }
307
+
308
+ export async function verifyBlockProposerSignature(
309
+ chain: IBeaconChain,
310
+ signedBlock: SignedBeaconBlock,
311
+ blockRoot: RootHex,
312
+ opts: {verifyOnMainThread?: boolean} = {}
313
+ ): Promise<void> {
314
+ const blockSlot = signedBlock.message.slot;
315
+ if (chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature)) {
316
+ return;
317
+ }
318
+
319
+ const signatureSet = getBlockProposerSignatureSet(chain.config, signedBlock);
320
+ // Don't batch so verification is not delayed
321
+ if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: opts.verifyOnMainThread ?? true}))) {
322
+ throw new BlockGossipError(GossipAction.REJECT, {
323
+ code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
324
+ blockSlot,
325
+ });
326
+ }
327
+
328
+ chain.seenBlockInputCache.markVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature);
329
+ }
@@ -1708,6 +1708,41 @@ export function createLodestarMetrics(
1708
1708
  }),
1709
1709
  },
1710
1710
 
1711
+ // Pre-verify builder-deposit signatures in the epochs before the Gloas fork (prepareNextSlot).
1712
+ builderDepositPreVerify: {
1713
+ duration: register.histogram({
1714
+ name: "lodestar_builder_deposit_preverify_duration_seconds",
1715
+ help: "Duration of one preVerifyBuilderDepositsPreGloas call (BLS batch verify + scan)",
1716
+ buckets: [1, 2, 3, 4],
1717
+ }),
1718
+ pendingDeposits: register.gauge({
1719
+ name: "lodestar_builder_deposit_preverify_pending_deposits",
1720
+ help: "Current state.pendingDeposits length (backlog to drain before the fork)",
1721
+ }),
1722
+ cachedDeposits: register.gauge({
1723
+ name: "lodestar_builder_deposit_preverify_cached_deposits",
1724
+ help: "Deposit signatures verified & cached so far this pre-fork window (valid + invalid)",
1725
+ }),
1726
+ scannedDeposits: register.gauge({
1727
+ name: "lodestar_builder_deposit_preverify_scanned_deposits",
1728
+ help: "Pending deposits examined by the last pre-verify call (< pending_deposits ⇒ cap hit)",
1729
+ }),
1730
+ builderPubkeys: register.gauge({
1731
+ name: "lodestar_builder_deposit_preverify_builder_pubkeys",
1732
+ help: "Distinct builder pubkeys tracked this window (validator deposits for these are pre-verified)",
1733
+ }),
1734
+ validSignatures: register.counter<{type: "builder" | "validator"}>({
1735
+ name: "lodestar_builder_deposit_preverify_valid_signatures_total",
1736
+ help: "Cumulative deposit signatures whose BLS verification passed (VALID), by credential type",
1737
+ labelNames: ["type"],
1738
+ }),
1739
+ invalidSignatures: register.counter<{type: "builder" | "validator"}>({
1740
+ name: "lodestar_builder_deposit_preverify_invalid_signatures_total",
1741
+ help: "Cumulative deposit signatures whose BLS verification failed (INVALID), by credential type",
1742
+ labelNames: ["type"],
1743
+ }),
1744
+ },
1745
+
1711
1746
  // reprocess attestations
1712
1747
  reprocessApiAttestations: {
1713
1748
  total: register.gauge({
@@ -33,9 +33,28 @@ export function onOutgoingReqRespError(e: RequestError, method: ReqRespMethod):
33
33
 
34
34
  case RequestErrorCode.DIAL_TIMEOUT:
35
35
  case RequestErrorCode.DIAL_ERROR:
36
- return e.message.includes(multiStreamSelectErrorCodes.protocolSelectionFailed) && method === ReqRespMethod.Ping
37
- ? PeerAction.Fatal
38
- : PeerAction.LowToleranceError;
36
+ // `RequestError` renders `e.message` as just the error code (see `renderErrorMessage`), so the
37
+ // multistream "protocol selection failed" text is only on the wrapped inner error, which is
38
+ // available on `DIAL_ERROR` via `e.type.error` (`DIAL_TIMEOUT` carries no inner error).
39
+ if (
40
+ e.type.code === RequestErrorCode.DIAL_ERROR &&
41
+ e.type.error.message.includes(multiStreamSelectErrorCodes.protocolSelectionFailed)
42
+ ) {
43
+ // Peer does not support the protocol, a real incompatibility rather than a transient
44
+ // failure, so keep the stronger penalty (Fatal for Ping, as before).
45
+ return method === ReqRespMethod.Ping ? PeerAction.Fatal : PeerAction.LowToleranceError;
46
+ }
47
+ switch (method) {
48
+ // Ping and Status are liveness probes; their dial timeouts are dominated by transient
49
+ // network congestion rather than peer misbehavior, so penalize leniently to avoid
50
+ // self-inflicted peer starvation (https://github.com/ChainSafe/lodestar/issues/9562),
51
+ // while still applying some penalty so genuinely dead peers eventually free the slot.
52
+ case ReqRespMethod.Ping:
53
+ case ReqRespMethod.Status:
54
+ return PeerAction.HighToleranceError;
55
+ default:
56
+ return PeerAction.LowToleranceError;
57
+ }
39
58
  // TODO: Detect SSZDecodeError and return PeerAction.Fatal
40
59
 
41
60
  case RequestErrorCode.RESP_TIMEOUT:
package/src/util/clock.ts CHANGED
@@ -94,10 +94,7 @@ export class Clock extends EventEmitter implements IClock {
94
94
  }
95
95
  /**
96
96
  * If it's too close to next slot given MAXIMUM_GOSSIP_CLOCK_DISPARITY, return currentSlot + 1.
97
- * Otherwise return currentSlot
98
- *
99
- * Spec: phase0/p2p-interface.md - gossip validation uses `current_time + MAXIMUM_GOSSIP_CLOCK_DISPARITY < message_time`
100
- * to reject future messages (strict `<`), so the boundary (exactly equal) is accepted, hence `<=` here.
97
+ * Spec: phase0/p2p-interface.md rejects future messages with strict `<`, hence `<=` here.
101
98
  */
102
99
  get currentSlotWithGossipDisparity(): Slot {
103
100
  const currentSlot = this.currentSlot;
@@ -123,9 +120,7 @@ export class Clock extends EventEmitter implements IClock {
123
120
 
124
121
  /**
125
122
  * Check if a slot is current slot given MAXIMUM_GOSSIP_CLOCK_DISPARITY.
126
- *
127
- * Uses `<=` for disparity checks because the spec rejects with strict `<`
128
- * (phase0/p2p-interface.md), meaning the boundary (exactly equal) is accepted.
123
+ * Spec: phase0/p2p-interface.md rejects future messages with strict `<`, hence `<=`.
129
124
  */
130
125
  isCurrentSlotGivenGossipDisparity(slot: Slot): boolean {
131
126
  const currentSlot = this.currentSlot;