-
-
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
Open
vedant-asati
wants to merge
5
commits into
ChainSafe:backfill
Choose a base branch
from
vedant-asati:va/backfill
base: backfill
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aebe674
update backfill related db repositories
vedant-asati 7e2e0d1
minor fixes
vedant-asati 3c034dd
modify epochbackfillstate type & minor fixes
vedant-asati 3691979
add unit test for backfillstate db repo
vedant-asati 854858f
fix bfstate: add Optional ssz type
vedant-asati File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import {ContainerType, ListUintNum64Type, ValueOf} from "@chainsafe/ssz"; | ||
| import {ChainForkConfig} from "@lodestar/config/lib"; | ||
| import {DatabaseController, Repository} from "@lodestar/db"; | ||
| import {Epoch, ssz} from "@lodestar/types"; | ||
| import {Bucket, getBucketNameByValue} from "../buckets.js"; | ||
| import {BACKFILL_RANGE_KEY} from "../single/backfillRange.js"; | ||
|
|
||
| // TODO: Fix the null possibilities. ssz types dont work with null values | ||
| export const epochBackfillStateSSZ = new ContainerType( | ||
| { | ||
| hasBlock: ssz.Boolean, | ||
| hasBlobs: ssz.Boolean || null, | ||
| columnIndices: new ListUintNum64Type(128) || null, | ||
matthewkeil marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| // {typeName: "EpochBackfillState", jsonCase: "eth2"} | ||
vedant-asati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| export type EpochBackfillState = ValueOf<typeof epochBackfillStateSSZ>; | ||
|
|
||
| export class BackfillState extends Repository<Epoch, EpochBackfillState> { | ||
| 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"); | ||
vedant-asati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return super.encodeKey(key); | ||
| } | ||
| } | ||
matthewkeil marked this conversation as resolved.
Show resolved
Hide resolved
vedant-asati marked this conversation as resolved.
Show resolved
Hide resolved
|
||
29 changes: 0 additions & 29 deletions
29
packages/beacon-node/src/db/repositories/backfilledRanges.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.UintNum64, | ||
vedant-asati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| endingEpoch: ssz.UintNum64, | ||
| } | ||
| // {typeName: "BackfillRange", jsonCase: "eth2"} | ||
vedant-asati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| 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 = Infinity; | ||
vedant-asati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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); // set unique key: [0x2a, 0xff, 0xff, ...0xff] | ||
vedant-asati marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.