Skip to content

Commit

Permalink
Merge 33c14dc into 9a2cf74
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig authored Feb 22, 2025
2 parents 9a2cf74 + 33c14dc commit a6b6394
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/cli/src/cmds/beacon/initBeaconState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ export async function initBeaconState(
// i) used directly as the anchor state
// ii) used to load and verify a weak subjectivity state,
const lastDbSlot = await db.stateArchive.lastKey();
const stateBytes = lastDbSlot !== null ? await db.stateArchive.getBinary(lastDbSlot) : null;
let stateBytes = lastDbSlot !== null ? await db.stateArchive.getBinary(lastDbSlot) : null;
// Convert to `Uint8Array` to avoid unexpected behavior such as `Buffer.prototype.slice` not copying memory
stateBytes = stateBytes ? new Uint8Array(stateBytes.buffer, stateBytes.byteOffset, stateBytes.byteLength) : null;
let lastDbState: BeaconStateAllForks | null = null;
let lastDbValidatorsBytes: Uint8Array | null = null;
let lastDbStateWithBytes: StateWithBytes | null = null;
Expand Down Expand Up @@ -181,7 +183,9 @@ export async function initBeaconState(

const genesisStateFile = args.genesisStateFile || getGenesisFileUrl(args.network || defaultNetwork);
if (genesisStateFile && !args.forceGenesis) {
const stateBytes = await downloadOrLoadFile(genesisStateFile);
let stateBytes = await downloadOrLoadFile(genesisStateFile);
// Convert to `Uint8Array` to avoid unexpected behavior such as `Buffer.prototype.slice` not copying memory
stateBytes = new Uint8Array(stateBytes.buffer, stateBytes.byteOffset, stateBytes.byteLength);
const anchorState = getStateTypeFromBytes(chainForkConfig, stateBytes).deserializeToViewDU(stateBytes);
const config = createBeaconConfig(chainForkConfig, anchorState.genesisValidatorsRoot);
const wssCheck = isWithinWeakSubjectivityPeriod(config, anchorState, getCheckpointFromState(anchorState));
Expand Down

0 comments on commit a6b6394

Please sign in to comment.