-
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc88c4a
commit 7eb7c17
Showing
3 changed files
with
31 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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
15 changes: 11 additions & 4 deletions
15
packages/beacon-node/src/chain/historicalState/utils/snapshot.ts
This file contains 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,14 +1,21 @@ | ||
import {Slot} from "@lodestar/types"; | ||
import {IBeaconDb} from "../../../db/index.js"; | ||
|
||
export async function getSnapshotStateWithFallback(slot: Slot, db: IBeaconDb): Promise<Uint8Array | null> { | ||
export async function getSnapshotStateWithFallback( | ||
slot: Slot, | ||
db: IBeaconDb | ||
): Promise<{stateBytes: Uint8Array | null; slot: Slot}> { | ||
const state = await db.stateSnapshotArchive.getBinary(slot); | ||
if (state) return state; | ||
if (state) return {slot, stateBytes: state}; | ||
|
||
// There is a possibility that node is started with checkpoint and initial snapshot | ||
// is not persisted on expected slot | ||
const lastSnapshotSlot = await db.stateSnapshotArchive.lastKey(); | ||
if (lastSnapshotSlot !== null) return db.stateSnapshotArchive.getBinary(lastSnapshotSlot); | ||
if (lastSnapshotSlot !== null) | ||
return { | ||
slot: lastSnapshotSlot, | ||
stateBytes: await db.stateSnapshotArchive.getBinary(lastSnapshotSlot), | ||
}; | ||
|
||
return null; | ||
return {stateBytes: null, slot}; | ||
} |