@lodestar/beacon-node 1.36.0-dev.8b33937cc4 → 1.36.0-dev.9f2bb12ea7
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 +41 -22
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.d.ts +17 -14
- package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.js +4 -0
- package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +2 -1
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts +16 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.d.ts.map +1 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js +31 -1
- package/lib/chain/stateCache/persistentCheckpointsCache.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +32 -15
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/network/core/networkCore.d.ts.map +1 -1
- package/lib/network/core/networkCore.js +5 -1
- package/lib/network/core/networkCore.js.map +1 -1
- package/lib/network/core/networkCoreWorker.js +6 -1
- package/lib/network/core/networkCoreWorker.js.map +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js +1 -1
- package/lib/network/core/networkCoreWorkerHandler.js.map +1 -1
- package/lib/network/events.d.ts +1 -0
- package/lib/network/events.d.ts.map +1 -1
- package/lib/network/metadata.d.ts +1 -1
- package/lib/network/metadata.d.ts.map +1 -1
- package/lib/network/metadata.js +1 -0
- package/lib/network/metadata.js.map +1 -1
- package/lib/network/processor/gossipHandlers.js +1 -1
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/reqresp/ReqRespBeaconNode.d.ts.map +1 -1
- package/lib/network/reqresp/ReqRespBeaconNode.js +3 -1
- package/lib/network/reqresp/ReqRespBeaconNode.js.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts +2 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js +11 -2
- package/lib/network/reqresp/handlers/beaconBlocksByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts +2 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +9 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts +2 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +9 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
- package/lib/network/reqresp/handlers/index.js +6 -6
- package/lib/network/reqresp/handlers/index.js.map +1 -1
- package/lib/network/reqresp/types.d.ts +1 -0
- package/lib/network/reqresp/types.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +58 -13
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +201 -82
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/util/blobs.d.ts +1 -1
- package/lib/util/blobs.d.ts.map +1 -1
- package/lib/util/blobs.js +53 -20
- package/lib/util/blobs.js.map +1 -1
- package/package.json +15 -14
- package/src/api/impl/beacon/blocks/index.ts +47 -25
- package/src/chain/errors/dataColumnSidecarError.ts +20 -14
- package/src/chain/options.ts +2 -0
- package/src/chain/stateCache/persistentCheckpointsCache.ts +45 -2
- package/src/chain/validation/dataColumnSidecar.ts +34 -16
- package/src/network/core/networkCore.ts +5 -1
- package/src/network/core/networkCoreWorker.ts +7 -2
- package/src/network/core/networkCoreWorkerHandler.ts +1 -1
- package/src/network/events.ts +1 -1
- package/src/network/metadata.ts +3 -1
- package/src/network/processor/gossipHandlers.ts +1 -1
- package/src/network/reqresp/ReqRespBeaconNode.ts +3 -1
- package/src/network/reqresp/handlers/beaconBlocksByRange.ts +15 -2
- package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +13 -1
- package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +13 -1
- package/src/network/reqresp/handlers/index.ts +6 -6
- package/src/network/reqresp/types.ts +1 -0
- package/src/sync/utils/downloadByRange.ts +259 -103
- package/src/util/blobs.ts +64 -20
|
@@ -6,7 +6,6 @@ import { SeenBlockInput } from "../../chain/seenCache/seenGossipBlockInput.js";
|
|
|
6
6
|
import { INetwork } from "../../network/index.js";
|
|
7
7
|
import { PeerIdStr } from "../../util/peerId.js";
|
|
8
8
|
import { WarnResult } from "../../util/wrapError.js";
|
|
9
|
-
import { DownloadByRootErrorCode } from "./downloadByRoot.js";
|
|
10
9
|
export type DownloadByRangeRequests = {
|
|
11
10
|
blocksRequest?: phase0.BeaconBlocksByRangeRequest;
|
|
12
11
|
blobsRequest?: deneb.BlobSidecarsByRangeRequest;
|
|
@@ -76,7 +75,7 @@ export declare function validateResponses({ config, batchBlocks, blocksRequest,
|
|
|
76
75
|
* - must allow for skip slots
|
|
77
76
|
* - check is a chain of blocks where via parentRoot matches hashTreeRoot of block before
|
|
78
77
|
*/
|
|
79
|
-
export declare function validateBlockByRangeResponse(config: ChainForkConfig, blocksRequest: phase0.BeaconBlocksByRangeRequest, blocks: SignedBeaconBlock[]): ValidatedBlock[]
|
|
78
|
+
export declare function validateBlockByRangeResponse(config: ChainForkConfig, blocksRequest: phase0.BeaconBlocksByRangeRequest, blocks: SignedBeaconBlock[]): WarnResult<ValidatedBlock[], DownloadByRangeError>;
|
|
80
79
|
/**
|
|
81
80
|
* Should not be called directly. Only exported for unit testing purposes.
|
|
82
81
|
* This is used only in Deneb and Electra
|
|
@@ -84,8 +83,47 @@ export declare function validateBlockByRangeResponse(config: ChainForkConfig, bl
|
|
|
84
83
|
export declare function validateBlobsByRangeResponse(dataRequestBlocks: ValidatedBlock[], blobSidecars: deneb.BlobSidecars): Promise<ValidatedBlobSidecars[]>;
|
|
85
84
|
/**
|
|
86
85
|
* Should not be called directly. Only exported for unit testing purposes
|
|
86
|
+
*
|
|
87
|
+
* Spec states:
|
|
88
|
+
* 1) must be within range [start_slot, start_slot + count]
|
|
89
|
+
* 2) should respond with all columns in the range or and 3:ResourceUnavailable (and potentially get down-scored)
|
|
90
|
+
* 3) must response with at least the sidecars of the first blob-carrying block that exists in the range
|
|
91
|
+
* 4) must include all sidecars from each block from which there are blobs
|
|
92
|
+
* 5) where they exists, sidecars must be sent in (slot, index) order
|
|
93
|
+
* 6) clients may limit the number of sidecars in a response
|
|
94
|
+
* 7) clients may stop responding mid-response if their view of fork-choice changes
|
|
95
|
+
*
|
|
96
|
+
* We will interpret the spec as follows
|
|
97
|
+
* - Errors when validating: 1, 3, 5
|
|
98
|
+
* - Warnings when validating: 2, 4, 6, 7
|
|
99
|
+
*
|
|
100
|
+
* For "warning" cases, where we get a partial response but sidecars are validated and correct with respect to the
|
|
101
|
+
* blocks, then they will be kept. This loosening of the spec is to help ensure sync goes smoothly and we can find
|
|
102
|
+
* the data needed in difficult network situations.
|
|
103
|
+
*
|
|
104
|
+
* Assume for the following two examples we request indices 5, 10, 15 for a range of slots 32-63
|
|
105
|
+
*
|
|
106
|
+
* For slots where we receive no sidecars, example slot 45, but blobs exist we will stop validating subsequent
|
|
107
|
+
* slots, 45-63. The next round of requests will get structured to pull the from the slot that had columns
|
|
108
|
+
* missing to the end of the range for all columns indices that were requested for the current partially failed
|
|
109
|
+
* request (slots 45-63 and indices 5, 10, 15).
|
|
110
|
+
*
|
|
111
|
+
* For slots where only some of the requested sidecars are received we will proceed with validation. For simplicity sake
|
|
112
|
+
* we will assume that if we only get some indices back for a (or several) slot(s) that the indices we get will be
|
|
113
|
+
* consistent. IE if a peer returns only index 5, they will most likely return that same index for subsequent slot
|
|
114
|
+
* (index 5 for slots 34, 35, 36, etc). They will not likely return 5 on slot 34, 10 on slot 35, 15 on slot 36, etc.
|
|
115
|
+
* This assumption makes the code simpler. For both cases the request for the next round will be structured correctly
|
|
116
|
+
* to pull any missing column indices for whatever range remains. The simplification just leads to re-verification
|
|
117
|
+
* of the columns but the number of columns downloaded will be the same regardless of if they are validated twice.
|
|
118
|
+
*
|
|
119
|
+
* validateColumnsByRangeResponse makes some assumptions about the data being passed in
|
|
120
|
+
* blocks are:
|
|
121
|
+
* - slotwise in order
|
|
122
|
+
* - form a chain
|
|
123
|
+
* - non-sparse response (any missing block is a skipped slot not a bad response)
|
|
124
|
+
* - last block is last slot received
|
|
87
125
|
*/
|
|
88
|
-
export declare function validateColumnsByRangeResponse(request: fulu.DataColumnSidecarsByRangeRequest,
|
|
126
|
+
export declare function validateColumnsByRangeResponse(config: ChainForkConfig, request: fulu.DataColumnSidecarsByRangeRequest, blocks: ValidatedBlock[], columnSidecars: fulu.DataColumnSidecars): Promise<WarnResult<ValidatedColumnSidecars[], DownloadByRangeError>>;
|
|
89
127
|
/**
|
|
90
128
|
* Given a data request, return only the blocks and roots that correspond to the data request (sorted). Assumes that
|
|
91
129
|
* cached have slots that are all before the current batch of downloaded blocks
|
|
@@ -95,7 +133,7 @@ export declare function getBlocksForDataValidation(dataRequest: {
|
|
|
95
133
|
count: number;
|
|
96
134
|
}, cached: IBlockInput[] | undefined, current: ValidatedBlock[] | undefined): ValidatedBlock[];
|
|
97
135
|
export declare enum DownloadByRangeErrorCode {
|
|
98
|
-
|
|
136
|
+
MISSING_BLOCKS_RESPONSE = "DOWNLOAD_BY_RANGE_ERROR_MISSING_BLOCK_RESPONSE",
|
|
99
137
|
MISSING_BLOBS_RESPONSE = "DOWNLOAD_BY_RANGE_ERROR_MISSING_BLOBS_RESPONSE",
|
|
100
138
|
MISSING_COLUMNS_RESPONSE = "DOWNLOAD_BY_RANGE_ERROR_MISSING_COLUMNS_RESPONSE",
|
|
101
139
|
/** Error at the reqresp layer */
|
|
@@ -110,26 +148,29 @@ export declare enum DownloadByRangeErrorCode {
|
|
|
110
148
|
MISSING_COLUMNS = "DOWNLOAD_BY_RANGE_ERROR_MISSING_COLUMNS",
|
|
111
149
|
OVER_COLUMNS = "DOWNLOAD_BY_RANGE_ERROR_OVER_COLUMNS",
|
|
112
150
|
EXTRA_COLUMNS = "DOWNLOAD_BY_RANGE_ERROR_EXTRA_COLUMNS",
|
|
151
|
+
NO_COLUMNS_FOR_BLOCK = "DOWNLOAD_BY_RANGE_ERROR_NO_COLUMNS_FOR_BLOCK",
|
|
152
|
+
DUPLICATE_COLUMN = "DOWNLOAD_BY_RANGE_ERROR_DUPLICATE_COLUMN",
|
|
153
|
+
OUT_OF_ORDER_COLUMNS = "DOWNLOAD_BY_RANGE_OUT_OF_ORDER_COLUMNS",
|
|
113
154
|
/** Cached block input type mismatches new data */
|
|
155
|
+
MISMATCH_BLOCK_FORK = "DOWNLOAD_BY_RANGE_ERROR_MISMATCH_BLOCK_FORK",
|
|
114
156
|
MISMATCH_BLOCK_INPUT_TYPE = "DOWNLOAD_BY_RANGE_ERROR_MISMATCH_BLOCK_INPUT_TYPE"
|
|
115
157
|
}
|
|
116
158
|
export type DownloadByRangeErrorType = {
|
|
117
|
-
code:
|
|
118
|
-
expectedCount: number;
|
|
119
|
-
} | {
|
|
120
|
-
code: DownloadByRangeErrorCode.MISSING_BLOCKS | DownloadByRangeErrorCode.MISSING_BLOBS_RESPONSE | DownloadByRangeErrorCode.MISSING_COLUMNS_RESPONSE;
|
|
159
|
+
code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE | DownloadByRangeErrorCode.MISSING_BLOBS_RESPONSE | DownloadByRangeErrorCode.MISSING_COLUMNS_RESPONSE;
|
|
121
160
|
blockStartSlot?: number;
|
|
122
161
|
blockCount?: number;
|
|
123
162
|
blobStartSlot?: number;
|
|
124
163
|
blobCount?: number;
|
|
125
164
|
columnStartSlot?: number;
|
|
126
165
|
columnCount?: number;
|
|
127
|
-
} | {
|
|
128
|
-
code: DownloadByRootErrorCode.MISSING_BLOCK_RESPONSE;
|
|
129
|
-
expectedCount: number;
|
|
130
166
|
} | {
|
|
131
167
|
code: DownloadByRangeErrorCode.OUT_OF_RANGE_BLOCKS;
|
|
132
168
|
slot: number;
|
|
169
|
+
} | {
|
|
170
|
+
code: DownloadByRangeErrorCode.MISMATCH_BLOCK_FORK;
|
|
171
|
+
slot: number;
|
|
172
|
+
dataFork: string;
|
|
173
|
+
blockFork: string;
|
|
133
174
|
} | {
|
|
134
175
|
code: DownloadByRangeErrorCode.OUT_OF_ORDER_BLOCKS;
|
|
135
176
|
} | {
|
|
@@ -155,7 +196,7 @@ export type DownloadByRangeErrorType = {
|
|
|
155
196
|
expected: number;
|
|
156
197
|
actual: number;
|
|
157
198
|
} | {
|
|
158
|
-
code: DownloadByRangeErrorCode.OUT_OF_ORDER_BLOBS;
|
|
199
|
+
code: DownloadByRangeErrorCode.OUT_OF_ORDER_BLOBS | DownloadByRangeErrorCode.OUT_OF_ORDER_COLUMNS;
|
|
159
200
|
slot: number;
|
|
160
201
|
} | {
|
|
161
202
|
code: DownloadByRangeErrorCode.EXTRA_BLOBS;
|
|
@@ -171,7 +212,11 @@ export type DownloadByRangeErrorType = {
|
|
|
171
212
|
blockRoot: string;
|
|
172
213
|
missingIndices: string;
|
|
173
214
|
} | {
|
|
174
|
-
code: DownloadByRangeErrorCode.
|
|
215
|
+
code: DownloadByRangeErrorCode.DUPLICATE_COLUMN;
|
|
216
|
+
slot: Slot;
|
|
217
|
+
index: number;
|
|
218
|
+
} | {
|
|
219
|
+
code: DownloadByRangeErrorCode.EXTRA_COLUMNS | DownloadByRangeErrorCode.NO_COLUMNS_FOR_BLOCK;
|
|
175
220
|
slot: Slot;
|
|
176
221
|
blockRoot: string;
|
|
177
222
|
invalidIndices: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"downloadByRange.d.ts","sourceRoot":"","sources":["../../../src/sync/utils/downloadByRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"downloadByRange.d.ts","sourceRoot":"","sources":["../../../src/sync/utils/downloadByRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,kBAAkB,CAAC;AASjD,OAAO,EAAC,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAC,MAAM,iBAAiB,CAAC;AAC7E,OAAO,EAAC,aAAa,EAAE,MAAM,EAAyC,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAEL,MAAM,EACN,WAAW,EAGZ,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,+CAA+C,CAAC;AAG7E,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAC,SAAS,EAAC,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAC;AAEnD,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC,0BAA0B,CAAC;IAClD,YAAY,CAAC,EAAE,KAAK,CAAC,0BAA0B,CAAC;IAChD,cAAc,CAAC,EAAE,IAAI,CAAC,gCAAgC,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC7B,YAAY,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC;IAClC,cAAc,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,uBAAuB,GAAG;IACnE,MAAM,EAAE,eAAe,C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AAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB,GACD;IACE,IAAI,EAAE,wBAAwB,CAAC,gBAAgB,CAAC;IAChD,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IACE,IAAI,EAAE,wBAAwB,CAAC,aAAa,GAAG,wBAAwB,CAAC,oBAAoB,CAAC;IAC7F,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB,GACD;IACE,IAAI,EAAE,wBAAwB,CAAC,yBAAyB,CAAC;IACzD,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEN,qBAAa,oBAAqB,SAAQ,aAAa,CAAC,wBAAwB,CAAC;CAAG"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isForkPostFulu, isForkPostGloas, } from "@lodestar/params";
|
|
2
|
+
import { LodestarError, fromHex, prettyPrintIndices, toRootHex } from "@lodestar/utils";
|
|
2
3
|
import { BlockInputSource, DAType, isBlockInputBlobs, isBlockInputColumns, } from "../../chain/blocks/blockInput/index.js";
|
|
3
4
|
import { validateBlockBlobSidecars } from "../../chain/validation/blobSidecar.js";
|
|
4
5
|
import { validateBlockDataColumnSidecars } from "../../chain/validation/dataColumnSidecar.js";
|
|
@@ -37,7 +38,11 @@ export function cacheByRangeResponses({ cache, peerIdStr, responses, batchBlocks
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
for (const { blockRoot, blobSidecars } of responses.validatedBlobSidecars ?? []) {
|
|
40
|
-
const
|
|
41
|
+
const dataSlot = blobSidecars.at(0)?.signedBlockHeader.message.slot;
|
|
42
|
+
if (dataSlot === undefined) {
|
|
43
|
+
throw new Error(`Coding Error: empty blobSidecars returned for blockRoot=${toRootHex(blockRoot)} from validation functions`);
|
|
44
|
+
}
|
|
45
|
+
const existing = updatedBatchBlocks.get(dataSlot);
|
|
41
46
|
const blockRootHex = toRootHex(blockRoot);
|
|
42
47
|
if (!existing) {
|
|
43
48
|
throw new Error("Coding error: blockInput must exist when adding blobs");
|
|
@@ -46,7 +51,7 @@ export function cacheByRangeResponses({ cache, peerIdStr, responses, batchBlocks
|
|
|
46
51
|
throw new DownloadByRangeError({
|
|
47
52
|
code: DownloadByRangeErrorCode.MISMATCH_BLOCK_INPUT_TYPE,
|
|
48
53
|
slot: existing.slot,
|
|
49
|
-
blockRoot:
|
|
54
|
+
blockRoot: existing.blockRootHex,
|
|
50
55
|
expected: DAType.Blobs,
|
|
51
56
|
actual: existing.type,
|
|
52
57
|
});
|
|
@@ -63,16 +68,20 @@ export function cacheByRangeResponses({ cache, peerIdStr, responses, batchBlocks
|
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
for (const { blockRoot, columnSidecars } of responses.validatedColumnSidecars ?? []) {
|
|
66
|
-
const
|
|
71
|
+
const dataSlot = columnSidecars.at(0)?.signedBlockHeader.message.slot;
|
|
72
|
+
if (dataSlot === undefined) {
|
|
73
|
+
throw new Error(`Coding Error: empty columnSidecars returned for blockRoot=${toRootHex(blockRoot)} from validation functions`);
|
|
74
|
+
}
|
|
75
|
+
const existing = updatedBatchBlocks.get(dataSlot);
|
|
67
76
|
const blockRootHex = toRootHex(blockRoot);
|
|
68
77
|
if (!existing) {
|
|
69
|
-
throw new Error("Coding error: blockInput must exist when adding
|
|
78
|
+
throw new Error("Coding error: blockInput must exist when adding columns");
|
|
70
79
|
}
|
|
71
80
|
if (!isBlockInputColumns(existing)) {
|
|
72
81
|
throw new DownloadByRangeError({
|
|
73
82
|
code: DownloadByRangeErrorCode.MISMATCH_BLOCK_INPUT_TYPE,
|
|
74
83
|
slot: existing.slot,
|
|
75
|
-
blockRoot:
|
|
84
|
+
blockRoot: existing.blockRootHex,
|
|
76
85
|
expected: DAType.Columns,
|
|
77
86
|
actual: existing.type,
|
|
78
87
|
});
|
|
@@ -157,23 +166,27 @@ export async function validateResponses({ config, batchBlocks, blocksRequest, bl
|
|
|
157
166
|
// If no blocksRequest is provided, batchBlocks must have been provided from cache
|
|
158
167
|
if ((blobsRequest || columnsRequest) && !(blocks || batchBlocks)) {
|
|
159
168
|
throw new DownloadByRangeError({
|
|
160
|
-
code: DownloadByRangeErrorCode.
|
|
169
|
+
code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
|
|
161
170
|
...requestsLogMeta({ blobsRequest, columnsRequest }),
|
|
162
171
|
}, "No blocks to validate data requests against");
|
|
163
172
|
}
|
|
164
173
|
const validatedResponses = {};
|
|
165
174
|
let warnings = null;
|
|
166
175
|
if (blocksRequest) {
|
|
167
|
-
|
|
176
|
+
const result = validateBlockByRangeResponse(config, blocksRequest, blocks ?? []);
|
|
177
|
+
if (result.warnings?.length) {
|
|
178
|
+
warnings = result.warnings;
|
|
179
|
+
}
|
|
180
|
+
validatedResponses.validatedBlocks = result.result;
|
|
168
181
|
}
|
|
169
182
|
const dataRequest = blobsRequest ?? columnsRequest;
|
|
170
183
|
if (!dataRequest) {
|
|
171
|
-
return { result: validatedResponses, warnings
|
|
184
|
+
return { result: validatedResponses, warnings };
|
|
172
185
|
}
|
|
173
|
-
const
|
|
174
|
-
if (!
|
|
186
|
+
const blocksForDataValidation = getBlocksForDataValidation(dataRequest, batchBlocks, validatedResponses.validatedBlocks?.length ? validatedResponses.validatedBlocks : undefined);
|
|
187
|
+
if (!blocksForDataValidation.length) {
|
|
175
188
|
throw new DownloadByRangeError({
|
|
176
|
-
code: DownloadByRangeErrorCode.
|
|
189
|
+
code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
|
|
177
190
|
...requestsLogMeta({ blobsRequest, columnsRequest }),
|
|
178
191
|
}, "No blocks in data request slot range to validate data response against");
|
|
179
192
|
}
|
|
@@ -184,7 +197,7 @@ export async function validateResponses({ config, batchBlocks, blocksRequest, bl
|
|
|
184
197
|
...requestsLogMeta({ blobsRequest, columnsRequest }),
|
|
185
198
|
}, "No blobSidecars to validate against blobsRequest");
|
|
186
199
|
}
|
|
187
|
-
validatedResponses.validatedBlobSidecars = await validateBlobsByRangeResponse(
|
|
200
|
+
validatedResponses.validatedBlobSidecars = await validateBlobsByRangeResponse(blocksForDataValidation, blobSidecars);
|
|
188
201
|
}
|
|
189
202
|
if (columnsRequest) {
|
|
190
203
|
if (!columnSidecars) {
|
|
@@ -193,7 +206,7 @@ export async function validateResponses({ config, batchBlocks, blocksRequest, bl
|
|
|
193
206
|
...requestsLogMeta({ blobsRequest, columnsRequest }),
|
|
194
207
|
}, "No columnSidecars to check columnRequest against");
|
|
195
208
|
}
|
|
196
|
-
const validatedColumnSidecarsResult = await validateColumnsByRangeResponse(columnsRequest,
|
|
209
|
+
const validatedColumnSidecarsResult = await validateColumnsByRangeResponse(config, columnsRequest, blocksForDataValidation, columnSidecars);
|
|
197
210
|
validatedResponses.validatedColumnSidecars = validatedColumnSidecarsResult.result;
|
|
198
211
|
warnings = validatedColumnSidecarsResult.warnings;
|
|
199
212
|
}
|
|
@@ -210,17 +223,27 @@ export async function validateResponses({ config, batchBlocks, blocksRequest, bl
|
|
|
210
223
|
*/
|
|
211
224
|
export function validateBlockByRangeResponse(config, blocksRequest, blocks) {
|
|
212
225
|
const { startSlot, count } = blocksRequest;
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
//
|
|
216
|
-
//
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
226
|
+
// An error was thrown here by @twoeths in #8150 but it breaks for epochs with 0 blocks during chain
|
|
227
|
+
// liveness issues. See comment https://github.com/ChainSafe/lodestar/issues/8147#issuecomment-3246434697
|
|
228
|
+
// There are instances where clients return no blocks though. Need to monitor this via the warns to see
|
|
229
|
+
// if what the correct behavior should be
|
|
230
|
+
if (!blocks.length) {
|
|
231
|
+
throw new DownloadByRangeError({
|
|
232
|
+
code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
|
|
233
|
+
...requestsLogMeta({ blocksRequest }),
|
|
234
|
+
});
|
|
235
|
+
// TODO: this was causing deadlock again. need to come back and fix this so that its possible to process through
|
|
236
|
+
// an empty epoch for periods with poor liveness
|
|
237
|
+
// return {
|
|
238
|
+
// result: [],
|
|
239
|
+
// warnings: [
|
|
240
|
+
// new DownloadByRangeError({
|
|
241
|
+
// code: DownloadByRangeErrorCode.MISSING_BLOCKS_RESPONSE,
|
|
242
|
+
// ...requestsLogMeta({blocksRequest}),
|
|
243
|
+
// }),
|
|
244
|
+
// ],
|
|
245
|
+
// };
|
|
246
|
+
}
|
|
224
247
|
if (blocks.length > count) {
|
|
225
248
|
throw new DownloadByRangeError({
|
|
226
249
|
code: DownloadByRangeErrorCode.EXTRA_BLOCKS,
|
|
@@ -260,13 +283,16 @@ export function validateBlockByRangeResponse(config, blocksRequest, blocks) {
|
|
|
260
283
|
throw new DownloadByRangeError({
|
|
261
284
|
code: DownloadByRangeErrorCode.PARENT_ROOT_MISMATCH,
|
|
262
285
|
slot: blocks[i].message.slot,
|
|
263
|
-
expected:
|
|
264
|
-
actual:
|
|
286
|
+
expected: toRootHex(blockRoot),
|
|
287
|
+
actual: toRootHex(parentRoot),
|
|
265
288
|
}, `Block parent root does not match the previous block's root in BeaconBlocksByRange response`);
|
|
266
289
|
}
|
|
267
290
|
}
|
|
268
291
|
}
|
|
269
|
-
return
|
|
292
|
+
return {
|
|
293
|
+
result: response,
|
|
294
|
+
warnings: null,
|
|
295
|
+
};
|
|
270
296
|
}
|
|
271
297
|
/**
|
|
272
298
|
* Should not be called directly. Only exported for unit testing purposes.
|
|
@@ -313,82 +339,171 @@ export async function validateBlobsByRangeResponse(dataRequestBlocks, blobSideca
|
|
|
313
339
|
}
|
|
314
340
|
/**
|
|
315
341
|
* Should not be called directly. Only exported for unit testing purposes
|
|
342
|
+
*
|
|
343
|
+
* Spec states:
|
|
344
|
+
* 1) must be within range [start_slot, start_slot + count]
|
|
345
|
+
* 2) should respond with all columns in the range or and 3:ResourceUnavailable (and potentially get down-scored)
|
|
346
|
+
* 3) must response with at least the sidecars of the first blob-carrying block that exists in the range
|
|
347
|
+
* 4) must include all sidecars from each block from which there are blobs
|
|
348
|
+
* 5) where they exists, sidecars must be sent in (slot, index) order
|
|
349
|
+
* 6) clients may limit the number of sidecars in a response
|
|
350
|
+
* 7) clients may stop responding mid-response if their view of fork-choice changes
|
|
351
|
+
*
|
|
352
|
+
* We will interpret the spec as follows
|
|
353
|
+
* - Errors when validating: 1, 3, 5
|
|
354
|
+
* - Warnings when validating: 2, 4, 6, 7
|
|
355
|
+
*
|
|
356
|
+
* For "warning" cases, where we get a partial response but sidecars are validated and correct with respect to the
|
|
357
|
+
* blocks, then they will be kept. This loosening of the spec is to help ensure sync goes smoothly and we can find
|
|
358
|
+
* the data needed in difficult network situations.
|
|
359
|
+
*
|
|
360
|
+
* Assume for the following two examples we request indices 5, 10, 15 for a range of slots 32-63
|
|
361
|
+
*
|
|
362
|
+
* For slots where we receive no sidecars, example slot 45, but blobs exist we will stop validating subsequent
|
|
363
|
+
* slots, 45-63. The next round of requests will get structured to pull the from the slot that had columns
|
|
364
|
+
* missing to the end of the range for all columns indices that were requested for the current partially failed
|
|
365
|
+
* request (slots 45-63 and indices 5, 10, 15).
|
|
366
|
+
*
|
|
367
|
+
* For slots where only some of the requested sidecars are received we will proceed with validation. For simplicity sake
|
|
368
|
+
* we will assume that if we only get some indices back for a (or several) slot(s) that the indices we get will be
|
|
369
|
+
* consistent. IE if a peer returns only index 5, they will most likely return that same index for subsequent slot
|
|
370
|
+
* (index 5 for slots 34, 35, 36, etc). They will not likely return 5 on slot 34, 10 on slot 35, 15 on slot 36, etc.
|
|
371
|
+
* This assumption makes the code simpler. For both cases the request for the next round will be structured correctly
|
|
372
|
+
* to pull any missing column indices for whatever range remains. The simplification just leads to re-verification
|
|
373
|
+
* of the columns but the number of columns downloaded will be the same regardless of if they are validated twice.
|
|
374
|
+
*
|
|
375
|
+
* validateColumnsByRangeResponse makes some assumptions about the data being passed in
|
|
376
|
+
* blocks are:
|
|
377
|
+
* - slotwise in order
|
|
378
|
+
* - form a chain
|
|
379
|
+
* - non-sparse response (any missing block is a skipped slot not a bad response)
|
|
380
|
+
* - last block is last slot received
|
|
316
381
|
*/
|
|
317
|
-
export async function validateColumnsByRangeResponse(request,
|
|
318
|
-
// Expected column count considering currently-validated batch blocks
|
|
319
|
-
// TODO GLOAS: Post-gloas's blobKzgCommitments is not in beacon block body. Need to source it from somewhere else.
|
|
320
|
-
const expectedColumnCount = dataRequestBlocks.reduce((acc, { block }) => {
|
|
321
|
-
return block.message.body.blobKzgCommitments.length > 0
|
|
322
|
-
? request.columns.length + acc
|
|
323
|
-
: acc;
|
|
324
|
-
}, 0);
|
|
325
|
-
const nextSlot = dataRequestBlocks.length
|
|
326
|
-
? dataRequestBlocks.at(-1).block.message.slot + 1
|
|
327
|
-
: request.startSlot;
|
|
328
|
-
const possiblyMissingBlocks = nextSlot - request.startSlot + request.count;
|
|
329
|
-
// Allow for extra columns if some blocks are missing from the end of a batch
|
|
330
|
-
// Eg: If we requested 10 blocks but only 8 were returned, allow for up to 2 * columns.length extra columns
|
|
331
|
-
const maxColumnCount = expectedColumnCount + possiblyMissingBlocks * request.columns.length;
|
|
332
|
-
if (columnSidecars.length > maxColumnCount) {
|
|
333
|
-
// this never happens on devnet, so throw error for now
|
|
334
|
-
throw new DownloadByRangeError({
|
|
335
|
-
code: DownloadByRangeErrorCode.OVER_COLUMNS,
|
|
336
|
-
max: maxColumnCount,
|
|
337
|
-
actual: columnSidecars.length,
|
|
338
|
-
}, "Extra data columns received in DataColumnSidecarsByRange response");
|
|
339
|
-
}
|
|
382
|
+
export async function validateColumnsByRangeResponse(config, request, blocks, columnSidecars) {
|
|
340
383
|
const warnings = [];
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const slot =
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
.
|
|
351
|
-
|
|
352
|
-
if (
|
|
384
|
+
const seenColumns = new Map();
|
|
385
|
+
let currentSlot = -1;
|
|
386
|
+
let currentIndex = -1;
|
|
387
|
+
// Check for duplicates and order
|
|
388
|
+
for (const columnSidecar of columnSidecars) {
|
|
389
|
+
const slot = columnSidecar.signedBlockHeader.message.slot;
|
|
390
|
+
let seenSlotColumns = seenColumns.get(slot);
|
|
391
|
+
if (!seenSlotColumns) {
|
|
392
|
+
seenSlotColumns = new Map();
|
|
393
|
+
seenColumns.set(slot, seenSlotColumns);
|
|
394
|
+
}
|
|
395
|
+
if (seenSlotColumns.has(columnSidecar.index)) {
|
|
396
|
+
warnings.push(new DownloadByRangeError({
|
|
397
|
+
code: DownloadByRangeErrorCode.DUPLICATE_COLUMN,
|
|
398
|
+
slot,
|
|
399
|
+
index: columnSidecar.index,
|
|
400
|
+
}));
|
|
353
401
|
continue;
|
|
354
402
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
403
|
+
if (currentSlot > slot) {
|
|
404
|
+
warnings.push(new DownloadByRangeError({
|
|
405
|
+
code: DownloadByRangeErrorCode.OUT_OF_ORDER_COLUMNS,
|
|
406
|
+
slot,
|
|
407
|
+
}, "ColumnSidecars received out of slot order"));
|
|
408
|
+
}
|
|
409
|
+
if (currentSlot === slot && currentIndex > columnSidecar.index) {
|
|
410
|
+
warnings.push(new DownloadByRangeError({
|
|
411
|
+
code: DownloadByRangeErrorCode.OUT_OF_ORDER_COLUMNS,
|
|
412
|
+
slot,
|
|
413
|
+
}, "Column indices out of order within a slot"));
|
|
414
|
+
}
|
|
415
|
+
seenSlotColumns.set(columnSidecar.index, columnSidecar);
|
|
416
|
+
if (currentSlot !== slot) {
|
|
417
|
+
// a new slot has started, reset index
|
|
418
|
+
currentIndex = -1;
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
currentIndex = columnSidecar.index;
|
|
422
|
+
}
|
|
423
|
+
currentSlot = slot;
|
|
424
|
+
}
|
|
425
|
+
const validationPromises = [];
|
|
426
|
+
for (const { blockRoot, block } of blocks) {
|
|
427
|
+
const slot = block.message.slot;
|
|
428
|
+
const rootHex = toRootHex(blockRoot);
|
|
429
|
+
const forkName = config.getForkName(slot);
|
|
430
|
+
const columnSidecarsMap = seenColumns.get(slot) ?? new Map();
|
|
431
|
+
const columnSidecars = Array.from(columnSidecarsMap.values()).sort((a, b) => a.index - b.index);
|
|
432
|
+
let blobCount;
|
|
433
|
+
if (!isForkPostFulu(forkName)) {
|
|
434
|
+
const dataSlot = columnSidecars.at(0)?.signedBlockHeader.message.slot;
|
|
435
|
+
throw new DownloadByRangeError({
|
|
436
|
+
code: DownloadByRangeErrorCode.MISMATCH_BLOCK_FORK,
|
|
437
|
+
slot,
|
|
438
|
+
blockFork: forkName,
|
|
439
|
+
dataFork: dataSlot ? config.getForkName(dataSlot) : "unknown",
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
if (isForkPostGloas(forkName)) {
|
|
443
|
+
// TODO GLOAS: Post-gloas's blobKzgCommitments is not in beacon block body. Need to source it from somewhere else.
|
|
444
|
+
// if block without columns is passed default to zero and throw below
|
|
445
|
+
blobCount = 0;
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
blobCount = block.message.body.blobKzgCommitments.length;
|
|
449
|
+
}
|
|
450
|
+
if (columnSidecars.length === 0) {
|
|
451
|
+
if (!blobCount) {
|
|
452
|
+
// no columns in the slot
|
|
453
|
+
continue;
|
|
361
454
|
}
|
|
362
|
-
|
|
363
|
-
|
|
455
|
+
/**
|
|
456
|
+
* If no columns are found for a block and there are commitments on the block then stop checking and just
|
|
457
|
+
* return early. Even if there were columns returned for subsequent slots that doesn't matter because
|
|
458
|
+
* we will be re-requesting them again anyway. Leftovers just get ignored
|
|
459
|
+
*/
|
|
460
|
+
warnings.push(new DownloadByRangeError({
|
|
461
|
+
code: DownloadByRangeErrorCode.MISSING_COLUMNS,
|
|
462
|
+
slot,
|
|
463
|
+
blockRoot: rootHex,
|
|
464
|
+
missingIndices: prettyPrintIndices(request.columns),
|
|
465
|
+
}));
|
|
466
|
+
break;
|
|
364
467
|
}
|
|
365
|
-
const returnedColumns =
|
|
366
|
-
|
|
468
|
+
const returnedColumns = Array.from(columnSidecarsMap.keys()).sort();
|
|
469
|
+
if (!blobCount) {
|
|
470
|
+
// columns for a block that does not have blobs
|
|
471
|
+
// TODO(fulu): should this be a hard error with no data retained from peer or just a warning
|
|
472
|
+
throw new DownloadByRangeError({
|
|
473
|
+
code: DownloadByRangeErrorCode.NO_COLUMNS_FOR_BLOCK,
|
|
474
|
+
slot,
|
|
475
|
+
blockRoot: rootHex,
|
|
476
|
+
invalidIndices: prettyPrintIndices(returnedColumns),
|
|
477
|
+
}, "Block has no blob commitments but data column sidecars were provided");
|
|
478
|
+
}
|
|
479
|
+
const missingIndices = request.columns.filter((i) => !columnSidecarsMap.has(i));
|
|
367
480
|
if (missingIndices.length > 0) {
|
|
368
481
|
warnings.push(new DownloadByRangeError({
|
|
369
482
|
code: DownloadByRangeErrorCode.MISSING_COLUMNS,
|
|
370
483
|
slot,
|
|
371
|
-
blockRoot:
|
|
484
|
+
blockRoot: rootHex,
|
|
372
485
|
missingIndices: prettyPrintIndices(missingIndices),
|
|
373
486
|
}, "Missing data columns in DataColumnSidecarsByRange response"));
|
|
374
487
|
}
|
|
375
|
-
const extraIndices =
|
|
488
|
+
const extraIndices = returnedColumns.filter((i) => !request.columns.includes(i));
|
|
376
489
|
if (extraIndices.length > 0) {
|
|
377
490
|
warnings.push(new DownloadByRangeError({
|
|
378
491
|
code: DownloadByRangeErrorCode.EXTRA_COLUMNS,
|
|
379
492
|
slot,
|
|
380
|
-
blockRoot:
|
|
493
|
+
blockRoot: rootHex,
|
|
381
494
|
invalidIndices: prettyPrintIndices(extraIndices),
|
|
382
495
|
}, "Data column in not in requested columns in DataColumnSidecarsByRange response"));
|
|
383
496
|
}
|
|
384
|
-
|
|
497
|
+
validationPromises.push(validateBlockDataColumnSidecars(slot, blockRoot, blobCount, columnSidecars).then(() => ({
|
|
385
498
|
blockRoot,
|
|
386
|
-
columnSidecars
|
|
499
|
+
columnSidecars,
|
|
387
500
|
})));
|
|
388
501
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
502
|
+
const validatedColumns = await Promise.all(validationPromises);
|
|
503
|
+
return {
|
|
504
|
+
result: validatedColumns,
|
|
505
|
+
warnings: warnings.length ? warnings : null,
|
|
506
|
+
};
|
|
392
507
|
}
|
|
393
508
|
/**
|
|
394
509
|
* Given a data request, return only the blocks and roots that correspond to the data request (sorted). Assumes that
|
|
@@ -438,7 +553,7 @@ function requestsLogMeta({ blocksRequest, blobsRequest, columnsRequest }) {
|
|
|
438
553
|
}
|
|
439
554
|
export var DownloadByRangeErrorCode;
|
|
440
555
|
(function (DownloadByRangeErrorCode) {
|
|
441
|
-
DownloadByRangeErrorCode["
|
|
556
|
+
DownloadByRangeErrorCode["MISSING_BLOCKS_RESPONSE"] = "DOWNLOAD_BY_RANGE_ERROR_MISSING_BLOCK_RESPONSE";
|
|
442
557
|
DownloadByRangeErrorCode["MISSING_BLOBS_RESPONSE"] = "DOWNLOAD_BY_RANGE_ERROR_MISSING_BLOBS_RESPONSE";
|
|
443
558
|
DownloadByRangeErrorCode["MISSING_COLUMNS_RESPONSE"] = "DOWNLOAD_BY_RANGE_ERROR_MISSING_COLUMNS_RESPONSE";
|
|
444
559
|
/** Error at the reqresp layer */
|
|
@@ -454,7 +569,11 @@ export var DownloadByRangeErrorCode;
|
|
|
454
569
|
DownloadByRangeErrorCode["MISSING_COLUMNS"] = "DOWNLOAD_BY_RANGE_ERROR_MISSING_COLUMNS";
|
|
455
570
|
DownloadByRangeErrorCode["OVER_COLUMNS"] = "DOWNLOAD_BY_RANGE_ERROR_OVER_COLUMNS";
|
|
456
571
|
DownloadByRangeErrorCode["EXTRA_COLUMNS"] = "DOWNLOAD_BY_RANGE_ERROR_EXTRA_COLUMNS";
|
|
572
|
+
DownloadByRangeErrorCode["NO_COLUMNS_FOR_BLOCK"] = "DOWNLOAD_BY_RANGE_ERROR_NO_COLUMNS_FOR_BLOCK";
|
|
573
|
+
DownloadByRangeErrorCode["DUPLICATE_COLUMN"] = "DOWNLOAD_BY_RANGE_ERROR_DUPLICATE_COLUMN";
|
|
574
|
+
DownloadByRangeErrorCode["OUT_OF_ORDER_COLUMNS"] = "DOWNLOAD_BY_RANGE_OUT_OF_ORDER_COLUMNS";
|
|
457
575
|
/** Cached block input type mismatches new data */
|
|
576
|
+
DownloadByRangeErrorCode["MISMATCH_BLOCK_FORK"] = "DOWNLOAD_BY_RANGE_ERROR_MISMATCH_BLOCK_FORK";
|
|
458
577
|
DownloadByRangeErrorCode["MISMATCH_BLOCK_INPUT_TYPE"] = "DOWNLOAD_BY_RANGE_ERROR_MISMATCH_BLOCK_INPUT_TYPE";
|
|
459
578
|
})(DownloadByRangeErrorCode || (DownloadByRangeErrorCode = {}));
|
|
460
579
|
export class DownloadByRangeError extends LodestarError {
|