@lodestar/beacon-node 1.46.0-dev.281a8ee194 → 1.46.0-dev.3e8651f2dc
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.
- package/lib/api/impl/beacon/blocks/index.d.ts.map +1 -1
- package/lib/api/impl/beacon/blocks/index.js +37 -15
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +15 -6
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/blocks/importBlock.d.ts.map +1 -1
- package/lib/chain/blocks/importBlock.js +3 -3
- package/lib/chain/blocks/importBlock.js.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.js +3 -4
- package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
- package/lib/chain/blocks/index.d.ts.map +1 -1
- package/lib/chain/blocks/index.js +6 -0
- package/lib/chain/blocks/index.js.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.d.ts.map +1 -1
- package/lib/chain/blocks/utils/chainSegment.js +31 -25
- package/lib/chain/blocks/utils/chainSegment.js.map +1 -1
- package/lib/chain/blocks/utils/polarBearBanner.d.ts +2 -0
- package/lib/chain/blocks/utils/polarBearBanner.d.ts.map +1 -0
- package/lib/chain/blocks/utils/polarBearBanner.js +51 -0
- package/lib/chain/blocks/utils/polarBearBanner.js.map +1 -0
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +21 -1
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/chain.d.ts +5 -0
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +55 -0
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/emitter.d.ts +6 -0
- package/lib/chain/emitter.d.ts.map +1 -1
- package/lib/chain/emitter.js +5 -0
- package/lib/chain/emitter.js.map +1 -1
- package/lib/chain/interface.d.ts +2 -0
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/options.d.ts +2 -0
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +1 -0
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +74 -6
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +6 -6
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.d.ts +20 -4
- package/lib/chain/seenCache/seenBlockProposers.d.ts.map +1 -1
- package/lib/chain/seenCache/seenBlockProposers.js +49 -2
- package/lib/chain/seenCache/seenBlockProposers.js.map +1 -1
- package/lib/chain/validation/block.d.ts +4 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +32 -18
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +14 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +38 -0
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/core/networkCore.d.ts.map +1 -1
- package/lib/network/core/networkCore.js +12 -1
- package/lib/network/core/networkCore.js.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js +20 -3
- package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
- package/lib/network/network.d.ts +1 -0
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +11 -1
- package/lib/network/network.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +8 -0
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/score.d.ts.map +1 -1
- package/lib/network/reqresp/score.js +20 -3
- package/lib/network/reqresp/score.js.map +1 -1
- package/lib/util/clock.d.ts +2 -7
- package/lib/util/clock.d.ts.map +1 -1
- package/lib/util/clock.js +2 -7
- package/lib/util/clock.js.map +1 -1
- package/lib/util/workerEvents.d.ts +7 -1
- package/lib/util/workerEvents.d.ts.map +1 -1
- package/lib/util/workerEvents.js +17 -5
- package/lib/util/workerEvents.js.map +1 -1
- package/package.json +15 -15
- package/src/api/impl/beacon/blocks/index.ts +65 -16
- package/src/api/impl/validator/index.ts +19 -6
- package/src/chain/blocks/importBlock.ts +3 -2
- package/src/chain/blocks/importExecutionPayload.ts +8 -4
- package/src/chain/blocks/index.ts +7 -0
- package/src/chain/blocks/utils/chainSegment.ts +35 -28
- package/src/chain/blocks/utils/polarBearBanner.ts +50 -0
- package/src/chain/blocks/verifyBlock.ts +28 -2
- package/src/chain/chain.ts +60 -0
- package/src/chain/emitter.ts +7 -0
- package/src/chain/interface.ts +3 -0
- package/src/chain/options.ts +3 -0
- package/src/chain/prepareNextSlot.ts +82 -6
- package/src/chain/produceBlock/produceBlockBody.ts +11 -6
- package/src/chain/seenCache/seenBlockProposers.ts +72 -5
- package/src/chain/validation/block.ts +41 -19
- package/src/metrics/metrics/lodestar.ts +39 -0
- package/src/network/core/networkCore.ts +13 -1
- package/src/network/core/networkCoreWorkerHandler.ts +18 -3
- package/src/network/network.ts +16 -1
- package/src/network/processor/gossipHandlers.ts +7 -0
- package/src/network/reqresp/score.ts +22 -3
- package/src/util/clock.ts +2 -7
- package/src/util/workerEvents.ts +18 -6
package/src/chain/chain.ts
CHANGED
|
@@ -130,6 +130,7 @@ import {CPStateDatastore} from "./stateCache/datastore/types.js";
|
|
|
130
130
|
import {FIFOBlockStateCache} from "./stateCache/fifoBlockStateCache.js";
|
|
131
131
|
import {PersistentCheckpointStateCache} from "./stateCache/persistentCheckpointsCache.js";
|
|
132
132
|
import {CheckpointStateCache} from "./stateCache/types.js";
|
|
133
|
+
import {validateApiProposerSlashing} from "./validation/proposerSlashing.js";
|
|
133
134
|
import {ValidatorMonitor} from "./validatorMonitor.js";
|
|
134
135
|
|
|
135
136
|
/**
|
|
@@ -200,6 +201,8 @@ export class BeaconChain implements IBeaconChain {
|
|
|
200
201
|
readonly seenAggregatedAttestations: SeenAggregatedAttestations;
|
|
201
202
|
readonly seenExecutionPayloadBids = new SeenExecutionPayloadBids();
|
|
202
203
|
readonly seenBlockProposers = new SeenBlockProposers();
|
|
204
|
+
/** Proposer indexes with an in-flight proposer slashing production */
|
|
205
|
+
private readonly producingProposerSlashing = new Set<ValidatorIndex>();
|
|
203
206
|
readonly seenSyncCommitteeMessages = new SeenSyncCommitteeMessages();
|
|
204
207
|
readonly seenContributionAndProof: SeenContributionAndProof;
|
|
205
208
|
readonly seenAttestationDatas: SeenAttestationDatas;
|
|
@@ -1163,6 +1166,63 @@ export class BeaconChain implements IBeaconChain {
|
|
|
1163
1166
|
return this.payloadEnvelopeProcessor.processPayloadEnvelopeJob(payloadInput, opts);
|
|
1164
1167
|
}
|
|
1165
1168
|
|
|
1169
|
+
processProposerEquivocation(blockSlot: Slot, proposerIndex: ValidatorIndex): void {
|
|
1170
|
+
this.produceProposerSlashing(blockSlot, proposerIndex).catch((e) => {
|
|
1171
|
+
this.logger.debug("Error producing proposer slashing", {slot: blockSlot, proposerIndex}, e as Error);
|
|
1172
|
+
});
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/** Produce a proposer slashing from two conflicting signed block headers observed for the same slot and proposer */
|
|
1176
|
+
private async produceProposerSlashing(blockSlot: Slot, proposerIndex: ValidatorIndex): Promise<void> {
|
|
1177
|
+
if (this.opts.disableProposerSlashings === true || this.producingProposerSlashing.has(proposerIndex)) {
|
|
1178
|
+
return;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
if (this.opPool.hasSeenProposerSlashing(proposerIndex)) {
|
|
1182
|
+
this.logger.debug("Not producing proposer slashing, already in the op pool", {
|
|
1183
|
+
slot: blockSlot,
|
|
1184
|
+
proposerIndex,
|
|
1185
|
+
});
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
const headers = this.seenBlockProposers.getEquivocationHeaders(blockSlot, proposerIndex);
|
|
1190
|
+
if (headers === null) {
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
this.producingProposerSlashing.add(proposerIndex);
|
|
1195
|
+
try {
|
|
1196
|
+
const [header1, header2] = headers;
|
|
1197
|
+
// ProposerSlashing uses the bigint variant of the signed block header, see types package for details
|
|
1198
|
+
const proposerSlashing: phase0.ProposerSlashing = {
|
|
1199
|
+
signedHeader1: {
|
|
1200
|
+
message: {...header1.message, slot: BigInt(header1.message.slot)},
|
|
1201
|
+
signature: header1.signature,
|
|
1202
|
+
},
|
|
1203
|
+
signedHeader2: {
|
|
1204
|
+
message: {...header2.message, slot: BigInt(header2.message.slot)},
|
|
1205
|
+
signature: header2.signature,
|
|
1206
|
+
},
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
try {
|
|
1210
|
+
await validateApiProposerSlashing(this, proposerSlashing);
|
|
1211
|
+
} catch (e) {
|
|
1212
|
+
this.logger.debug("Produced proposer slashing is not valid", {slot: blockSlot, proposerIndex}, e as Error);
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
this.opPool.insertProposerSlashing(proposerSlashing);
|
|
1217
|
+
this.emitter.emit(routes.events.EventType.proposerSlashing, proposerSlashing);
|
|
1218
|
+
this.emitter.emit(ChainEvent.publishProposerSlashing, proposerSlashing);
|
|
1219
|
+
this.metrics?.opPool.proposerSlashingsProduced.inc();
|
|
1220
|
+
this.logger.info("Produced proposer slashing from observed equivocation", {slot: blockSlot, proposerIndex});
|
|
1221
|
+
} finally {
|
|
1222
|
+
this.producingProposerSlashing.delete(proposerIndex);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1166
1226
|
getStatus(): Status {
|
|
1167
1227
|
const head = this.forkChoice.getHead();
|
|
1168
1228
|
const finalizedCheckpoint = this.forkChoice.getFinalizedCheckpoint();
|
package/src/chain/emitter.ts
CHANGED
|
@@ -50,6 +50,11 @@ export enum ChainEvent {
|
|
|
50
50
|
* and are ready to be published.
|
|
51
51
|
*/
|
|
52
52
|
publishBlobSidecars = "publishBlobSidecars",
|
|
53
|
+
/**
|
|
54
|
+
* This event signals that a proposer slashing has been produced from an observed equivocation
|
|
55
|
+
* and is ready to be published.
|
|
56
|
+
*/
|
|
57
|
+
publishProposerSlashing = "publishProposerSlashing",
|
|
53
58
|
/**
|
|
54
59
|
* Trigger an update of status so reqresp by peers have current earliestAvailableSlot
|
|
55
60
|
*/
|
|
@@ -110,6 +115,8 @@ export type IChainEvents = ApiEvents & {
|
|
|
110
115
|
|
|
111
116
|
[ChainEvent.publishBlobSidecars]: (sidecars: deneb.BlobSidecar[]) => void;
|
|
112
117
|
|
|
118
|
+
[ChainEvent.publishProposerSlashing]: (proposerSlashing: phase0.ProposerSlashing) => void;
|
|
119
|
+
|
|
113
120
|
[ChainEvent.updateStatus]: () => void;
|
|
114
121
|
|
|
115
122
|
// Sync events that are chain->chain. Initiated from network requests but do not cross the network
|
package/src/chain/interface.ts
CHANGED
|
@@ -262,6 +262,9 @@ export interface IBeaconChain {
|
|
|
262
262
|
/** Process execution payload envelope: verify, import to fork choice, and persist to DB */
|
|
263
263
|
processExecutionPayload(payloadInput: PayloadEnvelopeInput, opts?: ImportPayloadOpts): Promise<void>;
|
|
264
264
|
|
|
265
|
+
/** Produce and publish a proposer slashing from an observed equivocation. Does not throw, only logs errors */
|
|
266
|
+
processProposerEquivocation(blockSlot: Slot, proposerIndex: ValidatorIndex): void;
|
|
267
|
+
|
|
265
268
|
getStatus(): Status;
|
|
266
269
|
|
|
267
270
|
recomputeForkChoiceHead(caller: ForkchoiceCaller): ProtoBlock;
|
package/src/chain/options.ts
CHANGED
|
@@ -37,6 +37,8 @@ export type IChainOptions = BlockProcessOpts &
|
|
|
37
37
|
suggestedFeeRecipient: string;
|
|
38
38
|
graffitiAppend?: boolean;
|
|
39
39
|
maxSkipSlots?: number;
|
|
40
|
+
/** Do not produce proposer slashings from observed equivocations and do not include proposer slashings in produced blocks */
|
|
41
|
+
disableProposerSlashings?: boolean;
|
|
40
42
|
/** Ensure blobs returned by the execution engine are valid */
|
|
41
43
|
sanityCheckExecutionEngineBlobs?: boolean;
|
|
42
44
|
/** Max number of produced blobs by local validators to cache */
|
|
@@ -122,6 +124,7 @@ export const defaultChainOptions: IChainOptions = {
|
|
|
122
124
|
// for gossip block validation, it's unlikely we see a reorg with 32 slots
|
|
123
125
|
// for attestation validation, having this value ensures we don't have to regen states most of the time
|
|
124
126
|
maxSkipSlots: 32,
|
|
127
|
+
disableProposerSlashings: false,
|
|
125
128
|
broadcastValidationStrictness: "warn",
|
|
126
129
|
// should be less than or equal to MIN_SIGNATURE_SETS_TO_BATCH_VERIFY
|
|
127
130
|
// batching too much may block the I/O thread so if useWorker=false, suggest this value to be 32
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {routes} from "@lodestar/api";
|
|
2
2
|
import {ChainForkConfig} from "@lodestar/config";
|
|
3
|
-
import {getSafeExecutionBlockHash} from "@lodestar/fork-choice";
|
|
3
|
+
import {getFinalizedExecutionBlockHash, getSafeExecutionBlockHash} from "@lodestar/fork-choice";
|
|
4
4
|
import {
|
|
5
5
|
ForkPostBellatrix,
|
|
6
6
|
ForkSeq,
|
|
@@ -10,17 +10,20 @@ import {
|
|
|
10
10
|
isForkPostGloas,
|
|
11
11
|
} from "@lodestar/params";
|
|
12
12
|
import {
|
|
13
|
+
GLOAS_PREVERIFY_WINDOW_EPOCHS,
|
|
13
14
|
IBeaconStateView,
|
|
14
15
|
IBeaconStateViewBellatrix,
|
|
16
|
+
MAX_BUILDER_DEPOSITS_PER_SLOT,
|
|
15
17
|
StateHashTreeRootSource,
|
|
16
18
|
computeEpochAtSlot,
|
|
17
19
|
computeTimeAtSlot,
|
|
18
20
|
isStatePostBellatrix,
|
|
21
|
+
isStatePostFulu,
|
|
19
22
|
isStatePostGloas,
|
|
20
23
|
} from "@lodestar/state-transition";
|
|
21
24
|
import {Bytes32, Slot, ValidatorIndex} from "@lodestar/types";
|
|
22
25
|
import {Logger, fromHex, isErrorAborted, sleep} from "@lodestar/utils";
|
|
23
|
-
import {GENESIS_SLOT
|
|
26
|
+
import {GENESIS_SLOT} from "../constants/constants.js";
|
|
24
27
|
import {BuilderStatus} from "../execution/builder/http.js";
|
|
25
28
|
import {Metrics} from "../metrics/index.js";
|
|
26
29
|
import {ClockEvent} from "../util/clock.js";
|
|
@@ -37,6 +40,11 @@ export const PREPARE_NEXT_SLOT_BPS = 6667;
|
|
|
37
40
|
/* We don't want to do more epoch transition than this */
|
|
38
41
|
const PREPARE_EPOCH_LIMIT = 1;
|
|
39
42
|
|
|
43
|
+
/* Fraction of a slot (out of 10_000) the pre-Gloas builder-deposit pre-verify may spend per tick.
|
|
44
|
+
* 2000 = 20% of slot (2.4s on mainnet), within the spare window left after PREPARE_NEXT_SLOT_BPS.
|
|
45
|
+
* Expressed in bps so it scales with slot duration (mainnet vs minimal/devnet). */
|
|
46
|
+
const BUILDER_PREVERIFY_LIMIT_BPS = 2000;
|
|
47
|
+
|
|
40
48
|
/**
|
|
41
49
|
* At Bellatrix, if we are responsible for proposing in next slot, we want to prepare payload
|
|
42
50
|
* 4s before the start of next slot at PREPARE_NEXT_SLOT_BPS of the current slot.
|
|
@@ -117,6 +125,7 @@ export class PrepareNextSlotScheduler {
|
|
|
117
125
|
? this.metrics?.precomputeNextEpochTransition.duration.startTimer()
|
|
118
126
|
: null;
|
|
119
127
|
const start = Date.now();
|
|
128
|
+
let feeRecipient: string | undefined;
|
|
120
129
|
// No need to wait for this or the clock drift
|
|
121
130
|
if (isForkPostBellatrix(fork)) {
|
|
122
131
|
let preparedState: IBeaconStateView | undefined;
|
|
@@ -140,7 +149,7 @@ export class PrepareNextSlotScheduler {
|
|
|
140
149
|
};
|
|
141
150
|
|
|
142
151
|
const proposerIndex = await getProposerIndex();
|
|
143
|
-
|
|
152
|
+
feeRecipient = this.chain.beaconProposerCache.get(proposerIndex);
|
|
144
153
|
|
|
145
154
|
if (feeRecipient) {
|
|
146
155
|
// If we are proposing next slot, we need to predict if we can proposer-boost-reorg or not
|
|
@@ -214,9 +223,8 @@ export class PrepareNextSlotScheduler {
|
|
|
214
223
|
computeTimeAtSlot(this.config, prepareSlot, this.chain.genesisTime) - Date.now() / 1000;
|
|
215
224
|
this.metrics?.blockPayload.payloadAdvancePrepTime.observe(preparationTime);
|
|
216
225
|
|
|
217
|
-
const safeBlockHash = getSafeExecutionBlockHash(this.chain.forkChoice);
|
|
218
|
-
const finalizedBlockHash =
|
|
219
|
-
this.chain.forkChoice.getFinalizedBlock().executionPayloadBlockHash ?? ZERO_HASH_HEX;
|
|
226
|
+
const safeBlockHash = getSafeExecutionBlockHash(this.chain.forkChoice, this.logger);
|
|
227
|
+
const finalizedBlockHash = getFinalizedExecutionBlockHash(this.chain.forkChoice, this.logger);
|
|
220
228
|
|
|
221
229
|
// awaiting here instead of throwing an async call because there is no other task
|
|
222
230
|
// left for scheduler and this gives nice semantics to catch and log errors in the
|
|
@@ -287,6 +295,74 @@ export class PrepareNextSlotScheduler {
|
|
|
287
295
|
});
|
|
288
296
|
|
|
289
297
|
precomputeEpochTransitionTimer?.();
|
|
298
|
+
|
|
299
|
+
// Nothing more to do on an epoch-transition slot: that precompute already ran a full (>1s)
|
|
300
|
+
// epoch transition, so we don't pile the builder-deposit pre-verify (below) on top of it.
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Pre-verify builder-deposit signatures in the GLOAS_PREVERIFY_WINDOW_EPOCHS epochs leading
|
|
305
|
+
// up to the Gloas fork, off the block-import hot path, so onboardBuildersFromPendingDeposits
|
|
306
|
+
// at the transition is mostly cache hits. Reached only on non-epoch-transition slots (the
|
|
307
|
+
// epoch-transition branch returned above). Runs on the head state — its pendingDeposits are
|
|
308
|
+
// what the fork transition derives from, and its epochCtx holds the shared, app-wide
|
|
309
|
+
// builderDepositSignatureCache.
|
|
310
|
+
const headState = this.chain.getHeadState();
|
|
311
|
+
if (isStatePostFulu(headState)) {
|
|
312
|
+
const gloasEpoch = this.config.GLOAS_FORK_EPOCH;
|
|
313
|
+
const finalizedEpoch = this.chain.forkChoice.getFinalizedCheckpoint().epoch;
|
|
314
|
+
if (finalizedEpoch >= gloasEpoch) {
|
|
315
|
+
// Gloas is finalized — the pre-verify cache has served its purpose; release its memory.
|
|
316
|
+
headState.clearPreGloasBuilderDepositCache();
|
|
317
|
+
} else {
|
|
318
|
+
const clockEpoch = computeEpochAtSlot(clockSlot);
|
|
319
|
+
if (
|
|
320
|
+
ForkSeq[fork] < ForkSeq.gloas && // only before the fork
|
|
321
|
+
clockEpoch >= gloasEpoch - GLOAS_PREVERIFY_WINDOW_EPOCHS && // Infinity when Gloas unscheduled → skip
|
|
322
|
+
clockEpoch < gloasEpoch &&
|
|
323
|
+
// skip when we're the next-slot proposer — don't compete with block-production prep.
|
|
324
|
+
feeRecipient === undefined
|
|
325
|
+
) {
|
|
326
|
+
const maxDurationMs = this.config.getSlotComponentDurationMs(BUILDER_PREVERIFY_LIMIT_BPS);
|
|
327
|
+
const preVerifyTimer = this.metrics?.builderDepositPreVerify.duration.startTimer();
|
|
328
|
+
const result = headState.preVerifyBuilderDepositsPreGloas(MAX_BUILDER_DEPOSITS_PER_SLOT, maxDurationMs);
|
|
329
|
+
preVerifyTimer?.();
|
|
330
|
+
|
|
331
|
+
const preVerifyMetrics = this.metrics?.builderDepositPreVerify;
|
|
332
|
+
if (preVerifyMetrics) {
|
|
333
|
+
preVerifyMetrics.pendingDeposits.set(result.pendingDepositsCount);
|
|
334
|
+
preVerifyMetrics.cachedDeposits.set(result.totalCachedDeposits);
|
|
335
|
+
preVerifyMetrics.scannedDeposits.set(result.scannedPendingDeposits);
|
|
336
|
+
preVerifyMetrics.builderPubkeys.set(result.totalBuilderPubkeys);
|
|
337
|
+
if (result.validBuilderSignaturesCount > 0) {
|
|
338
|
+
preVerifyMetrics.validSignatures.inc({type: "builder"}, result.validBuilderSignaturesCount);
|
|
339
|
+
}
|
|
340
|
+
if (result.validValidatorSignaturesCount > 0) {
|
|
341
|
+
preVerifyMetrics.validSignatures.inc({type: "validator"}, result.validValidatorSignaturesCount);
|
|
342
|
+
}
|
|
343
|
+
if (result.invalidBuilderSignaturesCount > 0) {
|
|
344
|
+
preVerifyMetrics.invalidSignatures.inc({type: "builder"}, result.invalidBuilderSignaturesCount);
|
|
345
|
+
}
|
|
346
|
+
if (result.invalidValidatorSignaturesCount > 0) {
|
|
347
|
+
preVerifyMetrics.invalidSignatures.inc({type: "validator"}, result.invalidValidatorSignaturesCount);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Always log (once per slot, only within the pre-fork window) so devnets show the
|
|
352
|
+
// pre-verify draining even on all-cache-hit ticks.
|
|
353
|
+
this.logger.verbose("PrepareNextSlotScheduler pre-verified deposit signatures", {
|
|
354
|
+
clockSlot,
|
|
355
|
+
validBuilderSignaturesCount: result.validBuilderSignaturesCount,
|
|
356
|
+
invalidBuilderSignaturesCount: result.invalidBuilderSignaturesCount,
|
|
357
|
+
validValidatorSignaturesCount: result.validValidatorSignaturesCount,
|
|
358
|
+
invalidValidatorSignaturesCount: result.invalidValidatorSignaturesCount,
|
|
359
|
+
scannedPendingDeposits: result.scannedPendingDeposits,
|
|
360
|
+
totalCachedDeposits: result.totalCachedDeposits,
|
|
361
|
+
totalBuilderPubkeys: result.totalBuilderPubkeys,
|
|
362
|
+
pendingDepositsCount: result.pendingDepositsCount,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
290
366
|
}
|
|
291
367
|
} catch (e) {
|
|
292
368
|
if (!isErrorAborted(e) && !isQueueErrorAborted(e)) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import {BitArray} from "@chainsafe/ssz";
|
|
2
2
|
import {ChainForkConfig} from "@lodestar/config";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
IForkChoice,
|
|
5
|
+
ProtoBlock,
|
|
6
|
+
getFinalizedExecutionBlockHash,
|
|
7
|
+
getSafeExecutionBlockHash,
|
|
8
|
+
} from "@lodestar/fork-choice";
|
|
4
9
|
import {
|
|
5
10
|
BUILDER_INDEX_SELF_BUILD,
|
|
6
11
|
ForkName,
|
|
@@ -265,8 +270,8 @@ export async function produceBlockBody<T extends BlockType>(
|
|
|
265
270
|
// TODO GLOAS: support non self-building here, the block type differentiation between
|
|
266
271
|
// full and blinded no longer makes sense in gloas, it might be a good idea to move
|
|
267
272
|
// this into a completely separate function and have pre/post gloas more separated
|
|
268
|
-
const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice);
|
|
269
|
-
const finalizedBlockHash = this.forkChoice.
|
|
273
|
+
const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
|
|
274
|
+
const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
|
|
270
275
|
// TODO GLOAS: post-Gloas, proposer feeRecipient is also carried (signed) in
|
|
271
276
|
// ProposerPreferencesPool. Consider using this unified cache instead
|
|
272
277
|
// see https://github.com/ChainSafe/lodestar/issues/9379
|
|
@@ -411,8 +416,8 @@ export async function produceBlockBody<T extends BlockType>(
|
|
|
411
416
|
throw new Error("Expected Bellatrix state for execution block production");
|
|
412
417
|
}
|
|
413
418
|
|
|
414
|
-
const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice);
|
|
415
|
-
const finalizedBlockHash = this.forkChoice.
|
|
419
|
+
const safeBlockHash = getSafeExecutionBlockHash(this.forkChoice, this.logger);
|
|
420
|
+
const finalizedBlockHash = getFinalizedExecutionBlockHash(this.forkChoice, this.logger);
|
|
416
421
|
const feeRecipient = requestedFeeRecipient ?? this.beaconProposerCache.getOrDefault(proposerIndex);
|
|
417
422
|
const feeRecipientType = requestedFeeRecipient
|
|
418
423
|
? "requested"
|
|
@@ -1037,7 +1042,7 @@ export async function produceCommonBlockBody<T extends BlockType>(
|
|
|
1037
1042
|
graffiti,
|
|
1038
1043
|
// Eth1 data voting is no longer required since electra
|
|
1039
1044
|
eth1Data: currentState.eth1Data,
|
|
1040
|
-
proposerSlashings,
|
|
1045
|
+
proposerSlashings: this.opts.disableProposerSlashings === true ? [] : proposerSlashings,
|
|
1041
1046
|
attesterSlashings,
|
|
1042
1047
|
attestations,
|
|
1043
1048
|
// Since electra, deposits are processed by the execution layer,
|
|
@@ -1,21 +1,83 @@
|
|
|
1
1
|
import {computeStartSlotAtEpoch} from "@lodestar/state-transition";
|
|
2
|
-
import {Epoch, Slot, ValidatorIndex} from "@lodestar/types";
|
|
2
|
+
import {Epoch, RootHex, Slot, ValidatorIndex, phase0} 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
|
-
*
|
|
9
|
-
*
|
|
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 signed block header of each observed root is kept so a proposer slashing can be produced from the two
|
|
17
|
+
* conflicting headers once an equivocation is established.
|
|
18
|
+
*
|
|
19
|
+
* The cache is pruned on finalization and bounds the number of roots stored per proposer and slot
|
|
10
20
|
*/
|
|
11
21
|
export class SeenBlockProposers {
|
|
12
22
|
private readonly proposerIndexesBySlot = new MapDef<Slot, Set<ValidatorIndex>>(() => new Set<ValidatorIndex>());
|
|
13
|
-
private
|
|
23
|
+
private readonly signedBlockHeadersBySlot = new MapDef<
|
|
24
|
+
Slot,
|
|
25
|
+
MapDef<ValidatorIndex, Map<RootHex, phase0.SignedBeaconBlockHeader>>
|
|
26
|
+
>(() => new MapDef<ValidatorIndex, Map<RootHex, phase0.SignedBeaconBlockHeader>>(() => new Map()));
|
|
27
|
+
private finalizedSlot: Slot = 0;
|
|
14
28
|
|
|
15
29
|
isKnown(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
16
30
|
return this.proposerIndexesBySlot.get(blockSlot)?.has(proposerIndex) === true;
|
|
17
31
|
}
|
|
18
32
|
|
|
33
|
+
hasBlockRoot(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): boolean {
|
|
34
|
+
return this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.has(blockRoot) === true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
isEquivocating(blockSlot: Slot, proposerIndex: ValidatorIndex): boolean {
|
|
38
|
+
return (
|
|
39
|
+
(this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex)?.size ?? 0) >= MAX_BLOCK_ROOTS_PER_PROPOSAL
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getConflictingBlockRoots(blockSlot: Slot, proposerIndex: ValidatorIndex, blockRoot: RootHex): RootHex[] {
|
|
44
|
+
const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex);
|
|
45
|
+
return signedBlockHeaderByRoot === undefined
|
|
46
|
+
? []
|
|
47
|
+
: Array.from(signedBlockHeaderByRoot.keys()).filter((root) => root !== blockRoot);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Return the two signed block headers that establish an equivocation, or null if there is none */
|
|
51
|
+
getEquivocationHeaders(
|
|
52
|
+
blockSlot: Slot,
|
|
53
|
+
proposerIndex: ValidatorIndex
|
|
54
|
+
): [phase0.SignedBeaconBlockHeader, phase0.SignedBeaconBlockHeader] | null {
|
|
55
|
+
const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.get(blockSlot)?.get(proposerIndex);
|
|
56
|
+
if (signedBlockHeaderByRoot === undefined || signedBlockHeaderByRoot.size < MAX_BLOCK_ROOTS_PER_PROPOSAL) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const [signedHeader1, signedHeader2] = signedBlockHeaderByRoot.values();
|
|
60
|
+
return [signedHeader1, signedHeader2];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Record a block only after its proposer signature has been verified */
|
|
64
|
+
observeBlockRoot(
|
|
65
|
+
blockSlot: Slot,
|
|
66
|
+
proposerIndex: ValidatorIndex,
|
|
67
|
+
blockRoot: RootHex,
|
|
68
|
+
signedBlockHeader: phase0.SignedBeaconBlockHeader
|
|
69
|
+
): void {
|
|
70
|
+
if (blockSlot < this.finalizedSlot) {
|
|
71
|
+
throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const signedBlockHeaderByRoot = this.signedBlockHeadersBySlot.getOrDefault(blockSlot).getOrDefault(proposerIndex);
|
|
75
|
+
if (signedBlockHeaderByRoot.size < MAX_BLOCK_ROOTS_PER_PROPOSAL && !signedBlockHeaderByRoot.has(blockRoot)) {
|
|
76
|
+
signedBlockHeaderByRoot.set(blockRoot, signedBlockHeader);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Mark a block as known from gossip or another block import path */
|
|
19
81
|
add(blockSlot: Slot, proposerIndex: ValidatorIndex): void {
|
|
20
82
|
if (blockSlot < this.finalizedSlot) {
|
|
21
83
|
throw Error(`blockSlot ${blockSlot} < finalizedSlot ${this.finalizedSlot}`);
|
|
@@ -31,9 +93,14 @@ export class SeenBlockProposers {
|
|
|
31
93
|
this.proposerIndexesBySlot.delete(slot);
|
|
32
94
|
}
|
|
33
95
|
}
|
|
96
|
+
for (const slot of this.signedBlockHeadersBySlot.keys()) {
|
|
97
|
+
if (slot < finalizedSlot) {
|
|
98
|
+
this.signedBlockHeadersBySlot.delete(slot);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
34
101
|
}
|
|
35
102
|
|
|
36
|
-
seenAtEpoch(epoch:
|
|
103
|
+
seenAtEpoch(epoch: Epoch, index: ValidatorIndex): boolean {
|
|
37
104
|
const fromSlot = computeStartSlotAtEpoch(epoch);
|
|
38
105
|
const toSlot = computeStartSlotAtEpoch(epoch + 1);
|
|
39
106
|
|
|
@@ -23,8 +23,9 @@ import {
|
|
|
23
23
|
getBlockProposerSignatureSet,
|
|
24
24
|
isExecutionBlockBodyType,
|
|
25
25
|
isStatePostBellatrix,
|
|
26
|
+
signedBlockToSignedHeader,
|
|
26
27
|
} from "@lodestar/state-transition";
|
|
27
|
-
import {SignedBeaconBlock, deneb, gloas, isGloasBeaconBlock} from "@lodestar/types";
|
|
28
|
+
import {RootHex, SignedBeaconBlock, deneb, gloas, isGloasBeaconBlock, ssz} from "@lodestar/types";
|
|
28
29
|
import {byteArrayEquals, sleep, toRootHex} from "@lodestar/utils";
|
|
29
30
|
import {BlockErrorCode, BlockGossipError, GossipAction} from "../errors/index.js";
|
|
30
31
|
import {IBeaconChain} from "../interface.js";
|
|
@@ -75,7 +76,10 @@ export async function validateGossipBlock(
|
|
|
75
76
|
// reboot if the `observed_block_producers` cache is empty. In that case, without this
|
|
76
77
|
// check, we will load the parent and state from disk only to find out later that we
|
|
77
78
|
// already know this block.
|
|
78
|
-
|
|
79
|
+
// A block's hash tree root is identical to its header's, so the root is derived from the header
|
|
80
|
+
// which is also used as potential equivocation evidence
|
|
81
|
+
const signedBlockHeader = signedBlockToSignedHeader(config, signedBlock);
|
|
82
|
+
const blockRoot = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(signedBlockHeader.message));
|
|
79
83
|
if (chain.forkChoice.getBlockHexDefaultStatus(blockRoot) !== null) {
|
|
80
84
|
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.ALREADY_KNOWN, root: blockRoot});
|
|
81
85
|
}
|
|
@@ -85,7 +89,12 @@ export async function validateGossipBlock(
|
|
|
85
89
|
|
|
86
90
|
// [IGNORE] The block is the first block with valid signature received for the proposer for the slot, signed_beacon_block.message.slot.
|
|
87
91
|
const proposerIndex = block.proposerIndex;
|
|
92
|
+
const hasBlockRoot = chain.seenBlockProposers.hasBlockRoot(blockSlot, proposerIndex, blockRoot);
|
|
88
93
|
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
|
|
94
|
+
if (!hasBlockRoot && !chain.seenBlockProposers.isEquivocating(blockSlot, proposerIndex)) {
|
|
95
|
+
await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
|
|
96
|
+
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
|
|
97
|
+
}
|
|
89
98
|
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
|
|
90
99
|
}
|
|
91
100
|
|
|
@@ -270,18 +279,8 @@ export async function validateGossipBlock(
|
|
|
270
279
|
}
|
|
271
280
|
|
|
272
281
|
// [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
|
|
273
|
-
|
|
274
|
-
|
|
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
|
-
}
|
|
282
|
+
await verifyBlockProposerSignature(chain, signedBlock, blockRoot);
|
|
283
|
+
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
|
|
285
284
|
|
|
286
285
|
// [REJECT] The block is proposed by the expected proposer_index for the block's slot in the context of the current
|
|
287
286
|
// shuffling (defined by parent_root/slot). If the proposer_index cannot immediately be verified against the expected
|
|
@@ -291,11 +290,6 @@ export async function validateGossipBlock(
|
|
|
291
290
|
throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.INCORRECT_PROPOSER, proposerIndex});
|
|
292
291
|
}
|
|
293
292
|
|
|
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
293
|
// Simple implementation of a pending block queue. Keeping the block here recycles the queue logic, and keeps the
|
|
300
294
|
// gossip validation promise without any extra infrastructure.
|
|
301
295
|
// Do the sleep at the end, since regen and signature validation can already take longer than `msToBlockSlot`.
|
|
@@ -305,7 +299,35 @@ export async function validateGossipBlock(
|
|
|
305
299
|
await sleep(msToBlockSlot);
|
|
306
300
|
}
|
|
307
301
|
|
|
302
|
+
// Check again after all async validation and the early-block delay so concurrent proposals cannot both pass
|
|
303
|
+
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
|
|
304
|
+
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
|
|
305
|
+
}
|
|
306
|
+
|
|
308
307
|
chain.seenBlockProposers.add(blockSlot, proposerIndex);
|
|
309
308
|
|
|
310
309
|
return {skippedSlots};
|
|
311
310
|
}
|
|
311
|
+
|
|
312
|
+
export async function verifyBlockProposerSignature(
|
|
313
|
+
chain: IBeaconChain,
|
|
314
|
+
signedBlock: SignedBeaconBlock,
|
|
315
|
+
blockRoot: RootHex,
|
|
316
|
+
opts: {verifyOnMainThread?: boolean} = {}
|
|
317
|
+
): Promise<void> {
|
|
318
|
+
const blockSlot = signedBlock.message.slot;
|
|
319
|
+
if (chain.seenBlockInputCache.isVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature)) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const signatureSet = getBlockProposerSignatureSet(chain.config, signedBlock);
|
|
324
|
+
// Don't batch so verification is not delayed
|
|
325
|
+
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: opts.verifyOnMainThread ?? true}))) {
|
|
326
|
+
throw new BlockGossipError(GossipAction.REJECT, {
|
|
327
|
+
code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
328
|
+
blockSlot,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
chain.seenBlockInputCache.markVerifiedProposerSignature(blockSlot, blockRoot, signedBlock.signature);
|
|
333
|
+
}
|
|
@@ -1179,6 +1179,10 @@ export function createLodestarMetrics(
|
|
|
1179
1179
|
name: "lodestar_oppool_proposer_slashing_pool_size",
|
|
1180
1180
|
help: "Current size of the ProposerSlashingPool",
|
|
1181
1181
|
}),
|
|
1182
|
+
proposerSlashingsProduced: register.counter({
|
|
1183
|
+
name: "lodestar_oppool_proposer_slashings_produced_total",
|
|
1184
|
+
help: "Total number of proposer slashings produced from observed equivocations",
|
|
1185
|
+
}),
|
|
1182
1186
|
voluntaryExitPoolSize: register.gauge({
|
|
1183
1187
|
name: "lodestar_oppool_voluntary_exit_pool_size",
|
|
1184
1188
|
help: "Current size of the VoluntaryExitPool",
|
|
@@ -1708,6 +1712,41 @@ export function createLodestarMetrics(
|
|
|
1708
1712
|
}),
|
|
1709
1713
|
},
|
|
1710
1714
|
|
|
1715
|
+
// Pre-verify builder-deposit signatures in the epochs before the Gloas fork (prepareNextSlot).
|
|
1716
|
+
builderDepositPreVerify: {
|
|
1717
|
+
duration: register.histogram({
|
|
1718
|
+
name: "lodestar_builder_deposit_preverify_duration_seconds",
|
|
1719
|
+
help: "Duration of one preVerifyBuilderDepositsPreGloas call (BLS batch verify + scan)",
|
|
1720
|
+
buckets: [1, 2, 3, 4],
|
|
1721
|
+
}),
|
|
1722
|
+
pendingDeposits: register.gauge({
|
|
1723
|
+
name: "lodestar_builder_deposit_preverify_pending_deposits",
|
|
1724
|
+
help: "Current state.pendingDeposits length (backlog to drain before the fork)",
|
|
1725
|
+
}),
|
|
1726
|
+
cachedDeposits: register.gauge({
|
|
1727
|
+
name: "lodestar_builder_deposit_preverify_cached_deposits",
|
|
1728
|
+
help: "Deposit signatures verified & cached so far this pre-fork window (valid + invalid)",
|
|
1729
|
+
}),
|
|
1730
|
+
scannedDeposits: register.gauge({
|
|
1731
|
+
name: "lodestar_builder_deposit_preverify_scanned_deposits",
|
|
1732
|
+
help: "Pending deposits examined by the last pre-verify call (< pending_deposits ⇒ cap hit)",
|
|
1733
|
+
}),
|
|
1734
|
+
builderPubkeys: register.gauge({
|
|
1735
|
+
name: "lodestar_builder_deposit_preverify_builder_pubkeys",
|
|
1736
|
+
help: "Distinct builder pubkeys tracked this window (validator deposits for these are pre-verified)",
|
|
1737
|
+
}),
|
|
1738
|
+
validSignatures: register.counter<{type: "builder" | "validator"}>({
|
|
1739
|
+
name: "lodestar_builder_deposit_preverify_valid_signatures_total",
|
|
1740
|
+
help: "Cumulative deposit signatures whose BLS verification passed (VALID), by credential type",
|
|
1741
|
+
labelNames: ["type"],
|
|
1742
|
+
}),
|
|
1743
|
+
invalidSignatures: register.counter<{type: "builder" | "validator"}>({
|
|
1744
|
+
name: "lodestar_builder_deposit_preverify_invalid_signatures_total",
|
|
1745
|
+
help: "Cumulative deposit signatures whose BLS verification failed (INVALID), by credential type",
|
|
1746
|
+
labelNames: ["type"],
|
|
1747
|
+
}),
|
|
1748
|
+
},
|
|
1749
|
+
|
|
1711
1750
|
// reprocess attestations
|
|
1712
1751
|
reprocessApiAttestations: {
|
|
1713
1752
|
total: register.gauge({
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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> {
|