@lodestar/beacon-node 2.0.0-rc.1 → 2.0.0
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 +4 -3
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/api/impl/beacon/pool/index.js +1 -1
- package/lib/api/impl/beacon/pool/index.js.map +1 -1
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +74 -44
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
- package/lib/chain/chain.d.ts +1 -1
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +18 -21
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/executionPayloadBid.d.ts +6 -1
- package/lib/chain/errors/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadBid.js +1 -0
- package/lib/chain/errors/executionPayloadBid.js.map +1 -1
- 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/prepareNextSlot.d.ts +45 -0
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +265 -69
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts +6 -2
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +54 -64
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/validation/attesterSlashing.d.ts.map +1 -1
- package/lib/chain/validation/attesterSlashing.js +4 -2
- package/lib/chain/validation/attesterSlashing.js.map +1 -1
- package/lib/chain/validation/executionPayloadBid.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadBid.js +17 -2
- package/lib/chain/validation/executionPayloadBid.js.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.js +21 -5
- package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/validation/proposerSlashing.js +4 -2
- package/lib/chain/validation/proposerSlashing.js.map +1 -1
- package/lib/chain/validation/signatureSets/contributionAndProof.d.ts +2 -2
- package/lib/chain/validation/signatureSets/contributionAndProof.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/contributionAndProof.js +2 -2
- package/lib/chain/validation/signatureSets/contributionAndProof.js.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommittee.d.ts +2 -2
- package/lib/chain/validation/signatureSets/syncCommittee.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommittee.js +2 -2
- package/lib/chain/validation/signatureSets/syncCommittee.js.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts +2 -2
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.js +2 -2
- package/lib/chain/validation/signatureSets/syncCommitteeContribution.js.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts +2 -2
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.d.ts.map +1 -1
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js +2 -2
- package/lib/chain/validation/signatureSets/syncCommitteeSelectionProof.js.map +1 -1
- package/lib/chain/validation/syncCommittee.d.ts +1 -1
- package/lib/chain/validation/syncCommittee.d.ts.map +1 -1
- package/lib/chain/validation/syncCommittee.js +5 -5
- package/lib/chain/validation/syncCommittee.js.map +1 -1
- package/lib/chain/validation/syncCommitteeContributionAndProof.js +3 -3
- package/lib/chain/validation/syncCommitteeContributionAndProof.js.map +1 -1
- package/lib/chain/validation/voluntaryExit.d.ts.map +1 -1
- package/lib/chain/validation/voluntaryExit.js +39 -6
- package/lib/chain/validation/voluntaryExit.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/payloadIdCache.d.ts +6 -1
- package/lib/execution/engine/payloadIdCache.d.ts.map +1 -1
- package/lib/execution/engine/payloadIdCache.js +7 -2
- package/lib/execution/engine/payloadIdCache.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/beacon.d.ts +5 -0
- package/lib/metrics/metrics/beacon.d.ts.map +1 -1
- package/lib/metrics/metrics/beacon.js +5 -0
- package/lib/metrics/metrics/beacon.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/core/events.d.ts +6 -2
- package/lib/network/core/events.d.ts.map +1 -1
- package/lib/network/core/events.js +9 -0
- package/lib/network/core/events.js.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.d.ts.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js +3 -2
- package/lib/network/core/networkCoreWorkerHandler.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/network/reqresp/handlers/dataColumnSidecarsByRange.js +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
- package/lib/sync/range/batch.d.ts +4 -0
- package/lib/sync/range/batch.d.ts.map +1 -1
- package/lib/sync/range/batch.js +12 -0
- package/lib/sync/range/batch.js.map +1 -1
- package/lib/sync/range/chain.d.ts +17 -2
- package/lib/sync/range/chain.d.ts.map +1 -1
- package/lib/sync/range/chain.js +52 -19
- package/lib/sync/range/chain.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +1 -0
- package/lib/sync/range/range.js.map +1 -1
- package/lib/sync/range/utils/batches.d.ts +20 -4
- package/lib/sync/range/utils/batches.d.ts.map +1 -1
- package/lib/sync/range/utils/batches.js +31 -13
- package/lib/sync/range/utils/batches.js.map +1 -1
- package/lib/sync/range/utils/peerBalancer.d.ts +1 -1
- package/lib/sync/range/utils/peerBalancer.d.ts.map +1 -1
- package/lib/sync/range/utils/peerBalancer.js +5 -2
- package/lib/sync/range/utils/peerBalancer.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/downloadByRange.d.ts +8 -0
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +43 -23
- package/lib/sync/utils/downloadByRange.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/lib/util/asyncIterableToEvents.d.ts +20 -3
- package/lib/util/asyncIterableToEvents.d.ts.map +1 -1
- package/lib/util/asyncIterableToEvents.js +76 -20
- package/lib/util/asyncIterableToEvents.js.map +1 -1
- package/lib/util/dataColumns.d.ts +1 -1
- package/lib/util/dataColumns.d.ts.map +1 -1
- package/lib/util/dataColumns.js +4 -1
- package/lib/util/dataColumns.js.map +1 -1
- package/package.json +25 -25
- package/src/api/impl/beacon/blocks/index.ts +4 -3
- package/src/api/impl/beacon/pool/index.ts +1 -1
- package/src/api/impl/validator/index.ts +107 -61
- package/src/chain/archiveStore/utils/archiveBlocks.ts +1 -1
- package/src/chain/chain.ts +17 -41
- package/src/chain/errors/executionPayloadBid.ts +6 -0
- package/src/chain/errors/executionPayloadEnvelope.ts +8 -0
- package/src/chain/prepareNextSlot.ts +347 -89
- package/src/chain/produceBlock/produceBlockBody.ts +69 -80
- package/src/chain/validation/attesterSlashing.ts +4 -2
- package/src/chain/validation/executionPayloadBid.ts +20 -2
- package/src/chain/validation/executionPayloadEnvelope.ts +28 -5
- package/src/chain/validation/proposerSlashing.ts +4 -2
- package/src/chain/validation/signatureSets/contributionAndProof.ts +4 -6
- package/src/chain/validation/signatureSets/syncCommittee.ts +2 -3
- package/src/chain/validation/signatureSets/syncCommitteeContribution.ts +2 -3
- package/src/chain/validation/signatureSets/syncCommitteeSelectionProof.ts +2 -3
- package/src/chain/validation/syncCommittee.ts +3 -5
- package/src/chain/validation/syncCommitteeContributionAndProof.ts +3 -3
- package/src/chain/validation/voluntaryExit.ts +44 -6
- 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/payloadIdCache.ts +12 -4
- 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/beacon.ts +9 -0
- package/src/metrics/metrics/lodestar.ts +5 -0
- package/src/network/core/events.ts +12 -0
- package/src/network/core/networkCoreWorkerHandler.ts +6 -2
- 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/network/reqresp/handlers/dataColumnSidecarsByRange.ts +1 -1
- package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +1 -1
- package/src/sync/range/batch.ts +13 -0
- package/src/sync/range/chain.ts +64 -17
- package/src/sync/range/range.ts +1 -0
- package/src/sync/range/utils/batches.ts +38 -13
- package/src/sync/range/utils/peerBalancer.ts +4 -1
- package/src/sync/types.ts +2 -0
- package/src/sync/unknownBlock.ts +110 -21
- package/src/sync/utils/downloadByRange.ts +60 -26
- package/src/sync/utils/downloadByRoot.ts +7 -5
- package/src/util/asyncIterableToEvents.ts +100 -21
- package/src/util/dataColumns.ts +4 -1
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
IteratorEvent,
|
|
6
6
|
RequestCancelEvent,
|
|
7
7
|
RequestEvent,
|
|
8
|
+
ResponsePullEvent,
|
|
8
9
|
} from "../../util/asyncIterableToEvents.js";
|
|
9
10
|
import {StrictEventEmitterSingleArg} from "../../util/strictEvents.js";
|
|
10
11
|
import {EventDirection} from "../events.js";
|
|
@@ -14,18 +15,22 @@ export enum ReqRespBridgeEvent {
|
|
|
14
15
|
outgoingRequest = "reqresp.outgoingRequest",
|
|
15
16
|
outgoingRequestCancel = "reqresp.outgoingRequestCancel",
|
|
16
17
|
outgoingResponse = "reqresp.outgoingResponse",
|
|
18
|
+
outgoingResponsePull = "reqresp.outgoingResponsePull",
|
|
17
19
|
incomingRequest = "reqresp.incomingRequest",
|
|
18
20
|
incomingRequestCancel = "reqresp.incomingRequestCancel",
|
|
19
21
|
incomingResponse = "reqresp.incomingResponse",
|
|
22
|
+
incomingResponsePull = "reqresp.incomingResponsePull",
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
export type ReqRespBridgeEventData = {
|
|
23
26
|
[ReqRespBridgeEvent.outgoingRequest]: RequestEvent<OutgoingRequestArgs>;
|
|
24
27
|
[ReqRespBridgeEvent.outgoingRequestCancel]: RequestCancelEvent;
|
|
25
28
|
[ReqRespBridgeEvent.outgoingResponse]: IteratorEvent<ResponseOutgoing>;
|
|
29
|
+
[ReqRespBridgeEvent.outgoingResponsePull]: ResponsePullEvent;
|
|
26
30
|
[ReqRespBridgeEvent.incomingRequest]: RequestEvent<IncomingRequestArgs>;
|
|
27
31
|
[ReqRespBridgeEvent.incomingRequestCancel]: RequestCancelEvent;
|
|
28
32
|
[ReqRespBridgeEvent.incomingResponse]: IteratorEvent<ResponseIncoming>;
|
|
33
|
+
[ReqRespBridgeEvent.incomingResponsePull]: ResponsePullEvent;
|
|
29
34
|
};
|
|
30
35
|
|
|
31
36
|
type IReqRespBridgeEventBus = StrictEventEmitterSingleArg<ReqRespBridgeEventData>;
|
|
@@ -37,9 +42,12 @@ export const reqRespBridgeEventDirection: Record<ReqRespBridgeEvent, EventDirect
|
|
|
37
42
|
[ReqRespBridgeEvent.outgoingRequest]: EventDirection.mainToWorker,
|
|
38
43
|
[ReqRespBridgeEvent.outgoingRequestCancel]: EventDirection.mainToWorker,
|
|
39
44
|
[ReqRespBridgeEvent.outgoingResponse]: EventDirection.mainToWorker,
|
|
45
|
+
// Credit flows from the consumer back to the producer, opposite the response it paces
|
|
46
|
+
[ReqRespBridgeEvent.outgoingResponsePull]: EventDirection.workerToMain,
|
|
40
47
|
[ReqRespBridgeEvent.incomingRequest]: EventDirection.workerToMain,
|
|
41
48
|
[ReqRespBridgeEvent.incomingRequestCancel]: EventDirection.workerToMain,
|
|
42
49
|
[ReqRespBridgeEvent.incomingResponse]: EventDirection.workerToMain,
|
|
50
|
+
[ReqRespBridgeEvent.incomingResponsePull]: EventDirection.mainToWorker,
|
|
43
51
|
};
|
|
44
52
|
|
|
45
53
|
export function getReqRespBridgeReqEvents(
|
|
@@ -49,9 +57,11 @@ export function getReqRespBridgeReqEvents(
|
|
|
49
57
|
emitRequest: (data) => events.emit(ReqRespBridgeEvent.outgoingRequest, data),
|
|
50
58
|
emitRequestCancel: (data) => events.emit(ReqRespBridgeEvent.outgoingRequestCancel, data),
|
|
51
59
|
emitResponse: (data) => events.emit(ReqRespBridgeEvent.incomingResponse, data),
|
|
60
|
+
emitResponsePull: (data) => events.emit(ReqRespBridgeEvent.incomingResponsePull, data),
|
|
52
61
|
onRequest: (cb) => events.on(ReqRespBridgeEvent.outgoingRequest, cb),
|
|
53
62
|
onRequestCancel: (cb) => events.on(ReqRespBridgeEvent.outgoingRequestCancel, cb),
|
|
54
63
|
onResponse: (cb) => events.on(ReqRespBridgeEvent.incomingResponse, cb),
|
|
64
|
+
onResponsePull: (cb) => events.on(ReqRespBridgeEvent.incomingResponsePull, cb),
|
|
55
65
|
};
|
|
56
66
|
}
|
|
57
67
|
|
|
@@ -62,9 +72,11 @@ export function getReqRespBridgeRespEvents(
|
|
|
62
72
|
emitRequest: (data) => events.emit(ReqRespBridgeEvent.incomingRequest, data),
|
|
63
73
|
emitRequestCancel: (data) => events.emit(ReqRespBridgeEvent.incomingRequestCancel, data),
|
|
64
74
|
emitResponse: (data) => events.emit(ReqRespBridgeEvent.outgoingResponse, data),
|
|
75
|
+
emitResponsePull: (data) => events.emit(ReqRespBridgeEvent.outgoingResponsePull, data),
|
|
65
76
|
onRequest: (cb) => events.on(ReqRespBridgeEvent.incomingRequest, cb),
|
|
66
77
|
onRequestCancel: (cb) => events.on(ReqRespBridgeEvent.incomingRequestCancel, cb),
|
|
67
78
|
onResponse: (cb) => events.on(ReqRespBridgeEvent.outgoingResponse, cb),
|
|
79
|
+
onResponsePull: (cb) => events.on(ReqRespBridgeEvent.outgoingResponsePull, cb),
|
|
68
80
|
};
|
|
69
81
|
}
|
|
70
82
|
|
|
@@ -74,8 +74,12 @@ export class WorkerNetworkCore implements INetworkCore {
|
|
|
74
74
|
private readonly reqRespBridgeEventBus = new ReqRespBridgeEventBus();
|
|
75
75
|
|
|
76
76
|
constructor(private readonly modules: WorkerNetworkCoreModules) {
|
|
77
|
-
// Get called from main thread to issue a ReqResp request, and emits event to worker
|
|
78
|
-
|
|
77
|
+
// Get called from main thread to issue a ReqResp request, and emits event to worker. Unbounded: we
|
|
78
|
+
// buffer the whole response into an array anyway, so pacing the worker only risks a read buffer overflow
|
|
79
|
+
this.reqRespBridgeReqCaller = new AsyncIterableBridgeCaller(
|
|
80
|
+
getReqRespBridgeReqEvents(this.reqRespBridgeEventBus),
|
|
81
|
+
Infinity
|
|
82
|
+
);
|
|
79
83
|
// Handles ReqResp response from worker and calls async generator in main thread
|
|
80
84
|
this.reqRespBridgeRespHandler = new AsyncIterableBridgeHandler(
|
|
81
85
|
getReqRespBridgeRespEvents(this.reqRespBridgeEventBus),
|
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) {
|
|
@@ -216,7 +216,7 @@ export function validateDataColumnSidecarsByRangeRequest(
|
|
|
216
216
|
throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis");
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
// Spec: [max(
|
|
219
|
+
// Spec: [max(current_epoch - MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS, FULU_FORK_EPOCH), current_epoch]
|
|
220
220
|
const minimumRequestEpoch = Math.max(getBlobDataRetentionStartEpoch(config, currentEpoch), config.FULU_FORK_EPOCH);
|
|
221
221
|
if (computeEpochAtSlot(startSlot) < minimumRequestEpoch) {
|
|
222
222
|
throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, "startSlot is before the blob data retention window");
|
|
@@ -19,7 +19,7 @@ export async function* onDataColumnSidecarsByRoot(
|
|
|
19
19
|
peerId: PeerId,
|
|
20
20
|
peerClient: string
|
|
21
21
|
): AsyncIterable<ResponseOutgoing> {
|
|
22
|
-
// SPEC: minimum_request_epoch = max(
|
|
22
|
+
// SPEC: minimum_request_epoch = max(current_epoch - MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS, FULU_FORK_EPOCH)
|
|
23
23
|
const currentEpoch = chain.clock.currentEpoch;
|
|
24
24
|
const minimumRequestEpoch = Math.max(
|
|
25
25
|
getBlobDataRetentionStartEpoch(chain.config, currentEpoch),
|
package/src/sync/range/batch.ts
CHANGED
|
@@ -430,6 +430,19 @@ export class Batch {
|
|
|
430
430
|
return [...this.failedProcessingAttempts, ...this.executionErrorAttempts].filter((a) => a.peerAttributable);
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
+
/**
|
|
434
|
+
* How many failed processing/execution attempts each peer took part in, peer-attributable or not
|
|
435
|
+
*/
|
|
436
|
+
getTriedPeerCounts(): Map<PeerIdStr, number> {
|
|
437
|
+
const counts = new Map<PeerIdStr, number>();
|
|
438
|
+
for (const attempt of [...this.failedProcessingAttempts, ...this.executionErrorAttempts]) {
|
|
439
|
+
for (const peer of attempt.peers) {
|
|
440
|
+
counts.set(peer, (counts.get(peer) ?? 0) + 1);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return counts;
|
|
444
|
+
}
|
|
445
|
+
|
|
433
446
|
/**
|
|
434
447
|
* True only if the peer has already returned a successful response for the current request.
|
|
435
448
|
* A by_range success may update `this.requests` to parent_payload, and the same peer is then
|
package/src/sync/range/chain.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
|
-
import {Epoch, Root, Slot} from "@lodestar/types";
|
|
2
|
+
import {Epoch, Root, RootHex, Slot} from "@lodestar/types";
|
|
3
3
|
import {ErrorAborted, LodestarError, Logger, prettyPrintIndices, toRootHex} from "@lodestar/utils";
|
|
4
4
|
import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
|
|
5
5
|
import {BlockInputErrorCode} from "../../chain/blocks/blockInput/errors.js";
|
|
@@ -68,6 +68,8 @@ export type SyncChainFns = {
|
|
|
68
68
|
onEnd: (err: Error | null, target: ChainTarget | null) => void;
|
|
69
69
|
/** Deletes an array of BlockInputs from the BlockInputCache */
|
|
70
70
|
pruneBlockInputs: (blockInputs: IBlockInput[]) => void;
|
|
71
|
+
/** Returns true if the block is known to fork choice */
|
|
72
|
+
hasBlock: (blockRoot: Root) => boolean;
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
/**
|
|
@@ -81,6 +83,15 @@ export type ChainTarget = {
|
|
|
81
83
|
|
|
82
84
|
export class SyncChainStartError extends Error {}
|
|
83
85
|
|
|
86
|
+
export enum SyncChainErrorCode {
|
|
87
|
+
/** The terminal batch has 0 blocks but the target block is not known */
|
|
88
|
+
MISSING_TARGET_BLOCK = "SYNC_CHAIN_ERROR_MISSING_TARGET_BLOCK",
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
type SyncChainErrorType = {code: SyncChainErrorCode.MISSING_TARGET_BLOCK; targetSlot: Slot; targetRoot: RootHex};
|
|
92
|
+
|
|
93
|
+
export class SyncChainError extends LodestarError<SyncChainErrorType> {}
|
|
94
|
+
|
|
84
95
|
export type SyncChainDebugState = {
|
|
85
96
|
targetRoot: string | null;
|
|
86
97
|
targetSlot: number | null;
|
|
@@ -136,6 +147,7 @@ export class SyncChain {
|
|
|
136
147
|
private readonly reportPeer: SyncChainFns["reportPeer"];
|
|
137
148
|
private readonly getConnectedPeerSyncMeta: SyncChainFns["getConnectedPeerSyncMeta"];
|
|
138
149
|
private readonly pruneBlockInputs: SyncChainFns["pruneBlockInputs"];
|
|
150
|
+
private readonly hasBlock: SyncChainFns["hasBlock"];
|
|
139
151
|
|
|
140
152
|
/** AsyncIterable that guarantees processChainSegment is run only at once at anytime */
|
|
141
153
|
private readonly batchProcessor = new ItTrigger();
|
|
@@ -178,6 +190,7 @@ export class SyncChain {
|
|
|
178
190
|
this.downloadByRange = fns.downloadByRange;
|
|
179
191
|
this.reportPeer = fns.reportPeer;
|
|
180
192
|
this.pruneBlockInputs = fns.pruneBlockInputs;
|
|
193
|
+
this.hasBlock = fns.hasBlock;
|
|
181
194
|
this.getConnectedPeerSyncMeta = fns.getConnectedPeerSyncMeta;
|
|
182
195
|
this.config = config;
|
|
183
196
|
this.clock = clock;
|
|
@@ -335,6 +348,32 @@ export class SyncChain {
|
|
|
335
348
|
|
|
336
349
|
// Returns true if SyncChain has processed all possible blocks with slot <= target.slot
|
|
337
350
|
if (isSyncChainDone(toArr(this.batches), this.lastEpochWithProcessBlocks, this.target.slot)) {
|
|
351
|
+
// A 0-block terminal batch is only trusted once the target block is known, otherwise a peer returning no
|
|
352
|
+
// blocks for the last range ends the chain short of its target
|
|
353
|
+
const lastAwaitingValidation = toArr(this.batches).findLast(
|
|
354
|
+
(b) => b.state.status === BatchStatus.AwaitingValidation
|
|
355
|
+
);
|
|
356
|
+
if (
|
|
357
|
+
lastAwaitingValidation !== undefined &&
|
|
358
|
+
lastAwaitingValidation.getBlocks().length === 0 &&
|
|
359
|
+
!this.hasBlock(this.target.root)
|
|
360
|
+
) {
|
|
361
|
+
this.logger.verbose("Terminal 0-block batch without target block", {
|
|
362
|
+
id: this.logId,
|
|
363
|
+
...lastAwaitingValidation.getMetadata(),
|
|
364
|
+
});
|
|
365
|
+
// Not peer attributable: throws MAX_PROCESSING_ATTEMPTS after MAX_BATCH_PROCESSING_ATTEMPTS without
|
|
366
|
+
// reporting any peer
|
|
367
|
+
lastAwaitingValidation.validationError(
|
|
368
|
+
new SyncChainError({
|
|
369
|
+
code: SyncChainErrorCode.MISSING_TARGET_BLOCK,
|
|
370
|
+
targetSlot: this.target.slot,
|
|
371
|
+
targetRoot: toRootHex(this.target.root),
|
|
372
|
+
})
|
|
373
|
+
);
|
|
374
|
+
this.triggerBatchDownloader();
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
338
377
|
break;
|
|
339
378
|
}
|
|
340
379
|
|
|
@@ -509,9 +548,12 @@ export class SyncChain {
|
|
|
509
548
|
// if last processed epoch is n, we don't want to request batches with epoch > n + MAX_LOOK_AHEAD_EPOCHS
|
|
510
549
|
// we should have enough batches to process in the buffer: n + 1, ..., n + MAX_LOOK_AHEAD_EPOCHS
|
|
511
550
|
// let's focus on redownloading these batches first because it may have to reach different peers to get enough sampled columns
|
|
551
|
+
// Note: Don't count batches in the AwaitingValidation state, 0-block batches never advance
|
|
552
|
+
// lastEpochWithProcessBlocks so more than MAX_LOOK_AHEAD_EPOCHS of them in a row would stall sync
|
|
553
|
+
const pendingBatches = batches.filter((batch) => batch.state.status !== BatchStatus.AwaitingValidation);
|
|
512
554
|
if (
|
|
513
|
-
|
|
514
|
-
Math.max(...
|
|
555
|
+
pendingBatches.length > 0 &&
|
|
556
|
+
Math.max(...pendingBatches.map((b) => b.startEpoch)) >= this.lastEpochWithProcessBlocks + MAX_LOOK_AHEAD_EPOCHS
|
|
515
557
|
) {
|
|
516
558
|
return null;
|
|
517
559
|
}
|
|
@@ -576,6 +618,7 @@ export class SyncChain {
|
|
|
576
618
|
}
|
|
577
619
|
}
|
|
578
620
|
switch (errCode) {
|
|
621
|
+
case DownloadByRangeErrorCode.DATA_WITHOUT_BLOCKS:
|
|
579
622
|
case DownloadByRangeErrorCode.EXTRA_BLOCKS:
|
|
580
623
|
case DownloadByRangeErrorCode.OUT_OF_ORDER_BLOCKS:
|
|
581
624
|
case DownloadByRangeErrorCode.OUT_OF_RANGE_BLOCKS:
|
|
@@ -722,39 +765,43 @@ export class SyncChain {
|
|
|
722
765
|
} else {
|
|
723
766
|
this.logger.verbose("Batch process error", logCtx, res.err);
|
|
724
767
|
|
|
725
|
-
|
|
726
|
-
|
|
768
|
+
// advanceChain() drops every batch before the last batch with blocks, so the AwaitingValidation batches before
|
|
769
|
+
// `batch` are that batch followed by 0-block batches, see classifyProcessingFault(). With no batch with blocks
|
|
770
|
+
// yet, fall back to the first 0-block batch so a wrong 0-block answer at the start of the chain is retried
|
|
771
|
+
const awaitingValidationBefore = toArr(this.batches).filter(
|
|
772
|
+
(b) => b.startEpoch < batch.startEpoch && b.state.status === BatchStatus.AwaitingValidation
|
|
773
|
+
);
|
|
774
|
+
const parentBatch =
|
|
775
|
+
awaitingValidationBefore.findLast((b) => b.getBlocks().length > 0) ?? awaitingValidationBefore[0];
|
|
776
|
+
// The 0-block batches after `parentBatch` are invalidated with it: an AwaitingValidation batch must not follow a
|
|
777
|
+
// batch that is downloaded again, see validateBatchesStatus()
|
|
778
|
+
const invalidateFromParentBatch = (faultyParentBatch: Batch): void => {
|
|
727
779
|
for (const pendingBatch of this.batches.values()) {
|
|
728
780
|
if (
|
|
781
|
+
pendingBatch.startEpoch >= faultyParentBatch.startEpoch &&
|
|
729
782
|
pendingBatch.startEpoch < batch.startEpoch &&
|
|
730
783
|
pendingBatch.state.status === BatchStatus.AwaitingValidation
|
|
731
784
|
) {
|
|
732
785
|
this.logger.verbose("Batch validation error", {id: this.logId, ...pendingBatch.getMetadata()});
|
|
733
786
|
pendingBatch.validationError(res.err);
|
|
734
|
-
invalidatedCount++;
|
|
735
787
|
}
|
|
736
788
|
}
|
|
737
|
-
return invalidatedCount;
|
|
738
789
|
};
|
|
739
790
|
|
|
740
|
-
const
|
|
741
|
-
switch (
|
|
791
|
+
const fault = classifyProcessingFault(res.err, batch, parentBatch);
|
|
792
|
+
switch (fault.kind) {
|
|
742
793
|
case ProcessingFaultKind.CurrentBatch:
|
|
743
794
|
batch.processingError(res.err);
|
|
744
795
|
break;
|
|
745
796
|
|
|
746
|
-
case ProcessingFaultKind.
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
batch.processingError(res.err);
|
|
750
|
-
} else {
|
|
751
|
-
batch.retainForReprocessing();
|
|
752
|
-
}
|
|
797
|
+
case ProcessingFaultKind.ParentBatch:
|
|
798
|
+
invalidateFromParentBatch(fault.parentBatch);
|
|
799
|
+
batch.retainForReprocessing();
|
|
753
800
|
break;
|
|
754
801
|
|
|
755
802
|
case ProcessingFaultKind.Ambiguous:
|
|
756
803
|
batch.processingError(res.err);
|
|
757
|
-
|
|
804
|
+
invalidateFromParentBatch(fault.parentBatch);
|
|
758
805
|
break;
|
|
759
806
|
}
|
|
760
807
|
}
|
package/src/sync/range/range.ts
CHANGED
|
@@ -461,6 +461,7 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
|
|
|
461
461
|
reportPeer: this.reportPeer,
|
|
462
462
|
getConnectedPeerSyncMeta: this.getConnectedPeerSyncMeta,
|
|
463
463
|
pruneBlockInputs: this.pruneBlockInputs,
|
|
464
|
+
hasBlock: (blockRoot) => this.chain.forkChoice.hasBlock(blockRoot),
|
|
464
465
|
onEnd: this.onSyncChainEnd,
|
|
465
466
|
},
|
|
466
467
|
{
|
|
@@ -125,39 +125,64 @@ export function isSyncChainDone(batches: Batch[], lastEpochWithProcessBlocks: Ep
|
|
|
125
125
|
export enum ProcessingFaultKind {
|
|
126
126
|
/** This batch's own blocks are bad or incomplete, so redownload this batch. */
|
|
127
127
|
CurrentBatch = "CurrentBatch",
|
|
128
|
-
/** This batch is valid, but
|
|
129
|
-
|
|
130
|
-
/** The fault could be in this batch or
|
|
128
|
+
/** This batch is valid, but the parent batch did not deliver the parent. */
|
|
129
|
+
ParentBatch = "ParentBatch",
|
|
130
|
+
/** The fault could be in this batch or the parent batch, so hedge both ways. */
|
|
131
131
|
Ambiguous = "Ambiguous",
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
export type ProcessingFault =
|
|
135
|
+
| {kind: ProcessingFaultKind.CurrentBatch}
|
|
136
|
+
| {kind: ProcessingFaultKind.ParentBatch; parentBatch: Batch}
|
|
137
|
+
| {kind: ProcessingFaultKind.Ambiguous; parentBatch: Batch};
|
|
138
|
+
|
|
134
139
|
/**
|
|
135
140
|
* Classify a processChainSegment error for a batch so range sync only redownloads
|
|
136
141
|
* the batch or batches that could actually be at fault.
|
|
137
142
|
* Note that range sync is supposed to only handle linear chain, for forky condition we'll handle it via backward sync
|
|
138
143
|
* in BlockInputSync or the upcoming/TODO beacon_blocks_by_head req/resp.
|
|
144
|
+
*
|
|
145
|
+
* `parentBatch` is the last batch with blocks before `batch`, it may be followed by 0-block batches. If no batch with
|
|
146
|
+
* blocks awaits validation, it is the first 0-block batch before `batch`.
|
|
147
|
+
* Epochs with 0 blocks usually happen on devnets, during periods of poor liveness when no proposer gets a block
|
|
148
|
+
* included for whole epochs. A wrong 0-block response only shows up as an unknown parent in `batch`, so with 0-block
|
|
149
|
+
* batches in between the fault is never pinned on `batch` alone: `parentBatch` and the 0-block batches after it are
|
|
150
|
+
* downloaded again.
|
|
139
151
|
*/
|
|
140
|
-
export function classifyProcessingFault(err: Error, batch: Batch,
|
|
152
|
+
export function classifyProcessingFault(err: Error, batch: Batch, parentBatch: Batch | undefined): ProcessingFault {
|
|
141
153
|
if (!(err instanceof BlockError)) {
|
|
142
|
-
return ProcessingFaultKind.CurrentBatch;
|
|
154
|
+
return {kind: ProcessingFaultKind.CurrentBatch};
|
|
143
155
|
}
|
|
144
156
|
|
|
145
157
|
const {code} = err.type;
|
|
146
158
|
if (code !== BlockErrorCode.PARENT_BLOCK_UNKNOWN && code !== BlockErrorCode.PARENT_PAYLOAD_UNKNOWN) {
|
|
147
|
-
return ProcessingFaultKind.CurrentBatch;
|
|
159
|
+
return {kind: ProcessingFaultKind.CurrentBatch};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (parentBatch === undefined) {
|
|
163
|
+
return {kind: ProcessingFaultKind.CurrentBatch};
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
const firstErrorSlot = err.signedBlock.message.slot;
|
|
151
167
|
if (firstErrorSlot === batch.startSlot) {
|
|
152
|
-
// note that range sync is for linear chain, so this is clearly an issue of the
|
|
153
|
-
return
|
|
168
|
+
// note that range sync is for linear chain, so this is clearly an issue of the parent batch
|
|
169
|
+
return {kind: ProcessingFaultKind.ParentBatch, parentBatch};
|
|
154
170
|
}
|
|
155
171
|
|
|
156
|
-
|
|
157
|
-
const
|
|
172
|
+
// `parentBatch` can be followed by 0-block batches, so its tail is the end of its own range
|
|
173
|
+
const parentTailSlot = parentBatch.startSlot + parentBatch.count - 1;
|
|
174
|
+
const parentHasFullTail =
|
|
158
175
|
code === BlockErrorCode.PARENT_PAYLOAD_UNKNOWN
|
|
159
|
-
? (
|
|
160
|
-
:
|
|
176
|
+
? (parentBatch.getPayloadEnvelopes()?.get(parentTailSlot)?.hasPayloadEnvelope() ?? false)
|
|
177
|
+
: parentBatch.getBlocks().some((b) => b.slot === parentTailSlot);
|
|
161
178
|
|
|
162
|
-
|
|
179
|
+
// With 0-block batches in between, it could be a wrong 0-block batch
|
|
180
|
+
const hasZeroBlockGap = parentTailSlot + 1 < batch.startSlot;
|
|
181
|
+
|
|
182
|
+
// Assumes the tail block / payload delivered by `parentBatch` is canonical. If it is orphaned, `parentBatch` is at
|
|
183
|
+
// fault: `batch` keeps failing until MAX_PROCESSING_ATTEMPTS and a new SyncChain is created.
|
|
184
|
+
if (parentHasFullTail && !hasZeroBlockGap) {
|
|
185
|
+
return {kind: ProcessingFaultKind.CurrentBatch};
|
|
186
|
+
}
|
|
187
|
+
return {kind: ProcessingFaultKind.Ambiguous, parentBatch};
|
|
163
188
|
}
|
|
@@ -52,7 +52,7 @@ export class ChainPeersBalancer {
|
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Return the most suitable peer to retry
|
|
55
|
-
* Sort peers by (1) less active requests (
|
|
55
|
+
* Sort peers by (1) fewer failed attempts for this batch (2) less active requests (3) most columns we need.
|
|
56
56
|
* Peers that failed this batch or already succeeded for the same request are excluded inside `filterPeers`.
|
|
57
57
|
*/
|
|
58
58
|
bestPeerToRetryBatch(batch: Batch): PeerSyncMeta | undefined {
|
|
@@ -63,9 +63,12 @@ export class ChainPeersBalancer {
|
|
|
63
63
|
// TODO(fulu): This is fulu specific and hinders our peer selection PreFulu
|
|
64
64
|
const pendingDataColumns = columnsRequest?.columns ?? this.custodyConfig.sampledColumns;
|
|
65
65
|
const eligiblePeers = this.filterPeers(batch, pendingDataColumns, false);
|
|
66
|
+
const triedPeerCounts = batch.getTriedPeerCounts();
|
|
66
67
|
|
|
67
68
|
const sortedBestPeers = sortBy(
|
|
68
69
|
eligiblePeers,
|
|
70
|
+
// prefer peers not tried for this batch yet
|
|
71
|
+
({syncInfo}) => triedPeerCounts.get(syncInfo.peerId) ?? 0,
|
|
69
72
|
({syncInfo}) => this.activeRequestsByPeer.get(syncInfo.peerId) ?? 0, // prefer peers with least active req
|
|
70
73
|
({columns}) => -1 * columns // prefer peers with the most columns
|
|
71
74
|
);
|
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
|
};
|