From bad40392654104b550dd64b7423eae90382fda9c Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 12 Sep 2024 13:03:48 +0200 Subject: [PATCH] Fix some code after rebase --- .../src/chain/historicalState/metrics.ts | 4 ++++ .../cli/src/cmds/beacon/initBeaconState.ts | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/beacon-node/src/chain/historicalState/metrics.ts b/packages/beacon-node/src/chain/historicalState/metrics.ts index ddf285b74d93..dc9a7fd5ba9d 100644 --- a/packages/beacon-node/src/chain/historicalState/metrics.ts +++ b/packages/beacon-node/src/chain/historicalState/metrics.ts @@ -40,6 +40,10 @@ export function getMetrics(metricsRegister: RegistryMetricCreator): HistoricalSt buckets: [0.05, 0.1, 0.2, 0.5, 1, 1.5], labelNames: ["source"], }), + numEffectiveBalanceUpdates: metricsRegister.gauge({ + name: "lodestar_historical_state_stfn_effective_balance_updates_count", + help: "Total count of effective balance updates", + }), preStateBalancesNodesPopulatedMiss: metricsRegister.gauge<{source: StateCloneSource}>({ name: "lodestar_historical_state_stfn_balances_nodes_populated_miss_total", help: "Total count state.balances nodesPopulated is false on stfn", diff --git a/packages/cli/src/cmds/beacon/initBeaconState.ts b/packages/cli/src/cmds/beacon/initBeaconState.ts index 2b4da1f070a9..b0bbca8ff9a2 100644 --- a/packages/cli/src/cmds/beacon/initBeaconState.ts +++ b/packages/cli/src/cmds/beacon/initBeaconState.ts @@ -1,11 +1,12 @@ import {ssz} from "@lodestar/types"; import {createBeaconConfig, BeaconConfig, ChainForkConfig} from "@lodestar/config"; -import {Logger} from "@lodestar/utils"; +import {formatBytes, Logger} from "@lodestar/utils"; import { isWithinWeakSubjectivityPeriod, ensureWithinWeakSubjectivityPeriod, BeaconStateAllForks, loadState, + loadStateAndValidators, } from "@lodestar/state-transition"; import { IBeaconDb, @@ -103,11 +104,17 @@ export async function initBeaconState( // fetch the latest state stored in the db which will be used in all cases, if it exists, either // i) used directly as the anchor state // ii) used during verification of a weak subjectivity state, - const {stateBytes: lastDbStateBytes, slot: lastDbSlot} = await getLastStoredState({db, diffLayers: new DiffLayers()}); - const lastDbState = - lastDbStateBytes && lastDbSlot !== null && lastDbSlot !== undefined - ? chainForkConfig.getForkTypes(lastDbSlot).BeaconState.deserializeToViewDU(lastDbStateBytes) - : null; + const {stateBytes, slot: lastDbSlot} = await getLastStoredState({db, diffLayers: new DiffLayers()}); + let lastDbState: BeaconStateAllForks | null = null; + let lastDbValidatorsBytes: Uint8Array | null = null; + let lastDbStateWithBytes: StateWithBytes | null = null; + if (stateBytes) { + logger.verbose("Found the last archived state", {slot: lastDbSlot, size: formatBytes(stateBytes.length)}); + const {state, validatorsBytes} = loadStateAndValidators(chainForkConfig, stateBytes); + lastDbState = state; + lastDbValidatorsBytes = validatorsBytes; + lastDbStateWithBytes = {state, stateBytes: stateBytes}; + } if (lastDbState) { const config = createBeaconConfig(chainForkConfig, lastDbState.genesisValidatorsRoot);