@lodestar/beacon-node 1.51.0-dev.0b0a00b836 → 1.51.0-dev.0bb5c87a7e
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/validator/index.d.ts +6 -0
- package/lib/api/impl/validator/index.d.ts.map +1 -1
- package/lib/api/impl/validator/index.js +38 -25
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.d.ts +2 -10
- package/lib/chain/blocks/importExecutionPayload.d.ts.map +1 -1
- package/lib/chain/blocks/importExecutionPayload.js +2 -14
- package/lib/chain/blocks/importExecutionPayload.js.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeProcessor.d.ts +10 -7
- package/lib/chain/blocks/payloadEnvelopeProcessor.d.ts.map +1 -1
- package/lib/chain/blocks/payloadEnvelopeProcessor.js +21 -16
- package/lib/chain/blocks/payloadEnvelopeProcessor.js.map +1 -1
- package/lib/chain/blocks/types.d.ts +4 -1
- package/lib/chain/blocks/types.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlock.js +17 -6
- package/lib/chain/blocks/verifyBlock.js.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.d.ts.map +1 -1
- package/lib/chain/blocks/verifyBlocksSignatures.js +7 -5
- package/lib/chain/blocks/verifyBlocksSignatures.js.map +1 -1
- package/lib/chain/blocks/verifyPayloadsDataAvailability.d.ts.map +1 -1
- package/lib/chain/blocks/verifyPayloadsDataAvailability.js +1 -3
- package/lib/chain/blocks/verifyPayloadsDataAvailability.js.map +1 -1
- package/lib/chain/bls/interface.d.ts +2 -0
- package/lib/chain/bls/interface.d.ts.map +1 -1
- package/lib/chain/bls/multithread/index.d.ts.map +1 -1
- package/lib/chain/bls/multithread/index.js +8 -6
- package/lib/chain/bls/multithread/index.js.map +1 -1
- package/lib/db/flatFileStore/flatFileStore.js +5 -5
- package/lib/db/flatFileStore/flatFileStore.js.map +1 -1
- package/lib/db/flatFileStore/slotIndex.d.ts.map +1 -1
- package/lib/db/flatFileStore/slotIndex.js +2 -2
- package/lib/db/flatFileStore/slotIndex.js.map +1 -1
- package/lib/execution/builder/apiClient.d.ts +14 -8
- package/lib/execution/builder/apiClient.d.ts.map +1 -1
- package/lib/execution/builder/apiClient.js +12 -10
- package/lib/execution/builder/apiClient.js.map +1 -1
- package/lib/execution/builder/http.d.ts +2 -0
- package/lib/execution/builder/http.d.ts.map +1 -1
- package/lib/execution/builder/http.js +2 -0
- package/lib/execution/builder/http.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/libp2p/index.d.ts.map +1 -1
- package/lib/network/libp2p/index.js +5 -1
- package/lib/network/libp2p/index.js.map +1 -1
- package/lib/network/options.d.ts +2 -0
- package/lib/network/options.d.ts.map +1 -1
- package/lib/network/options.js.map +1 -1
- package/lib/network/processor/gossipHandlers.js +3 -3
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +1 -0
- package/lib/node/nodejs.js.map +1 -1
- package/lib/node/options.d.ts +3 -1
- package/lib/node/options.d.ts.map +1 -1
- package/lib/node/options.js +4 -2
- package/lib/node/options.js.map +1 -1
- package/lib/util/file.d.ts.map +1 -1
- package/lib/util/file.js +8 -9
- package/lib/util/file.js.map +1 -1
- package/package.json +16 -17
- package/src/api/impl/validator/index.ts +43 -29
- package/src/chain/blocks/importExecutionPayload.ts +2 -20
- package/src/chain/blocks/payloadEnvelopeProcessor.ts +32 -21
- package/src/chain/blocks/types.ts +4 -1
- package/src/chain/blocks/verifyBlock.ts +30 -16
- package/src/chain/blocks/verifyBlocksSignatures.ts +7 -5
- package/src/chain/blocks/verifyPayloadsDataAvailability.ts +1 -3
- package/src/chain/bls/interface.ts +2 -0
- package/src/chain/bls/multithread/index.ts +9 -5
- package/src/db/flatFileStore/flatFileStore.ts +7 -7
- package/src/db/flatFileStore/slotIndex.ts +4 -3
- package/src/execution/builder/apiClient.ts +16 -13
- package/src/execution/builder/http.ts +4 -0
- package/src/metrics/metrics/lodestar.ts +5 -0
- package/src/network/libp2p/index.ts +5 -1
- package/src/network/options.ts +2 -0
- package/src/network/processor/gossipHandlers.ts +3 -3
- package/src/node/nodejs.ts +1 -0
- package/src/node/options.ts +5 -1
- package/src/util/file.ts +8 -9
|
@@ -94,7 +94,7 @@ import {
|
|
|
94
94
|
import {validateGossipProposerPreferences} from "../../../chain/validation/proposerPreferences.js";
|
|
95
95
|
import {validateSyncCommitteeGossipContributionAndProof} from "../../../chain/validation/syncCommitteeContributionAndProof.js";
|
|
96
96
|
import {ZERO_HASH} from "../../../constants/index.js";
|
|
97
|
-
import {
|
|
97
|
+
import {BuilderApiBid, decodeBuilderUrl} from "../../../execution/builder/apiClient.js";
|
|
98
98
|
import {BuilderStatus, NoBidReceived} from "../../../execution/builder/http.js";
|
|
99
99
|
import {getBuilderBidTotalGwei, validateBuilderApiExecutionPayloadBid} from "../../../execution/builder/validateBid.js";
|
|
100
100
|
import {validateGossipFnRetryUnknownRoot} from "../../../network/processor/gossipHandlers.js";
|
|
@@ -123,10 +123,14 @@ import {
|
|
|
123
123
|
* A cutoff of 1667 BPS (2 seconds for 12s slots) gives enough time and if there are unexpected delays
|
|
124
124
|
* it ensures we publish in time as proposals after the attestation deadline will likely be orphaned
|
|
125
125
|
* due to proposer boost reorg.
|
|
126
|
-
*
|
|
127
|
-
* TODO GLOAS: re-evaluate cutoff timing due to attestation deadline changes in gloas
|
|
128
126
|
*/
|
|
129
127
|
const BLOCK_PRODUCTION_RACE_CUTOFF_BPS = 1667;
|
|
128
|
+
/**
|
|
129
|
+
* Post-gloas cutoff, kept at 1667 BPS (2 seconds for 12s slots) for now.
|
|
130
|
+
*
|
|
131
|
+
* TODO GLOAS: revisit, the block propagates faster as it only commits to a bid and the attestation deadline changed
|
|
132
|
+
*/
|
|
133
|
+
export const BLOCK_PRODUCTION_RACE_CUTOFF_GLOAS_BPS = 1667;
|
|
130
134
|
/** Rejection message of the bid block branch when there is no viable bid to commit to */
|
|
131
135
|
const NO_BID_AVAILABLE = "No builder bid available";
|
|
132
136
|
|
|
@@ -1005,33 +1009,50 @@ export function getValidatorApi(
|
|
|
1005
1009
|
(!circuitBreakerActive &&
|
|
1006
1010
|
chain.executionPayloadBidPool.getBestBid(slot, bidParentBlockHash, parentBlockRootHex) !== null);
|
|
1007
1011
|
|
|
1008
|
-
//
|
|
1009
|
-
//
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
});
|
|
1022
|
-
return null;
|
|
1023
|
-
}
|
|
1024
|
-
return p2pBid;
|
|
1025
|
-
});
|
|
1012
|
+
// Calculate cutoff time based on start of the slot, ensures a slow local payload build does
|
|
1013
|
+
// not delay the proposal when a builder bid block is available (and vice versa)
|
|
1014
|
+
const cutoffMs = Math.max(
|
|
1015
|
+
0,
|
|
1016
|
+
config.getSlotComponentDurationMs(fork, BLOCK_PRODUCTION_RACE_CUTOFF_GLOAS_BPS) - chain.clock.msFromSlot(slot)
|
|
1017
|
+
);
|
|
1018
|
+
|
|
1019
|
+
// Give p2p bids the same time to bid up as granted to builder API bid requests via the advertised
|
|
1020
|
+
// deadline, the pool is read once the deadline passed and the bid requests settled. A late request
|
|
1021
|
+
// does not wait past the race cutoff, a pooled bid is still the fastest fallback if the local block fails
|
|
1022
|
+
const bidDeadlinePromise = circuitBreakerActive
|
|
1023
|
+
? Promise.resolve()
|
|
1024
|
+
: sleep(Math.min(chain.builderApiClient.bidDeadline, cutoffMs));
|
|
1026
1025
|
|
|
1027
1026
|
// Candidates are ranked by their boosted counted total payment, the p2p bid is governed
|
|
1028
1027
|
// by the top-level factors and each builder API bid by its own entry. Ties prefer the
|
|
1029
1028
|
// earliest received builder API bid, so the signed block can be routed back to its
|
|
1030
1029
|
// builder directly.
|
|
1031
1030
|
const bestBidPromise: Promise<BidCandidate | null> = (async () => {
|
|
1032
|
-
|
|
1031
|
+
// Past the race cutoff a pooled p2p bid is used right away rather than waiting for pending
|
|
1032
|
+
// builder API requests, the local block is selected at the cutoff anyway if it is ready
|
|
1033
|
+
let [builderApiBids] = await Promise.all([
|
|
1034
|
+
Promise.race([builderApiBidsPromise, sleep(cutoffMs).then(() => null)]),
|
|
1035
|
+
bidDeadlinePromise,
|
|
1036
|
+
]);
|
|
1033
1037
|
let parentExecutionRequestsPromise: Promise<gloas.ExecutionRequests> | null = null;
|
|
1034
1038
|
|
|
1039
|
+
let p2pBid: PooledExecutionPayloadBid | null = circuitBreakerActive
|
|
1040
|
+
? null
|
|
1041
|
+
: chain.executionPayloadBidPool.getBestBid(slot, bidParentBlockHash, parentBlockRootHex);
|
|
1042
|
+
// Discard p2p bids below the proposer's configured floor on the total payment.
|
|
1043
|
+
// A p2p bid's total is just its value since gossip validation enforces executionPayment=0.
|
|
1044
|
+
if (p2pBid !== null && BigInt(p2pBid.signedBid.message.value) < builderConfig.minBid) {
|
|
1045
|
+
logger.info("Best p2p bid below configured minimum", {
|
|
1046
|
+
slot,
|
|
1047
|
+
bidValue: prettyGweiToEth(p2pBid.signedBid.message.value),
|
|
1048
|
+
minBid: prettyGweiToEth(builderConfig.minBid),
|
|
1049
|
+
});
|
|
1050
|
+
p2pBid = null;
|
|
1051
|
+
}
|
|
1052
|
+
if (builderApiBids === null) {
|
|
1053
|
+
builderApiBids = p2pBid !== null ? [] : await builderApiBidsPromise;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1035
1056
|
const candidates = (
|
|
1036
1057
|
await Promise.all(
|
|
1037
1058
|
builderApiBids.map(async ({url, entry, signedBid, receivedMs}): Promise<BidCandidate | null> => {
|
|
@@ -1118,13 +1139,6 @@ export function getValidatorApi(
|
|
|
1118
1139
|
return fn().finally(() => t?.({source}));
|
|
1119
1140
|
};
|
|
1120
1141
|
|
|
1121
|
-
// Calculate cutoff time based on start of the slot, ensures a slow local payload build does
|
|
1122
|
-
// not delay the proposal when a builder bid block is available (and vice versa)
|
|
1123
|
-
const cutoffMs = Math.max(
|
|
1124
|
-
0,
|
|
1125
|
-
config.getSlotComponentDurationMs(fork, BLOCK_PRODUCTION_RACE_CUTOFF_BPS) - chain.clock.msFromSlot(slot)
|
|
1126
|
-
);
|
|
1127
|
-
|
|
1128
1142
|
// use abort controller to stop waiting for the bid block if the engine block will be selected
|
|
1129
1143
|
const controller = new AbortController();
|
|
1130
1144
|
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
verifyExecutionPayloadEnvelope,
|
|
27
27
|
verifyExecutionPayloadEnvelopeSignature,
|
|
28
28
|
} from "./verifyExecutionPayloadEnvelope.js";
|
|
29
|
-
import {verifyPayloadsDataAvailability} from "./verifyPayloadsDataAvailability.js";
|
|
30
29
|
|
|
31
30
|
const EVENTSTREAM_EMIT_RECENT_EXECUTION_PAYLOAD_SLOTS = 64;
|
|
32
31
|
|
|
@@ -99,7 +98,8 @@ function toForkChoiceExecutionStatus(status: ExecutionPayloadStatus): PayloadExe
|
|
|
99
98
|
* are applied on the next block via processParentExecutionPayload.
|
|
100
99
|
*
|
|
101
100
|
* The DA wait must have run upstream (range sync awaits DA in `verifyBlocksInEpoch` for the
|
|
102
|
-
* whole segment; gossip / API path
|
|
101
|
+
* whole segment; the gossip / API / unknown-payload sync path waits in `PayloadEnvelopeProcessor`
|
|
102
|
+
* before the import is queued).
|
|
103
103
|
*
|
|
104
104
|
* Steps:
|
|
105
105
|
* 1. Emit `execution_payload_available` event for payload attestation
|
|
@@ -378,21 +378,3 @@ export async function importExecutionPayload(
|
|
|
378
378
|
delaySec,
|
|
379
379
|
});
|
|
380
380
|
}
|
|
381
|
-
|
|
382
|
-
/**
|
|
383
|
-
* Process an execution payload envelope end-to-end: wait for DA, then import.
|
|
384
|
-
*
|
|
385
|
-
* Used by the PayloadEnvelopeProcessor queue (gossip / API / unknown-payload sync) — i.e.
|
|
386
|
-
* callers that have NOT already awaited DA themselves. Range sync's inline dispatch in
|
|
387
|
-
* processBlocks skips this wrapper and calls `importExecutionPayload` directly, since
|
|
388
|
-
* `verifyBlocksInEpoch` already awaited DA for the segment.
|
|
389
|
-
*/
|
|
390
|
-
export async function processExecutionPayload(
|
|
391
|
-
this: BeaconChain,
|
|
392
|
-
payloadInput: PayloadEnvelopeInput,
|
|
393
|
-
signal: AbortSignal,
|
|
394
|
-
opts: ImportPayloadOpts = {}
|
|
395
|
-
): Promise<void> {
|
|
396
|
-
const {dataAvailabilityStatuses} = await verifyPayloadsDataAvailability(this.config, [payloadInput], signal);
|
|
397
|
-
await importExecutionPayload.call(this, payloadInput, dataAvailabilityStatuses[0], opts);
|
|
398
|
-
}
|
|
@@ -1,32 +1,37 @@
|
|
|
1
|
+
import {DataAvailabilityStatus} from "@lodestar/state-transition";
|
|
1
2
|
import {Metrics} from "../../metrics/metrics.js";
|
|
2
3
|
import {JobItemQueue} from "../../util/queue/index.js";
|
|
3
4
|
import type {BeaconChain} from "../chain.js";
|
|
4
5
|
import {PayloadEnvelopeInput} from "../seenCache/seenPayloadEnvelopeInput.js";
|
|
5
|
-
import {
|
|
6
|
+
import {importExecutionPayload} from "./importExecutionPayload.js";
|
|
6
7
|
import {ImportPayloadOpts} from "./types.js";
|
|
8
|
+
import {verifyPayloadsDataAvailability} from "./verifyPayloadsDataAvailability.js";
|
|
7
9
|
|
|
8
10
|
// TODO GLOAS: Set to be equal to DEFAULT_MAX_PENDING_UNFINALIZED_PAYLOAD_ENVELOPE_WRITES for now
|
|
9
11
|
const QUEUE_MAX_LENGTH = 16;
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* PayloadEnvelopeProcessor
|
|
14
|
+
* PayloadEnvelopeProcessor imports payload envelopes in a queued fashion, one after the other.
|
|
13
15
|
*
|
|
14
|
-
* Jobs are
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* caller observes the real import outcome. Resolving duplicates early instead would let
|
|
16
|
+
* Jobs are triggered only on envelope arrival (gossip or API). The envelope may reach us before the
|
|
17
|
+
* sampled data columns, the data availability wait runs before the job is queued. Duplicate
|
|
18
|
+
* triggers for the same payloadInput are deduped by sharing the in-flight promise: every caller
|
|
19
|
+
* observes the real import outcome. Resolving duplicates early instead would let
|
|
19
20
|
* BlockInputSync mark a still-pending payload as processed, re-queue it, and spin re-processing
|
|
20
21
|
* the same root until OOM while the import is blocked (e.g. EL syncing).
|
|
21
22
|
*/
|
|
22
23
|
export class PayloadEnvelopeProcessor {
|
|
23
|
-
readonly jobQueue: JobItemQueue<[PayloadEnvelopeInput, ImportPayloadOpts], void>;
|
|
24
|
+
readonly jobQueue: JobItemQueue<[PayloadEnvelopeInput, DataAvailabilityStatus, ImportPayloadOpts], void>;
|
|
24
25
|
private readonly imports = new WeakMap<PayloadEnvelopeInput, Promise<void>>();
|
|
25
26
|
|
|
26
|
-
constructor(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
constructor(
|
|
28
|
+
private readonly chain: BeaconChain,
|
|
29
|
+
metrics: Metrics | null,
|
|
30
|
+
private readonly signal: AbortSignal
|
|
31
|
+
) {
|
|
32
|
+
this.jobQueue = new JobItemQueue<[PayloadEnvelopeInput, DataAvailabilityStatus, ImportPayloadOpts], void>(
|
|
33
|
+
(payloadInput, dataAvailabilityStatus, opts) => {
|
|
34
|
+
return importExecutionPayload.call(chain, payloadInput, dataAvailabilityStatus, opts);
|
|
30
35
|
},
|
|
31
36
|
{maxLength: QUEUE_MAX_LENGTH, noYieldIfOneItem: true, signal},
|
|
32
37
|
metrics?.payloadEnvelopeProcessorQueue ?? undefined
|
|
@@ -39,15 +44,7 @@ export class PayloadEnvelopeProcessor {
|
|
|
39
44
|
return existing;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
// Re-check after await, as another call may have queued this payload.
|
|
45
|
-
const queued = this.imports.get(payloadInput);
|
|
46
|
-
if (queued !== undefined) {
|
|
47
|
-
return queued;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const importPromise = this.jobQueue.push(payloadInput, opts);
|
|
47
|
+
const importPromise = this.waitForDataAndImport(payloadInput, opts);
|
|
51
48
|
this.imports.set(payloadInput, importPromise);
|
|
52
49
|
|
|
53
50
|
try {
|
|
@@ -59,4 +56,18 @@ export class PayloadEnvelopeProcessor {
|
|
|
59
56
|
throw e;
|
|
60
57
|
}
|
|
61
58
|
}
|
|
59
|
+
|
|
60
|
+
private async waitForDataAndImport(payloadInput: PayloadEnvelopeInput, opts: ImportPayloadOpts): Promise<void> {
|
|
61
|
+
const {dataAvailabilityStatuses} = await verifyPayloadsDataAvailability(
|
|
62
|
+
this.chain.config,
|
|
63
|
+
[payloadInput],
|
|
64
|
+
this.signal
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
while (this.jobQueue.jobLen >= QUEUE_MAX_LENGTH) {
|
|
68
|
+
await this.jobQueue.waitForSpace();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this.jobQueue.push(payloadInput, dataAvailabilityStatuses[0], opts);
|
|
72
|
+
}
|
|
62
73
|
}
|
|
@@ -109,7 +109,10 @@ export type FullyVerifiedBlock = {
|
|
|
109
109
|
parentBlockSlot: Slot;
|
|
110
110
|
proposerBalanceDelta: number;
|
|
111
111
|
dataAvailabilityStatus: DataAvailabilityStatus;
|
|
112
|
-
/**
|
|
112
|
+
/**
|
|
113
|
+
* Pre-computed indexed attestations from signature verification to avoid duplicate work.
|
|
114
|
+
* Their `attestingIndices` are in committee order, not sorted, so they are not spec-valid `IndexedAttestation`s.
|
|
115
|
+
*/
|
|
113
116
|
indexedAttestations: IndexedAttestation[];
|
|
114
117
|
/** Seen timestamp seconds */
|
|
115
118
|
seenTimestampSec: number;
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
DataAvailabilityStatus,
|
|
5
5
|
IBeaconStateView,
|
|
6
6
|
computeEpochAtSlot,
|
|
7
|
-
|
|
7
|
+
getAttestingIndices,
|
|
8
8
|
signedBlockToSignedHeader,
|
|
9
9
|
} from "@lodestar/state-transition";
|
|
10
10
|
import {IndexedAttestation, Slot, deneb} from "@lodestar/types";
|
|
@@ -119,7 +119,13 @@ export async function verifyBlocksInEpoch(
|
|
|
119
119
|
const shuffling =
|
|
120
120
|
this.shufflingCache.getSync(attEpoch, preState0.getShufflingDecisionRoot(attEpoch)) ??
|
|
121
121
|
preState0.getShufflingAtEpoch(attEpoch);
|
|
122
|
-
|
|
122
|
+
// Unlike getIndexedAttestation, keep attestingIndices in committee order: sorting them dominates building
|
|
123
|
+
// these on mainnet blocks. See FullyVerifiedBlock.indexedAttestations.
|
|
124
|
+
return {
|
|
125
|
+
attestingIndices: getAttestingIndices(shuffling, fork, attestation),
|
|
126
|
+
data: attestation.data,
|
|
127
|
+
signature: attestation.signature,
|
|
128
|
+
};
|
|
123
129
|
});
|
|
124
130
|
}
|
|
125
131
|
|
|
@@ -175,16 +181,29 @@ export async function verifyBlocksInEpoch(
|
|
|
175
181
|
const [
|
|
176
182
|
segmentExecStatus,
|
|
177
183
|
{blockDAStatuses, payloadDAStatuses, availableTime},
|
|
178
|
-
{postStates, proposerBalanceDeltas, verifyStateTime},
|
|
179
184
|
{verifySignaturesTime},
|
|
185
|
+
{postStates, proposerBalanceDeltas, verifyStateTime},
|
|
180
186
|
] = await Promise.all([
|
|
181
187
|
verifyExecutionPayloadsPromise,
|
|
182
188
|
|
|
183
189
|
// data availability (fork-specific; see daAvailabilityPromise above)
|
|
184
190
|
daAvailabilityPromise,
|
|
185
191
|
|
|
192
|
+
// All signatures at once. Must be called before verifyBlocksStateTransitionOnly()
|
|
193
|
+
// so we hand the BLS job to the worker pool before the main thread
|
|
194
|
+
// is busy with the state transition.
|
|
195
|
+
verifyBlocksSignatures(
|
|
196
|
+
this.config,
|
|
197
|
+
this.bls,
|
|
198
|
+
this.logger,
|
|
199
|
+
this.metrics,
|
|
200
|
+
preState0,
|
|
201
|
+
blocks,
|
|
202
|
+
indexedAttestationsByBlock,
|
|
203
|
+
opts
|
|
204
|
+
),
|
|
205
|
+
|
|
186
206
|
// Run state transition only
|
|
187
|
-
// TODO: Ensure it yields to allow flushing to workers and engine API
|
|
188
207
|
verifyBlocksStateTransitionOnly(
|
|
189
208
|
preState0,
|
|
190
209
|
blockInputs,
|
|
@@ -198,22 +217,17 @@ export async function verifyBlocksInEpoch(
|
|
|
198
217
|
opts
|
|
199
218
|
),
|
|
200
219
|
|
|
201
|
-
// All signatures at once
|
|
202
|
-
verifyBlocksSignatures(
|
|
203
|
-
this.config,
|
|
204
|
-
this.bls,
|
|
205
|
-
this.logger,
|
|
206
|
-
this.metrics,
|
|
207
|
-
preState0,
|
|
208
|
-
blocks,
|
|
209
|
-
indexedAttestationsByBlock,
|
|
210
|
-
opts
|
|
211
|
-
),
|
|
212
|
-
|
|
213
220
|
// TODO GLOAS: can verify payload signatures in batch too
|
|
214
221
|
// maybe chain with the above verifyBlocksSignatures()
|
|
215
222
|
]);
|
|
216
223
|
|
|
224
|
+
if (blockInputs.length === 1 && opts.seenTimestampSec !== undefined) {
|
|
225
|
+
const consensusVerifiedTime = Math.max(verifyStateTime, verifySignaturesTime);
|
|
226
|
+
this.metrics?.gossipBlock.receivedToConsensusVerifiedTime.observe(
|
|
227
|
+
consensusVerifiedTime / 1000 - opts.seenTimestampSec
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
217
231
|
for (const blockInput of blockInputs) {
|
|
218
232
|
const block = blockInput.getBlock();
|
|
219
233
|
const {slot, proposerIndex} = block.message;
|
|
@@ -36,10 +36,9 @@ export async function verifyBlocksSignatures(
|
|
|
36
36
|
? preState0.currentSyncCommitteeIndexed
|
|
37
37
|
: new SyncCommitteeCacheEmpty();
|
|
38
38
|
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
// so the attester and proposer shufflings are correct.
|
|
39
|
+
// Runs concurrently with the state transition. Signature sets are built from preState0, which
|
|
40
|
+
// verifyBlocksInEpoch() guarantees is in the same epoch as every block, so the proposer and attester shufflings
|
|
41
|
+
// and the sync committee are the ones the blocks were signed under.
|
|
43
42
|
for (const [i, block] of blocks.entries()) {
|
|
44
43
|
// Use [i] to make clear that the index has to be correct to blame the right block below on BlockError()
|
|
45
44
|
isValidPromises[i] = opts.validSignatures
|
|
@@ -50,7 +49,10 @@ export async function verifyBlocksSignatures(
|
|
|
50
49
|
bls.verifySignatureSets(
|
|
51
50
|
getBlockSignatureSets(config, currentSyncCommitteeIndexed, preState0, block, indexedAttestationsByBlock[i], {
|
|
52
51
|
skipProposerSignature: opts.validProposerSignature,
|
|
53
|
-
})
|
|
52
|
+
}),
|
|
53
|
+
// Prioritize block verification over attestations, since
|
|
54
|
+
// attestations already buffer up to `MAX_BUFFER_WAIT_MS`
|
|
55
|
+
{priority: true}
|
|
54
56
|
);
|
|
55
57
|
|
|
56
58
|
// getBlockSignatureSets() takes 45ms in benchmarks for 2022Q2 mainnet blocks (100 sigs). When syncing a 32 blocks
|
|
@@ -22,9 +22,7 @@ export async function verifyPayloadsDataAvailability(
|
|
|
22
22
|
const promises: Promise<gloas.DataColumnSidecar[]>[] = [];
|
|
23
23
|
for (const payloadInput of payloadInputs) {
|
|
24
24
|
if (!payloadInput.hasAllData()) {
|
|
25
|
-
// Sync and reconstruction keep pulling the data columns from the network while we wait
|
|
26
|
-
// capped at one slot because the payload queue is serial: a longer wait lets consecutive unavailable
|
|
27
|
-
// payloads push every later payload import further behind with each slot.
|
|
25
|
+
// Sync and reconstruction keep pulling the data columns from the network while we wait
|
|
28
26
|
promises.push(
|
|
29
27
|
payloadInput.waitForAllData(config.getSlotDurationMs(payloadInput.forkName), signal).catch((e) => {
|
|
30
28
|
if (e instanceof TimeoutError) {
|
|
@@ -22,6 +22,8 @@ export type VerifySignatureOpts = {
|
|
|
22
22
|
verifyOnMainThread?: boolean;
|
|
23
23
|
/**
|
|
24
24
|
* Some signature sets are more important than others, and should be verified first.
|
|
25
|
+
* Non-batchable priority jobs are posted to an idle worker before this call returns, so the caller
|
|
26
|
+
* can run synchronous work right after without delaying the verification.
|
|
25
27
|
*/
|
|
26
28
|
priority?: boolean;
|
|
27
29
|
};
|
|
@@ -333,15 +333,19 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
+
// First hand work to an idle worker before returning to the caller.
|
|
337
|
+
// Deferring the post to the next macrotask would make the worker
|
|
338
|
+
// sit idle while waiting for the next synchronous work
|
|
339
|
+
else if (job.opts.priority) {
|
|
340
|
+
this.jobs.unshift(job);
|
|
341
|
+
void this.runJob();
|
|
342
|
+
}
|
|
343
|
+
|
|
336
344
|
// Push job and schedule to call `runJob` in the next macro event loop cycle.
|
|
337
345
|
// This is useful to allow batching job submitted from a synchronous for loop,
|
|
338
346
|
// and to prevent large stacks since runJob may be called recursively.
|
|
339
347
|
else {
|
|
340
|
-
|
|
341
|
-
this.jobs.unshift(job);
|
|
342
|
-
} else {
|
|
343
|
-
this.jobs.push(job);
|
|
344
|
-
}
|
|
348
|
+
this.jobs.push(job);
|
|
345
349
|
callInNextEventLoop(() => void this.runJob());
|
|
346
350
|
}
|
|
347
351
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {type FileHandle, open, readFile, rm} from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import {ChainForkConfig} from "@lodestar/config";
|
|
4
4
|
import {ForkPostFulu} from "@lodestar/params";
|
|
@@ -172,7 +172,7 @@ export class FlatFileStore implements IFlatFileStore {
|
|
|
172
172
|
for (const slot of slotsToPrune) {
|
|
173
173
|
const release = await this.acquireMutationLock(slot);
|
|
174
174
|
try {
|
|
175
|
-
await
|
|
175
|
+
await rm(path.join(this.dataColumnDir, padSlot(slot)), {recursive: true, force: true});
|
|
176
176
|
this.slotIndex.remove(slot);
|
|
177
177
|
this.metrics?.prunedDirectories.inc();
|
|
178
178
|
} finally {
|
|
@@ -212,7 +212,7 @@ export class FlatFileStore implements IFlatFileStore {
|
|
|
212
212
|
|
|
213
213
|
private async readFile(slot: Slot, rootHex: RootHex): Promise<Uint8Array | null> {
|
|
214
214
|
try {
|
|
215
|
-
return await
|
|
215
|
+
return await readFile(this.filePath(slot, rootHex));
|
|
216
216
|
} catch (e) {
|
|
217
217
|
if (!isFsNotFoundError(e)) throw e;
|
|
218
218
|
return null;
|
|
@@ -224,9 +224,9 @@ export class FlatFileStore implements IFlatFileStore {
|
|
|
224
224
|
rootHex: RootHex,
|
|
225
225
|
indices: number[]
|
|
226
226
|
): Promise<(Uint8Array | undefined)[] | null> {
|
|
227
|
-
let fd:
|
|
227
|
+
let fd: FileHandle;
|
|
228
228
|
try {
|
|
229
|
-
fd = await
|
|
229
|
+
fd = await open(this.filePath(slot, rootHex), "r");
|
|
230
230
|
} catch (e) {
|
|
231
231
|
if (!isFsNotFoundError(e)) throw e;
|
|
232
232
|
return null;
|
|
@@ -270,7 +270,7 @@ export class FlatFileStore implements IFlatFileStore {
|
|
|
270
270
|
await observeFlatFileStoreOperation(this.metrics, FlatFileStoreOperation.delete, async () => {
|
|
271
271
|
const release = await this.acquireMutationLock(slot);
|
|
272
272
|
try {
|
|
273
|
-
await
|
|
273
|
+
await rm(this.filePath(slot, rootHex), {force: true});
|
|
274
274
|
} finally {
|
|
275
275
|
release();
|
|
276
276
|
}
|
|
@@ -294,7 +294,7 @@ function validateDcolHeader(header: DcolHeader, slot: Slot, rootHex: RootHex): v
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
async function readExactly(fd:
|
|
297
|
+
async function readExactly(fd: FileHandle, buffer: Uint8Array, position: number): Promise<void> {
|
|
298
298
|
let totalRead = 0;
|
|
299
299
|
while (totalRead < buffer.length) {
|
|
300
300
|
const {bytesRead} = await fd.read(buffer, totalRead, buffer.length - totalRead, position + totalRead);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type {Dirent} from "node:fs";
|
|
2
|
+
import {readdir} from "node:fs/promises";
|
|
2
3
|
import {Slot} from "@lodestar/types";
|
|
3
4
|
import {isFsNotFoundError} from "./errors.js";
|
|
4
5
|
import {padSlot} from "./path.js";
|
|
@@ -33,9 +34,9 @@ export class SlotIndex {
|
|
|
33
34
|
|
|
34
35
|
async rebuildFromDisk(columnsDir: string): Promise<SlotIndexRebuildStats> {
|
|
35
36
|
this.slots.clear();
|
|
36
|
-
let entries:
|
|
37
|
+
let entries: Dirent[];
|
|
37
38
|
try {
|
|
38
|
-
entries = await
|
|
39
|
+
entries = await readdir(columnsDir, {withFileTypes: true});
|
|
39
40
|
} catch (e) {
|
|
40
41
|
if (!isFsNotFoundError(e)) throw e;
|
|
41
42
|
return {slots: 0, ignoredEntries: 0};
|
|
@@ -19,21 +19,20 @@ import {IClock} from "../../util/clock.js";
|
|
|
19
19
|
* Additional duration to account for potential event loop lag which causes
|
|
20
20
|
* builder bids to be rejected even though the response was sent in time.
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
22
|
+
export const BUILDER_BID_LAG_BUFFER_MS = 250;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
26
|
-
* is reached, advertised on each bid request via the `X-Timeout-Ms` header.
|
|
27
|
-
*
|
|
25
|
+
* Default duration given to a builder to provide a `SignedExecutionPayloadBid` before the deadline
|
|
26
|
+
* is reached, advertised on each bid request via the `X-Timeout-Ms` header. Bids received via
|
|
27
|
+
* p2p are given the same time to bid up.
|
|
28
28
|
*/
|
|
29
|
-
export const
|
|
30
|
-
|
|
31
|
-
/** Local timeout for bid requests, event loop lag must not discard bids that arrived in time */
|
|
32
|
-
export const BUILDER_BID_REQUEST_TIMEOUT_MS = BUILDER_BID_DEADLINE_MS + EVENT_LOOP_LAG_BUFFER;
|
|
29
|
+
export const DEFAULT_BUILDER_BID_DEADLINE_MS = 500;
|
|
33
30
|
|
|
34
31
|
export type BuilderApiClientOpts = {
|
|
35
|
-
/** Timeout for builder api requests, bid requests
|
|
32
|
+
/** Timeout for builder api requests, bid requests are bounded by `bidDeadline` instead */
|
|
36
33
|
timeout?: number;
|
|
34
|
+
/** Time builders are given to provide a bid once block production starts, in milliseconds */
|
|
35
|
+
bidDeadline?: number;
|
|
37
36
|
// Add User-Agent header to all requests
|
|
38
37
|
userAgent?: string;
|
|
39
38
|
};
|
|
@@ -69,6 +68,7 @@ export type BuilderApiBid = {
|
|
|
69
68
|
* each block production request, clients are dialed on demand based on the entry `url`.
|
|
70
69
|
*/
|
|
71
70
|
export class BuilderApiClient {
|
|
71
|
+
readonly bidDeadline: number;
|
|
72
72
|
private readonly clients = new Map<BuilderUrl, BuilderApi>();
|
|
73
73
|
|
|
74
74
|
constructor(
|
|
@@ -78,7 +78,9 @@ export class BuilderApiClient {
|
|
|
78
78
|
private readonly bls: IBlsVerifier,
|
|
79
79
|
private readonly metrics: Metrics | null = null,
|
|
80
80
|
private readonly logger?: Logger
|
|
81
|
-
) {
|
|
81
|
+
) {
|
|
82
|
+
this.bidDeadline = opts.bidDeadline ?? DEFAULT_BUILDER_BID_DEADLINE_MS;
|
|
83
|
+
}
|
|
82
84
|
|
|
83
85
|
/**
|
|
84
86
|
* Fan out bid requests to the builders named by the entries, one request per unique
|
|
@@ -139,9 +141,10 @@ export class BuilderApiClient {
|
|
|
139
141
|
proposerPubkey,
|
|
140
142
|
requestAuth: entry.auth,
|
|
141
143
|
dateMilliseconds: Date.now(),
|
|
142
|
-
timeoutMs:
|
|
144
|
+
timeoutMs: this.bidDeadline,
|
|
143
145
|
},
|
|
144
|
-
|
|
146
|
+
// Event loop lag must not discard bids that arrived in time
|
|
147
|
+
{timeoutMs: this.bidDeadline + BUILDER_BID_LAG_BUFFER_MS}
|
|
145
148
|
);
|
|
146
149
|
const signedBid = res.value();
|
|
147
150
|
if (signedBid === undefined) {
|
|
@@ -203,7 +206,7 @@ export class BuilderApiClient {
|
|
|
203
206
|
|
|
204
207
|
/**
|
|
205
208
|
* Establish the connection to every known builder outside the bid deadline, a cold TCP/TLS handshake
|
|
206
|
-
* to a distant builder can exhaust
|
|
209
|
+
* to a distant builder can exhaust the bid deadline on its own, and a long idle connection
|
|
207
210
|
* may be half-open and only fail once written to.
|
|
208
211
|
*/
|
|
209
212
|
async checkStatus(): Promise<void> {
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from "@lodestar/types";
|
|
21
21
|
import {toPrintableUrl} from "@lodestar/utils";
|
|
22
22
|
import {Metrics} from "../../metrics/metrics.js";
|
|
23
|
+
import {DEFAULT_BUILDER_BID_DEADLINE_MS} from "./apiClient.js";
|
|
23
24
|
import {ValidatorRegistration, ValidatorRegistrationCache} from "./cache.js";
|
|
24
25
|
import {IExecutionBuilder} from "./interface.js";
|
|
25
26
|
|
|
@@ -29,6 +30,8 @@ export type ExecutionBuilderHttpOpts = {
|
|
|
29
30
|
timeout?: number;
|
|
30
31
|
faultInspectionWindow?: number;
|
|
31
32
|
allowedFaults?: number;
|
|
33
|
+
/** Post-gloas only, time builders are given to provide a bid once block production starts, in milliseconds */
|
|
34
|
+
bidDeadline?: number;
|
|
32
35
|
|
|
33
36
|
// Only required for merge-mock runs, no need to expose it to cli
|
|
34
37
|
issueLocalFcUWithFeeRecipient?: string;
|
|
@@ -40,6 +43,7 @@ export const defaultExecutionBuilderHttpOpts: ExecutionBuilderHttpOpts = {
|
|
|
40
43
|
enabled: false,
|
|
41
44
|
url: "http://localhost:8661",
|
|
42
45
|
timeout: 12000,
|
|
46
|
+
bidDeadline: DEFAULT_BUILDER_BID_DEADLINE_MS,
|
|
43
47
|
};
|
|
44
48
|
|
|
45
49
|
export enum BuilderStatus {
|
|
@@ -1013,6 +1013,11 @@ export function createLodestarMetrics(
|
|
|
1013
1013
|
help: "Time elapsed between block received and fully verified state, signatures and payload",
|
|
1014
1014
|
buckets: [0.05, 0.1, 0.3, 0.5, 0.7, 1, 1.3, 1.6, 2, 2.5, 3, 3.5, 4],
|
|
1015
1015
|
}),
|
|
1016
|
+
receivedToConsensusVerifiedTime: register.histogram({
|
|
1017
|
+
name: "lodestar_gossip_block_received_to_consensus_verified_seconds",
|
|
1018
|
+
help: "Time from gossip block arrival until both the state transition and all block signature verifications are complete, excluding execution payload verification",
|
|
1019
|
+
buckets: [0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1],
|
|
1020
|
+
}),
|
|
1016
1021
|
verifiedToBlobsAvailabiltyTime: register.histogram<{numBlobs: number}>({
|
|
1017
1022
|
name: "lodestar_gossip_block_verified_to_blobs_availability_time",
|
|
1018
1023
|
help: "Time elapsed between block verified and blobs became available",
|
|
@@ -150,7 +150,11 @@ export async function createNodeJsLibp2p(
|
|
|
150
150
|
nodeInfo: {
|
|
151
151
|
name: "lodestar",
|
|
152
152
|
version: networkOpts.version ?? "unknown",
|
|
153
|
-
userAgent: networkOpts.private
|
|
153
|
+
userAgent: networkOpts.private
|
|
154
|
+
? ""
|
|
155
|
+
: networkOpts.advertiseVersion && networkOpts.version
|
|
156
|
+
? `lodestar/${networkOpts.version}`
|
|
157
|
+
: "lodestar",
|
|
154
158
|
},
|
|
155
159
|
addresses: {
|
|
156
160
|
listen: localMultiaddrs,
|
package/src/network/options.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface NetworkOptions
|
|
|
25
25
|
mdns?: boolean;
|
|
26
26
|
connectToDiscv5Bootnodes?: boolean;
|
|
27
27
|
version?: string;
|
|
28
|
+
/** Include the version in libp2p Identify. Private mode takes precedence. */
|
|
29
|
+
advertiseVersion?: boolean;
|
|
28
30
|
private?: boolean;
|
|
29
31
|
useWorker?: boolean;
|
|
30
32
|
maxYoungGenerationSizeMb?: number;
|
|
@@ -705,8 +705,8 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
705
705
|
|
|
706
706
|
// Immediately attempt fetch of data columns from execution engine as the bid contains kzg commitments
|
|
707
707
|
// which is all the information we need so there is no reason to delay until execution payload arrives
|
|
708
|
-
// Columns fetched here feed payloadInput.addColumn, which resolves waitForAllData
|
|
709
|
-
//
|
|
708
|
+
// Columns fetched here feed payloadInput.addColumn, which resolves the waitForAllData of a
|
|
709
|
+
// pending payload import. No processExecutionPayload trigger needed from this path.
|
|
710
710
|
chain.getBlobsTracker.triggerGetBlobs(payloadInput);
|
|
711
711
|
}
|
|
712
712
|
})
|
|
@@ -927,7 +927,7 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
|
|
|
927
927
|
}
|
|
928
928
|
|
|
929
929
|
// NOTE: we do NOT call chain.processExecutionPayload here. That is triggered only by
|
|
930
|
-
// envelope arrival (gossip or API).
|
|
930
|
+
// envelope arrival (gossip or API). A pending payload import is awaiting
|
|
931
931
|
// payloadInput.waitForAllData(); addColumn above will resolve it once hasAllData flips.
|
|
932
932
|
|
|
933
933
|
scheduleIncompletePayloadEnvelope(payloadInput, peerIdStr);
|
package/src/node/nodejs.ts
CHANGED
|
@@ -297,6 +297,7 @@ export class BeaconNode {
|
|
|
297
297
|
: undefined,
|
|
298
298
|
builderApiClientOpts: {
|
|
299
299
|
timeout: opts.executionBuilder.timeout,
|
|
300
|
+
bidDeadline: opts.executionBuilder.bidDeadline,
|
|
300
301
|
// Sent with all builder api requests, unless the node runs in private mode
|
|
301
302
|
userAgent: opts.executionBuilder.userAgent,
|
|
302
303
|
},
|