@lodestar/beacon-node 1.36.0-dev.6832b029e7 → 1.36.0-dev.68f0ed9071
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/chain/errors/blobSidecarError.d.ts +5 -0
- package/lib/chain/errors/blobSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/blobSidecarError.js.map +1 -1
- package/lib/chain/errors/blockError.d.ts +1 -0
- package/lib/chain/errors/blockError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.d.ts +4 -0
- package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
- package/lib/chain/validation/blobSidecar.d.ts +4 -1
- package/lib/chain/validation/blobSidecar.d.ts.map +1 -1
- package/lib/chain/validation/blobSidecar.js +46 -11
- package/lib/chain/validation/blobSidecar.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +1 -0
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts +4 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +33 -5
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/sync/unknownBlock.js +1 -1
- package/lib/sync/unknownBlock.js.map +1 -1
- package/lib/sync/utils/downloadByRange.d.ts +1 -2
- package/lib/sync/utils/downloadByRange.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRange.js +4 -2
- package/lib/sync/utils/downloadByRange.js.map +1 -1
- package/lib/sync/utils/downloadByRoot.d.ts +8 -14
- package/lib/sync/utils/downloadByRoot.d.ts.map +1 -1
- package/lib/sync/utils/downloadByRoot.js +12 -27
- package/lib/sync/utils/downloadByRoot.js.map +1 -1
- package/package.json +14 -14
- package/src/chain/errors/blobSidecarError.ts +12 -2
- package/src/chain/errors/blockError.ts +1 -1
- package/src/chain/errors/dataColumnSidecarError.ts +11 -2
- package/src/chain/validation/blobSidecar.ts +54 -10
- package/src/chain/validation/block.ts +1 -0
- package/src/chain/validation/dataColumnSidecar.ts +43 -4
- package/src/sync/unknownBlock.ts +1 -1
- package/src/sync/utils/downloadByRange.ts +15 -6
- package/src/sync/utils/downloadByRoot.ts +16 -50
|
@@ -58,8 +58,17 @@ export type DataColumnSidecarErrorType =
|
|
|
58
58
|
| {code: DataColumnSidecarErrorCode.ALREADY_KNOWN; columnIndex: number; slot: Slot}
|
|
59
59
|
| {code: DataColumnSidecarErrorCode.FUTURE_SLOT; blockSlot: Slot; currentSlot: Slot}
|
|
60
60
|
| {code: DataColumnSidecarErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
|
|
61
|
-
| {
|
|
62
|
-
|
|
61
|
+
| {
|
|
62
|
+
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN;
|
|
63
|
+
parentRoot: RootHex;
|
|
64
|
+
slot: Slot;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID;
|
|
68
|
+
slot: Slot;
|
|
69
|
+
blockRoot: RootHex;
|
|
70
|
+
index: number;
|
|
71
|
+
}
|
|
63
72
|
| {code: DataColumnSidecarErrorCode.NOT_LATER_THAN_PARENT; parentSlot: Slot; slot: Slot}
|
|
64
73
|
| {code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID; slot: Slot; columnIndex: number}
|
|
65
74
|
| {code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF; slot: Slot; columnIndex: number}
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
import {
|
|
9
9
|
computeEpochAtSlot,
|
|
10
10
|
computeStartSlotAtEpoch,
|
|
11
|
-
|
|
11
|
+
getBlockHeaderProposerSignatureSetByHeaderSlot,
|
|
12
|
+
getBlockHeaderProposerSignatureSetByParentStateSlot,
|
|
12
13
|
} from "@lodestar/state-transition";
|
|
13
14
|
import {BlobIndex, Root, Slot, SubnetID, deneb, ssz} from "@lodestar/types";
|
|
14
15
|
import {toRootHex, verifyMerkleBranch} from "@lodestar/utils";
|
|
@@ -100,7 +101,12 @@ export async function validateGossipBlobSidecar(
|
|
|
100
101
|
// descend from the finalized root.
|
|
101
102
|
// (Non-Lighthouse): Since we prune all blocks non-descendant from finalized checking the `db.block` database won't be useful to guard
|
|
102
103
|
// against known bad fork blocks, so we throw PARENT_UNKNOWN for cases (1) and (2)
|
|
103
|
-
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
104
|
+
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
105
|
+
code: BlobSidecarErrorCode.PARENT_UNKNOWN,
|
|
106
|
+
parentRoot,
|
|
107
|
+
blockRoot: blockHex,
|
|
108
|
+
slot: blobSlot,
|
|
109
|
+
});
|
|
104
110
|
}
|
|
105
111
|
|
|
106
112
|
// [REJECT] The blob is from a higher slot than its parent.
|
|
@@ -120,15 +126,23 @@ export async function validateGossipBlobSidecar(
|
|
|
120
126
|
const blockState = await chain.regen
|
|
121
127
|
.getBlockSlotState(parentRoot, blobSlot, {dontTransferCache: true}, RegenCaller.validateGossipBlock)
|
|
122
128
|
.catch(() => {
|
|
123
|
-
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
129
|
+
throw new BlobSidecarGossipError(GossipAction.IGNORE, {
|
|
130
|
+
code: BlobSidecarErrorCode.PARENT_UNKNOWN,
|
|
131
|
+
parentRoot,
|
|
132
|
+
blockRoot: blockHex,
|
|
133
|
+
slot: blobSlot,
|
|
134
|
+
});
|
|
124
135
|
});
|
|
125
136
|
|
|
126
137
|
// [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
|
|
127
|
-
const signatureSet =
|
|
138
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(blockState, blobSidecar.signedBlockHeader);
|
|
128
139
|
// Don't batch so verification is not delayed
|
|
129
140
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
|
|
130
141
|
throw new BlobSidecarGossipError(GossipAction.REJECT, {
|
|
131
142
|
code: BlobSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
143
|
+
blockRoot: blockHex,
|
|
144
|
+
index: blobSidecar.index,
|
|
145
|
+
slot: blobSlot,
|
|
132
146
|
});
|
|
133
147
|
}
|
|
134
148
|
|
|
@@ -175,8 +189,12 @@ export async function validateGossipBlobSidecar(
|
|
|
175
189
|
* Validate some blob sidecars in a block
|
|
176
190
|
*
|
|
177
191
|
* Requires the block to be known to the node
|
|
192
|
+
*
|
|
193
|
+
* NOTE: chain is optional to skip signature verification. Helpful for testing purposes and so that can control whether
|
|
194
|
+
* signature gets checked depending on the reqresp method that is being checked
|
|
178
195
|
*/
|
|
179
196
|
export async function validateBlockBlobSidecars(
|
|
197
|
+
chain: IBeaconChain | null,
|
|
180
198
|
blockSlot: Slot,
|
|
181
199
|
blockRoot: Root,
|
|
182
200
|
blockBlobCount: number,
|
|
@@ -196,7 +214,8 @@ export async function validateBlockBlobSidecars(
|
|
|
196
214
|
}
|
|
197
215
|
|
|
198
216
|
// Hash the first sidecar block header and compare the rest via (cheaper) equality
|
|
199
|
-
const
|
|
217
|
+
const firstSidecarSignedBlockHeader = blobSidecars[0].signedBlockHeader;
|
|
218
|
+
const firstSidecarBlockHeader = firstSidecarSignedBlockHeader.message;
|
|
200
219
|
const firstBlockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(firstSidecarBlockHeader);
|
|
201
220
|
if (Buffer.compare(blockRoot, firstBlockRoot) !== 0) {
|
|
202
221
|
throw new BlobSidecarValidationError(
|
|
@@ -211,17 +230,42 @@ export async function validateBlockBlobSidecars(
|
|
|
211
230
|
);
|
|
212
231
|
}
|
|
213
232
|
|
|
233
|
+
if (chain !== null) {
|
|
234
|
+
const headState = await chain.getHeadState();
|
|
235
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(headState, firstSidecarSignedBlockHeader);
|
|
236
|
+
|
|
237
|
+
if (
|
|
238
|
+
!(await chain.bls.verifySignatureSets([signatureSet], {
|
|
239
|
+
batchable: true,
|
|
240
|
+
priority: true,
|
|
241
|
+
verifyOnMainThread: false,
|
|
242
|
+
}))
|
|
243
|
+
) {
|
|
244
|
+
throw new BlobSidecarValidationError({
|
|
245
|
+
code: BlobSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
246
|
+
blockRoot: toRootHex(blockRoot),
|
|
247
|
+
slot: blockSlot,
|
|
248
|
+
index: blobSidecars[0].index,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
214
253
|
const commitments = [];
|
|
215
254
|
const blobs = [];
|
|
216
255
|
const proofs = [];
|
|
217
|
-
for (
|
|
218
|
-
const
|
|
219
|
-
|
|
256
|
+
for (let i = 0; i < blobSidecars.length; i++) {
|
|
257
|
+
const blobSidecar = blobSidecars[i];
|
|
258
|
+
const blobIndex = blobSidecar.index;
|
|
259
|
+
|
|
260
|
+
if (
|
|
261
|
+
i !== 0 &&
|
|
262
|
+
!ssz.phase0.SignedBeaconBlockHeader.equals(blobSidecar.signedBlockHeader, firstSidecarSignedBlockHeader)
|
|
263
|
+
) {
|
|
220
264
|
throw new BlobSidecarValidationError(
|
|
221
265
|
{
|
|
222
266
|
code: BlobSidecarErrorCode.INCORRECT_BLOCK,
|
|
223
267
|
slot: blockSlot,
|
|
224
|
-
blobIdx,
|
|
268
|
+
blobIdx: blobIndex,
|
|
225
269
|
expected: toRootHex(blockRoot),
|
|
226
270
|
actual: "unknown - compared via equality",
|
|
227
271
|
},
|
|
@@ -234,7 +278,7 @@ export async function validateBlockBlobSidecars(
|
|
|
234
278
|
{
|
|
235
279
|
code: BlobSidecarErrorCode.INCLUSION_PROOF_INVALID,
|
|
236
280
|
slot: blockSlot,
|
|
237
|
-
blobIdx,
|
|
281
|
+
blobIdx: blobIndex,
|
|
238
282
|
},
|
|
239
283
|
"BlobSidecar inclusion proof invalid"
|
|
240
284
|
);
|
|
@@ -158,6 +158,7 @@ export async function validateGossipBlock(
|
|
|
158
158
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
|
|
159
159
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
160
160
|
code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
161
|
+
blockSlot,
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
164
|
|
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
computeEpochAtSlot,
|
|
9
9
|
computeStartSlotAtEpoch,
|
|
10
|
-
|
|
10
|
+
getBlockHeaderProposerSignatureSetByHeaderSlot,
|
|
11
|
+
getBlockHeaderProposerSignatureSetByParentStateSlot,
|
|
11
12
|
} from "@lodestar/state-transition";
|
|
12
13
|
import {Root, Slot, SubnetID, fulu, ssz} from "@lodestar/types";
|
|
13
14
|
import {toRootHex, verifyMerkleBranch} from "@lodestar/utils";
|
|
@@ -86,6 +87,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
86
87
|
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
87
88
|
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN,
|
|
88
89
|
parentRoot,
|
|
90
|
+
slot: blockHeader.slot,
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
93
|
|
|
@@ -108,6 +110,7 @@ export async function validateGossipDataColumnSidecar(
|
|
|
108
110
|
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
|
|
109
111
|
code: DataColumnSidecarErrorCode.PARENT_UNKNOWN,
|
|
110
112
|
parentRoot,
|
|
113
|
+
slot: blockHeader.slot,
|
|
111
114
|
});
|
|
112
115
|
});
|
|
113
116
|
|
|
@@ -128,15 +131,23 @@ export async function validateGossipDataColumnSidecar(
|
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
// 5) [REJECT] The proposer signature of sidecar.signed_block_header, is valid with respect to the block_header.proposer_index pubkey.
|
|
131
|
-
const signatureSet =
|
|
134
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByParentStateSlot(
|
|
135
|
+
blockState,
|
|
136
|
+
dataColumnSidecar.signedBlockHeader
|
|
137
|
+
);
|
|
132
138
|
// Don't batch so verification is not delayed
|
|
133
139
|
if (
|
|
134
140
|
!(await chain.bls.verifySignatureSets([signatureSet], {
|
|
135
141
|
verifyOnMainThread: blockHeader.slot > chain.forkChoice.getHead().slot,
|
|
136
142
|
}))
|
|
137
143
|
) {
|
|
144
|
+
const blockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(dataColumnSidecar.signedBlockHeader.message);
|
|
145
|
+
const blockRootHex = toRootHex(blockRoot);
|
|
138
146
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
139
147
|
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
148
|
+
blockRoot: blockRootHex,
|
|
149
|
+
index: dataColumnSidecar.index,
|
|
150
|
+
slot: blockHeader.slot,
|
|
140
151
|
});
|
|
141
152
|
}
|
|
142
153
|
|
|
@@ -271,8 +282,12 @@ export function verifyDataColumnSidecarInclusionProof(dataColumnSidecar: fulu.Da
|
|
|
271
282
|
* Validate a subset of data column sidecars in a block
|
|
272
283
|
*
|
|
273
284
|
* Requires the block to be known to the node
|
|
285
|
+
*
|
|
286
|
+
* NOTE: chain is optional to skip signature verification. Helpful for testing purposes and so that can control whether
|
|
287
|
+
* signature gets checked depending on the reqresp method that is being checked
|
|
274
288
|
*/
|
|
275
289
|
export async function validateBlockDataColumnSidecars(
|
|
290
|
+
chain: IBeaconChain | null,
|
|
276
291
|
blockSlot: Slot,
|
|
277
292
|
blockRoot: Root,
|
|
278
293
|
blockBlobCount: number,
|
|
@@ -294,7 +309,8 @@ export async function validateBlockDataColumnSidecars(
|
|
|
294
309
|
);
|
|
295
310
|
}
|
|
296
311
|
// Hash the first sidecar block header and compare the rest via (cheaper) equality
|
|
297
|
-
const
|
|
312
|
+
const firstSidecarSignedBlockHeader = dataColumnSidecars[0].signedBlockHeader;
|
|
313
|
+
const firstSidecarBlockHeader = firstSidecarSignedBlockHeader.message;
|
|
298
314
|
const firstBlockRoot = ssz.phase0.BeaconBlockHeader.hashTreeRoot(firstSidecarBlockHeader);
|
|
299
315
|
if (Buffer.compare(blockRoot, firstBlockRoot) !== 0) {
|
|
300
316
|
throw new DataColumnSidecarValidationError(
|
|
@@ -309,6 +325,26 @@ export async function validateBlockDataColumnSidecars(
|
|
|
309
325
|
);
|
|
310
326
|
}
|
|
311
327
|
|
|
328
|
+
if (chain !== null) {
|
|
329
|
+
const headState = await chain.getHeadState();
|
|
330
|
+
const signatureSet = getBlockHeaderProposerSignatureSetByHeaderSlot(headState, firstSidecarSignedBlockHeader);
|
|
331
|
+
|
|
332
|
+
if (
|
|
333
|
+
!(await chain.bls.verifySignatureSets([signatureSet], {
|
|
334
|
+
batchable: true,
|
|
335
|
+
priority: true,
|
|
336
|
+
verifyOnMainThread: false,
|
|
337
|
+
}))
|
|
338
|
+
) {
|
|
339
|
+
throw new DataColumnSidecarValidationError({
|
|
340
|
+
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
341
|
+
blockRoot: toRootHex(blockRoot),
|
|
342
|
+
slot: blockSlot,
|
|
343
|
+
index: dataColumnSidecars[0].index,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
312
348
|
const commitments: Uint8Array[] = [];
|
|
313
349
|
const cellIndices: number[] = [];
|
|
314
350
|
const cells: Uint8Array[] = [];
|
|
@@ -316,7 +352,10 @@ export async function validateBlockDataColumnSidecars(
|
|
|
316
352
|
for (let i = 0; i < dataColumnSidecars.length; i++) {
|
|
317
353
|
const columnSidecar = dataColumnSidecars[i];
|
|
318
354
|
|
|
319
|
-
if (
|
|
355
|
+
if (
|
|
356
|
+
i !== 0 &&
|
|
357
|
+
!ssz.phase0.SignedBeaconBlockHeader.equals(firstSidecarSignedBlockHeader, columnSidecar.signedBlockHeader)
|
|
358
|
+
) {
|
|
320
359
|
throw new DataColumnSidecarValidationError({
|
|
321
360
|
code: DataColumnSidecarErrorCode.INCORRECT_HEADER_ROOT,
|
|
322
361
|
slot: blockSlot,
|
package/src/sync/unknownBlock.ts
CHANGED
|
@@ -532,7 +532,7 @@ export class BlockInputSync {
|
|
|
532
532
|
const downloadResult = await downloadByRoot({
|
|
533
533
|
config: this.config,
|
|
534
534
|
network: this.network,
|
|
535
|
-
|
|
535
|
+
chain: this.chain,
|
|
536
536
|
emitter: this.chain.emitter,
|
|
537
537
|
peerMeta,
|
|
538
538
|
cacheItem,
|
|
@@ -37,7 +37,6 @@ export type DownloadByRangeResponses = {
|
|
|
37
37
|
|
|
38
38
|
export type DownloadAndCacheByRangeProps = DownloadByRangeRequests & {
|
|
39
39
|
config: ChainForkConfig;
|
|
40
|
-
cache: SeenBlockInput;
|
|
41
40
|
network: INetwork;
|
|
42
41
|
logger: Logger;
|
|
43
42
|
peerIdStr: string;
|
|
@@ -203,7 +202,7 @@ export async function downloadByRange({
|
|
|
203
202
|
blocksRequest,
|
|
204
203
|
blobsRequest,
|
|
205
204
|
columnsRequest,
|
|
206
|
-
}:
|
|
205
|
+
}: DownloadAndCacheByRangeProps): Promise<WarnResult<ValidatedResponses, DownloadByRangeError>> {
|
|
207
206
|
let response: DownloadByRangeResponses;
|
|
208
207
|
try {
|
|
209
208
|
response = await requestByRange({
|
|
@@ -555,9 +554,13 @@ export async function validateBlobsByRangeResponse(
|
|
|
555
554
|
}
|
|
556
555
|
|
|
557
556
|
validateSidecarsPromises.push(
|
|
558
|
-
validateBlockBlobSidecars(
|
|
559
|
-
|
|
560
|
-
|
|
557
|
+
validateBlockBlobSidecars(
|
|
558
|
+
null, // do not pass chain here so we do not validate header signature
|
|
559
|
+
block.message.slot,
|
|
560
|
+
blockRoot,
|
|
561
|
+
blockKzgCommitments.length,
|
|
562
|
+
blockBlobSidecars
|
|
563
|
+
).then(() => ({blockRoot, blobSidecars: blockBlobSidecars}))
|
|
561
564
|
);
|
|
562
565
|
}
|
|
563
566
|
|
|
@@ -768,7 +771,13 @@ export async function validateColumnsByRangeResponse(
|
|
|
768
771
|
}
|
|
769
772
|
|
|
770
773
|
validationPromises.push(
|
|
771
|
-
validateBlockDataColumnSidecars(
|
|
774
|
+
validateBlockDataColumnSidecars(
|
|
775
|
+
null, // do not pass chain here so we do not validate header signature
|
|
776
|
+
slot,
|
|
777
|
+
blockRoot,
|
|
778
|
+
blobCount,
|
|
779
|
+
columnSidecars
|
|
780
|
+
).then(() => ({
|
|
772
781
|
blockRoot,
|
|
773
782
|
columnSidecars,
|
|
774
783
|
}))
|
|
@@ -13,7 +13,7 @@ import {LodestarError, fromHex, prettyPrintIndices, toHex, toRootHex} from "@lod
|
|
|
13
13
|
import {isBlockInputBlobs, isBlockInputColumns} from "../../chain/blocks/blockInput/blockInput.js";
|
|
14
14
|
import {BlockInputSource, IBlockInput} from "../../chain/blocks/blockInput/types.js";
|
|
15
15
|
import {ChainEventEmitter} from "../../chain/emitter.js";
|
|
16
|
-
import {
|
|
16
|
+
import {IBeaconChain} from "../../chain/interface.ts";
|
|
17
17
|
import {validateBlockBlobSidecars} from "../../chain/validation/blobSidecar.js";
|
|
18
18
|
import {validateBlockDataColumnSidecars} from "../../chain/validation/dataColumnSidecar.js";
|
|
19
19
|
import {INetwork} from "../../network/interface.js";
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
|
|
33
33
|
export type FetchByRootCoreProps = {
|
|
34
34
|
config: ChainForkConfig;
|
|
35
|
+
chain: IBeaconChain | null; // null for testing purposes
|
|
35
36
|
network: INetwork;
|
|
36
37
|
peerMeta: PeerSyncMeta;
|
|
37
38
|
};
|
|
@@ -63,13 +64,13 @@ export type FetchByRootResponses = {
|
|
|
63
64
|
|
|
64
65
|
export type DownloadByRootProps = FetchByRootCoreProps & {
|
|
65
66
|
cacheItem: BlockInputSyncCacheItem;
|
|
66
|
-
|
|
67
|
+
chain: IBeaconChain;
|
|
67
68
|
emitter: ChainEventEmitter;
|
|
68
69
|
};
|
|
69
70
|
|
|
70
71
|
export async function downloadByRoot({
|
|
71
72
|
config,
|
|
72
|
-
|
|
73
|
+
chain,
|
|
73
74
|
network,
|
|
74
75
|
emitter,
|
|
75
76
|
peerMeta,
|
|
@@ -84,6 +85,7 @@ export async function downloadByRoot({
|
|
|
84
85
|
warnings,
|
|
85
86
|
} = await fetchByRoot({
|
|
86
87
|
config,
|
|
88
|
+
chain,
|
|
87
89
|
network,
|
|
88
90
|
cacheItem,
|
|
89
91
|
blockRoot,
|
|
@@ -103,7 +105,7 @@ export async function downloadByRoot({
|
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
107
|
} else {
|
|
106
|
-
blockInput =
|
|
108
|
+
blockInput = chain.seenBlockInputCache.getByBlock({
|
|
107
109
|
block,
|
|
108
110
|
peerIdStr,
|
|
109
111
|
blockRootHex: rootHex,
|
|
@@ -210,6 +212,7 @@ export async function downloadByRoot({
|
|
|
210
212
|
|
|
211
213
|
export async function fetchByRoot({
|
|
212
214
|
config,
|
|
215
|
+
chain,
|
|
213
216
|
network,
|
|
214
217
|
peerMeta,
|
|
215
218
|
blockRoot,
|
|
@@ -237,6 +240,7 @@ export async function fetchByRoot({
|
|
|
237
240
|
if (isBlockInputBlobs(cacheItem.blockInput)) {
|
|
238
241
|
blobSidecars = await fetchAndValidateBlobs({
|
|
239
242
|
config,
|
|
243
|
+
chain,
|
|
240
244
|
network,
|
|
241
245
|
peerIdStr,
|
|
242
246
|
forkName: forkName as ForkPreFulu,
|
|
@@ -248,6 +252,7 @@ export async function fetchByRoot({
|
|
|
248
252
|
if (isBlockInputColumns(cacheItem.blockInput)) {
|
|
249
253
|
columnSidecarResult = await fetchAndValidateColumns({
|
|
250
254
|
config,
|
|
255
|
+
chain,
|
|
251
256
|
network,
|
|
252
257
|
peerMeta,
|
|
253
258
|
forkName: forkName as ForkPostFulu,
|
|
@@ -268,6 +273,7 @@ export async function fetchByRoot({
|
|
|
268
273
|
if (isForkPostFulu(forkName)) {
|
|
269
274
|
columnSidecarResult = await fetchAndValidateColumns({
|
|
270
275
|
config,
|
|
276
|
+
chain,
|
|
271
277
|
network,
|
|
272
278
|
peerMeta,
|
|
273
279
|
forkName,
|
|
@@ -280,6 +286,7 @@ export async function fetchByRoot({
|
|
|
280
286
|
const blobCount = commitments.length;
|
|
281
287
|
blobSidecars = await fetchAndValidateBlobs({
|
|
282
288
|
config,
|
|
289
|
+
chain,
|
|
283
290
|
network,
|
|
284
291
|
peerIdStr,
|
|
285
292
|
forkName: forkName as ForkPreFulu,
|
|
@@ -305,7 +312,7 @@ export async function fetchAndValidateBlock({
|
|
|
305
312
|
network,
|
|
306
313
|
peerIdStr,
|
|
307
314
|
blockRoot,
|
|
308
|
-
}: FetchByRootAndValidateBlockProps): Promise<SignedBeaconBlock> {
|
|
315
|
+
}: Omit<FetchByRootAndValidateBlockProps, "chain">): Promise<SignedBeaconBlock> {
|
|
309
316
|
const response = await network.sendBeaconBlocksByRoot(peerIdStr, [blockRoot]);
|
|
310
317
|
const block = response.at(0)?.data;
|
|
311
318
|
if (!block) {
|
|
@@ -331,6 +338,7 @@ export async function fetchAndValidateBlock({
|
|
|
331
338
|
}
|
|
332
339
|
|
|
333
340
|
export async function fetchAndValidateBlobs({
|
|
341
|
+
chain,
|
|
334
342
|
network,
|
|
335
343
|
peerIdStr,
|
|
336
344
|
blockRoot,
|
|
@@ -344,7 +352,7 @@ export async function fetchAndValidateBlobs({
|
|
|
344
352
|
missing,
|
|
345
353
|
});
|
|
346
354
|
|
|
347
|
-
await validateBlockBlobSidecars(block.message.slot, blockRoot, missing.length, blobSidecars);
|
|
355
|
+
await validateBlockBlobSidecars(chain, block.message.slot, blockRoot, missing.length, blobSidecars);
|
|
348
356
|
|
|
349
357
|
return blobSidecars;
|
|
350
358
|
}
|
|
@@ -368,6 +376,7 @@ export async function fetchBlobsByRoot({
|
|
|
368
376
|
}
|
|
369
377
|
|
|
370
378
|
export async function fetchAndValidateColumns({
|
|
379
|
+
chain,
|
|
371
380
|
network,
|
|
372
381
|
peerMeta,
|
|
373
382
|
block,
|
|
@@ -438,7 +447,7 @@ export async function fetchAndValidateColumns({
|
|
|
438
447
|
);
|
|
439
448
|
}
|
|
440
449
|
|
|
441
|
-
await validateBlockDataColumnSidecars(slot, blockRoot, blobCount, columnSidecars);
|
|
450
|
+
await validateBlockDataColumnSidecars(chain, slot, blockRoot, blobCount, columnSidecars);
|
|
442
451
|
|
|
443
452
|
return {result: columnSidecars, warnings: warnings.length > 0 ? warnings : null};
|
|
444
453
|
}
|
|
@@ -456,49 +465,6 @@ export async function fetchColumnsByRoot({
|
|
|
456
465
|
return await network.sendDataColumnSidecarsByRoot(peerMeta.peerId, [{blockRoot, columns: missing}]);
|
|
457
466
|
}
|
|
458
467
|
|
|
459
|
-
// TODO(fulu) not in use, remove?
|
|
460
|
-
export type ValidateColumnSidecarsProps = Pick<
|
|
461
|
-
FetchByRootAndValidateColumnsProps,
|
|
462
|
-
"config" | "peerMeta" | "blockRoot" | "missing"
|
|
463
|
-
> & {
|
|
464
|
-
slot: number;
|
|
465
|
-
blobCount: number;
|
|
466
|
-
needed?: fulu.DataColumnSidecars;
|
|
467
|
-
needToPublish?: fulu.DataColumnSidecars;
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
// TODO(fulu) not in use, remove?
|
|
471
|
-
export async function validateColumnSidecars({
|
|
472
|
-
peerMeta,
|
|
473
|
-
slot,
|
|
474
|
-
blockRoot,
|
|
475
|
-
blobCount,
|
|
476
|
-
missing,
|
|
477
|
-
needed = [],
|
|
478
|
-
needToPublish = [],
|
|
479
|
-
}: ValidateColumnSidecarsProps): Promise<void> {
|
|
480
|
-
const requestedIndices = missing;
|
|
481
|
-
const extraIndices: number[] = [];
|
|
482
|
-
for (const columnSidecar of needed) {
|
|
483
|
-
if (!requestedIndices.includes(columnSidecar.index)) {
|
|
484
|
-
extraIndices.push(columnSidecar.index);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
if (extraIndices.length > 0) {
|
|
488
|
-
throw new DownloadByRootError(
|
|
489
|
-
{
|
|
490
|
-
code: DownloadByRootErrorCode.EXTRA_SIDECAR_RECEIVED,
|
|
491
|
-
peer: prettyPrintPeerIdStr(peerMeta.peerId),
|
|
492
|
-
slot,
|
|
493
|
-
blockRoot: toRootHex(blockRoot),
|
|
494
|
-
invalidIndices: prettyPrintIndices(extraIndices),
|
|
495
|
-
},
|
|
496
|
-
"Received a columnSidecar that was not requested"
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
await validateBlockDataColumnSidecars(slot, blockRoot, blobCount, [...needed, ...needToPublish]);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
468
|
export enum DownloadByRootErrorCode {
|
|
503
469
|
MISMATCH_BLOCK_ROOT = "DOWNLOAD_BY_ROOT_ERROR_MISMATCH_BLOCK_ROOT",
|
|
504
470
|
EXTRA_SIDECAR_RECEIVED = "DOWNLOAD_BY_ROOT_ERROR_EXTRA_SIDECAR_RECEIVED",
|