Skip to content
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

fix: ensure loaded state is typed as Uint8Array #7488

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading