@lodestar/beacon-node 1.46.0-dev.e6f04acd82 → 1.46.0-dev.eabf12abae

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 (110) 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 +21 -1
  25. package/lib/chain/blocks/verifyBlock.js.map +1 -1
  26. package/lib/chain/chain.d.ts +5 -0
  27. package/lib/chain/chain.d.ts.map +1 -1
  28. package/lib/chain/chain.js +55 -0
  29. package/lib/chain/chain.js.map +1 -1
  30. package/lib/chain/emitter.d.ts +6 -0
  31. package/lib/chain/emitter.d.ts.map +1 -1
  32. package/lib/chain/emitter.js +5 -0
  33. package/lib/chain/emitter.js.map +1 -1
  34. package/lib/chain/interface.d.ts +2 -0
  35. package/lib/chain/interface.d.ts.map +1 -1
  36. package/lib/chain/options.d.ts +2 -0
  37. package/lib/chain/options.d.ts.map +1 -1
  38. package/lib/chain/options.js +1 -0
  39. package/lib/chain/options.js.map +1 -1
  40. package/lib/chain/prepareNextSlot.d.ts.map +1 -1
  41. package/lib/chain/prepareNextSlot.js +107 -29
  42. package/lib/chain/prepareNextSlot.js.map +1 -1
  43. package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
  44. package/lib/chain/produceBlock/produceBlockBody.js +6 -6
  45. package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
  46. package/lib/chain/seenCache/seenBlockProposers.d.ts +20 -4
  47. package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
  48. package/lib/chain/seenCache/seenBlockProposers.js +49 -2
  49. package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
  50. package/lib/chain/validation/block.d.ts +4 -1
  51. package/lib/chain/validation/block.d.ts.map +1 -1
  52. package/lib/chain/validation/block.js +32 -18
  53. package/lib/chain/validation/block.js.map +1 -1
  54. package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
  55. package/lib/chain/validation/dataColumnSidecar.js +21 -16
  56. package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
  57. package/lib/metrics/metrics/lodestar.d.ts +14 -0
  58. package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
  59. package/lib/metrics/metrics/lodestar.js +38 -0
  60. package/lib/metrics/metrics/lodestar.js.map +1 -1
  61. package/lib/network/core/networkCore.d.ts.map +1 -1
  62. package/lib/network/core/networkCore.js +12 -1
  63. package/lib/network/core/networkCore.js.map +1 -1
  64. package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
  65. package/lib/network/core/networkCoreWorkerHandler.js +20 -3
  66. package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
  67. package/lib/network/network.d.ts +1 -0
  68. package/lib/network/network.d.ts.map +1 -1
  69. package/lib/network/network.js +11 -1
  70. package/lib/network/network.js.map +1 -1
  71. package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
  72. package/lib/network/processor/gossipHandlers.js +8 -0
  73. package/lib/network/processor/gossipHandlers.js.map +1 -1
  74. package/lib/network/reqresp/score.d.ts.map +1 -1
  75. package/lib/network/reqresp/score.js +20 -3
  76. package/lib/network/reqresp/score.js.map +1 -1
  77. package/lib/util/clock.d.ts +2 -7
  78. package/lib/util/clock.d.ts.map +1 -1
  79. package/lib/util/clock.js +2 -7
  80. package/lib/util/clock.js.map +1 -1
  81. package/lib/util/workerEvents.d.ts +7 -1
  82. package/lib/util/workerEvents.d.ts.map +1 -1
  83. package/lib/util/workerEvents.js +17 -5
  84. package/lib/util/workerEvents.js.map +1 -1
  85. package/package.json +15 -15
  86. package/src/api/impl/beacon/blocks/index.ts +65 -16
  87. package/src/api/impl/validator/index.ts +19 -6
  88. package/src/chain/blocks/importBlock.ts +3 -2
  89. package/src/chain/blocks/importExecutionPayload.ts +8 -4
  90. package/src/chain/blocks/index.ts +7 -0
  91. package/src/chain/blocks/utils/chainSegment.ts +35 -28
  92. package/src/chain/blocks/utils/polarBearBanner.ts +50 -0
  93. package/src/chain/blocks/verifyBlock.ts +28 -2
  94. package/src/chain/chain.ts +60 -0
  95. package/src/chain/emitter.ts +7 -0
  96. package/src/chain/interface.ts +3 -0
  97. package/src/chain/options.ts +3 -0
  98. package/src/chain/prepareNextSlot.ts +140 -39
  99. package/src/chain/produceBlock/produceBlockBody.ts +11 -6
  100. package/src/chain/seenCache/seenBlockProposers.ts +72 -5
  101. package/src/chain/validation/block.ts +41 -19
  102. package/src/chain/validation/dataColumnSidecar.ts +27 -17
  103. package/src/metrics/metrics/lodestar.ts +39 -0
  104. package/src/network/core/networkCore.ts +13 -1
  105. package/src/network/core/networkCoreWorkerHandler.ts +18 -3
  106. package/src/network/network.ts +16 -1
  107. package/src/network/processor/gossipHandlers.ts +7 -0
  108. package/src/network/reqresp/score.ts +22 -3
  109. package/src/util/clock.ts +2 -7
  110. package/src/util/workerEvents.ts +18 -6
@@ -70,6 +70,15 @@ export type BaseNetworkInit = {
70
70
  initialCustodyGroupCount: number;
71
71
  };
72
72
 
73
+ /** Counts of what is still keeping this thread's event loop alive, e.g. `TCPWrap=3,Timeout=1` */
74
+ function formatActiveResources(): string {
75
+ const counts = new Map<string, number>();
76
+ for (const resource of process.getActiveResourcesInfo()) {
77
+ counts.set(resource, (counts.get(resource) ?? 0) + 1);
78
+ }
79
+ return Array.from(counts, ([name, count]) => `${name}=${count}`).join(",");
80
+ }
81
+
73
82
  /**
74
83
  * This class is meant to work both:
75
84
  * - In a libp2p worker
@@ -289,7 +298,10 @@ export class NetworkCore implements INetworkCore {
289
298
  this.attnetsService.close();
290
299
  this.syncnetsService.close();
291
300
  await this.libp2p.stop();
292
- this.logger.debug("network lib2p closed");
301
+ // Diagnostic for the shutdown hang, this thread can spin in `Environment::CleanupHandles()` on
302
+ // a handle that never closes and `Worker.terminate()` then never resolves. Diffing this list
303
+ // between a clean and a stuck shutdown should narrow down which handle it is
304
+ this.logger.debug("network lib2p closed", {activeResources: formatActiveResources()});
293
305
 
294
306
  this.closed = true;
295
307
  }
@@ -10,6 +10,7 @@ import {BeaconConfig, chainConfigToJson} from "@lodestar/config";
10
10
  import type {LoggerNode} from "@lodestar/logger/node";
11
11
  import {ResponseIncoming, ResponseOutgoing} from "@lodestar/reqresp";
12
12
  import {Status} from "@lodestar/types";
13
+ import {withTimeout} from "@lodestar/utils";
13
14
  import {Metrics} from "../../metrics/index.js";
14
15
  import {AsyncIterableBridgeCaller, AsyncIterableBridgeHandler} from "../../util/asyncIterableToEvents.js";
15
16
  import {PeerIdStr, peerIdFromString} from "../../util/peerId.js";
@@ -58,6 +59,10 @@ type WorkerNetworkCoreModules = WorkerNetworkCoreInitModules & {
58
59
 
59
60
  const NETWORK_WORKER_EXIT_TIMEOUT_MS = 1000;
60
61
  const NETWORK_WORKER_EXIT_RETRY_COUNT = 3;
62
+ /** `getApi().close()` is an unbounded RPC into the worker and runs before `BeaconNode.close()`
63
+ * archives chain state to disk, so it is bounded here. Set well above the ~2-4s a close takes on
64
+ * mainnet, tripping it leaves libp2p half torn down */
65
+ const NETWORK_CORE_CLOSE_TIMEOUT_MS = 5000;
61
66
 
