-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
Use single state tree at startup #7027
Comments
tested with finalized state slot 1885504 of holesky const chainForkConfig = createChainForkConfig(holeskyChainConfig);
const now = Date.now();
const wsState = getStateTypeFromBytes(chainForkConfig, stateBytes).deserializeToViewDU(stateBytes);
console.log("@@@ loaded state", wsState.slot, Date.now() - now, "ms");
const root = wsState.hashTreeRoot();
console.log("@@@ state root", toRootHex(root), Date.now() - now, "ms"); this gives
the initial full note that initially we always have to compute state root
export function getCheckpointFromState(state: BeaconStateAllForks): Checkpoint {
return {
// the correct checkpoint is based on state's slot, its latestBlockHeader's slot's epoch can be
// behind the state
epoch: computeCheckpointEpochAtStateSlot(state.slot),
root: getLatestBlockRoot(state),
};
}
export function getLatestBlockRoot(state: BeaconStateAllForks): Root {
const header = ssz.phase0.BeaconBlockHeader.clone(state.latestBlockHeader);
if (ssz.Root.equals(header.stateRoot, ZERO_HASH)) {
header.stateRoot = state.hashTreeRoot();
}
return ssz.phase0.BeaconBlockHeader.hashTreeRoot(header);
} |
on a common node, when start up we block for 3 times:
the goal is to get rid of the 2nd blocking time |
Problem description
Right now if user provides a
checkpointState
orcheckpointSyncUrl
we'll deserialize states to 2 separate trees: one with the last state stored in db and the other one downloaded fromcheckpointState
orcheckpointSyncUrl
. This takes a lot of memory and time of the node unnecessarilySolution description
Once we load state with the last db value, use
loadState()
util to load the other state from bytes. This ensures we use same state tree across applicationAdditional context
this will also gives us more confident on bringing n-historical state flags to production because we use
loadState()
api at every startupThe text was updated successfully, but these errors were encountered: