@lodestar/beacon-node 1.36.0-dev.d42eb95bf0 → 1.36.0-dev.d8afb6dc39
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/api/impl/lodestar/index.d.ts +5 -0
- package/lib/api/impl/lodestar/index.d.ts.map +1 -1
- package/lib/api/impl/lodestar/index.js +35 -10
- package/lib/api/impl/lodestar/index.js.map +1 -1
- package/lib/api/impl/node/utils.js +1 -1
- package/lib/api/impl/node/utils.js.map +1 -1
- package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.d.ts.map +1 -1
- package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js +6 -1
- package/lib/chain/archiveStore/strategies/frequencyStateArchiveStrategy.js.map +1 -1
- package/lib/chain/chain.d.ts +5 -2
- package/lib/chain/chain.d.ts.map +1 -1
- package/lib/chain/chain.js +32 -16
- package/lib/chain/chain.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/forkChoice/index.d.ts +9 -1
- package/lib/chain/forkChoice/index.d.ts.map +1 -1
- package/lib/chain/forkChoice/index.js +109 -4
- package/lib/chain/forkChoice/index.js.map +1 -1
- package/lib/chain/interface.d.ts +2 -0
- package/lib/chain/interface.d.ts.map +1 -1
- package/lib/chain/options.d.ts +0 -2
- package/lib/chain/options.d.ts.map +1 -1
- package/lib/chain/options.js +2 -2
- package/lib/chain/options.js.map +1 -1
- package/lib/chain/stateCache/datastore/db.d.ts +12 -0
- package/lib/chain/stateCache/datastore/db.d.ts.map +1 -1
- package/lib/chain/stateCache/datastore/db.js +70 -0
- package/lib/chain/stateCache/datastore/db.js.map +1 -1
- package/lib/chain/stateCache/datastore/file.d.ts +1 -0
- package/lib/chain/stateCache/datastore/file.d.ts.map +1 -1
- package/lib/chain/stateCache/datastore/file.js +7 -0
- package/lib/chain/stateCache/datastore/file.js.map +1 -1
- package/lib/chain/stateCache/datastore/types.d.ts +1 -0
- package/lib/chain/stateCache/datastore/types.d.ts.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/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/metrics/metrics/lodestar.js +1 -1
- package/lib/metrics/metrics/lodestar.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 +8 -8
- 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/discv5/worker.js +2 -7
- package/lib/network/discv5/worker.js.map +1 -1
- package/lib/network/events.d.ts +1 -0
- package/lib/network/events.d.ts.map +1 -1
- package/lib/network/gossip/encoding.js +1 -1
- package/lib/network/gossip/encoding.js.map +1 -1
- package/lib/network/gossip/snappy_bun.d.ts +3 -0
- package/lib/network/gossip/snappy_bun.d.ts.map +1 -0
- package/lib/network/gossip/snappy_bun.js +3 -0
- package/lib/network/gossip/snappy_bun.js.map +1 -0
- 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/options.d.ts +0 -1
- package/lib/network/options.d.ts.map +1 -1
- package/lib/network/options.js.map +1 -1
- package/lib/network/peers/discover.js +2 -2
- package/lib/network/peers/discover.js.map +1 -1
- package/lib/network/processor/gossipHandlers.d.ts.map +1 -1
- package/lib/network/processor/gossipHandlers.js +14 -8
- 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 +14 -3
- 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/node/nodejs.d.ts +2 -1
- package/lib/node/nodejs.d.ts.map +1 -1
- package/lib/node/nodejs.js +2 -1
- package/lib/node/nodejs.js.map +1 -1
- package/lib/sync/range/range.d.ts.map +1 -1
- package/lib/sync/range/range.js +2 -1
- package/lib/sync/range/range.js.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/sync/utils/remoteSyncType.d.ts +2 -1
- package/lib/sync/utils/remoteSyncType.d.ts.map +1 -1
- package/lib/sync/utils/remoteSyncType.js +19 -4
- package/lib/sync/utils/remoteSyncType.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/lib/util/profile.d.ts +6 -4
- package/lib/util/profile.d.ts.map +1 -1
- package/lib/util/profile.js +40 -3
- package/lib/util/profile.js.map +1 -1
- package/lib/util/sszBytes.d.ts +2 -0
- package/lib/util/sszBytes.d.ts.map +1 -1
- package/lib/util/sszBytes.js +25 -0
- package/lib/util/sszBytes.js.map +1 -1
- package/package.json +31 -24
- package/src/api/impl/beacon/blocks/index.ts +47 -25
- package/src/api/impl/lodestar/index.ts +42 -10
- package/src/api/impl/node/utils.ts +1 -1
- package/src/chain/archiveStore/strategies/frequencyStateArchiveStrategy.ts +5 -1
- package/src/chain/chain.ts +48 -23
- package/src/chain/errors/dataColumnSidecarError.ts +20 -14
- package/src/chain/forkChoice/index.ts +178 -2
- package/src/chain/interface.ts +2 -0
- package/src/chain/options.ts +2 -3
- package/src/chain/stateCache/datastore/db.ts +89 -1
- package/src/chain/stateCache/datastore/file.ts +8 -0
- package/src/chain/stateCache/datastore/types.ts +1 -0
- package/src/chain/stateCache/persistentCheckpointsCache.ts +45 -2
- package/src/chain/validation/dataColumnSidecar.ts +34 -16
- package/src/index.ts +2 -0
- package/src/metrics/metrics/lodestar.ts +1 -1
- package/src/network/core/networkCore.ts +5 -1
- package/src/network/core/networkCoreWorker.ts +9 -9
- package/src/network/core/networkCoreWorkerHandler.ts +1 -1
- package/src/network/discv5/worker.ts +2 -7
- package/src/network/events.ts +1 -1
- package/src/network/gossip/encoding.ts +1 -1
- package/src/network/gossip/snappy_bun.ts +2 -0
- package/src/network/metadata.ts +3 -1
- package/src/network/options.ts +0 -1
- package/src/network/peers/discover.ts +2 -2
- package/src/network/processor/gossipHandlers.ts +16 -7
- package/src/network/reqresp/ReqRespBeaconNode.ts +3 -1
- package/src/network/reqresp/handlers/beaconBlocksByRange.ts +18 -3
- 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/node/nodejs.ts +3 -0
- package/src/sync/range/range.ts +2 -1
- package/src/sync/utils/downloadByRange.ts +259 -103
- package/src/sync/utils/remoteSyncType.ts +23 -4
- package/src/util/blobs.ts +64 -20
- package/src/util/profile.ts +45 -3
- package/src/util/sszBytes.ts +30 -0
package/src/util/blobs.ts
CHANGED
|
@@ -149,41 +149,85 @@ export async function dataColumnMatrixRecovery(
|
|
|
149
149
|
* Reconstruct blobs from a set of data columns, at least 50%+ of all the columns
|
|
150
150
|
* must be provided to allow to reconstruct the full data matrix
|
|
151
151
|
*/
|
|
152
|
-
export async function reconstructBlobs(sidecars: fulu.DataColumnSidecars): Promise<deneb.Blobs> {
|
|
152
|
+
export async function reconstructBlobs(sidecars: fulu.DataColumnSidecars, indices?: number[]): Promise<deneb.Blobs> {
|
|
153
153
|
if (sidecars.length < NUMBER_OF_COLUMNS / 2) {
|
|
154
154
|
throw Error(
|
|
155
155
|
`Expected at least ${NUMBER_OF_COLUMNS / 2} data columns to reconstruct blobs, received ${sidecars.length}`
|
|
156
156
|
);
|
|
157
157
|
}
|
|
158
|
+
const blobCount = sidecars[0].column.length;
|
|
158
159
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// Full columns, no need to recover
|
|
163
|
-
fullSidecars = sidecars;
|
|
164
|
-
} else {
|
|
165
|
-
const sidecarsByIndex = new Map<number, fulu.DataColumnSidecar>(sidecars.map((sc) => [sc.index, sc]));
|
|
166
|
-
const recoveredSidecars = await dataColumnMatrixRecovery(sidecarsByIndex);
|
|
167
|
-
if (recoveredSidecars === null) {
|
|
168
|
-
// Should not happen because we check the column count above
|
|
169
|
-
throw Error("Failed to reconstruct the full data matrix");
|
|
160
|
+
for (const index of indices ?? []) {
|
|
161
|
+
if (index < 0 || index >= blobCount) {
|
|
162
|
+
throw Error(`Invalid blob index ${index}, must be between 0 and ${blobCount - 1}`);
|
|
170
163
|
}
|
|
171
|
-
|
|
164
|
+
}
|
|
165
|
+
const indicesToReconstruct = indices ?? Array.from({length: blobCount}, (_, i) => i);
|
|
166
|
+
|
|
167
|
+
const recoveredCells = await recoverBlobCells(sidecars, indicesToReconstruct);
|
|
168
|
+
if (recoveredCells === null) {
|
|
169
|
+
// Should not happen because we check the column count above
|
|
170
|
+
throw Error("Failed to recover cells to reconstruct blobs");
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
const
|
|
175
|
-
const blobs: deneb.Blobs = new Array(blobCount);
|
|
173
|
+
const blobs: deneb.Blobs = new Array(indicesToReconstruct.length);
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
175
|
+
for (let i = 0; i < indicesToReconstruct.length; i++) {
|
|
176
|
+
const blobIndex = indicesToReconstruct[i];
|
|
177
|
+
const cells = recoveredCells.get(blobIndex);
|
|
178
|
+
if (!cells) {
|
|
179
|
+
throw Error(`Failed to get recovered cells for blob index ${blobIndex}`);
|
|
180
|
+
}
|
|
181
|
+
blobs[i] = cellsToBlob(cells);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
return blobs;
|
|
185
185
|
}
|
|
186
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Recover cells for specific blob indices from a set of data columns
|
|
189
|
+
*/
|
|
190
|
+
async function recoverBlobCells(
|
|
191
|
+
partialSidecars: fulu.DataColumnSidecar[],
|
|
192
|
+
blobIndices: number[]
|
|
193
|
+
): Promise<Map<number, fulu.Cell[]> | null> {
|
|
194
|
+
const columnCount = partialSidecars.length;
|
|
195
|
+
if (columnCount < NUMBER_OF_COLUMNS / 2) {
|
|
196
|
+
// We don't have enough columns to recover
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const recoveredCells = new Map<number, fulu.Cell[]>();
|
|
201
|
+
// Sort data columns by index in ascending order
|
|
202
|
+
const partialSidecarsSorted = partialSidecars.slice().sort((a, b) => a.index - b.index);
|
|
203
|
+
|
|
204
|
+
if (columnCount === NUMBER_OF_COLUMNS) {
|
|
205
|
+
// Full columns, no need to recover
|
|
206
|
+
for (const blobIndex of blobIndices) {
|
|
207
|
+
// 128 cells that make up one "extended blob" row
|
|
208
|
+
const cells = partialSidecarsSorted.map((col) => col.column[blobIndex]);
|
|
209
|
+
recoveredCells.set(blobIndex, cells);
|
|
210
|
+
}
|
|
211
|
+
return recoveredCells;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
await Promise.all(
|
|
215
|
+
blobIndices.map(async (blobIndex) => {
|
|
216
|
+
const cellIndices: number[] = [];
|
|
217
|
+
const cells: fulu.Cell[] = [];
|
|
218
|
+
for (const dataColumn of partialSidecarsSorted) {
|
|
219
|
+
cellIndices.push(dataColumn.index);
|
|
220
|
+
cells.push(dataColumn.column[blobIndex]);
|
|
221
|
+
}
|
|
222
|
+
// Recover cells for this specific blob row
|
|
223
|
+
const recovered = await kzg.asyncRecoverCellsAndKzgProofs(cellIndices, cells);
|
|
224
|
+
recoveredCells.set(blobIndex, recovered.cells);
|
|
225
|
+
})
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
return recoveredCells;
|
|
229
|
+
}
|
|
230
|
+
|
|
187
231
|
/**
|
|
188
232
|
* Concatenate the systematic half (columns 0‑63) of a row of cells into
|
|
189
233
|
* the original 131072 byte blob. The parity half (64‑127) is ignored as
|
package/src/util/profile.ts
CHANGED
|
@@ -1,13 +1,32 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
1
3
|
import {sleep} from "@lodestar/utils";
|
|
2
4
|
|
|
5
|
+
export enum ProfileThread {
|
|
6
|
+
MAIN = "main",
|
|
7
|
+
NETWORK = "network",
|
|
8
|
+
DISC5 = "discv5",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The time to take a Bun profile.
|
|
13
|
+
* If we increase this time it'll potentiall cause the app to crash.
|
|
14
|
+
* If we decrease this time, profile recorded will be fragmented and hard to analyze.
|
|
15
|
+
*/
|
|
16
|
+
const BUN_PROFILE_MS = 3 * 1000;
|
|
17
|
+
|
|
18
|
+
export async function profileThread(thread: ProfileThread, durationMs: number, dirpath: string): Promise<string> {
|
|
19
|
+
return globalThis.Bun ? profileBun(thread, durationMs) : profileNodeJS(thread, durationMs, dirpath);
|
|
20
|
+
}
|
|
21
|
+
|
|
3
22
|
/**
|
|
4
|
-
* Take
|
|
23
|
+
* Take `durationMs` profile of the current thread and return the persisted file path.
|
|
5
24
|
*/
|
|
6
|
-
|
|
25
|
+
async function profileNodeJS(thread: ProfileThread, durationMs: number, dirpath: string): Promise<string> {
|
|
7
26
|
const inspector = await import("node:inspector");
|
|
8
27
|
|
|
9
28
|
// due to some typing issues, not able to use promisify here
|
|
10
|
-
|
|
29
|
+
const profile = await new Promise<string>((resolve, reject) => {
|
|
11
30
|
// Start the inspector and connect to it
|
|
12
31
|
const session = new inspector.Session();
|
|
13
32
|
session.connect();
|
|
@@ -29,6 +48,29 @@ export async function profileNodeJS(durationMs: number): Promise<string> {
|
|
|
29
48
|
});
|
|
30
49
|
});
|
|
31
50
|
});
|
|
51
|
+
|
|
52
|
+
const filePath = path.join(dirpath, `${thread}_thread_${new Date().toISOString()}.cpuprofile`);
|
|
53
|
+
fs.writeFileSync(filePath, profile);
|
|
54
|
+
return filePath;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Unlike NodeJS, Bun console.profile() api flush data to the inspector,
|
|
59
|
+
* so this api returns ms taken of this profile instead of file path.
|
|
60
|
+
*/
|
|
61
|
+
async function profileBun(thread: ProfileThread, durationMs: number): Promise<string> {
|
|
62
|
+
const start = Date.now();
|
|
63
|
+
let now = Date.now();
|
|
64
|
+
while (now - start < durationMs) {
|
|
65
|
+
// biome-ignore lint/suspicious/noConsole: need to use console api to profile in Bun
|
|
66
|
+
console.profile(String(now));
|
|
67
|
+
await sleep(BUN_PROFILE_MS);
|
|
68
|
+
// biome-ignore lint/suspicious/noConsole: need to use console api to profile in Bun
|
|
69
|
+
console.profileEnd(String(now));
|
|
70
|
+
now = Date.now();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return `Successfully take Bun ${thread} thread profile in ${now - start}ms. Check your inspector to see the profile.`;
|
|
32
74
|
}
|
|
33
75
|
|
|
34
76
|
/**
|
package/src/util/sszBytes.ts
CHANGED
|
@@ -417,6 +417,36 @@ export function getSlotFromDataColumnSidecarSerialized(data: Uint8Array): Slot |
|
|
|
417
417
|
return getSlotFromOffset(data, SLOT_BYTES_POSITION_IN_SIGNED_DATA_COLUMN_SIDECAR);
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
+
/**
|
|
421
|
+
* BeaconState of all forks (up until Electra, check with new forks)
|
|
422
|
+
* class BeaconState(Container):
|
|
423
|
+
* genesis_time: uint64 - 8 bytes
|
|
424
|
+
* genesis_validators_root: Root - 32 bytes
|
|
425
|
+
* slot: Slot - 8 bytes
|
|
426
|
+
* fork: Fork - 16 bytes
|
|
427
|
+
* latest_block_header: BeaconBlockHeader - fixed size
|
|
428
|
+
* slot: Slot - 8 bytes
|
|
429
|
+
*
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
const BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE = 8 + 32 + 8 + 16;
|
|
433
|
+
export function getLastProcessedSlotFromBeaconStateSerialized(data: Uint8Array): Slot | null {
|
|
434
|
+
if (data.length < BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE + SLOT_SIZE) {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return getSlotFromOffset(data, BLOCK_HEADER_SLOT_BYTES_POSITION_IN_BEACON_STATE);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const SLOT_BYTES_POSITION_IN_BEACON_STATE = 8 + 32;
|
|
442
|
+
export function getSlotFromBeaconStateSerialized(data: Uint8Array): Slot | null {
|
|
443
|
+
if (data.length < SLOT_BYTES_POSITION_IN_BEACON_STATE) {
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return getSlotFromOffset(data, SLOT_BYTES_POSITION_IN_BEACON_STATE);
|
|
448
|
+
}
|
|
449
|
+
|
|
420
450
|
/**
|
|
421
451
|
* Read only the first 4 bytes of Slot, max value is 4,294,967,295 will be reached 1634 years after genesis
|
|
422
452
|
*
|