-
-
Notifications
You must be signed in to change notification settings - Fork 410
refactor: make the db interface consistent #8238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -299,55 +299,40 @@ async function migrateBlobSidecarsFromHotToColdDb( | |
| return migratedWrappedBlobSidecars; | ||
| } | ||
|
|
||
| // TODO: This function can be simplified further by reducing layers of promises in a loop | ||
| async function migrateDataColumnSidecarsFromHotToColdDb( | ||
| config: ChainForkConfig, | ||
| db: IBeaconDb, | ||
| blocks: BlockRootSlot[], | ||
| currentEpoch: Epoch | ||
| ): Promise<number> { | ||
| let migratedWrappedDataColumns = 0; | ||
| // Only Fulu and newer blocks and within the retention window | ||
| const withinDataColumnWindow = (slot: Slot) => | ||
| config.getForkSeq(slot) >= ForkSeq.fulu && | ||
| computeEpochAtSlot(slot) < currentEpoch - config.MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS; | ||
| let migratedDataColumnsCount = 0; | ||
|
|
||
| for (let i = 0; i < blocks.length; i += BLOB_SIDECAR_BATCH_SIZE) { | ||
| const toIdx = Math.min(i + BLOB_SIDECAR_BATCH_SIZE, blocks.length); | ||
| const canonicalBlocks = blocks.slice(i, toIdx); | ||
|
|
||
| // processCanonicalBlocks | ||
| if (canonicalBlocks.length === 0) break; | ||
| const promises = []; | ||
|
|
||
| // load Buffer instead of ssz deserialized to improve performance | ||
| for (const block of canonicalBlocks) { | ||
| const blockSlot = block.slot; | ||
| const blockEpoch = computeEpochAtSlot(blockSlot); | ||
|
|
||
| if ( | ||
| config.getForkSeq(blockSlot) < ForkSeq.fulu || | ||
| // if block is out of ${config.MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS}, skip this step | ||
| blockEpoch < currentEpoch - config.MIN_EPOCHS_FOR_DATA_COLUMN_SIDECARS_REQUESTS | ||
| ) { | ||
| continue; | ||
| } | ||
| if (!withinDataColumnWindow(block.slot)) continue; | ||
|
|
||
| const dataColumnSidecarBytes = await db.dataColumnSidecar.valuesBinary(block.root); | ||
| if (!dataColumnSidecarBytes) { | ||
| const dataColumnSidecars = await db.dataColumnSidecar.valuesBinary(block.root); | ||
| if (!dataColumnSidecars || dataColumnSidecars.length === 0) { | ||
| throw Error(`No dataColumnSidecars found for slot ${block.slot} root ${toHex(block.root)}`); | ||
| } | ||
| promises.push( | ||
| db.dataColumnSidecarArchive.putManyBinary( | ||
| block.slot, | ||
| dataColumnSidecarBytes.map((p) => ({key: p.id, value: p.value})) | ||
| ) | ||
| ); | ||
| migratedWrappedDataColumns += dataColumnSidecarBytes.length; | ||
|
|
||
| promises.push(db.dataColumnSidecarArchive.putManyBinary(block.slot, dataColumnSidecars)); | ||
| migratedDataColumnsCount += dataColumnSidecars.length; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the refactoring has simplified the code, there's still a performance improvement that can be made here. The const blocksToProcess = canonicalBlocks.filter((block) => withinDataColumnWindow(block.slot));
const sidecarsByBlock = await Promise.all(
blocksToProcess.map((block) => db.dataColumnSidecar.valuesBinary(block.root))
);
for (let i = 0; i < blocksToProcess.length; i++) {
const block = blocksToProcess[i];
const dataColumnSidecars = sidecarsByBlock[i];
if (!dataColumnSidecars || dataColumnSidecars.length === 0) {
throw Error(`No dataColumnSidecars found for slot ${block.slot} root ${toHex(block.root)}`);
}
promises.push(db.dataColumnSidecarArchive.putManyBinary(block.slot, dataColumnSidecars));
migratedDataColumnsCount += dataColumnSidecars.length;
}There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iterating over all |
||
|
|
||
| promises.push(db.dataColumnSidecar.deleteMany(canonicalBlocks.map((block) => block.root))); | ||
|
|
||
| // put to blockArchive db and delete block db | ||
| await Promise.all(promises); | ||
| } | ||
|
|
||
| return migratedWrappedDataColumns; | ||
| return migratedDataColumnsCount; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.