-
-
Notifications
You must be signed in to change notification settings - Fork 410
feat: update backfill related db repositories #8085
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: backfill
Are you sure you want to change the base?
Changes from 3 commits
aebe674
7e2e0d1
3c034dd
3691979
854858f
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 | ||
|---|---|---|---|---|
| @@ -0,0 +1,79 @@ | ||||
| import {ContainerType, ListBasicType, ValueOf} from "@chainsafe/ssz"; | ||||
| import {ChainForkConfig} from "@lodestar/config"; | ||||
| import {DatabaseController, Repository} from "@lodestar/db"; | ||||
| import {ForkName, NUMBER_OF_COLUMNS} from "@lodestar/params"; | ||||
| import {computeStartSlotAtEpoch} from "@lodestar/state-transition"; | ||||
| import {Epoch, ssz} from "@lodestar/types"; | ||||
| import {bytesToInt} from "@lodestar/utils"; | ||||
| import {Bucket, getBucketNameByValue} from "../buckets.js"; | ||||
| import {BACKFILL_RANGE_KEY} from "../single/backfillRange.js"; | ||||
|
|
||||
| export const epochBackfillStateSSZ = new ContainerType( | ||||
| { | ||||
| hasBlock: ssz.Boolean, | ||||
| hasBlobs: ssz.Boolean, | ||||
| columnIndices: new ListBasicType(ssz.ColumnIndex, NUMBER_OF_COLUMNS), | ||||
| }, | ||||
| {typeName: "EpochBackfillState", jsonCase: "eth2"} | ||||
| ); | ||||
| export type EpochBackfillStateWrapper = ValueOf<typeof epochBackfillStateSSZ>; | ||||
| export type EpochBackfillState = { | ||||
| hasBlock: boolean; | ||||
| hasBlobs: boolean | null; | ||||
| columnIndices: number[] | null; | ||||
| }; | ||||
|
|
||||
| export class BackfillState extends Repository<Epoch, EpochBackfillStateWrapper> { | ||||
| constructor(config: ChainForkConfig, db: DatabaseController<Uint8Array, Uint8Array>) { | ||||
| const bucket = Bucket.backfill_state; | ||||
| super(config, db, bucket, epochBackfillStateSSZ, getBucketNameByValue(bucket)); | ||||
| } | ||||
|
|
||||
| encodeKey(key: Epoch): Uint8Array { | ||||
| if (key === BACKFILL_RANGE_KEY) { | ||||
| throw new Error("Reserved key for backfill range singleton object"); | ||||
| } | ||||
| return super.encodeKey(key); | ||||
| } | ||||
|
|
||||
| decodeKey(data: Uint8Array): number { | ||||
| return bytesToInt(super.decodeKey(data) as unknown as Uint8Array, "be"); | ||||
| } | ||||
|
|
||||
| async _get(epoch: Epoch): Promise<EpochBackfillState | null> { | ||||
| const wrappedValue = await super.get(epoch); | ||||
| if (!wrappedValue) return null; | ||||
| return this.unwrapEpochBackfillState(wrappedValue, epoch); | ||||
| } | ||||
|
|
||||
| async _put(epoch: Epoch, value: EpochBackfillState): Promise<void> { | ||||
| const wrappedValue = this.wrapEpochBackfillState(value); | ||||
| await super.put(epoch, wrappedValue); | ||||
| } | ||||
|
||||
| export enum DAType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason we have EpochBackfillState type which deviates from repository type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the DB, we can't store EpochBackfillState with nullable fields as it is not compatible with ssz types. We need null in certain situations, for example, to differentiate between blobs' availability and when they are not even present i.e. pre-Deneb (hasBlobs: boolean | null).
So thought to store EpochBackfillStateWrapper in DB and convert it to EpochBackfillState while putting and getting as needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't even implement backfill for pre-fulu and only consider data columns, this might simplify things
Edit: even if we don't support pre-fulu we might still need to handle the case if we backfill outside of the DA period (~18 days) after which we only need to backfill sync blocks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use Optional ssz type which allows the value to be nullable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Added OptionalType, modified the unit tests, they're successfully passing.
Please check once.
vedant-asati marked this conversation as resolved.
Show resolved
Hide resolved
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import {ContainerType, Type, ValueOf} from "@chainsafe/ssz"; | ||
| import {ChainForkConfig} from "@lodestar/config"; | ||
| import {Db, DbReqOpts, encodeKey as _encodeKey} from "@lodestar/db"; | ||
| import {ssz} from "@lodestar/types"; | ||
| import {Bucket, getBucketNameByValue} from "../buckets.js"; | ||
|
|
||
| export const backfillRangeSSZ = new ContainerType( | ||
| { | ||
| beginningEpoch: ssz.Epoch, | ||
| endingEpoch: ssz.Epoch, | ||
| }, | ||
| {typeName: "BackfillRange", jsonCase: "eth2"} | ||
| ); | ||
| export type BackfillRangeWrapper = ValueOf<typeof backfillRangeSSZ>; | ||
|
|
||
| // unique & practically impossible key to store BackfillRange inside 'backfill_state' | ||
| // bucket which stores Epoch -> EpochBackfillState key value pairs | ||
| export const BACKFILL_RANGE_KEY = -1; | ||
|
|
||
| export class BackfillRange { | ||
| private readonly bucket: Bucket; | ||
| private readonly db: Db; | ||
| private readonly dbReqOpts: DbReqOpts; // to record metrics | ||
| private readonly key: Uint8Array; | ||
| private readonly type: Type<BackfillRangeWrapper>; | ||
|
|
||
| constructor(_config: ChainForkConfig, db: Db) { | ||
| this.db = db; | ||
| this.bucket = Bucket.backfill_state; | ||
| this.key = _encodeKey(this.bucket, BACKFILL_RANGE_KEY); | ||
| this.type = backfillRangeSSZ; | ||
| this.dbReqOpts = {bucketId: getBucketNameByValue(this.bucket)}; | ||
| } | ||
|
|
||
| async put(value: BackfillRangeWrapper): Promise<void> { | ||
| await this.db.put(this.key, this.type.serialize(value), this.dbReqOpts); | ||
| } | ||
|
|
||
| async get(): Promise<BackfillRangeWrapper | null> { | ||
| const value = await this.db.get(this.key, this.dbReqOpts); | ||
| return value ? this.type.deserialize(value) : null; | ||
| } | ||
|
|
||
| async delete(): Promise<void> { | ||
| await this.db.delete(this.key, this.dbReqOpts); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export {BackfillRange} from "./backfillRange.js"; | ||
| export {PreGenesisState} from "./preGenesisState.js"; | ||
| export {PreGenesisStateLastProcessedBlock} from "./preGenesisStateLastProcessedBlock.js"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using the term "state" here could be misleading, I'd rather call this
BackfillTrackerorBackfillProgressThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthewkeil please confirm