@lodestar/beacon-node 1.48.0-dev.fd70e5fc15 → 1.48.0-dev.ff9749be2c
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 +4 -4
- package/lib/api/impl/beacon/blocks/index.js.map +1 -1
- package/lib/chain/archiveStore/archiveStore.d.ts +1 -0
- package/lib/chain/archiveStore/archiveStore.d.ts.map +1 -1
- package/lib/chain/archiveStore/archiveStore.js +1 -0
- package/lib/chain/archiveStore/archiveStore.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/historicalStateRegen.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/historicalStateRegen.js +1 -0
- package/lib/chain/archiveStore/historicalState/historicalStateRegen.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/metrics.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/metrics.js +12 -1
- package/lib/chain/archiveStore/historicalState/metrics.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/types.d.ts +2 -0
- package/lib/chain/archiveStore/historicalState/types.d.ts.map +1 -1
- package/lib/chain/archiveStore/historicalState/types.js.map +1 -1
- package/lib/chain/archiveStore/historicalState/worker.js +4 -1
- package/lib/chain/archiveStore/historicalState/worker.js.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.d.ts.map +1 -1
- package/lib/chain/archiveStore/utils/archiveBlocks.js +31 -34
- package/lib/chain/archiveStore/utils/archiveBlocks.js.map +1 -1
- package/lib/chain/blocks/index.d.ts.map +1 -1
- package/lib/chain/blocks/index.js +3 -2
- package/lib/chain/blocks/index.js.map +1 -1
- package/lib/chain/blocks/writeBlockInputToDb.d.ts.map +1 -1
- package/lib/chain/blocks/writeBlockInputToDb.js +9 -16
- package/lib/chain/blocks/writeBlockInputToDb.js.map +1 -1
- package/lib/chain/chain.d.ts +4 -3
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +60 -35
- package/lib/chain/chain.js.map +1 -1
- package/lib/chain/errors/blockError.d.ts +14 -7
- package/lib/chain/errors/blockError.d.ts.map +1 -1
- package/lib/chain/errors/blockError.js +0 -2
- package/lib/chain/errors/blockError.js.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.d.ts +15 -2
- package/lib/chain/errors/dataColumnSidecarError.d.ts.map +1 -1
- package/lib/chain/errors/dataColumnSidecarError.js.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.d.ts +10 -0
- package/lib/chain/errors/executionPayloadEnvelope.d.ts.map +1 -1
- package/lib/chain/errors/executionPayloadEnvelope.js.map +1 -1
- package/lib/chain/interface.d.ts +2 -2
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.d.ts.map +1 -1
- package/lib/chain/prepareNextSlot.js +16 -14
- package/lib/chain/prepareNextSlot.js.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.d.ts +4 -2
- package/lib/chain/produceBlock/produceBlockBody.d.ts.map +1 -1
- package/lib/chain/produceBlock/produceBlockBody.js +11 -8
- package/lib/chain/produceBlock/produceBlockBody.js.map +1 -1
- package/lib/chain/validation/block.d.ts.map +1 -1
- package/lib/chain/validation/block.js +24 -11
- package/lib/chain/validation/block.js.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.d.ts.map +1 -1
- package/lib/chain/validation/dataColumnSidecar.js +38 -13
- package/lib/chain/validation/dataColumnSidecar.js.map +1 -1
- package/lib/chain/validation/executionPayloadEnvelope.js +10 -0
- package/lib/chain/validation/executionPayloadEnvelope.js.map +1 -1
- package/lib/db/beacon.d.ts +14 -5
- package/lib/db/beacon.d.ts.map +1 -1
- package/lib/db/beacon.js +17 -3
- package/lib/db/beacon.js.map +1 -1
- package/lib/db/dataColumnStore.d.ts +39 -0
- package/lib/db/dataColumnStore.d.ts.map +1 -0
- package/lib/db/dataColumnStore.js +81 -0
- package/lib/db/dataColumnStore.js.map +1 -0
- package/lib/db/flatFileStore/atomicWrite.d.ts +8 -0
- package/lib/db/flatFileStore/atomicWrite.d.ts.map +1 -0
- package/lib/db/flatFileStore/atomicWrite.js +61 -0
- package/lib/db/flatFileStore/atomicWrite.js.map +1 -0
- package/lib/db/flatFileStore/dcolFormat.d.ts +90 -0
- package/lib/db/flatFileStore/dcolFormat.d.ts.map +1 -0
- package/lib/db/flatFileStore/dcolFormat.js +286 -0
- package/lib/db/flatFileStore/dcolFormat.js.map +1 -0
- package/lib/db/flatFileStore/errors.d.ts +82 -0
- package/lib/db/flatFileStore/errors.d.ts.map +1 -0
- package/lib/db/flatFileStore/errors.js +32 -0
- package/lib/db/flatFileStore/errors.js.map +1 -0
- package/lib/db/flatFileStore/flatFileStore.d.ts +41 -0
- package/lib/db/flatFileStore/flatFileStore.d.ts.map +1 -0
- package/lib/db/flatFileStore/flatFileStore.js +251 -0
- package/lib/db/flatFileStore/flatFileStore.js.map +1 -0
- package/lib/db/flatFileStore/index.d.ts +4 -0
- package/lib/db/flatFileStore/index.d.ts.map +1 -0
- package/lib/db/flatFileStore/index.js +2 -0
- package/lib/db/flatFileStore/index.js.map +1 -0
- package/lib/db/flatFileStore/interface.d.ts +25 -0
- package/lib/db/flatFileStore/interface.d.ts.map +1 -0
- package/lib/db/flatFileStore/interface.js +2 -0
- package/lib/db/flatFileStore/interface.js.map +1 -0
- package/lib/db/flatFileStore/metrics.d.ts +24 -0
- package/lib/db/flatFileStore/metrics.d.ts.map +1 -0
- package/lib/db/flatFileStore/metrics.js +25 -0
- package/lib/db/flatFileStore/metrics.js.map +1 -0
- package/lib/db/flatFileStore/path.d.ts +9 -0
- package/lib/db/flatFileStore/path.d.ts.map +1 -0
- package/lib/db/flatFileStore/path.js +21 -0
- package/lib/db/flatFileStore/path.js.map +1 -0
- package/lib/db/flatFileStore/slotIndex.d.ts +14 -0
- package/lib/db/flatFileStore/slotIndex.d.ts.map +1 -0
- package/lib/db/flatFileStore/slotIndex.js +46 -0
- package/lib/db/flatFileStore/slotIndex.js.map +1 -0
- package/lib/db/flatFileStore/snappy.d.ts +3 -0
- package/lib/db/flatFileStore/snappy.d.ts.map +1 -0
- package/lib/db/flatFileStore/snappy.js +12 -0
- package/lib/db/flatFileStore/snappy.js.map +1 -0
- package/lib/db/index.d.ts +1 -0
- package/lib/db/index.d.ts.map +1 -1
- package/lib/db/interface.d.ts +8 -1
- package/lib/db/interface.d.ts.map +1 -1
- package/lib/db/repositories/blockArchive.d.ts +8 -1
- package/lib/db/repositories/blockArchive.d.ts.map +1 -1
- package/lib/db/repositories/blockArchive.js +65 -28
- package/lib/db/repositories/blockArchive.js.map +1 -1
- package/lib/db/repositories/blockArchiveIndex.d.ts +1 -2
- package/lib/db/repositories/blockArchiveIndex.d.ts.map +1 -1
- package/lib/db/repositories/blockArchiveIndex.js +3 -7
- package/lib/db/repositories/blockArchiveIndex.js.map +1 -1
- package/lib/metrics/metrics/lodestar.d.ts +18 -0
- package/lib/metrics/metrics/lodestar.d.ts.map +1 -1
- package/lib/metrics/metrics/lodestar.js +55 -1
- package/lib/metrics/metrics/lodestar.js.map +1 -1
- package/lib/monitoring/clientStats.js +1 -1
- package/lib/monitoring/clientStats.js.map +1 -1
- package/lib/network/gossip/encoding.d.ts.map +1 -1
- package/lib/network/gossip/encoding.js +0 -7
- package/lib/network/gossip/encoding.js.map +1 -1
- package/lib/network/gossip/topic.d.ts +2 -1
- package/lib/network/gossip/topic.d.ts.map +1 -1
- package/lib/network/gossip/topic.js +4 -20
- package/lib/network/gossip/topic.js.map +1 -1
- package/lib/network/libp2p/index.d.ts +9 -1
- package/lib/network/libp2p/index.d.ts.map +1 -1
- package/lib/network/libp2p/index.js +23 -0
- package/lib/network/libp2p/index.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +6 -7
- package/lib/network/processor/gossipHandlers.js.map +1 -1
- package/lib/network/processor/index.d.ts +49 -3
- package/lib/network/processor/index.d.ts.map +1 -1
- package/lib/network/processor/index.js +232 -98
- package/lib/network/processor/index.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js +112 -91
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRange.js.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.d.ts.map +1 -1
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js +2 -0
- package/lib/network/reqresp/handlers/dataColumnSidecarsByRoot.js.map +1 -1
- package/lib/network/reqresp/protocols.d.ts.map +1 -1
- package/lib/network/reqresp/protocols.js +6 -22
- package/lib/network/reqresp/protocols.js.map +1 -1
- package/lib/network/reqresp/utils/dataColumnResponseValidation.d.ts +2 -1
- package/lib/network/reqresp/utils/dataColumnResponseValidation.d.ts.map +1 -1
- package/lib/network/reqresp/utils/dataColumnResponseValidation.js +14 -9
- package/lib/network/reqresp/utils/dataColumnResponseValidation.js.map +1 -1
- package/lib/node/nodejs.d.ts +2 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +4 -2
- package/lib/node/nodejs.js.map +1 -1
- package/lib/util/sszBytes.d.ts +6 -0
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +1 -1
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +18 -19
- package/src/api/impl/beacon/blocks/index.ts +8 -4
- package/src/chain/archiveStore/archiveStore.ts +6 -1
- package/src/chain/archiveStore/historicalState/historicalStateRegen.ts +1 -0
- package/src/chain/archiveStore/historicalState/metrics.ts +14 -1
- package/src/chain/archiveStore/historicalState/types.ts +2 -0
- package/src/chain/archiveStore/historicalState/worker.ts +4 -1
- package/src/chain/archiveStore/utils/archiveBlocks.ts +34 -39
- package/src/chain/blocks/index.ts +13 -2
- package/src/chain/blocks/writeBlockInputToDb.ts +10 -17
- package/src/chain/chain.ts +75 -34
- package/src/chain/errors/blockError.ts +19 -10
- package/src/chain/errors/dataColumnSidecarError.ts +24 -8
- package/src/chain/errors/executionPayloadEnvelope.ts +14 -2
- package/src/chain/interface.ts +2 -2
- package/src/chain/prepareNextSlot.ts +21 -17
- package/src/chain/produceBlock/produceBlockBody.ts +12 -8
- package/src/chain/validation/block.ts +24 -12
- package/src/chain/validation/dataColumnSidecar.ts +47 -14
- package/src/chain/validation/executionPayloadEnvelope.ts +10 -0
- package/src/db/beacon.ts +33 -6
- package/src/db/dataColumnStore.ts +113 -0
- package/src/db/flatFileStore/atomicWrite.ts +65 -0
- package/src/db/flatFileStore/dcolFormat.ts +389 -0
- package/src/db/flatFileStore/errors.ts +53 -0
- package/src/db/flatFileStore/flatFileStore.ts +310 -0
- package/src/db/flatFileStore/index.ts +3 -0
- package/src/db/flatFileStore/interface.ts +21 -0
- package/src/db/flatFileStore/metrics.ts +48 -0
- package/src/db/flatFileStore/path.ts +32 -0
- package/src/db/flatFileStore/slotIndex.ts +56 -0
- package/src/db/flatFileStore/snappy.ts +14 -0
- package/src/db/index.ts +1 -0
- package/src/db/interface.ts +9 -1
- package/src/db/repositories/blockArchive.ts +89 -30
- package/src/db/repositories/blockArchiveIndex.ts +4 -9
- package/src/metrics/metrics/lodestar.ts +57 -1
- package/src/monitoring/clientStats.ts +1 -1
- package/src/network/gossip/encoding.ts +0 -7
- package/src/network/gossip/topic.ts +3 -25
- package/src/network/libp2p/index.ts +28 -1
- package/src/network/processor/gossipHandlers.ts +11 -11
- package/src/network/processor/index.ts +263 -148
- package/src/network/reqresp/handlers/dataColumnSidecarsByRange.ts +139 -105
- package/src/network/reqresp/handlers/dataColumnSidecarsByRoot.ts +2 -0
- package/src/network/reqresp/protocols.ts +7 -24
- package/src/network/reqresp/utils/dataColumnResponseValidation.ts +15 -7
- package/src/node/nodejs.ts +6 -1
- package/src/util/sszBytes.ts +1 -1
|
@@ -134,8 +134,9 @@ export async function validateGossipBlock(
|
|
|
134
134
|
if (parentBlock.slot >= blockSlot) {
|
|
135
135
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
136
136
|
code: BlockErrorCode.NOT_LATER_THAN_PARENT,
|
|
137
|
-
parentSlot: parentBlock.slot,
|
|
138
137
|
slot: blockSlot,
|
|
138
|
+
root: blockRoot,
|
|
139
|
+
parentSlot: parentBlock.slot,
|
|
139
140
|
});
|
|
140
141
|
}
|
|
141
142
|
|
|
@@ -150,6 +151,8 @@ export async function validateGossipBlock(
|
|
|
150
151
|
if (blobKzgCommitmentsLen > maxBlobsPerBlock) {
|
|
151
152
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
152
153
|
code: BlockErrorCode.TOO_MANY_KZG_COMMITMENTS,
|
|
154
|
+
slot: blockSlot,
|
|
155
|
+
root: blockRoot,
|
|
153
156
|
blobKzgCommitmentsLen,
|
|
154
157
|
commitmentLimit: maxBlobsPerBlock,
|
|
155
158
|
});
|
|
@@ -167,6 +170,8 @@ export async function validateGossipBlock(
|
|
|
167
170
|
if (blobKzgCommitmentsLen > maxBlobsPerBlock) {
|
|
168
171
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
169
172
|
code: BlockErrorCode.TOO_MANY_KZG_COMMITMENTS,
|
|
173
|
+
slot: blockSlot,
|
|
174
|
+
root: blockRoot,
|
|
170
175
|
blobKzgCommitmentsLen,
|
|
171
176
|
commitmentLimit: maxBlobsPerBlock,
|
|
172
177
|
});
|
|
@@ -176,19 +181,13 @@ export async function validateGossipBlock(
|
|
|
176
181
|
if (!byteArrayEquals(bid.parentBlockRoot, block.parentRoot)) {
|
|
177
182
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
178
183
|
code: BlockErrorCode.BID_PARENT_ROOT_MISMATCH,
|
|
184
|
+
slot: blockSlot,
|
|
185
|
+
root: blockRoot,
|
|
179
186
|
bidParentRoot: toRootHex(bid.parentBlockRoot),
|
|
180
187
|
blockParentRoot: parentRoot,
|
|
181
188
|
});
|
|
182
189
|
}
|
|
183
190
|
|
|
184
|
-
// [REJECT] The block contains no deposits.
|
|
185
|
-
if (body.deposits.length !== 0) {
|
|
186
|
-
throw new BlockGossipError(GossipAction.REJECT, {
|
|
187
|
-
code: BlockErrorCode.NON_ZERO_DEPOSITS,
|
|
188
|
-
count: body.deposits.length,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
191
|
// TODO GLOAS: [REJECT] The block's execution payload parent (defined by bid.parent_block_hash) passes all validation
|
|
193
192
|
// This requires execution engine integration to verify the parent block hash
|
|
194
193
|
}
|
|
@@ -249,6 +248,8 @@ export async function validateGossipBlock(
|
|
|
249
248
|
if (executionPayload.timestamp !== computeTimeAtSlot(config, blockSlot, chain.genesisTime)) {
|
|
250
249
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
251
250
|
code: BlockErrorCode.INCORRECT_TIMESTAMP,
|
|
251
|
+
slot: blockSlot,
|
|
252
|
+
root: blockRoot,
|
|
252
253
|
timestamp: executionPayload.timestamp,
|
|
253
254
|
expectedTimestamp,
|
|
254
255
|
});
|
|
@@ -258,7 +259,12 @@ export async function validateGossipBlock(
|
|
|
258
259
|
|
|
259
260
|
// [REJECT] The proposer index is a valid validator index
|
|
260
261
|
if (proposerIndex >= state.validatorCount) {
|
|
261
|
-
throw new BlockGossipError(GossipAction.REJECT, {
|
|
262
|
+
throw new BlockGossipError(GossipAction.REJECT, {
|
|
263
|
+
code: BlockErrorCode.UNKNOWN_PROPOSER,
|
|
264
|
+
slot: blockSlot,
|
|
265
|
+
root: blockRoot,
|
|
266
|
+
proposerIndex,
|
|
267
|
+
});
|
|
262
268
|
}
|
|
263
269
|
|
|
264
270
|
// [REJECT] The proposer signature, signed_beacon_block.signature, is valid with respect to the proposer_index pubkey.
|
|
@@ -270,7 +276,12 @@ export async function validateGossipBlock(
|
|
|
270
276
|
// shuffling, the block MAY be queued for later processing while proposers for the block's branch are calculated --
|
|
271
277
|
// in such a case do not REJECT, instead IGNORE this message.
|
|
272
278
|
if (state.getBeaconProposer(blockSlot) !== proposerIndex) {
|
|
273
|
-
throw new BlockGossipError(GossipAction.REJECT, {
|
|
279
|
+
throw new BlockGossipError(GossipAction.REJECT, {
|
|
280
|
+
code: BlockErrorCode.INCORRECT_PROPOSER,
|
|
281
|
+
slot: blockSlot,
|
|
282
|
+
root: blockRoot,
|
|
283
|
+
proposerIndex,
|
|
284
|
+
});
|
|
274
285
|
}
|
|
275
286
|
|
|
276
287
|
// Simple implementation of a pending block queue. Keeping the block here recycles the queue logic, and keeps the
|
|
@@ -315,7 +326,8 @@ export async function verifyBlockProposerSignature(
|
|
|
315
326
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: opts.verifyOnMainThread ?? true}))) {
|
|
316
327
|
throw new BlockGossipError(GossipAction.REJECT, {
|
|
317
328
|
code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
318
|
-
blockSlot,
|
|
329
|
+
slot: blockSlot,
|
|
330
|
+
root: blockRoot,
|
|
319
331
|
});
|
|
320
332
|
}
|
|
321
333
|
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
computeStartSlotAtEpoch,
|
|
12
12
|
getBlockHeaderProposerSignatureSetByHeaderSlot,
|
|
13
13
|
} from "@lodestar/state-transition";
|
|
14
|
-
import {DataColumnSidecar, Root, Slot, SubnetID, ValidatorIndex, fulu, gloas, ssz} from "@lodestar/types";
|
|
14
|
+
import {DataColumnSidecar, Root, RootHex, Slot, SubnetID, ValidatorIndex, fulu, gloas, ssz} from "@lodestar/types";
|
|
15
15
|
import {byteArrayEquals, toRootHex, verifyMerkleBranch} from "@lodestar/utils";
|
|
16
16
|
import {BeaconMetrics} from "../../metrics/metrics/beacon.js";
|
|
17
17
|
import {Metrics} from "../../metrics/metrics.js";
|
|
@@ -39,12 +39,14 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
39
39
|
const blockRootHex = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader));
|
|
40
40
|
|
|
41
41
|
// 1) [REJECT] The sidecar is valid as verified by verify_data_column_sidecar
|
|
42
|
-
verifyFuluDataColumnSidecar(chain.config, dataColumnSidecar);
|
|
42
|
+
verifyFuluDataColumnSidecar(chain.config, dataColumnSidecar, blockRootHex);
|
|
43
43
|
|
|
44
44
|
// 2) [REJECT] The sidecar is for the correct subnet -- i.e. compute_subnet_for_data_column_sidecar(sidecar.index) == subnet_id
|
|
45
45
|
if (computeSubnetForDataColumnSidecar(chain.config, dataColumnSidecar) !== gossipSubnet) {
|
|
46
46
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
47
47
|
code: DataColumnSidecarErrorCode.INVALID_SUBNET,
|
|
48
|
+
slot: blockHeader.slot,
|
|
49
|
+
root: blockRootHex,
|
|
48
50
|
columnIndex: dataColumnSidecar.index,
|
|
49
51
|
gossipSubnet: gossipSubnet,
|
|
50
52
|
});
|
|
@@ -100,8 +102,9 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
100
102
|
if (parentBlock.slot >= blockHeader.slot) {
|
|
101
103
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
102
104
|
code: DataColumnSidecarErrorCode.NOT_LATER_THAN_PARENT,
|
|
103
|
-
parentSlot: parentBlock.slot,
|
|
104
105
|
slot: blockHeader.slot,
|
|
106
|
+
root: blockRootHex,
|
|
107
|
+
parentSlot: parentBlock.slot,
|
|
105
108
|
});
|
|
106
109
|
}
|
|
107
110
|
|
|
@@ -140,6 +143,8 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
140
143
|
if (proposerIndex !== expectedProposerIndex) {
|
|
141
144
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
142
145
|
code: DataColumnSidecarErrorCode.INCORRECT_PROPOSER,
|
|
146
|
+
slot: blockHeader.slot,
|
|
147
|
+
root: blockRootHex,
|
|
143
148
|
actualProposerIndex: proposerIndex,
|
|
144
149
|
expectedProposerIndex,
|
|
145
150
|
});
|
|
@@ -161,9 +166,9 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
161
166
|
) {
|
|
162
167
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
163
168
|
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
164
|
-
blockRoot: blockRootHex,
|
|
165
|
-
index: dataColumnSidecar.index,
|
|
166
169
|
slot: blockHeader.slot,
|
|
170
|
+
root: blockRootHex,
|
|
171
|
+
index: dataColumnSidecar.index,
|
|
167
172
|
});
|
|
168
173
|
}
|
|
169
174
|
|
|
@@ -185,7 +190,8 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
185
190
|
if (!valid) {
|
|
186
191
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
187
192
|
code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID,
|
|
188
|
-
slot:
|
|
193
|
+
slot: blockHeader.slot,
|
|
194
|
+
root: blockRootHex,
|
|
189
195
|
columnIndex: dataColumnSidecar.index,
|
|
190
196
|
});
|
|
191
197
|
}
|
|
@@ -204,6 +210,7 @@ export async function validateGossipFuluDataColumnSidecar(
|
|
|
204
210
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
205
211
|
code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF,
|
|
206
212
|
slot: blockHeader.slot,
|
|
213
|
+
root: blockRootHex,
|
|
207
214
|
columnIndex: dataColumnSidecar.index,
|
|
208
215
|
});
|
|
209
216
|
} finally {
|
|
@@ -240,6 +247,7 @@ export async function validateGossipGloasDataColumnSidecar(
|
|
|
240
247
|
if (block.slot !== dataColumnSidecar.slot) {
|
|
241
248
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
242
249
|
code: DataColumnSidecarErrorCode.INCORRECT_SIDECAR_SLOT,
|
|
250
|
+
root: blockRootHex,
|
|
243
251
|
columnIndex: dataColumnSidecar.index,
|
|
244
252
|
expected: block.slot,
|
|
245
253
|
actual: dataColumnSidecar.slot,
|
|
@@ -248,12 +256,14 @@ export async function validateGossipGloasDataColumnSidecar(
|
|
|
248
256
|
|
|
249
257
|
// [REJECT] The sidecar must pass verify_data_column_sidecar against the block commitments
|
|
250
258
|
const kzgCommitments = payloadInput.getBlobKzgCommitments();
|
|
251
|
-
verifyGloasDataColumnSidecar(dataColumnSidecar, kzgCommitments);
|
|
259
|
+
verifyGloasDataColumnSidecar(dataColumnSidecar, kzgCommitments, blockRootHex);
|
|
252
260
|
|
|
253
261
|
// [REJECT] The sidecar must be on the correct subnet
|
|
254
262
|
if (computeSubnetForDataColumnSidecar(chain.config, dataColumnSidecar) !== gossipSubnet) {
|
|
255
263
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
256
264
|
code: DataColumnSidecarErrorCode.INVALID_SUBNET,
|
|
265
|
+
slot: dataColumnSidecar.slot,
|
|
266
|
+
root: blockRootHex,
|
|
257
267
|
columnIndex: dataColumnSidecar.index,
|
|
258
268
|
gossipSubnet,
|
|
259
269
|
});
|
|
@@ -272,6 +282,7 @@ export async function validateGossipGloasDataColumnSidecar(
|
|
|
272
282
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
273
283
|
code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF,
|
|
274
284
|
slot: dataColumnSidecar.slot,
|
|
285
|
+
root: blockRootHex,
|
|
275
286
|
columnIndex: dataColumnSidecar.index,
|
|
276
287
|
});
|
|
277
288
|
} finally {
|
|
@@ -283,11 +294,17 @@ export async function validateGossipGloasDataColumnSidecar(
|
|
|
283
294
|
* SPEC FUNCTION
|
|
284
295
|
* https://github.com/ethereum/consensus-specs/blob/v1.6.0-alpha.4/specs/fulu/p2p-interface.md#verify_data_column_sidecar
|
|
285
296
|
*/
|
|
286
|
-
function verifyFuluDataColumnSidecar(
|
|
297
|
+
function verifyFuluDataColumnSidecar(
|
|
298
|
+
config: ChainForkConfig,
|
|
299
|
+
dataColumnSidecar: fulu.DataColumnSidecar,
|
|
300
|
+
blockRootHex: RootHex
|
|
301
|
+
): void {
|
|
302
|
+
const slot = dataColumnSidecar.signedBlockHeader.message.slot;
|
|
287
303
|
if (dataColumnSidecar.index >= NUMBER_OF_COLUMNS) {
|
|
288
304
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
289
305
|
code: DataColumnSidecarErrorCode.INVALID_INDEX,
|
|
290
|
-
slot
|
|
306
|
+
slot,
|
|
307
|
+
root: blockRootHex,
|
|
291
308
|
columnIndex: dataColumnSidecar.index,
|
|
292
309
|
});
|
|
293
310
|
}
|
|
@@ -295,18 +312,20 @@ function verifyFuluDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar:
|
|
|
295
312
|
if (dataColumnSidecar.kzgCommitments.length === 0) {
|
|
296
313
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
297
314
|
code: DataColumnSidecarErrorCode.NO_COMMITMENTS,
|
|
298
|
-
slot
|
|
315
|
+
slot,
|
|
316
|
+
root: blockRootHex,
|
|
299
317
|
columnIndex: dataColumnSidecar.index,
|
|
300
318
|
});
|
|
301
319
|
}
|
|
302
320
|
|
|
303
|
-
const epoch = computeEpochAtSlot(
|
|
321
|
+
const epoch = computeEpochAtSlot(slot);
|
|
304
322
|
const maxBlobsPerBlock = config.getMaxBlobsPerBlock(epoch);
|
|
305
323
|
|
|
306
324
|
if (dataColumnSidecar.kzgCommitments.length > maxBlobsPerBlock) {
|
|
307
325
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
308
326
|
code: DataColumnSidecarErrorCode.TOO_MANY_KZG_COMMITMENTS,
|
|
309
|
-
slot
|
|
327
|
+
slot,
|
|
328
|
+
root: blockRootHex,
|
|
310
329
|
columnIndex: dataColumnSidecar.index,
|
|
311
330
|
count: dataColumnSidecar.kzgCommitments.length,
|
|
312
331
|
limit: maxBlobsPerBlock,
|
|
@@ -319,6 +338,8 @@ function verifyFuluDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar:
|
|
|
319
338
|
) {
|
|
320
339
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
321
340
|
code: DataColumnSidecarErrorCode.MISMATCHED_LENGTHS,
|
|
341
|
+
slot,
|
|
342
|
+
root: blockRootHex,
|
|
322
343
|
columnLength: dataColumnSidecar.column.length,
|
|
323
344
|
commitmentsLength: dataColumnSidecar.kzgCommitments.length,
|
|
324
345
|
proofsLength: dataColumnSidecar.kzgProofs.length,
|
|
@@ -330,12 +351,17 @@ function verifyFuluDataColumnSidecar(config: ChainForkConfig, dataColumnSidecar:
|
|
|
330
351
|
* SPEC FUNCTION
|
|
331
352
|
* https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.3/specs/gloas/p2p-interface.md#modified-verify_data_column_sidecar
|
|
332
353
|
*/
|
|
333
|
-
function verifyGloasDataColumnSidecar(
|
|
354
|
+
function verifyGloasDataColumnSidecar(
|
|
355
|
+
dataColumnSidecar: gloas.DataColumnSidecar,
|
|
356
|
+
kzgCommitments: Uint8Array[],
|
|
357
|
+
blockRootHex: RootHex
|
|
358
|
+
): void {
|
|
334
359
|
const slot = getDataColumnSidecarSlot(dataColumnSidecar);
|
|
335
360
|
if (dataColumnSidecar.index >= NUMBER_OF_COLUMNS) {
|
|
336
361
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
337
362
|
code: DataColumnSidecarErrorCode.INVALID_INDEX,
|
|
338
363
|
slot,
|
|
364
|
+
root: blockRootHex,
|
|
339
365
|
columnIndex: dataColumnSidecar.index,
|
|
340
366
|
});
|
|
341
367
|
}
|
|
@@ -344,6 +370,7 @@ function verifyGloasDataColumnSidecar(dataColumnSidecar: gloas.DataColumnSidecar
|
|
|
344
370
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
345
371
|
code: DataColumnSidecarErrorCode.NO_COMMITMENTS,
|
|
346
372
|
slot,
|
|
373
|
+
root: blockRootHex,
|
|
347
374
|
columnIndex: dataColumnSidecar.index,
|
|
348
375
|
});
|
|
349
376
|
}
|
|
@@ -354,6 +381,8 @@ function verifyGloasDataColumnSidecar(dataColumnSidecar: gloas.DataColumnSidecar
|
|
|
354
381
|
) {
|
|
355
382
|
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
|
|
356
383
|
code: DataColumnSidecarErrorCode.MISMATCHED_LENGTHS,
|
|
384
|
+
slot,
|
|
385
|
+
root: blockRootHex,
|
|
357
386
|
columnLength: dataColumnSidecar.column.length,
|
|
358
387
|
commitmentsLength: kzgCommitments.length,
|
|
359
388
|
proofsLength: dataColumnSidecar.kzgProofs.length,
|
|
@@ -465,8 +494,8 @@ export async function validateFuluBlockDataColumnSidecars(
|
|
|
465
494
|
) {
|
|
466
495
|
throw new DataColumnSidecarValidationError({
|
|
467
496
|
code: DataColumnSidecarErrorCode.PROPOSAL_SIGNATURE_INVALID,
|
|
468
|
-
blockRoot: rootHex,
|
|
469
497
|
slot: blockSlot,
|
|
498
|
+
root: rootHex,
|
|
470
499
|
index: dataColumnSidecars[0].index,
|
|
471
500
|
});
|
|
472
501
|
}
|
|
@@ -499,6 +528,7 @@ export async function validateFuluBlockDataColumnSidecars(
|
|
|
499
528
|
{
|
|
500
529
|
code: DataColumnSidecarErrorCode.INVALID_INDEX,
|
|
501
530
|
slot: blockSlot,
|
|
531
|
+
root: toRootHex(blockRoot),
|
|
502
532
|
columnIndex: columnSidecar.index,
|
|
503
533
|
},
|
|
504
534
|
"DataColumnSidecar has invalid index"
|
|
@@ -543,6 +573,7 @@ export async function validateFuluBlockDataColumnSidecars(
|
|
|
543
573
|
{
|
|
544
574
|
code: DataColumnSidecarErrorCode.INCLUSION_PROOF_INVALID,
|
|
545
575
|
slot: blockSlot,
|
|
576
|
+
root: toRootHex(blockRoot),
|
|
546
577
|
columnIndex: columnSidecar.index,
|
|
547
578
|
},
|
|
548
579
|
"DataColumnSidecar has invalid inclusion proof"
|
|
@@ -623,6 +654,7 @@ export async function validateGloasBlockDataColumnSidecars(
|
|
|
623
654
|
if (columnSidecar.slot !== blockSlot) {
|
|
624
655
|
throw new DataColumnSidecarValidationError({
|
|
625
656
|
code: DataColumnSidecarErrorCode.INCORRECT_SIDECAR_SLOT,
|
|
657
|
+
root: toRootHex(blockRoot),
|
|
626
658
|
columnIndex: columnSidecar.index,
|
|
627
659
|
expected: blockSlot,
|
|
628
660
|
actual: columnSidecar.slot,
|
|
@@ -644,6 +676,7 @@ export async function validateGloasBlockDataColumnSidecars(
|
|
|
644
676
|
{
|
|
645
677
|
code: DataColumnSidecarErrorCode.INVALID_INDEX,
|
|
646
678
|
slot: blockSlot,
|
|
679
|
+
root: toRootHex(blockRoot),
|
|
647
680
|
columnIndex: columnSidecar.index,
|
|
648
681
|
},
|
|
649
682
|
"DataColumnSidecar has invalid index"
|
|
@@ -82,6 +82,8 @@ async function validateExecutionPayloadEnvelope(
|
|
|
82
82
|
if (block.slot !== payload.slotNumber) {
|
|
83
83
|
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
84
84
|
code: ExecutionPayloadEnvelopeErrorCode.SLOT_MISMATCH,
|
|
85
|
+
slot: payload.slotNumber,
|
|
86
|
+
root: blockRootHex,
|
|
85
87
|
envelopeSlot: payload.slotNumber,
|
|
86
88
|
blockSlot: block.slot,
|
|
87
89
|
});
|
|
@@ -91,6 +93,8 @@ async function validateExecutionPayloadEnvelope(
|
|
|
91
93
|
if (envelope.builderIndex !== payloadInput.getBuilderIndex()) {
|
|
92
94
|
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
93
95
|
code: ExecutionPayloadEnvelopeErrorCode.BUILDER_INDEX_MISMATCH,
|
|
96
|
+
slot: payload.slotNumber,
|
|
97
|
+
root: blockRootHex,
|
|
94
98
|
envelopeBuilderIndex: envelope.builderIndex,
|
|
95
99
|
bidBuilderIndex: payloadInput.getBuilderIndex(),
|
|
96
100
|
});
|
|
@@ -100,6 +104,8 @@ async function validateExecutionPayloadEnvelope(
|
|
|
100
104
|
if (toRootHex(payload.blockHash) !== payloadInput.getBlockHashHex()) {
|
|
101
105
|
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
102
106
|
code: ExecutionPayloadEnvelopeErrorCode.BLOCK_HASH_MISMATCH,
|
|
107
|
+
slot: payload.slotNumber,
|
|
108
|
+
root: blockRootHex,
|
|
103
109
|
envelopeBlockHash: toRootHex(payload.blockHash),
|
|
104
110
|
bidBlockHash: payloadInput.getBlockHashHex(),
|
|
105
111
|
});
|
|
@@ -110,6 +116,8 @@ async function validateExecutionPayloadEnvelope(
|
|
|
110
116
|
if (!byteArrayEquals(requestsRoot, payloadInput.getBid().executionRequestsRoot)) {
|
|
111
117
|
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
112
118
|
code: ExecutionPayloadEnvelopeErrorCode.EXECUTION_REQUESTS_ROOT_MISMATCH,
|
|
119
|
+
slot: payload.slotNumber,
|
|
120
|
+
root: blockRootHex,
|
|
113
121
|
envelopeRequestsRoot: toRootHex(requestsRoot),
|
|
114
122
|
bidRequestsRoot: toRootHex(payloadInput.getBid().executionRequestsRoot),
|
|
115
123
|
});
|
|
@@ -141,6 +149,8 @@ async function validateExecutionPayloadEnvelope(
|
|
|
141
149
|
if (!(await chain.bls.verifySignatureSets([signatureSet], {verifyOnMainThread: true}))) {
|
|
142
150
|
throw new ExecutionPayloadEnvelopeError(GossipAction.REJECT, {
|
|
143
151
|
code: ExecutionPayloadEnvelopeErrorCode.INVALID_SIGNATURE,
|
|
152
|
+
slot: payload.slotNumber,
|
|
153
|
+
root: blockRootHex,
|
|
144
154
|
});
|
|
145
155
|
}
|
|
146
156
|
}
|
package/src/db/beacon.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import {ChainForkConfig} from "@lodestar/config";
|
|
2
2
|
import {Db, LevelDbControllerMetrics, encodeKey} from "@lodestar/db";
|
|
3
|
+
import {Slot} from "@lodestar/types";
|
|
4
|
+
import {Logger} from "@lodestar/utils";
|
|
3
5
|
import {Bucket} from "./buckets.js";
|
|
6
|
+
import {type IDataColumnStore, LegacyDataColumnStore} from "./dataColumnStore.js";
|
|
7
|
+
import {FlatFileStore} from "./flatFileStore/flatFileStore.js";
|
|
8
|
+
import type {FlatFileStoreMetrics} from "./flatFileStore/metrics.js";
|
|
4
9
|
import {IBeaconDb} from "./interface.js";
|
|
5
10
|
import {CheckpointStateRepository} from "./repositories/checkpointState.js";
|
|
6
11
|
import {
|
|
@@ -24,9 +29,10 @@ import {
|
|
|
24
29
|
VoluntaryExitRepository,
|
|
25
30
|
} from "./repositories/index.js";
|
|
26
31
|
|
|
27
|
-
export type
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
export type BeaconDbOpts = {
|
|
33
|
+
dataColumnDir: string;
|
|
34
|
+
logger: Logger;
|
|
35
|
+
metrics?: FlatFileStoreMetrics | null;
|
|
30
36
|
};
|
|
31
37
|
|
|
32
38
|
export class BeaconDb implements IBeaconDb {
|
|
@@ -57,9 +63,14 @@ export class BeaconDb implements IBeaconDb {
|
|
|
57
63
|
|
|
58
64
|
backfilledRanges: BackfilledRanges;
|
|
59
65
|
|
|
66
|
+
readonly dataColumns: IDataColumnStore;
|
|
67
|
+
lastLegacyArchiveSlot: Slot | null = null;
|
|
68
|
+
private readonly flatFileStore: FlatFileStore;
|
|
69
|
+
|
|
60
70
|
constructor(
|
|
61
71
|
config: ChainForkConfig,
|
|
62
|
-
protected readonly db: Db
|
|
72
|
+
protected readonly db: Db,
|
|
73
|
+
opts: BeaconDbOpts
|
|
63
74
|
) {
|
|
64
75
|
// Warning: If code is ever run in the constructor, must change this stub to not extend 'packages/beacon-node/test/utils/stub/beaconDb.ts' -
|
|
65
76
|
this.block = new BlockRepository(config, db);
|
|
@@ -87,14 +98,30 @@ export class BeaconDb implements IBeaconDb {
|
|
|
87
98
|
this.syncCommitteeWitness = new SyncCommitteeWitnessRepository(config, db);
|
|
88
99
|
|
|
89
100
|
this.backfilledRanges = new BackfilledRanges(config, db);
|
|
101
|
+
|
|
102
|
+
this.flatFileStore = new FlatFileStore(opts.dataColumnDir, config, opts.logger, opts.metrics);
|
|
103
|
+
this.dataColumns = new LegacyDataColumnStore(
|
|
104
|
+
this.flatFileStore,
|
|
105
|
+
this.dataColumnSidecar,
|
|
106
|
+
this.dataColumnSidecarArchive,
|
|
107
|
+
this.blockArchive
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async init(): Promise<void> {
|
|
112
|
+
await this.flatFileStore.init();
|
|
113
|
+
const [lastLegacyKey] = await this.dataColumnSidecarArchive.keys({reverse: true, limit: 1});
|
|
114
|
+
this.lastLegacyArchiveSlot = lastLegacyKey?.prefix ?? null;
|
|
90
115
|
}
|
|
91
116
|
|
|
92
|
-
close(): Promise<void> {
|
|
117
|
+
async close(): Promise<void> {
|
|
118
|
+
await this.flatFileStore.close();
|
|
93
119
|
return this.db.close();
|
|
94
120
|
}
|
|
95
121
|
|
|
96
|
-
setMetrics(metrics: LevelDbControllerMetrics): void {
|
|
122
|
+
setMetrics(metrics: LevelDbControllerMetrics, flatFileStoreMetrics: FlatFileStoreMetrics | null = null): void {
|
|
97
123
|
this.db.setMetrics(metrics);
|
|
124
|
+
this.flatFileStore.setMetrics(flatFileStoreMetrics);
|
|
98
125
|
}
|
|
99
126
|
|
|
100
127
|
async pruneHotDb(): Promise<void> {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {ColumnIndex, DataColumnSidecar, RootHex, Slot} from "@lodestar/types";
|
|
2
|
+
import {fromHex} from "@lodestar/utils";
|
|
3
|
+
import type {IFlatFileStore} from "./flatFileStore/interface.js";
|
|
4
|
+
import type {
|
|
5
|
+
BlockArchiveRepository,
|
|
6
|
+
DataColumnSidecarArchiveRepository,
|
|
7
|
+
DataColumnSidecarRepository,
|
|
8
|
+
} from "./repositories/index.js";
|
|
9
|
+
|
|
10
|
+
export type DataColumnKey = {slot: Slot; blockRoot: RootHex};
|
|
11
|
+
export type IndexedDataColumnBytes = {index: ColumnIndex; data: Uint8Array};
|
|
12
|
+
|
|
13
|
+
type LegacyHotDataColumnStore = Pick<DataColumnSidecarRepository, "values" | "getManyBinary" | "deleteMany">;
|
|
14
|
+
type LegacyArchiveDataColumnStore = Pick<
|
|
15
|
+
DataColumnSidecarArchiveRepository,
|
|
16
|
+
"values" | "getManyBinary" | "keys" | "deleteMany"
|
|
17
|
+
>;
|
|
18
|
+
type BlockRootIndex = Pick<BlockArchiveRepository, "getSlotByRoot">;
|
|
19
|
+
|
|
20
|
+
export interface IDataColumnStore {
|
|
21
|
+
getAll(key: DataColumnKey): Promise<DataColumnSidecar[]>;
|
|
22
|
+
getManyBinary(key: DataColumnKey, indices: ColumnIndex[]): Promise<(Uint8Array | undefined)[]>;
|
|
23
|
+
putManyBinary(key: DataColumnKey, columns: IndexedDataColumnBytes[]): Promise<void>;
|
|
24
|
+
deleteMany(keys: DataColumnKey[]): Promise<void>;
|
|
25
|
+
pruneBefore(slot: Slot): Promise<Slot[]>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Bridges pre-flat-file LevelDB columns during the supported in-place upgrade window.
|
|
30
|
+
* Remove the legacy repositories after upgrades from the last pre-flat-file release are no longer supported.
|
|
31
|
+
*/
|
|
32
|
+
export class LegacyDataColumnStore implements IDataColumnStore {
|
|
33
|
+
constructor(
|
|
34
|
+
private readonly flatFiles: IFlatFileStore,
|
|
35
|
+
private readonly legacyHot: LegacyHotDataColumnStore,
|
|
36
|
+
private readonly legacyArchive: LegacyArchiveDataColumnStore,
|
|
37
|
+
private readonly blockArchive: BlockRootIndex
|
|
38
|
+
) {}
|
|
39
|
+
|
|
40
|
+
async getAll({slot, blockRoot}: DataColumnKey): Promise<DataColumnSidecar[]> {
|
|
41
|
+
const sidecars = await this.flatFiles.getDataColumns(slot, blockRoot);
|
|
42
|
+
if (sidecars.length > 0) return sidecars;
|
|
43
|
+
|
|
44
|
+
const sidecarsByIndex = new Map<ColumnIndex, DataColumnSidecar>();
|
|
45
|
+
const root = fromHex(blockRoot);
|
|
46
|
+
for (const sidecar of await this.legacyHot.values(root)) {
|
|
47
|
+
if (!sidecarsByIndex.has(sidecar.index)) sidecarsByIndex.set(sidecar.index, sidecar);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if ((await this.blockArchive.getSlotByRoot(root)) === slot) {
|
|
51
|
+
for (const sidecar of await this.legacyArchive.values(slot)) {
|
|
52
|
+
if (!sidecarsByIndex.has(sidecar.index)) sidecarsByIndex.set(sidecar.index, sidecar);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return [...sidecarsByIndex.values()].sort((a, b) => a.index - b.index);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getManyBinary({slot, blockRoot}: DataColumnKey, indices: ColumnIndex[]): Promise<(Uint8Array | undefined)[]> {
|
|
60
|
+
const flatFileSidecars = await this.flatFiles.getDataColumnsBinary(slot, blockRoot, indices);
|
|
61
|
+
if (flatFileSidecars !== null) return flatFileSidecars;
|
|
62
|
+
if (indices.length === 0) return [];
|
|
63
|
+
|
|
64
|
+
const root = fromHex(blockRoot);
|
|
65
|
+
const result = await this.legacyHot.getManyBinary(root, indices);
|
|
66
|
+
|
|
67
|
+
const missingPositions = getMissingPositions(result);
|
|
68
|
+
if (missingPositions.length === 0 || (await this.blockArchive.getSlotByRoot(root)) !== slot) return result;
|
|
69
|
+
|
|
70
|
+
const archivedSidecars = await this.legacyArchive.getManyBinary(
|
|
71
|
+
slot,
|
|
72
|
+
missingPositions.map((position) => indices[position])
|
|
73
|
+
);
|
|
74
|
+
fillMissing(result, missingPositions, archivedSidecars);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async putManyBinary({slot, blockRoot}: DataColumnKey, columns: IndexedDataColumnBytes[]): Promise<void> {
|
|
79
|
+
await this.flatFiles.putDataColumnsBinary(slot, blockRoot, columns);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async deleteMany(keys: DataColumnKey[]): Promise<void> {
|
|
83
|
+
await this.flatFiles.deleteMany(keys);
|
|
84
|
+
await this.legacyHot.deleteMany(keys.map(({blockRoot}) => fromHex(blockRoot)));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async pruneBefore(slot: Slot): Promise<Slot[]> {
|
|
88
|
+
const flatFileSlots = await this.flatFiles.pruneBefore(slot);
|
|
89
|
+
const prefixedKeys = await this.legacyArchive.keys({lt: {prefix: slot, id: 0}});
|
|
90
|
+
const slots = [...new Set(prefixedKeys.map(({prefix}) => prefix))];
|
|
91
|
+
if (slots.length > 0) await this.legacyArchive.deleteMany(slots);
|
|
92
|
+
return [...new Set([...flatFileSlots, ...slots])].sort((a, b) => a - b);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function getMissingPositions(sidecars: (Uint8Array | undefined)[]): number[] {
|
|
97
|
+
const positions: number[] = [];
|
|
98
|
+
for (let i = 0; i < sidecars.length; i++) {
|
|
99
|
+
if (sidecars[i] === undefined) positions.push(i);
|
|
100
|
+
}
|
|
101
|
+
return positions;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function fillMissing(
|
|
105
|
+
result: (Uint8Array | undefined)[],
|
|
106
|
+
missingPositions: number[],
|
|
107
|
+
sidecars: (Uint8Array | null | undefined)[]
|
|
108
|
+
): void {
|
|
109
|
+
for (let i = 0; i < missingPositions.length; i++) {
|
|
110
|
+
const sidecar = sidecars[i];
|
|
111
|
+
if (sidecar != null) result[missingPositions[i]] = sidecar;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {mkdir, open, rename, rm} from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
const pendingDirectorySyncs = new Map<string, string[]>();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Atomic write: write to `.part` temp file -> datasync -> rename to target.
|
|
8
|
+
* This guarantees crash-safe writes — if the process crashes mid-write,
|
|
9
|
+
* only the `.part` file is corrupted, never the target.
|
|
10
|
+
*/
|
|
11
|
+
export async function atomicWrite(targetPath: string, data: Uint8Array): Promise<void> {
|
|
12
|
+
const dir = path.dirname(targetPath);
|
|
13
|
+
const partPath = `${targetPath}.part-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
14
|
+
await mkdirDurable(dir);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const fd = await open(partPath, "wx");
|
|
18
|
+
try {
|
|
19
|
+
await fd.writeFile(data);
|
|
20
|
+
await fd.datasync();
|
|
21
|
+
} finally {
|
|
22
|
+
await fd.close();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await rename(partPath, targetPath);
|
|
26
|
+
|
|
27
|
+
// Ensure rename metadata is durable on crash.
|
|
28
|
+
await syncDirectory(dir);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
await rm(partPath, {force: true}).catch(() => {});
|
|
31
|
+
throw e;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function mkdirDurable(dir: string): Promise<void> {
|
|
36
|
+
const targetDir = path.resolve(dir);
|
|
37
|
+
let directoriesToSync = pendingDirectorySyncs.get(targetDir);
|
|
38
|
+
if (directoriesToSync === undefined) {
|
|
39
|
+
const firstCreatedDir = await mkdir(targetDir, {recursive: true});
|
|
40
|
+
if (firstCreatedDir === undefined) return;
|
|
41
|
+
|
|
42
|
+
let createdDir = path.resolve(firstCreatedDir);
|
|
43
|
+
directoriesToSync = [path.dirname(createdDir)];
|
|
44
|
+
while (createdDir !== targetDir) {
|
|
45
|
+
directoriesToSync.push(createdDir);
|
|
46
|
+
const [nextSegment] = path.relative(createdDir, targetDir).split(path.sep);
|
|
47
|
+
createdDir = path.join(createdDir, nextSegment);
|
|
48
|
+
}
|
|
49
|
+
pendingDirectorySyncs.set(targetDir, directoriesToSync);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const directory of directoriesToSync) {
|
|
53
|
+
await syncDirectory(directory);
|
|
54
|
+
}
|
|
55
|
+
pendingDirectorySyncs.delete(targetDir);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function syncDirectory(dir: string): Promise<void> {
|
|
59
|
+
const dirFd = await open(dir, "r");
|
|
60
|
+
try {
|
|
61
|
+
await dirFd.sync();
|
|
62
|
+
} finally {
|
|
63
|
+
await dirFd.close();
|
|
64
|
+
}
|
|
65
|
+
}
|