62
67
  /**
63
68
  * NetworkCore implementation using a Worker thread
@@ -165,15 +170,25 @@ export class WorkerNetworkCore implements INetworkCore {
165
170
 
166
171
  async close(): Promise<void> {
167
172
  this.modules.logger.debug("closing network core running in network worker");
168
- await this.getApi().close();
173
+ try {
174
+ await withTimeout(async () => this.getApi().close(), NETWORK_CORE_CLOSE_TIMEOUT_MS);
175
+ } catch (e) {
176
+ this.modules.logger.debug("Error closing network core", {}, e as Error);
177
+ }
169
178
  this.modules.logger.debug("terminating network worker");
170
- await terminateWorkerThread({
179
+ const terminated = await terminateWorkerThread({
171
180
  worker: this.getApi(),
172
181
  retryCount: NETWORK_WORKER_EXIT_RETRY_COUNT,
173
182
  retryMs: NETWORK_WORKER_EXIT_TIMEOUT_MS,
174
183
  logger: this.modules.logger,
175
184
  });
176
- this.modules.logger.debug("terminated network worker");
185
+ if (terminated) {
186
+ this.modules.logger.debug("terminated network worker");
187
+ } else {
188
+ // Nothing more to do, `process.exit()` joins the thread regardless so the process still waits
189
+ // on it. What matters is returning, so the caller can archive state and close the db
190
+ this.modules.logger.debug("Network worker did not terminate in time, continuing shutdown without it");
191
+ }
177
192
  }
178
193
 
179
194
  async test(): Promise<void> {
@@ -147,6 +147,7 @@ export class Network implements INetwork {
147
147
  this.chain.emitter.on(ChainEvent.updateTargetCustodyGroupCount, this.onTargetGroupCountUpdated);
148
148
  this.chain.emitter.on(ChainEvent.publishDataColumns, this.onPublishDataColumns);
149
149
  this.chain.emitter.on(ChainEvent.publishBlobSidecars, this.onPublishBlobSidecars);
150
+ this.chain.emitter.on(ChainEvent.publishProposerSlashing, this.onPublishProposerSlashing);
150
151
  this.chain.emitter.on(ChainEvent.updateStatus, this.onUpdateStatus);
151
152
  }
152
153
 
@@ -244,6 +245,7 @@ export class Network implements INetwork {
244
245
  this.chain.emitter.off(ChainEvent.updateTargetCustodyGroupCount, this.onTargetGroupCountUpdated);
245
246
  this.chain.emitter.off(ChainEvent.publishDataColumns, this.onPublishDataColumns);
246
247
  this.chain.emitter.off(ChainEvent.publishBlobSidecars, this.onPublishBlobSidecars);
248
+ this.chain.emitter.off(ChainEvent.publishProposerSlashing, this.onPublishProposerSlashing);
247
249
  this.chain.emitter.off(ChainEvent.updateStatus, this.onUpdateStatus);
248
250
  await this.core.close();
249
251
 
@@ -455,7 +457,8 @@ export class Network implements INetwork {
455
457
 
456
458
  return this.publishGossip<GossipType.proposer_slashing>(
457
459
  {type: GossipType.proposer_slashing, boundary},
458
- proposerSlashing
460
+ proposerSlashing,
461
+ {ignoreDuplicatePublishError: true}
459
462
  );
460
463
  }
461
464
 
@@ -877,6 +880,18 @@ export class Network implements INetwork {
877
880
  return promiseAllMaybeAsync(sidecars.map((sidecar) => () => this.publishBlobSidecar(sidecar)));
878
881
  };
879
882
 
883
+ private onPublishProposerSlashing = async (proposerSlashing: phase0.ProposerSlashing): Promise<void> => {
884
+ try {
885
+ await this.publishProposerSlashing(proposerSlashing);
886
+ } catch (e) {
887
+ this.logger.debug(
888
+ "Error publishing proposer slashing",
889
+ {proposerIndex: proposerSlashing.signedHeader1.message.proposerIndex},
890
+ e as Error
891
+ );
892
+ }
893
+ };
894
+
880
895
  private onUpdateStatus = async (): Promise<void> => {
881
896
  await this.core.updateStatus(this.chain.getStatus());
882
897
  };
@@ -257,6 +257,13 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
257
257
  chain.seenPayloadEnvelopeInputCache.prune(blockRootHex);
258
258
  }
259
259
  throw e;
260
+ } finally {
261
+ // The block received from the network may have established an equivocation, either by conflicting
262
+ // with a previously observed block root (REPEAT_PROPOSAL) or with a root observed during validation
263
+ const proposerIndex = signedBlock.message.proposerIndex;
264
+ if (chain.seenBlockProposers.isEquivocating(slot, proposerIndex)) {
265
+ chain.processProposerEquivocation(slot, proposerIndex);
266
+ }
260
267
  }
261
268
  }
262
269
 
@@ -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;
@@ -111,6 +111,12 @@ export function wireEventsOnMainThread<EventData>(
111
111
  }
112
112
  }
113
113
 
114
+ /**
115
+ * Terminate a worker thread, bounded to `retryCount * retryMs`.
116
+ *
117
+ * @returns `false` if it could not be terminated, the worker thread is then still running and the
118
+ * caller has to decide how to proceed without it.
119
+ */
114
120
  export async function terminateWorkerThread({
115
121
  worker,
116
122
  retryMs,
@@ -121,7 +127,7 @@ export async function terminateWorkerThread({
121
127
  retryMs: number;
122
128
  retryCount: number;
123
129
  logger?: Logger;
124
- }): Promise<void> {
130
+ }): Promise<boolean> {
125
131
  const terminated = new Promise((resolve) => {
126
132
  Thread.events(worker).subscribe((event) => {
127
133
  if (event.type === "termination") {
@@ -131,13 +137,19 @@ export async function terminateWorkerThread({
131
137
  });
132
138
 
133
139
  for (let i = 0; i < retryCount; i++) {
134
- await Thread.terminate(worker);
135
- const result = await Promise.race([terminated, sleep(retryMs).then(() => false)]);
140
+ // `Worker.terminate()` resolves only once the worker thread exits, and the thread can spin
141
+ // forever in `Environment::CleanupHandles()` when a libuv handle on its loop never closes, so
142
+ // it has to be raced too, otherwise `retryCount * retryMs` never applies.
143
+ const result = await Promise.race([
144
+ Thread.terminate(worker).then(() => terminated),
145
+ sleep(retryMs).then(() => false),
146
+ ]);
136
147
 
137
- if (result) return;
148
+ if (result) return true;
138
149
 
139
- logger?.warn("Worker thread failed to terminate, retrying...");
150
+ logger?.debug("Worker thread failed to terminate, retrying...");
140
151
  }
141
152
 
142
- throw new Error(`Worker thread failed to terminate in ${retryCount * retryMs}ms.`);
153
+ logger?.debug(`Worker thread failed to terminate in ${retryCount * retryMs}ms`);
154
+ return false;
143
155
  }