@lodestar/beacon-node 1.52.0-dev.e33126114e → 1.52.0-dev.e53da6424c
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.map +1 -1
- package/lib/api/impl/validator/index.js +2 -4
- 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.map +1 -1
- package/lib/chain/chain.js +9 -5
- 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 +1 -0
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +23 -15
- package/lib/chain/produceBlock/produceBlockBody.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/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.map +1 -1
- package/lib/execution/engine/http.js +2 -2
- package/lib/execution/engine/http.js.map +1 -1
- package/lib/execution/engine/interface.d.ts +14 -1
- 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/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/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/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 +60 -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/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 +17 -17
- package/src/api/impl/validator/index.ts +2 -4
- package/src/chain/archiveStore/utils/archiveBlocks.ts +1 -1
- package/src/chain/chain.ts +9 -5
- 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 +25 -16
- package/src/chain/validation/executionPayloadBid.ts +20 -2
- package/src/chain/validation/executionPayloadEnvelope.ts +28 -5
- package/src/chain/validation/voluntaryExit.ts +44 -6
- package/src/execution/engine/blockHash.ts +27 -0
- package/src/execution/engine/http.ts +3 -1
- package/src/execution/engine/interface.ts +14 -1
- package/src/execution/engine/mock.ts +13 -8
- package/src/execution/engine/payloadIdCache.ts +12 -4
- 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/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 +65 -21
- package/src/sync/utils/downloadByRange.ts +60 -26
- package/src/util/dataColumns.ts +4 -1
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
} from "@lodestar/state-transition";
|
|
8
8
|
import {gloas, ssz} from "@lodestar/types";
|
|
9
9
|
import {byteArrayEquals, toRootHex} from "@lodestar/utils";
|
|
10
|
+
import {computeExecutionBlockHash} from "../../execution/engine/blockHash.js";
|
|
10
11
|
import {
|
|
11
12
|
getBeaconBlockRootFromExecutionPayloadEnvelopeSerialized,
|
|
12
13
|
getSlotFromExecutionPayloadEnvelopeSerialized,
|
|
@@ -55,7 +56,7 @@ export function validateGossipExecutionPayloadEnvelopeSerialized(
|
|
|
55
56
|
|
|
56
57
|
const maxTransactionCount = getMaxTransactionCount(chain, block, payloadInput);
|
|
57
58
|
if (BigInt(transactionCount) > maxTransactionCount) {
|
|
58
|
-
throw new ExecutionPayloadEnvelopeError(GossipAction.
|
|
59
|
+
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
59
60
|
code: ExecutionPayloadEnvelopeErrorCode.TOO_MANY_TRANSACTIONS,
|
|
60
61
|
slot,
|
|
61
62
|
root: blockRootHex,
|
|
@@ -199,12 +200,13 @@ async function validateExecutionPayloadEnvelope(
|
|
|
199
200
|
});
|
|
200
201
|
}
|
|
201
202
|
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
//
|
|
203
|
+
// Execution request and withdrawal count limits are enforced by the SSZ list limits on decode
|
|
204
|
+
|
|
205
|
+
// [REJECT] The number of transactions is within the limit implied by the parent payload's gas limit,
|
|
206
|
+
// also checked before deserialization in validateGossipExecutionPayloadEnvelopeSerialized
|
|
205
207
|
const maxTransactionCount = getMaxTransactionCount(chain, block, payloadInput);
|
|
206
208
|
if (BigInt(payload.transactions.length) > maxTransactionCount) {
|
|
207
|
-
throw new ExecutionPayloadEnvelopeError(GossipAction.
|
|
209
|
+
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
208
210
|
code: ExecutionPayloadEnvelopeErrorCode.TOO_MANY_TRANSACTIONS,
|
|
209
211
|
slot: payload.slotNumber,
|
|
210
212
|
root: blockRootHex,
|
|
@@ -251,6 +253,8 @@ async function validateExecutionPayloadEnvelope(
|
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
// [REJECT] The payload contains no empty transactions
|
|
256
|
+
// An empty transaction is a deletion in the transactions trie, so trailing empty transactions would not change
|
|
257
|
+
// the block hash. The EL rejects such a payload, as `verify_and_notify_new_payload` does before hashing.
|
|
254
258
|
for (let i = 0; i < payload.transactions.length; i++) {
|
|
255
259
|
if (payload.transactions.getSize(i) === 0) {
|
|
256
260
|
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
@@ -275,6 +279,25 @@ async function validateExecutionPayloadEnvelope(
|
|
|
275
279
|
});
|
|
276
280
|
}
|
|
277
281
|
|
|
282
|
+
// [REJECT] The payload's block hash is computed correctly
|
|
283
|
+
const timer = chain.metrics?.gossipExecutionPayloadEnvelope.blockHashTime.startTimer();
|
|
284
|
+
const computedBlockHash = computeExecutionBlockHash(
|
|
285
|
+
blockState.forkName,
|
|
286
|
+
payload,
|
|
287
|
+
envelope.parentBeaconBlockRoot,
|
|
288
|
+
envelope.executionRequests
|
|
289
|
+
);
|
|
290
|
+
timer?.();
|
|
291
|
+
if (!byteArrayEquals(computedBlockHash, payload.blockHash)) {
|
|
292
|
+
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
293
|
+
code: ExecutionPayloadEnvelopeErrorCode.INVALID_BLOCK_HASH,
|
|
294
|
+
slot: payload.slotNumber,
|
|
295
|
+
root: blockRootHex,
|
|
296
|
+
blockHash: toRootHex(payload.blockHash),
|
|
297
|
+
computedBlockHash: toRootHex(computedBlockHash),
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
|
|
278
301
|
// [REJECT] `signed_execution_payload_envelope.signature` is valid as verified
|
|
279
302
|
// by `verify_execution_payload_envelope_signature`.
|
|
280
303
|
const signatureSet = getExecutionPayloadEnvelopeSignatureSet(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {FAR_FUTURE_EPOCH} from "@lodestar/params";
|
|
2
|
+
import {VoluntaryExitValidity, computeEpochAtSlot, getVoluntaryExitSignatureSet} from "@lodestar/state-transition";
|
|
2
3
|
import {phase0} from "@lodestar/types";
|
|
3
4
|
import {
|
|
4
5
|
GossipAction,
|
|
@@ -99,19 +100,56 @@ async function validateVoluntaryExit(
|
|
|
99
100
|
// The only condition that is time sensitive and may require a non-head state is
|
|
100
101
|
// -> Validator is active && validator has not initiated exit
|
|
101
102
|
// The voluntaryExit.epoch must be in the past but the validator's status may change in recent epochs.
|
|
102
|
-
// We dial the head state to the current epoch
|
|
103
|
-
// relevant on periods of many skipped slots.
|
|
104
|
-
const state = await chain.
|
|
103
|
+
// We dial the head state to the current epoch (with a MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance) to get the
|
|
104
|
+
// current status of the validator. This is relevant on periods of many skipped slots.
|
|
105
|
+
const state = await chain.getHeadStateAtEpoch(
|
|
106
|
+
computeEpochAtSlot(chain.clock.currentSlotWithGossipDisparity),
|
|
107
|
+
RegenCaller.validateGossipVoluntaryExit
|
|
108
|
+
);
|
|
105
109
|
|
|
106
|
-
// [REJECT] All of the conditions within process_voluntary_exit pass validation.
|
|
107
110
|
// verifySignature = false, verified in batch below
|
|
108
111
|
const validity = state.getVoluntaryExitValidity(voluntaryExit, false);
|
|
109
112
|
if (validity !== VoluntaryExitValidity.valid) {
|
|
110
|
-
|
|
113
|
+
let action: GossipAction;
|
|
114
|
+
switch (validity) {
|
|
115
|
+
// [IGNORE] The voluntary exit epoch is not in the future
|
|
116
|
+
case VoluntaryExitValidity.earlyEpoch:
|
|
117
|
+
// [IGNORE] The validator has not already initiated exit
|
|
118
|
+
case VoluntaryExitValidity.alreadyExited:
|
|
119
|
+
// [IGNORE] The validator has no pending partial withdrawals
|
|
120
|
+
case VoluntaryExitValidity.pendingWithdrawals:
|
|
121
|
+
action = GossipAction.IGNORE;
|
|
122
|
+
break;
|
|
123
|
+
// [REJECT] The validator index is valid
|
|
124
|
+
// [REJECT] The validator is active
|
|
125
|
+
// An exit in a future epoch or of a validator past its exit epoch can also be reported as inactive,
|
|
126
|
+
// the spec checks both conditions first and ignores the exit
|
|
127
|
+
case VoluntaryExitValidity.inactive: {
|
|
128
|
+
const {epoch, validatorIndex} = voluntaryExit.message;
|
|
129
|
+
if (epoch > state.epoch) {
|
|
130
|
+
throw new VoluntaryExitError(GossipAction.IGNORE, {code: VoluntaryExitErrorCode.EARLY_EPOCH});
|
|
131
|
+
}
|
|
132
|
+
if (
|
|
133
|
+
validatorIndex < state.validatorCount &&
|
|
134
|
+
state.getValidator(validatorIndex).exitEpoch !== FAR_FUTURE_EPOCH
|
|
135
|
+
) {
|
|
136
|
+
throw new VoluntaryExitError(GossipAction.IGNORE, {code: VoluntaryExitErrorCode.ALREADY_EXITED});
|
|
137
|
+
}
|
|
138
|
+
action = GossipAction.REJECT;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
// [REJECT] The validator has been active long enough
|
|
142
|
+
case VoluntaryExitValidity.shortTimeActive:
|
|
143
|
+
case VoluntaryExitValidity.invalidSignature:
|
|
144
|
+
action = GossipAction.REJECT;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
throw new VoluntaryExitError(action, {
|
|
111
148
|
code: voluntaryExitValidityToErrorCode(validity),
|
|
112
149
|
});
|
|
113
150
|
}
|
|
114
151
|
|
|
152
|
+
// [REJECT] The signature is valid
|
|
115
153
|
const signatureSet = getVoluntaryExitSignatureSet(chain.config, state, voluntaryExit);
|
|
116
154
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {batchable: true, priority: prioritizeBls}))) {
|
|
117
155
|
throw new VoluntaryExitError(GossipAction.REJECT, {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {computeExecutionBlockHash as computeExecutionBlockHashNative} from "@lodestar/native/execution-block-hash";
|
|
2
|
+
import {ForkPostBellatrix, ForkSeq, isForkPostElectra} from "@lodestar/params";
|
|
3
|
+
import {ExecutionPayload, ExecutionRequests, Root, sszTypesFor} from "@lodestar/types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Compute the execution block hash of `payload`: keccak256 of the RLP-encoded execution block header,
|
|
7
|
+
* with the header fields laid out as in execution-specs for the execution fork paired with `fork`.
|
|
8
|
+
*
|
|
9
|
+
* `parentBeaconBlockRoot` is required from deneb and `executionRequests` from electra.
|
|
10
|
+
*
|
|
11
|
+
* Throws if a transaction is empty. It would be a deletion in the transactions trie and not change the hash.
|
|
12
|
+
*/
|
|
13
|
+
export function computeExecutionBlockHash(
|
|
14
|
+
fork: ForkPostBellatrix,
|
|
15
|
+
payload: ExecutionPayload,
|
|
16
|
+
parentBeaconBlockRoot: Root | null,
|
|
17
|
+
executionRequests: ExecutionRequests | null
|
|
18
|
+
): Uint8Array {
|
|
19
|
+
return computeExecutionBlockHashNative(
|
|
20
|
+
ForkSeq[fork],
|
|
21
|
+
sszTypesFor(fork).ExecutionPayload.serialize(payload),
|
|
22
|
+
parentBeaconBlockRoot ?? undefined,
|
|
23
|
+
executionRequests !== null && isForkPostElectra(fork)
|
|
24
|
+
? sszTypesFor(fork).ExecutionRequests.serialize(executionRequests)
|
|
25
|
+
: undefined
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -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,
|
|
@@ -378,7 +380,7 @@ export class ExecutionEngineHttp implements IExecutionEngine {
|
|
|
378
380
|
case ExecutionPayloadStatus.SYNCING:
|
|
379
381
|
// Throw error on syncing if requested to produce a block, else silently ignore
|
|
380
382
|
if (payloadAttributes) {
|
|
381
|
-
throw
|
|
383
|
+
throw new ExecutionEngineError({code: ExecutionEngineErrorCode.SYNCING}, "Execution Layer Syncing");
|
|
382
384
|
}
|
|
383
385
|
return result;
|
|
384
386
|
|
|
@@ -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,7 +193,7 @@ 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,
|
|
@@ -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
|
|
@@ -12,6 +12,9 @@ const MAX_PAYLOAD_IDS = SLOTS_PER_EPOCH;
|
|
|
12
12
|
// Since we do no processing with this id, we have no need to deserialize it
|
|
13
13
|
export type PayloadId = string;
|
|
14
14
|
|
|
15
|
+
/** Payload id returned by the engine and when the payload was requested from it, monotonic `performance.now()` ms */
|
|
16
|
+
export type PreparedPayloadId = {payloadId: PayloadId; preparedAtMs: number};
|
|
17
|
+
|
|
15
18
|
export type WithdrawalV1 = {
|
|
16
19
|
index: QUANTITY;
|
|
17
20
|
validatorIndex: QUANTITY;
|
|
@@ -26,7 +29,7 @@ type FcuAttributes = {headBlockHash: DATA} & Omit<PayloadAttributesRpc, "withdra
|
|
|
26
29
|
export class PayloadIdCache {
|
|
27
30
|
private readonly payloadIdByFcuAttributes = new Map<
|
|
28
31
|
string,
|
|
29
|
-
|
|
32
|
+
PreparedPayloadId & {fullKey: string; inclusionListTransactions?: bellatrix.Transactions}
|
|
30
33
|
>();
|
|
31
34
|
|
|
32
35
|
getFullKey({headBlockHash, timestamp, prevRandao, suggestedFeeRecipient}: FcuAttributes): string {
|
|
@@ -45,7 +48,12 @@ export class PayloadIdCache {
|
|
|
45
48
|
const key = this.getKey(fcuAttributes);
|
|
46
49
|
const fullKey = this.getFullKey(fcuAttributes);
|
|
47
50
|
const {inclusionListTransactions} = fcuAttributes;
|
|
48
|
-
this.payloadIdByFcuAttributes.set(key, {
|
|
51
|
+
this.payloadIdByFcuAttributes.set(key, {
|
|
52
|
+
payloadId,
|
|
53
|
+
preparedAtMs: performance.now(),
|
|
54
|
+
fullKey,
|
|
55
|
+
inclusionListTransactions,
|
|
56
|
+
});
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
prune(): void {
|
|
@@ -53,13 +61,13 @@ export class PayloadIdCache {
|
|
|
53
61
|
pruneSetToMax(this.payloadIdByFcuAttributes, MAX_PAYLOAD_IDS);
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
get(fcuAttributes: FcuAttributes):
|
|
64
|
+
get(fcuAttributes: FcuAttributes): PreparedPayloadId | undefined {
|
|
57
65
|
const key = this.getKey(fcuAttributes);
|
|
58
66
|
const fullKey = this.getFullKey(fcuAttributes);
|
|
59
67
|
const payloadInfo = this.payloadIdByFcuAttributes.get(key);
|
|
60
68
|
return payloadInfo?.fullKey === fullKey &&
|
|
61
69
|
isSameInclusionList(payloadInfo.inclusionListTransactions, fcuAttributes.inclusionListTransactions)
|
|
62
|
-
? payloadInfo.payloadId
|
|
70
|
+
? {payloadId: payloadInfo.payloadId, preparedAtMs: payloadInfo.preparedAtMs}
|
|
63
71
|
: undefined;
|
|
64
72
|
}
|
|
65
73
|
}
|
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,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {ProducedBlockSource} from "@lodestar/types";
|
|
2
2
|
import {BlockSelectionResult} from "../../api/impl/validator/index.js";
|
|
3
3
|
import {InclusionListSource} from "../../chain/blocks/types.js";
|
|
4
|
+
import {PreparePayloadReason} from "../../chain/prepareNextSlot.js";
|
|
4
5
|
import {BlockProductionStep, PayloadPreparationType} from "../../chain/produceBlock/index.js";
|
|
5
6
|
import {RegistryMetricCreator} from "../utils/registryMetricCreator.js";
|
|
6
7
|
|
|
@@ -164,6 +165,14 @@ export function createBeaconMetrics(register: RegistryMetricCreator) {
|
|
|
164
165
|
help: "Time for preparing payload in advance",
|
|
165
166
|
buckets: [0.1, 1, 3, 5, 10],
|
|
166
167
|
}),
|
|
168
|
+
payloadReprepare: register.counter<{
|
|
169
|
+
reason: PreparePayloadReason;
|
|
170
|
+
result: "changed" | "unchanged" | "dropped" | "error";
|
|
171
|
+
}>({
|
|
172
|
+
name: "beacon_block_payload_reprepare_total",
|
|
173
|
+
help: "Re-runs of the next slot payload preparation after the scheduled run, by reason and result: prepared again as the head or its parent payload changed, unchanged, dropped as the proposal slot started, or failed",
|
|
174
|
+
labelNames: ["reason", "result"],
|
|
175
|
+
}),
|
|
167
176
|
executionPayloadEnvelopeProcessingTime: register.histogram({
|
|
168
177
|
name: "beacon_block_payload_envelope_processing_seconds",
|
|
169
178
|
help: "Time to process execution payload envelope during block production",
|
|
@@ -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",
|
|
@@ -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
|
{
|