@lodestar/beacon-node 1.52.0-dev.4996a91d93 → 1.52.0-dev.4c4ee3042c
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 +12 -3
- package/lib/api/impl/validator/index.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js +7 -0
- package/lib/chain/archiveStore/historicalState/getHistoricalState.js.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/pruneHistory.js +8 -4
- package/lib/chain/archiveStore/utils/pruneHistory.js.map +1 -1
- package/lib/chain/errors/attestationError.d.ts +15 -1
- package/lib/chain/errors/attestationError.d.ts.map +1 -1
- package/lib/chain/errors/attestationError.js +8 -0
- package/lib/chain/errors/attestationError.js.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.d.ts +48 -0
- package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.js +7 -0
- package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/validation/aggregateAndProof.d.ts.map +1 -1
- package/lib/chain/validation/aggregateAndProof.js +24 -7
- package/lib/chain/validation/aggregateAndProof.js.map +1 -1
- package/lib/chain/validation/attestation.d.ts.map +1 -1
- package/lib/chain/validation/attestation.js +32 -16
- package/lib/chain/validation/attestation.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +9 -1
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.js +79 -4
- package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
- package/lib/network/gossip/gossipsub.js +2 -2
- package/lib/network/gossip/gossipsub.js.map +1 -1
- package/lib/network/processor/gossipHandlers.js +2 -2
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/sync/unknownBlock.d.ts +3 -2
- package/lib/sync/unknownBlock.d.ts.map +1 -1
- package/lib/sync/unknownBlock.js +42 -6
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts +24 -2
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +41 -1
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/lib/util/eventLoop.d.ts +3 -3
- package/lib/util/eventLoop.d.ts.map +1 -1
- package/lib/util/eventLoop.js +3 -3
- package/lib/util/eventLoop.js.map +1 -1
- package/package.json +16 -16
- package/src/api/impl/validator/index.ts +14 -3
- package/src/chain/archiveStore/historicalState/getHistoricalState.ts +9 -0
- package/src/chain/archiveStore/utils/pruneHistory.ts +9 -4
- package/src/chain/errors/attestationError.ts +11 -1
- package/src/chain/errors/executionPayloadEnvelope.ts +50 -0
- package/src/chain/validation/aggregateAndProof.ts +24 -9
- package/src/chain/validation/attestation.ts +31 -20
- package/src/chain/validation/block.ts +9 -1
- package/src/chain/validation/executionPayloadEnvelope.ts +87 -3
- package/src/network/gossip/gossipsub.ts +2 -2
- package/src/network/processor/gossipHandlers.ts +2 -2
- package/src/sync/unknownBlock.ts +47 -5
- package/src/sync/utils/downloadByRoot.ts +66 -2
- package/src/util/eventLoop.ts +3 -3
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -13,6 +13,8 @@ import {PayloadEnvelopeInput, PayloadEnvelopeInputSource} from "../chain/blocks/
|
|
|
13
13
|
import {
|
|
14
14
|
BlockError,
|
|
15
15
|
BlockErrorCode,
|
|
16
|
+
DataColumnSidecarErrorCode,
|
|
17
|
+
DataColumnSidecarValidationError,
|
|
16
18
|
ExecutionPayloadEnvelopeError,
|
|
17
19
|
ExecutionPayloadEnvelopeErrorCode,
|
|
18
20
|
} from "../chain/errors/index.js";
|
|
@@ -52,7 +54,7 @@ import {
|
|
|
52
54
|
isPendingPayloadEnvelope,
|
|
53
55
|
isPendingPayloadInput,
|
|
54
56
|
} from "./types.js";
|
|
55
|
-
import {DownloadByRootError, downloadByRoot} from "./utils/downloadByRoot.js";
|
|
57
|
+
import {DownloadByRootError, DownloadByRootErrorCode, downloadByRoot} from "./utils/downloadByRoot.js";
|
|
56
58
|
import {getAllDescendantBlocks, getUnknownAndAncestorBlocks} from "./utils/pendingBlocksTree.js";
|
|
57
59
|
import {getRateLimitedUntilMs} from "./utils/rateLimit.js";
|
|
58
60
|
|
|
@@ -549,8 +551,9 @@ export class BlockInputSync {
|
|
|
549
551
|
/**
|
|
550
552
|
* Limit pending blocks to prevent DOS attacks that cause OOM. Any gossip message with an unknown root adds a root-only
|
|
551
553
|
* entry before validation, so those nothing waits on are evicted before a block or a root a pending block waits on.
|
|
552
|
-
* A downloaded block is only checked against its root
|
|
553
|
-
* fill at most half the cap, otherwise they could
|
|
554
|
+
* A downloaded block is only checked against its root and proposer signature, not that the proposer is due at its
|
|
555
|
+
* slot, so this only applies while blocks and the roots they wait on fill at most half the cap, otherwise they could
|
|
556
|
+
* pin it and evict every new root on insertion.
|
|
554
557
|
*/
|
|
555
558
|
private prunePendingBlocks(): void {
|
|
556
559
|
if (this.pendingBlocks.size <= this.maxPendingBlocks) {
|
|
@@ -1291,6 +1294,15 @@ export class BlockInputSync {
|
|
|
1291
1294
|
return;
|
|
1292
1295
|
}
|
|
1293
1296
|
|
|
1297
|
+
if (
|
|
1298
|
+
res.err instanceof DownloadByRootError &&
|
|
1299
|
+
res.err.type.code === DownloadByRootErrorCode.BELOW_FINALIZED_SLOT
|
|
1300
|
+
) {
|
|
1301
|
+
this.logger.debug("Downloaded block is before finalized slot", logCtx, res.err);
|
|
1302
|
+
this.removeAllDescendants(block, DroppedItemReason.belowFinalized);
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
|
|
1294
1306
|
this.metrics?.blockInputSync.downloadedBlocksError.inc();
|
|
1295
1307
|
this.logger.debug("Failed to download unknown block root, retained for retry", logCtx, res.err);
|
|
1296
1308
|
const pendingBlock = this.pendingBlocks.get(rootHex);
|
|
@@ -2046,8 +2058,12 @@ export class BlockInputSync {
|
|
|
2046
2058
|
for (const warning of warnings) {
|
|
2047
2059
|
this.logger.debug("BlockInputSync.fetchBlockInput: downloaded with warning", logCtx, warning);
|
|
2048
2060
|
this.metrics?.blockInputSync.downloadByRoot.warn.inc({code: warning.type.code, client: peerClient});
|
|
2061
|
+
// A partial response is legal, columns that were not requested are not
|
|
2062
|
+
if (warning.type.code === DownloadByRootErrorCode.EXTRA_SIDECAR_RECEIVED) {
|
|
2063
|
+
this.network.reportPeer(peerId, PeerAction.LowToleranceError, warning.type.code);
|
|
2064
|
+
excludedPeers.add(peerId);
|
|
2065
|
+
}
|
|
2049
2066
|
}
|
|
2050
|
-
// TODO: penalize peer?
|
|
2051
2067
|
}
|
|
2052
2068
|
} catch (e) {
|
|
2053
2069
|
this.logger.debug(
|
|
@@ -2056,10 +2072,36 @@ export class BlockInputSync {
|
|
|
2056
2072
|
e as Error
|
|
2057
2073
|
);
|
|
2058
2074
|
const downloadByRootMetrics = this.metrics?.blockInputSync.downloadByRoot;
|
|
2059
|
-
// TODO: penalize peer?
|
|
2060
2075
|
if (e instanceof DownloadByRootError) {
|
|
2061
2076
|
const errorCode = e.type.code;
|
|
2062
2077
|
downloadByRootMetrics?.error.inc({code: errorCode, client: peerClient});
|
|
2078
|
+
if (errorCode === DownloadByRootErrorCode.BELOW_FINALIZED_SLOT) {
|
|
2079
|
+
throw e;
|
|
2080
|
+
}
|
|
2081
|
+
// Low as in range sync, not Fatal as peers may serve unverified copies of a root with a bad signature
|
|
2082
|
+
if (
|
|
2083
|
+
errorCode === DownloadByRootErrorCode.MISMATCH_BLOCK_ROOT ||
|
|
2084
|
+
errorCode === DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID ||
|
|
2085
|
+
errorCode === DownloadByRootErrorCode.UNKNOWN_PROPOSER
|
|
2086
|
+
) {
|
|
2087
|
+
this.network.reportPeer(peerId, PeerAction.LowToleranceError, errorCode);
|
|
2088
|
+
}
|
|
2089
|
+
excludedPeers.add(peerId);
|
|
2090
|
+
} else if (e instanceof DataColumnSidecarValidationError) {
|
|
2091
|
+
const errorCode = e.type.code;
|
|
2092
|
+
downloadByRootMetrics?.error.inc({code: errorCode, client: peerClient});
|
|
2093
|
+
// Not PROPOSAL_SIGNATURE_INVALID or INCORRECT_HEADER_ROOT, which compares signatures too: the spec does not
|
|
2094
|
+
// require verifying the header signature of req/resp columns, so honest peers may serve a bad one
|
|
2095
|
+
switch (errorCode) {
|
|
2096
|
+
case DataColumnSidecarErrorCode.INCORRECT_BLOCK:
|
|
2097
|
+
case DataColumnSidecarErrorCode.INVALID_INDEX:
|
|
2098
|
+
case DataColumnSidecarErrorCode.INCORRECT_CELL_COUNT:
|
|
2099
|
+
case DataColumnSidecarErrorCode.INCORRECT_KZG_COMMITMENTS_COUNT:
|
|
2100
|
+
case DataColumnSidecarErrorCode.INCORRECT_KZG_PROOF_COUNT:
|
|
2101
|
+
case DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID:
|
|
2102
|
+
case DataColumnSidecarErrorCode.INVALID_KZG_PROOF_BATCH:
|
|
2103
|
+
this.network.reportPeer(peerId, PeerAction.LowToleranceError, errorCode);
|
|
2104
|
+
}
|
|
2063
2105
|
excludedPeers.add(peerId);
|
|
2064
2106
|
} else if (e instanceof RequestError) {
|
|
2065
2107
|
// should look into req_resp metrics in this case
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {routes} from "@lodestar/api";
|
|
2
2
|
import {ChainForkConfig} from "@lodestar/config";
|
|
3
3
|
import {ForkPostFulu, ForkPostGloas, isForkPostFulu, isForkPostGloas} from "@lodestar/params";
|
|
4
|
-
import {
|
|
4
|
+
import {getBlockProposerSignatureSet} from "@lodestar/state-transition";
|
|
5
|
+
import {ColumnIndex, SignedBeaconBlock, Slot, ValidatorIndex, fulu} from "@lodestar/types";
|
|
5
6
|
import {LodestarError, byteArrayEquals, fromHex, prettyPrintIndices, toHex, toRootHex} from "@lodestar/utils";
|
|
6
7
|
import {isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
|
|
7
8
|
import {BlockInputSource, IBlockInput} from "../../chain/blocks/blockInput/types.js";
|
|
@@ -30,10 +31,12 @@ export type FetchByRootCoreProps = {
|
|
|
30
31
|
peerMeta: PeerSyncMeta;
|
|
31
32
|
};
|
|
32
33
|
export type FetchByRootProps = FetchByRootCoreProps & {
|
|
34
|
+
chain: IBeaconChain;
|
|
33
35
|
cacheItem: BlockInputSyncCacheItem;
|
|
34
36
|
blockRoot: Uint8Array;
|
|
35
37
|
};
|
|
36
38
|
export type FetchByRootAndValidateBlockProps = Omit<FetchByRootCoreProps, "peerMeta"> & {
|
|
39
|
+
chain: IBeaconChain;
|
|
37
40
|
peerIdStr: PeerIdStr;
|
|
38
41
|
blockRoot: Uint8Array;
|
|
39
42
|
};
|
|
@@ -190,6 +193,7 @@ export async function fetchByRoot({
|
|
|
190
193
|
} else {
|
|
191
194
|
block = await fetchAndValidateBlock({
|
|
192
195
|
config,
|
|
196
|
+
chain,
|
|
193
197
|
network,
|
|
194
198
|
peerIdStr,
|
|
195
199
|
blockRoot,
|
|
@@ -212,6 +216,7 @@ export async function fetchByRoot({
|
|
|
212
216
|
} else {
|
|
213
217
|
block = await fetchAndValidateBlock({
|
|
214
218
|
config,
|
|
219
|
+
chain,
|
|
215
220
|
network,
|
|
216
221
|
peerIdStr,
|
|
217
222
|
blockRoot,
|
|
@@ -245,10 +250,11 @@ export async function fetchByRoot({
|
|
|
245
250
|
|
|
246
251
|
export async function fetchAndValidateBlock({
|
|
247
252
|
config,
|
|
253
|
+
chain,
|
|
248
254
|
network,
|
|
249
255
|
peerIdStr,
|
|
250
256
|
blockRoot,
|
|
251
|
-
}:
|
|
257
|
+
}: FetchByRootAndValidateBlockProps): Promise<SignedBeaconBlock> {
|
|
252
258
|
const response = await network.sendBeaconBlocksByRoot(peerIdStr, [blockRoot]);
|
|
253
259
|
const block = response.at(0);
|
|
254
260
|
if (!block) {
|
|
@@ -270,6 +276,41 @@ export async function fetchAndValidateBlock({
|
|
|
270
276
|
"block does not match requested root"
|
|
271
277
|
);
|
|
272
278
|
}
|
|
279
|
+
|
|
280
|
+
const blockRootHex = toRootHex(blockRoot);
|
|
281
|
+
const {slot, proposerIndex} = block.message;
|
|
282
|
+
// Before the signature check, honest peers serve the genesis block unsigned
|
|
283
|
+
const finalizedSlot = chain.forkChoice.getFinalizedBlock().slot;
|
|
284
|
+
if (slot < finalizedSlot) {
|
|
285
|
+
throw new DownloadByRootError({
|
|
286
|
+
code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT,
|
|
287
|
+
peer: prettyPrintPeerIdStr(peerIdStr),
|
|
288
|
+
slot,
|
|
289
|
+
finalizedSlot,
|
|
290
|
+
blockRoot: blockRootHex,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (proposerIndex >= chain.pubkeyCache.size) {
|
|
294
|
+
throw new DownloadByRootError({
|
|
295
|
+
code: DownloadByRootErrorCode.UNKNOWN_PROPOSER,
|
|
296
|
+
peer: prettyPrintPeerIdStr(peerIdStr),
|
|
297
|
+
slot,
|
|
298
|
+
blockRoot: blockRootHex,
|
|
299
|
+
proposerIndex,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
// Not marked as verified, the block has not passed proposer or ancestry checks yet
|
|
303
|
+
if (!chain.seenBlockInputCache.isVerifiedProposerSignature(slot, blockRootHex, block.signature)) {
|
|
304
|
+
const signatureSet = getBlockProposerSignatureSet(chain.config, block);
|
|
305
|
+
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: false}))) {
|
|
306
|
+
throw new DownloadByRootError({
|
|
307
|
+
code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
308
|
+
peer: prettyPrintPeerIdStr(peerIdStr),
|
|
309
|
+
slot,
|
|
310
|
+
blockRoot: blockRootHex,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
}
|
|
273
314
|
return block;
|
|
274
315
|
}
|
|
275
316
|
|
|
@@ -376,6 +417,9 @@ export enum DownloadByRootErrorCode {
|
|
|
376
417
|
INVALID_KZG_PROOF = "DOWNLOAD_BY_ROOT_ERROR_INVALID_KZG_PROOF",
|
|
377
418
|
MISSING_BLOCK_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_BLOCK_RESPONSE",
|
|
378
419
|
MISSING_COLUMN_RESPONSE = "DOWNLOAD_BY_ROOT_ERROR_MISSING_COLUMN_RESPONSE",
|
|
420
|
+
BELOW_FINALIZED_SLOT = "DOWNLOAD_BY_ROOT_ERROR_BELOW_FINALIZED_SLOT",
|
|
421
|
+
UNKNOWN_PROPOSER = "DOWNLOAD_BY_ROOT_ERROR_UNKNOWN_PROPOSER",
|
|
422
|
+
PROPOSAL_SIGNATURE_INVALID = "DOWNLOAD_BY_ROOT_ERROR_PROPOSAL_SIGNATURE_INVALID",
|
|
379
423
|
Z = "DOWNLOAD_BY_ROOT_ERROR_Z",
|
|
380
424
|
}
|
|
381
425
|
export type DownloadByRootErrorType =
|
|
@@ -425,6 +469,26 @@ export type DownloadByRootErrorType =
|
|
|
425
469
|
code: DownloadByRootErrorCode.MISSING_COLUMN_RESPONSE;
|
|
426
470
|
peer: string;
|
|
427
471
|
blockRoot: string;
|
|
472
|
+
}
|
|
473
|
+
| {
|
|
474
|
+
code: DownloadByRootErrorCode.BELOW_FINALIZED_SLOT;
|
|
475
|
+
peer: string;
|
|
476
|
+
slot: Slot;
|
|
477
|
+
finalizedSlot: Slot;
|
|
478
|
+
blockRoot: string;
|
|
479
|
+
}
|
|
480
|
+
| {
|
|
481
|
+
code: DownloadByRootErrorCode.UNKNOWN_PROPOSER;
|
|
482
|
+
peer: string;
|
|
483
|
+
slot: Slot;
|
|
484
|
+
blockRoot: string;
|
|
485
|
+
proposerIndex: ValidatorIndex;
|
|
486
|
+
}
|
|
487
|
+
| {
|
|
488
|
+
code: DownloadByRootErrorCode.PROPOSAL_SIGNATURE_INVALID;
|
|
489
|
+
peer: string;
|
|
490
|
+
slot: Slot;
|
|
491
|
+
blockRoot: string;
|
|
428
492
|
};
|
|
429
493
|
|
|
430
494
|
export class DownloadByRootError extends LodestarError<DownloadByRootErrorType> {}
|
package/src/util/eventLoop.ts
CHANGED
|
@@ -22,9 +22,9 @@ export function callInNextEventLoop(callback: () => void): void {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Schedules a callback for the `check` phase
|
|
26
|
-
* and there is no 1ms timer delay.
|
|
25
|
+
* Schedules a callback for the `check` phase, after the `poll` phase handles ready I/O.
|
|
26
|
+
* Pending promise continuations run first, and there is no 1ms timer delay.
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function callAfterIO(callback: () => void): void {
|
|
29
29
|
setImmediate(callback);
|
|
30
30
|
}
|