@lodestar/beacon-node 1.52.0-dev.8068b97a3f → 1.52.0-dev.82017afb22
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/chain/errors/executionPayloadEnvelope.d.ts +7 -0
- package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.js +1 -0
- package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/lightClient/index.d.ts +13 -6
- package/lib/chain/lightClient/index.d.ts.map +1 -1
- package/lib/chain/lightClient/index.js +95 -115
- package/lib/chain/lightClient/index.js.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.js +17 -0
- package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
- package/lib/execution/engine/blockHash.d.ts +12 -0
- package/lib/execution/engine/blockHash.d.ts.map +1 -0
- package/lib/execution/engine/blockHash.js +17 -0
- package/lib/execution/engine/blockHash.js.map +1 -0
- package/lib/execution/engine/http.d.ts +2 -2
- package/lib/execution/engine/http.d.ts.map +1 -1
- package/lib/execution/engine/http.js +13 -7
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/execution/engine/interface.d.ts +16 -3
- package/lib/execution/engine/interface.d.ts.map +1 -1
- package/lib/execution/engine/interface.js +11 -0
- package/lib/execution/engine/interface.js.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.d.ts +2 -0
- package/lib/execution/engine/jsonRpcHttpClient.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcHttpClient.js +14 -6
- package/lib/execution/engine/jsonRpcHttpClient.js.map +1 -1
- package/lib/execution/engine/jsonRpcTransport.d.ts +2 -2
- package/lib/execution/engine/jsonRpcTransport.d.ts.map +1 -1
- package/lib/execution/engine/jsonRpcTransport.js +4 -4
- package/lib/execution/engine/jsonRpcTransport.js.map +1 -1
- package/lib/execution/engine/mock.d.ts.map +1 -1
- package/lib/execution/engine/mock.js +6 -6
- package/lib/execution/engine/mock.js.map +1 -1
- package/lib/execution/engine/restHttpClient.d.ts.map +1 -1
- package/lib/execution/engine/restHttpClient.js +9 -5
- package/lib/execution/engine/restHttpClient.js.map +1 -1
- package/lib/execution/engine/restTransport.d.ts +2 -2
- package/lib/execution/engine/restTransport.d.ts.map +1 -1
- package/lib/execution/engine/restTransport.js +4 -4
- package/lib/execution/engine/restTransport.js.map +1 -1
- package/lib/execution/engine/signal.d.ts +6 -0
- package/lib/execution/engine/signal.d.ts.map +1 -0
- package/lib/execution/engine/signal.js +24 -0
- package/lib/execution/engine/signal.js.map +1 -0
- package/lib/execution/engine/transport.d.ts +2 -2
- package/lib/execution/engine/transport.d.ts.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +1 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +5 -0
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/network/gossip/gossipsub.d.ts +1 -0
- package/lib/network/gossip/gossipsub.d.ts.map +1 -1
- package/lib/network/gossip/gossipsub.js +3 -0
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/network.d.ts.map +1 -1
- package/lib/network/network.js +6 -1
- package/lib/network/network.js.map +1 -1
- package/lib/network/peers/peerManager.d.ts.map +1 -1
- package/lib/network/peers/peerManager.js +22 -2
- package/lib/network/peers/peerManager.js.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.d.ts +2 -0
- package/lib/network/peers/utils/prioritizePeers.d.ts.map +1 -1
- package/lib/network/peers/utils/prioritizePeers.js +11 -2
- package/lib/network/peers/utils/prioritizePeers.js.map +1 -1
- package/lib/sync/types.d.ts +2 -0
- package/lib/sync/types.d.ts.map +1 -1
- package/lib/sync/types.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +100 -19
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +5 -4
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/package.json +25 -25
- package/src/chain/errors/executionPayloadEnvelope.ts +8 -0
- package/src/chain/lightClient/index.ts +108 -142
- package/src/chain/validation/executionPayloadEnvelope.ts +24 -0
- package/src/execution/engine/blockHash.ts +27 -0
- package/src/execution/engine/http.ts +18 -10
- package/src/execution/engine/interface.ts +18 -3
- package/src/execution/engine/jsonRpcHttpClient.ts +26 -14
- package/src/execution/engine/jsonRpcTransport.ts +8 -4
- package/src/execution/engine/mock.ts +13 -8
- package/src/execution/engine/restHttpClient.ts +17 -11
- package/src/execution/engine/restTransport.ts +5 -4
- package/src/execution/engine/signal.ts +28 -0
- package/src/execution/engine/transport.ts +3 -2
- package/src/index.ts +6 -1
- package/src/metrics/metrics/lodestar.ts +5 -0
- package/src/network/gossip/gossipsub.ts +4 -0
- package/src/network/network.ts +6 -2
- package/src/network/peers/peerManager.ts +26 -2
- package/src/network/peers/utils/prioritizePeers.ts +14 -1
- package/src/sync/types.ts +2 -0
- package/src/sync/unknownBlock.ts +110 -21
- package/src/sync/utils/downloadByRoot.ts +7 -5
|
@@ -2,7 +2,7 @@ import {Logger} from "@lodestar/logger";
|
|
|
2
2
|
import {ForkName, ForkPostFulu, ForkSeq, SLOTS_PER_EPOCH, isForkPostBellatrix} from "@lodestar/params";
|
|
3
3
|
import {BlobsBundle, ExecutionPayload, ExecutionRequests, Root, RootHex, Wei, bellatrix} from "@lodestar/types";
|
|
4
4
|
import {BlobAndProofV2} from "@lodestar/types/fulu";
|
|
5
|
-
import {isErrorAborted} from "@lodestar/utils";
|
|
5
|
+
import {ErrorAborted, isErrorAborted} from "@lodestar/utils";
|
|
6
6
|
import {Metrics} from "../../metrics/index.js";
|
|
7
7
|
import {EPOCHS_PER_BATCH} from "../../sync/constants.js";
|
|
8
8
|
import {getLodestarClientVersion} from "../../util/metadata.js";
|
|
@@ -11,6 +11,8 @@ import {JobItemQueue} from "../../util/queue/index.js";
|
|
|
11
11
|
import {
|
|
12
12
|
ClientVersion,
|
|
13
13
|
ExecutePayloadResponse,
|
|
14
|
+
ExecutionEngineError,
|
|
15
|
+
ExecutionEngineErrorCode,
|
|
14
16
|
ExecutionEngineState,
|
|
15
17
|
ExecutionPayloadStatus,
|
|
16
18
|
ForkchoiceUpdatedResult,
|
|
@@ -334,13 +336,18 @@ export class ExecutionEngineHttp implements IExecutionEngine {
|
|
|
334
336
|
headBlockHash: RootHex,
|
|
335
337
|
safeBlockHash: RootHex,
|
|
336
338
|
finalizedBlockHash: RootHex,
|
|
337
|
-
payloadAttributes?: PayloadAttributes
|
|
339
|
+
payloadAttributes?: PayloadAttributes,
|
|
340
|
+
signal?: AbortSignal
|
|
338
341
|
): Promise<ForkchoiceUpdatedResult> {
|
|
339
|
-
const result = await this.enqueue(() =>
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
342
|
+
const result = await this.enqueue(() => {
|
|
343
|
+
// Aborted while waiting in the queue, do not select a transport and sign a request that is not sent
|
|
344
|
+
if (signal?.aborted) {
|
|
345
|
+
throw new ErrorAborted("notifyForkchoiceUpdate");
|
|
346
|
+
}
|
|
347
|
+
return this.withTransport(fork, undefined, (transport) =>
|
|
348
|
+
transport.forkchoiceUpdated(fork, headBlockHash, safeBlockHash, finalizedBlockHash, payloadAttributes, signal)
|
|
349
|
+
);
|
|
350
|
+
});
|
|
344
351
|
const {
|
|
345
352
|
payloadStatus: {status},
|
|
346
353
|
payloadId,
|
|
@@ -373,7 +380,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
|
|
|
373
380
|
case ExecutionPayloadStatus.SYNCING:
|
|
374
381
|
// Throw error on syncing if requested to produce a block, else silently ignore
|
|
375
382
|
if (payloadAttributes) {
|
|
376
|
-
throw
|
|
383
|
+
throw new ExecutionEngineError({code: ExecutionEngineErrorCode.SYNCING}, "Execution Layer Syncing");
|
|
377
384
|
}
|
|
378
385
|
return result;
|
|
379
386
|
|
|
@@ -394,7 +401,8 @@ export class ExecutionEngineHttp implements IExecutionEngine {
|
|
|
394
401
|
*/
|
|
395
402
|
async getPayload(
|
|
396
403
|
fork: ForkName,
|
|
397
|
-
payloadId: PayloadId
|
|
404
|
+
payloadId: PayloadId,
|
|
405
|
+
signal?: AbortSignal
|
|
398
406
|
): Promise<{
|
|
399
407
|
executionPayload: ExecutionPayload;
|
|
400
408
|
executionPayloadValue: Wei;
|
|
@@ -402,7 +410,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
|
|
|
402
410
|
executionRequests?: ExecutionRequests;
|
|
403
411
|
shouldOverrideBuilder?: boolean;
|
|
404
412
|
}> {
|
|
405
|
-
return this.withTransport(fork, undefined, (transport) => transport.getPayload(fork, payloadId));
|
|
413
|
+
return this.withTransport(fork, undefined, (transport) => transport.getPayload(fork, payloadId, signal));
|
|
406
414
|
}
|
|
407
415
|
|
|
408
416
|
async prunePayloadIdCache(): Promise<void> {
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
capella,
|
|
20
20
|
} from "@lodestar/types";
|
|
21
21
|
import {BlobAndProofV2} from "@lodestar/types/fulu";
|
|
22
|
+
import {LodestarError} from "@lodestar/utils";
|
|
22
23
|
import {PayloadId, PayloadIdCache, WithdrawalV1} from "./payloadIdCache.js";
|
|
23
24
|
import {ExecutionPayloadBodyV2} from "./types.js";
|
|
24
25
|
import {DATA} from "./utils.js";
|
|
@@ -131,6 +132,18 @@ export type PayloadAttributes = {
|
|
|
131
132
|
|
|
132
133
|
export type VersionedHashes = Uint8Array[];
|
|
133
134
|
|
|
135
|
+
export enum ExecutionEngineErrorCode {
|
|
136
|
+
/**
|
|
137
|
+
* `notifyForkchoiceUpdate` requested a payload while the execution client is syncing, the head block is not
|
|
138
|
+
* available to build on yet
|
|
139
|
+
*/
|
|
140
|
+
SYNCING = "EXECUTION_ENGINE_ERROR_SYNCING",
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type ExecutionEngineErrorType = {code: ExecutionEngineErrorCode.SYNCING};
|
|
144
|
+
|
|
145
|
+
export class ExecutionEngineError extends LodestarError<ExecutionEngineErrorType> {}
|
|
146
|
+
|
|
134
147
|
/**
|
|
135
148
|
* Execution engine represents an abstract protocol to interact with execution clients. Potential transports include:
|
|
136
149
|
* - JSON RPC over network
|
|
@@ -180,14 +193,15 @@ export interface IExecutionEngine {
|
|
|
180
193
|
* Should be called in response to fork-choice head and finalized events.
|
|
181
194
|
*
|
|
182
195
|
* An INVALID verdict is returned, not thrown: the caller feeds it back into fork choice together with the
|
|
183
|
-
* `latestValidHash`. Only SYNCING while building a payload is an error
|
|
196
|
+
* `latestValidHash`. Only SYNCING while building a payload is an error, thrown as `ExecutionEngineError` with code `SYNCING`.
|
|
184
197
|
*/
|
|
185
198
|
notifyForkchoiceUpdate(
|
|
186
199
|
fork: ForkName,
|
|
187
200
|
headBlockHash: RootHex,
|
|
188
201
|
safeBlockHash: RootHex,
|
|
189
202
|
finalizedBlockHash: RootHex,
|
|
190
|
-
payloadAttributes?: PayloadAttributes
|
|
203
|
+
payloadAttributes?: PayloadAttributes,
|
|
204
|
+
signal?: AbortSignal
|
|
191
205
|
): Promise<ForkchoiceUpdatedResult>;
|
|
192
206
|
|
|
193
207
|
/**
|
|
@@ -199,7 +213,8 @@ export interface IExecutionEngine {
|
|
|
199
213
|
*/
|
|
200
214
|
getPayload(
|
|
201
215
|
fork: ForkName,
|
|
202
|
-
payloadId: PayloadId
|
|
216
|
+
payloadId: PayloadId,
|
|
217
|
+
signal?: AbortSignal
|
|
203
218
|
): Promise<{
|
|
204
219
|
executionPayload: ExecutionPayload;
|
|
205
220
|
executionPayloadValue: Wei;
|
|
@@ -2,6 +2,7 @@ import {EventEmitter} from "node:events";
|
|
|
2
2
|
import {StrictEventEmitter} from "strict-event-emitter-types";
|
|
3
3
|
import {ErrorAborted, Gauge, Histogram, TimeoutError, fetch, isValidHttpUrl, retry} from "@lodestar/utils";
|
|
4
4
|
import {JwtClaim, encodeJwtToken} from "./jwt.js";
|
|
5
|
+
import {withRequestSignal} from "./signal.js";
|
|
5
6
|
import {EngineTransportMetrics} from "./transportMetrics.js";
|
|
6
7
|
import {IJson, RpcPayload} from "./utils.js";
|
|
7
8
|
|
|
@@ -54,6 +55,8 @@ export type ReqOpts = {
|
|
|
54
55
|
retries?: number;
|
|
55
56
|
retryDelay?: number;
|
|
56
57
|
shouldRetry?: (lastError: Error) => boolean;
|
|
58
|
+
/** Aborts this request only, in addition to the signal of the client */
|
|
59
|
+
signal?: AbortSignal;
|
|
57
60
|
};
|
|
58
61
|
|
|
59
62
|
export type JsonRpcHttpClientMetrics = EngineTransportMetrics & {
|
|
@@ -157,19 +160,23 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
|
|
|
157
160
|
return this.wrapWithEvents(async () => {
|
|
158
161
|
const routeId = opts?.routeId ?? "unknown";
|
|
159
162
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
retries: opts?.retries ?? this.opts?.retries ?? 0,
|
|
166
|
-
retryDelay: opts?.retryDelay ?? this.opts?.retryDelay,
|
|
167
|
-
shouldRetry: opts?.shouldRetry,
|
|
168
|
-
signal: this.opts?.signal,
|
|
169
|
-
onRetry: () => {
|
|
170
|
-
this.opts?.metrics?.retryCount.inc({routeId});
|
|
163
|
+
// The delay between retries has to end with the request signal as well
|
|
164
|
+
const res = await withRequestSignal(this.opts?.signal, opts?.signal, (signal) =>
|
|
165
|
+
retry<RpcResponse<R>>(
|
|
166
|
+
async (_attempt) => {
|
|
167
|
+
return this.fetchJson({jsonrpc: "2.0", id: this.id++, ...payload}, opts);
|
|
171
168
|
},
|
|
172
|
-
|
|
169
|
+
{
|
|
170
|
+
retries: opts?.retries ?? this.opts?.retries ?? 0,
|
|
171
|
+
retryDelay: opts?.retryDelay ?? this.opts?.retryDelay,
|
|
172
|
+
// An aborted request is no longer of interest to its caller
|
|
173
|
+
shouldRetry: (lastError) => !opts?.signal?.aborted && (opts?.shouldRetry?.(lastError) ?? true),
|
|
174
|
+
signal,
|
|
175
|
+
onRetry: () => {
|
|
176
|
+
this.opts?.metrics?.retryCount.inc({routeId});
|
|
177
|
+
},
|
|
178
|
+
}
|
|
179
|
+
)
|
|
173
180
|
);
|
|
174
181
|
return parseRpcResponse(res, payload);
|
|
175
182
|
}, payload);
|
|
@@ -244,6 +251,10 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
|
|
|
244
251
|
|
|
245
252
|
const onParentSignalAbort = (): void => controller.abort();
|
|
246
253
|
this.opts?.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
|
|
254
|
+
opts?.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
|
|
255
|
+
if (opts?.signal?.aborted) {
|
|
256
|
+
controller.abort();
|
|
257
|
+
}
|
|
247
258
|
|
|
248
259
|
// Default to "unknown" to prevent mixing metrics with others.
|
|
249
260
|
const routeId = opts?.routeId ?? "unknown";
|
|
@@ -306,8 +317,8 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
|
|
|
306
317
|
} catch (e) {
|
|
307
318
|
this.metrics?.requestErrors.inc({routeId});
|
|
308
319
|
if (controller.signal.aborted) {
|
|
309
|
-
// controller will abort on
|
|
310
|
-
if (this.opts?.signal?.aborted) {
|
|
320
|
+
// controller will abort on parent signal abort, request signal abort + timeout of this specific request
|
|
321
|
+
if (this.opts?.signal?.aborted || opts?.signal?.aborted) {
|
|
311
322
|
throw new ErrorAborted("request");
|
|
312
323
|
}
|
|
313
324
|
throw new TimeoutError("request");
|
|
@@ -319,6 +330,7 @@ export class JsonRpcHttpClient implements IJsonRpcHttpClient {
|
|
|
319
330
|
|
|
320
331
|
clearTimeout(timeout);
|
|
321
332
|
this.opts?.signal?.removeEventListener("abort", onParentSignalAbort);
|
|
333
|
+
opts?.signal?.removeEventListener("abort", onParentSignalAbort);
|
|
322
334
|
}
|
|
323
335
|
}
|
|
324
336
|
}
|
|
@@ -141,7 +141,8 @@ export class JsonRpcEngineTransport implements IEngineTransport {
|
|
|
141
141
|
headBlockHash: RootHex,
|
|
142
142
|
safeBlockHash: RootHex,
|
|
143
143
|
finalizedBlockHash: RootHex,
|
|
144
|
-
payloadAttributes?: PayloadAttributes
|
|
144
|
+
payloadAttributes?: PayloadAttributes,
|
|
145
|
+
signal?: AbortSignal
|
|
145
146
|
): Promise<ForkchoiceUpdatedResult> {
|
|
146
147
|
const method =
|
|
147
148
|
ForkSeq[fork] >= ForkSeq.heze
|
|
@@ -161,12 +162,15 @@ export class JsonRpcEngineTransport implements IEngineTransport {
|
|
|
161
162
|
const {payloadStatus, payloadId} = await this.rpc.fetchWithRetries<
|
|
162
163
|
EngineApiRpcReturnTypes[typeof method],
|
|
163
164
|
EngineApiRpcParamTypes[typeof method]
|
|
164
|
-
>(
|
|
165
|
+
>(
|
|
166
|
+
{method, params: [{headBlockHash, safeBlockHash, finalizedBlockHash}, payloadAttributesRpc]},
|
|
167
|
+
{...fcUReqOpts, signal}
|
|
168
|
+
);
|
|
165
169
|
|
|
166
170
|
return {payloadStatus, payloadId: payloadId && payloadId !== "0x" ? payloadId : null};
|
|
167
171
|
}
|
|
168
172
|
|
|
169
|
-
async getPayload(fork: ForkName, payloadId: PayloadId): Promise<GetPayloadResult> {
|
|
173
|
+
async getPayload(fork: ForkName, payloadId: PayloadId, signal?: AbortSignal): Promise<GetPayloadResult> {
|
|
170
174
|
let method: keyof EngineApiRpcReturnTypes;
|
|
171
175
|
switch (fork) {
|
|
172
176
|
case ForkName.phase0:
|
|
@@ -193,7 +197,7 @@ export class JsonRpcEngineTransport implements IEngineTransport {
|
|
|
193
197
|
const payloadResponse = await this.rpc.fetchWithRetries<
|
|
194
198
|
EngineApiRpcReturnTypes[typeof method],
|
|
195
199
|
EngineApiRpcParamTypes[typeof method]
|
|
196
|
-
>({method, params: [payloadId]}, getPayloadOpts);
|
|
200
|
+
>({method, params: [payloadId]}, {...getPayloadOpts, signal});
|
|
197
201
|
return parseExecutionPayload(fork, payloadResponse);
|
|
198
202
|
}
|
|
199
203
|
|
|
@@ -10,14 +10,16 @@ import {
|
|
|
10
10
|
ForkPostCapella,
|
|
11
11
|
ForkSeq,
|
|
12
12
|
SLOTS_PER_EPOCH,
|
|
13
|
+
isForkPostElectra,
|
|
13
14
|
} from "@lodestar/params";
|
|
14
15
|
import {computeTimeAtSlot} from "@lodestar/state-transition";
|
|
15
|
-
import {ExecutionPayload, RootHex, bellatrix, deneb, gloas, ssz} from "@lodestar/types";
|
|
16
|
+
import {ExecutionPayload, RootHex, bellatrix, deneb, gloas, ssz, sszTypesFor} from "@lodestar/types";
|
|
16
17
|
import {fromHex, toRootHex} from "@lodestar/utils";
|
|
17
18
|
import {ZERO_HASH_HEX} from "../../constants/index.js";
|
|
18
19
|
import {INTEROP_BLOCK_HASH} from "../../node/utils/interop/state.js";
|
|
19
20
|
import {kzgCommitmentToVersionedHash} from "../../util/blobs.js";
|
|
20
21
|
import {kzg} from "../../util/kzg.js";
|
|
22
|
+
import {computeExecutionBlockHash} from "./blockHash.js";
|
|
21
23
|
import {ClientCode, ExecutionPayloadStatus, PayloadIdCache} from "./interface.js";
|
|
22
24
|
import {
|
|
23
25
|
BlobsBundleRpc,
|
|
@@ -351,7 +353,6 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
|
|
|
351
353
|
executionPayload.gasLimit = INTEROP_GAS_LIMIT;
|
|
352
354
|
executionPayload.gasUsed = Math.floor(0.5 * INTEROP_GAS_LIMIT);
|
|
353
355
|
executionPayload.timestamp = payloadAttributes.timestamp;
|
|
354
|
-
executionPayload.blockHash = crypto.randomBytes(32);
|
|
355
356
|
const transactions: Uint8Array[] = [];
|
|
356
357
|
|
|
357
358
|
// Between 0 and 4 transactions for all forks
|
|
@@ -401,6 +402,15 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
|
|
|
401
402
|
(executionPayload as gloas.ExecutionPayload).slotNumber = payloadAttributes.slotNumber;
|
|
402
403
|
}
|
|
403
404
|
|
|
405
|
+
const executionRequests = isForkPostElectra(fork) ? sszTypesFor(fork).ExecutionRequests.defaultValue() : null;
|
|
406
|
+
|
|
407
|
+
executionPayload.blockHash = computeExecutionBlockHash(
|
|
408
|
+
fork,
|
|
409
|
+
executionPayload,
|
|
410
|
+
payloadAttributes.parentBeaconBlockRoot ?? null,
|
|
411
|
+
executionRequests
|
|
412
|
+
);
|
|
413
|
+
|
|
404
414
|
this.preparingPayloads.set(payloadId, {
|
|
405
415
|
executionPayload: serializeExecutionPayload(fork, executionPayload),
|
|
406
416
|
blobsBundle: serializeBlobsBundle({
|
|
@@ -408,12 +418,7 @@ export class ExecutionEngineMockBackend implements JsonRpcBackend {
|
|
|
408
418
|
blobs,
|
|
409
419
|
proofs,
|
|
410
420
|
}),
|
|
411
|
-
executionRequests: serializeExecutionRequests(
|
|
412
|
-
fork,
|
|
413
|
-
ForkSeq[fork] >= ForkSeq.gloas
|
|
414
|
-
? ssz.gloas.ExecutionRequests.defaultValue()
|
|
415
|
-
: ssz.electra.ExecutionRequests.defaultValue()
|
|
416
|
-
),
|
|
421
|
+
executionRequests: executionRequests !== null ? serializeExecutionRequests(fork, executionRequests) : [],
|
|
417
422
|
});
|
|
418
423
|
|
|
419
424
|
// IF the payload is deemed VALID and the build process has begun
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
ReqOpts,
|
|
7
7
|
} from "./jsonRpcHttpClient.js";
|
|
8
8
|
import {JwtClaim, encodeJwtToken} from "./jwt.js";
|
|
9
|
+
import {withRequestSignal} from "./signal.js";
|
|
9
10
|
import {ExecutionForkName} from "./sszTypes.js";
|
|
10
11
|
|
|
11
12
|
export const ENGINE_REST_BASE_PATH = "/engine/v1";
|
|
@@ -115,15 +116,18 @@ export class EngineRestHttpClient {
|
|
|
115
116
|
/** Perform request with retries without emitting events, used to probe support for the REST API */
|
|
116
117
|
async requestWithRetries(req: EngineRestRequest, opts?: ReqOpts): Promise<EngineRestResponse> {
|
|
117
118
|
const routeId = opts?.routeId ?? "unknown";
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
// The delay between retries has to end with the request signal as well
|
|
120
|
+
return withRequestSignal(this.opts.signal, opts?.signal, (signal) =>
|
|
121
|
+
retry(() => this.requestAnyUrl(req, opts), {
|
|
122
|
+
retries: opts?.retries ?? this.opts.retries ?? 0,
|
|
123
|
+
retryDelay: opts?.retryDelay ?? this.opts.retryDelay,
|
|
124
|
+
shouldRetry: opts?.shouldRetry ?? isRetryableEngineRestError,
|
|
125
|
+
signal,
|
|
126
|
+
onRetry: () => {
|
|
127
|
+
this.metrics?.retryCount.inc({routeId});
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
);
|
|
127
131
|
}
|
|
128
132
|
|
|
129
133
|
private async requestAnyUrl(req: EngineRestRequest, opts?: ReqOpts): Promise<EngineRestResponse> {
|
|
@@ -154,7 +158,8 @@ export class EngineRestHttpClient {
|
|
|
154
158
|
// Not AbortSignal.any(), Node retains every composite until the long-lived parent signal aborts
|
|
155
159
|
const onParentSignalAbort = (): void => controller.abort();
|
|
156
160
|
this.opts.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
|
|
157
|
-
|
|
161
|
+
opts?.signal?.addEventListener("abort", onParentSignalAbort, {once: true});
|
|
162
|
+
if (this.opts.signal?.aborted || opts?.signal?.aborted) {
|
|
158
163
|
controller.abort();
|
|
159
164
|
}
|
|
160
165
|
|
|
@@ -223,7 +228,7 @@ export class EngineRestHttpClient {
|
|
|
223
228
|
} catch (e) {
|
|
224
229
|
this.metrics?.requestErrors.inc({routeId});
|
|
225
230
|
if (controller.signal.aborted) {
|
|
226
|
-
if (this.opts.signal?.aborted) {
|
|
231
|
+
if (this.opts.signal?.aborted || opts?.signal?.aborted) {
|
|
227
232
|
throw new ErrorAborted("request");
|
|
228
233
|
}
|
|
229
234
|
throw new TimeoutError("request");
|
|
@@ -235,6 +240,7 @@ export class EngineRestHttpClient {
|
|
|
235
240
|
|
|
236
241
|
clearTimeout(timeout);
|
|
237
242
|
this.opts.signal?.removeEventListener("abort", onParentSignalAbort);
|
|
243
|
+
opts?.signal?.removeEventListener("abort", onParentSignalAbort);
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
246
|
}
|
|
@@ -241,7 +241,8 @@ export class RestEngineTransport implements IEngineTransport {
|
|
|
241
241
|
headBlockHash: RootHex,
|
|
242
242
|
safeBlockHash: RootHex,
|
|
243
243
|
finalizedBlockHash: RootHex,
|
|
244
|
-
payloadAttributes?: PayloadAttributes
|
|
244
|
+
payloadAttributes?: PayloadAttributes,
|
|
245
|
+
signal?: AbortSignal
|
|
245
246
|
): Promise<ForkchoiceUpdatedResult> {
|
|
246
247
|
const forkchoiceState = {
|
|
247
248
|
headBlockHash: fromHex(headBlockHash),
|
|
@@ -279,7 +280,7 @@ export class RestEngineTransport implements IEngineTransport {
|
|
|
279
280
|
|
|
280
281
|
const res = await this.client.request(
|
|
281
282
|
{method: "POST", path: "/forkchoice", executionFork: toExecutionForkName(fork), body, responseType: "ssz"},
|
|
282
|
-
fcUReqOpts
|
|
283
|
+
{...fcUReqOpts, signal}
|
|
283
284
|
);
|
|
284
285
|
const {payloadStatus, payloadId} = deserializeResponse(
|
|
285
286
|
ForkchoiceUpdateResponse,
|
|
@@ -293,14 +294,14 @@ export class RestEngineTransport implements IEngineTransport {
|
|
|
293
294
|
};
|
|
294
295
|
}
|
|
295
296
|
|
|
296
|
-
async getPayload(fork: ForkName, payloadId: PayloadId): Promise<GetPayloadResult> {
|
|
297
|
+
async getPayload(fork: ForkName, payloadId: PayloadId, signal?: AbortSignal): Promise<GetPayloadResult> {
|
|
297
298
|
if (!PAYLOAD_ID_REGEX.test(payloadId)) {
|
|
298
299
|
throw Error(`Invalid payloadId=${payloadId}, expected 0x prefixed 8 bytes hex`);
|
|
299
300
|
}
|
|
300
301
|
|
|
301
302
|
const res = await this.client.request(
|
|
302
303
|
{method: "GET", path: `/payloads/${payloadId}`, executionFork: toExecutionForkName(fork), responseType: "ssz"},
|
|
303
|
-
getPayloadOpts
|
|
304
|
+
{...getPayloadOpts, signal}
|
|
304
305
|
);
|
|
305
306
|
|
|
306
307
|
if (ForkSeq[fork] >= ForkSeq.gloas) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs `fn` with a signal that aborts with either the signal of the client or the signal of a single request.
|
|
3
|
+
* Not AbortSignal.any(), Node retains every composite until the long-lived client signal aborts.
|
|
4
|
+
*/
|
|
5
|
+
export async function withRequestSignal<T>(
|
|
6
|
+
clientSignal: AbortSignal | undefined,
|
|
7
|
+
requestSignal: AbortSignal | undefined,
|
|
8
|
+
fn: (signal: AbortSignal | undefined) => Promise<T>
|
|
9
|
+
): Promise<T> {
|
|
10
|
+
if (requestSignal === undefined) {
|
|
11
|
+
return fn(clientSignal);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
const onAbort = (): void => controller.abort();
|
|
16
|
+
clientSignal?.addEventListener("abort", onAbort, {once: true});
|
|
17
|
+
requestSignal.addEventListener("abort", onAbort, {once: true});
|
|
18
|
+
if (clientSignal?.aborted || requestSignal.aborted) {
|
|
19
|
+
controller.abort();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
return await fn(controller.signal);
|
|
24
|
+
} finally {
|
|
25
|
+
clientSignal?.removeEventListener("abort", onAbort);
|
|
26
|
+
requestSignal.removeEventListener("abort", onAbort);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -42,10 +42,11 @@ export interface IEngineTransport {
|
|
|
42
42
|
headBlockHash: RootHex,
|
|
43
43
|
safeBlockHash: RootHex,
|
|
44
44
|
finalizedBlockHash: RootHex,
|
|
45
|
-
payloadAttributes?: PayloadAttributes
|
|
45
|
+
payloadAttributes?: PayloadAttributes,
|
|
46
|
+
signal?: AbortSignal
|
|
46
47
|
): Promise<ForkchoiceUpdatedResult>;
|
|
47
48
|
|
|
48
|
-
getPayload(fork: ForkName, payloadId: PayloadId): Promise<GetPayloadResult>;
|
|
49
|
+
getPayload(fork: ForkName, payloadId: PayloadId, signal?: AbortSignal): Promise<GetPayloadResult>;
|
|
49
50
|
|
|
50
51
|
getPayloadBodiesByHashV2(blockHashes: RootHex[]): Promise<(ExecutionPayloadBodyV2 | null)[]>;
|
|
51
52
|
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,12 @@ export {DbCPStateDatastore} from "./chain/stateCache/datastore/db.js";
|
|
|
7
7
|
export {FileCPStateDatastore} from "./chain/stateCache/datastore/file.js";
|
|
8
8
|
export {BeaconDb, type IBeaconDb} from "./db/index.js";
|
|
9
9
|
// Export execution engine to make it usable by builder
|
|
10
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
ExecutionEngineError,
|
|
12
|
+
ExecutionEngineErrorCode,
|
|
13
|
+
ExecutionPayloadStatus,
|
|
14
|
+
initializeExecutionEngine,
|
|
15
|
+
} from "./execution/index.js";
|
|
11
16
|
// Export metrics utilities to de-duplicate validator metrics
|
|
12
17
|
export {
|
|
13
18
|
type HttpMetricsServer,
|
|
@@ -1068,6 +1068,11 @@ export function createLodestarMetrics(
|
|
|
1068
1068
|
help: "Count of errors, by error type, while processing execution payload envelopes",
|
|
1069
1069
|
labelNames: ["error"],
|
|
1070
1070
|
}),
|
|
1071
|
+
blockHashTime: register.histogram({
|
|
1072
|
+
name: "lodestar_gossip_execution_payload_envelope_block_hash_seconds",
|
|
1073
|
+
help: "Time to compute the execution block hash of a gossip execution payload envelope",
|
|
1074
|
+
buckets: [0.001, 0.002, 0.005, 0.01, 0.025, 0.05, 0.1, 0.5, 1],
|
|
1075
|
+
}),
|
|
1071
1076
|
executionPayload: {
|
|
1072
1077
|
recvToValidation: register.histogram({
|
|
1073
1078
|
name: "lodestar_gossip_execution_payload_envelope_received_to_execution_payload_verification_seconds",
|
package/src/network/network.ts
CHANGED
|
@@ -431,7 +431,7 @@ export class Network implements INetwork {
|
|
|
431
431
|
}
|
|
432
432
|
|
|
433
433
|
async publishBlsToExecutionChange(blsToExecutionChange: capella.SignedBLSToExecutionChange): Promise<number> {
|
|
434
|
-
const publishChanges = [];
|
|
434
|
+
const publishChanges: Promise<number>[] = [];
|
|
435
435
|
for (const boundary of getActiveForkBoundaries(this.config, this.clock.currentEpoch)) {
|
|
436
436
|
const fork = ForkSeq[boundary.fork];
|
|
437
437
|
|
|
@@ -447,7 +447,11 @@ export class Network implements INetwork {
|
|
|
447
447
|
if (publishChanges.length === 0) {
|
|
448
448
|
throw Error("No capella+ fork active yet to publish blsToExecutionChange");
|
|
449
449
|
}
|
|
450
|
-
|
|
450
|
+
try {
|
|
451
|
+
return await Promise.any(publishChanges);
|
|
452
|
+
} finally {
|
|
453
|
+
await Promise.allSettled(publishChanges);
|
|
454
|
+
}
|
|
451
455
|
}
|
|
452
456
|
|
|
453
457
|
async publishProposerSlashing(proposerSlashing: phase0.ProposerSlashing): Promise<number> {
|
|
@@ -449,7 +449,8 @@ export class PeerManager {
|
|
|
449
449
|
.catch((e) => this.logger.verbose("cannot tag peer", {peerId: peer.toString()}, e as Error));
|
|
450
450
|
peerData.relevantStatus = RelevantPeerStatus.relevant;
|
|
451
451
|
}
|
|
452
|
-
|
|
452
|
+
// A peer rejected on connect is not tracked and may still send a status before its goodbye completes
|
|
453
|
+
if (peerData && getConnection(this.libp2p, peer.toString())) {
|
|
453
454
|
const nodeId = peerData?.nodeId ?? computeNodeId(peer);
|
|
454
455
|
// TODO(fulu): Are we sure we've run Metadata before this?
|
|
455
456
|
const custodyGroupCount = peerData?.metadata?.custodyGroupCount ?? this.config.CUSTODY_REQUIREMENT;
|
|
@@ -554,6 +555,11 @@ export class PeerManager {
|
|
|
554
555
|
// ban and disconnect peers with bad score, collect rest of healthy peers
|
|
555
556
|
const connectedHealthyPeers: PeerId[] = [];
|
|
556
557
|
for (const peer of connectedPeers) {
|
|
558
|
+
// Direct peers are trusted by the operator, a bad score never disconnects them
|
|
559
|
+
if (this.gossipsub.isDirectPeer(peer.toString())) {
|
|
560
|
+
connectedHealthyPeers.push(peer);
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
557
563
|
switch (this.peerRpcScores.getScoreState(peer)) {
|
|
558
564
|
case ScoreState.Banned:
|
|
559
565
|
this.metrics?.peerManager.peersPruned.inc({reason: "banned"});
|
|
@@ -584,9 +590,11 @@ export class PeerManager {
|
|
|
584
590
|
const prioritizeTimer = this.metrics?.peerManager.prioritizePeersDuration.startTimer();
|
|
585
591
|
const {peersToDisconnect, peersToConnect, attnetQueries, syncnetQueries, custodyGroupQueries} = prioritizePeers(
|
|
586
592
|
connectedHealthyPeers.map((peer) => {
|
|
587
|
-
const
|
|
593
|
+
const peerIdStr = peer.toString();
|
|
594
|
+
const peerData = this.connectedPeers.get(peerIdStr);
|
|
588
595
|
return {
|
|
589
596
|
id: peer,
|
|
597
|
+
direct: this.gossipsub.isDirectPeer(peerIdStr),
|
|
590
598
|
direction: peerData?.direction ?? null,
|
|
591
599
|
status: peerData?.status ?? null,
|
|
592
600
|
attnets: peerData?.metadata?.attnets ?? null,
|
|
@@ -708,6 +716,10 @@ export class PeerManager {
|
|
|
708
716
|
private updateGossipsubScores(): void {
|
|
709
717
|
const gossipsubScores = new Map<string, number>();
|
|
710
718
|
for (const peerIdStr of this.connectedPeers.keys()) {
|
|
719
|
+
// Direct peers are never disconnected, they must not take the negative score allowance of other peers
|
|
720
|
+
if (this.gossipsub.isDirectPeer(peerIdStr)) {
|
|
721
|
+
continue;
|
|
722
|
+
}
|
|
711
723
|
gossipsubScores.set(peerIdStr, this.gossipsub.getScore(peerIdStr));
|
|
712
724
|
}
|
|
713
725
|
|
|
@@ -786,6 +798,18 @@ export class PeerManager {
|
|
|
786
798
|
return false;
|
|
787
799
|
}
|
|
788
800
|
|
|
801
|
+
// The heartbeat only disconnects peers that are already connected, a peer with a bad score
|
|
802
|
+
// could otherwise reconnect right after and stay connected until the next heartbeat
|
|
803
|
+
const scoreState = this.peerRpcScores.getScoreState(remotePeer);
|
|
804
|
+
if (scoreState !== ScoreState.Healthy && !this.gossipsub.isDirectPeer(remotePeerStr)) {
|
|
805
|
+
this.logger.debug("Peer with bad score connected, disconnecting", {peer: remotePeerPrettyStr, scoreState});
|
|
806
|
+
void this.goodbyeAndDisconnect(
|
|
807
|
+
remotePeer,
|
|
808
|
+
scoreState === ScoreState.Banned ? GoodByeReasonCode.BANNED : GoodByeReasonCode.SCORE_TOO_LOW
|
|
809
|
+
);
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
812
|
+
|
|
789
813
|
if (!opts.overwriteExisting && this.connectedPeers.has(remotePeerStr)) {
|
|
790
814
|
return false;
|
|
791
815
|
}
|
|
@@ -98,6 +98,7 @@ function computeStatusScore(ours: Status, theirs: Status | null, opts: Prioritiz
|
|
|
98
98
|
|
|
99
99
|
type PeerInfo = {
|
|
100
100
|
id: PeerId;
|
|
101
|
+
direct: boolean;
|
|
101
102
|
direction: MessageStreamDirection | null;
|
|
102
103
|
statusScore: StatusScore;
|
|
103
104
|
attnets: phase0.AttestationSubnets;
|
|
@@ -140,6 +141,7 @@ export enum ExcessPeerDisconnectReason {
|
|
|
140
141
|
export function prioritizePeers(
|
|
141
142
|
connectedPeersInfo: {
|
|
142
143
|
id: PeerId;
|
|
144
|
+
direct?: boolean;
|
|
143
145
|
direction: MessageStreamDirection | null;
|
|
144
146
|
status: Status | null;
|
|
145
147
|
attnets: phase0.AttestationSubnets | null;
|
|
@@ -169,6 +171,7 @@ export function prioritizePeers(
|
|
|
169
171
|
const connectedPeers = connectedPeersInfo.map(
|
|
170
172
|
(peer): PeerInfo => ({
|
|
171
173
|
id: peer.id,
|
|
174
|
+
direct: peer.direct ?? false,
|
|
172
175
|
direction: peer.direction,
|
|
173
176
|
statusScore: computeStatusScore(opts.status, peer.status, opts),
|
|
174
177
|
attnets: peer.attnets ?? attnetsZero,
|
|
@@ -365,6 +368,11 @@ function pruneExcessPeers(
|
|
|
365
368
|
const peersEligibleForPruning = sortedPeers
|
|
366
369
|
// Then, iterate from highest score to lowest doing a manual filter for duties and outbound ratio
|
|
367
370
|
.filter((peer) => {
|
|
371
|
+
// Direct peers are pinned by the operator, they count towards all targets but are never pruned
|
|
372
|
+
if (peer.direct) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
|
|
368
376
|
// Peers with duties are not eligible for pruning
|
|
369
377
|
if ((dutiesByPeer.get(peer) ?? 0) > 0) {
|
|
370
378
|
return false;
|
|
@@ -488,11 +496,12 @@ function pruneExcessPeers(
|
|
|
488
496
|
// otherwise we'll not able to accept new peer connection to consider better peers
|
|
489
497
|
// see https://github.com/ChainSafe/lodestar/issues/5198
|
|
490
498
|
const remainingPeersToDisconnect: PeerId[] = [];
|
|
491
|
-
for (const {id} of sortedPeers) {
|
|
499
|
+
for (const {id, direct} of sortedPeers) {
|
|
492
500
|
if (peersToDisconnectCount >= peersToDisconnectTarget) {
|
|
493
501
|
break;
|
|
494
502
|
}
|
|
495
503
|
if (
|
|
504
|
+
direct ||
|
|
496
505
|
noLongLivedSubnetPeersToDisconnect.includes(id) ||
|
|
497
506
|
badScorePeersToDisconnect.includes(id) ||
|
|
498
507
|
tooGroupedPeersToDisconnect.includes(id)
|
|
@@ -568,6 +577,10 @@ function findPeerToRemove(
|
|
|
568
577
|
const peersOnSubnet = sortBy(peersOnMostGroupedSubnet, (peer) => peer.attnetsTrueBitIndices.length);
|
|
569
578
|
let removedPeer: PeerInfo | null = null;
|
|
570
579
|
for (const candidatePeer of peersOnSubnet) {
|
|
580
|
+
if (candidatePeer.direct) {
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
|
|
571
584
|
// new logic of lodestar
|
|
572
585
|
const attnetIndices = candidatePeer.attnetsTrueBitIndices;
|
|
573
586
|
if (attnetIndices.length > 0) {
|
package/src/sync/types.ts
CHANGED
|
@@ -172,6 +172,8 @@ export type PendingPayloadRootHex = {
|
|
|
172
172
|
export type PendingPayloadEnvelope = {
|
|
173
173
|
status: PendingPayloadInputStatus.waitingForBlock;
|
|
174
174
|
envelope: SignedExecutionPayloadEnvelope;
|
|
175
|
+
/** Peer that served the envelope, undefined if it was already cached */
|
|
176
|
+
envelopePeerId?: string;
|
|
175
177
|
timeAddedSec: number;
|
|
176
178
|
peerIdStrings: Set<string>;
|
|
177
179
|
};
|