From c9c50583276aa0f49655c190ca82204e0bb0b612 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Mon, 21 Oct 2024 09:53:34 +0200 Subject: [PATCH] Update the code as per feedback --- packages/beacon-node/src/chain/archiver/archiver.ts | 7 +++++-- packages/beacon-node/src/chain/archiver/constants.ts | 11 ----------- packages/beacon-node/src/chain/archiver/index.ts | 1 - packages/beacon-node/src/chain/archiver/interface.ts | 3 ++- .../strategies/frequencyStateArchiveStrategy.ts | 7 ++++++- packages/beacon-node/src/chain/options.ts | 2 +- packages/cli/src/options/beaconNodeOptions/chain.ts | 4 ++-- 7 files changed, 16 insertions(+), 19 deletions(-) delete mode 100644 packages/beacon-node/src/chain/archiver/constants.ts diff --git a/packages/beacon-node/src/chain/archiver/archiver.ts b/packages/beacon-node/src/chain/archiver/archiver.ts index ade7a8deefb..2d79f584ea7 100644 --- a/packages/beacon-node/src/chain/archiver/archiver.ts +++ b/packages/beacon-node/src/chain/archiver/archiver.ts @@ -8,7 +8,10 @@ import {Metrics} from "../../metrics/metrics.js"; import {FrequencyStateArchiveStrategy} from "./strategies/frequencyStateArchiveStrategy.js"; import {archiveBlocks} from "./archiveBlocks.js"; import {StateArchiveMode, ArchiverOpts, StateArchiveStrategy} from "./interface.js"; -import {PROCESS_FINALIZED_CHECKPOINT_QUEUE_LEN} from "./constants.js"; + +export const DEFAULT_STATE_ARCHIVE_MODE = StateArchiveMode.Frequency; + +export const PROCESS_FINALIZED_CHECKPOINT_QUEUE_LEN = 256; /** * Used for running tasks that depends on some events or are executed @@ -61,7 +64,7 @@ export class Archiver { /** Archive latest finalized state */ async persistToDisk(): Promise { - await this.statesArchiverStrategy.maybeArchiveState(this.chain.forkChoice.getFinalizedCheckpoint()); + return this.statesArchiverStrategy.maybeArchiveState(this.chain.forkChoice.getFinalizedCheckpoint()); } private onFinalizedCheckpoint = async (finalized: CheckpointWithHex): Promise => { diff --git a/packages/beacon-node/src/chain/archiver/constants.ts b/packages/beacon-node/src/chain/archiver/constants.ts deleted file mode 100644 index 2bc0129ee48..00000000000 --- a/packages/beacon-node/src/chain/archiver/constants.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {StateArchiveMode} from "./interface.js"; - -/** - * Minimum number of epochs between single temp archived states - * These states will be pruned once a new state is persisted - */ -export const PERSIST_TEMP_STATE_EVERY_EPOCHS = 32; - -export const PROCESS_FINALIZED_CHECKPOINT_QUEUE_LEN = 256; - -export const DEFAULT_STATE_ARCHIVE_MODE = StateArchiveMode.Frequency; diff --git a/packages/beacon-node/src/chain/archiver/index.ts b/packages/beacon-node/src/chain/archiver/index.ts index fac923cc110..dbcafbe458a 100644 --- a/packages/beacon-node/src/chain/archiver/index.ts +++ b/packages/beacon-node/src/chain/archiver/index.ts @@ -1,3 +1,2 @@ export * from "./archiver.js"; export * from "./interface.js"; -export * from "./constants.js"; diff --git a/packages/beacon-node/src/chain/archiver/interface.ts b/packages/beacon-node/src/chain/archiver/interface.ts index 108b6976873..48c930c78cd 100644 --- a/packages/beacon-node/src/chain/archiver/interface.ts +++ b/packages/beacon-node/src/chain/archiver/interface.ts @@ -4,7 +4,8 @@ import {RootHex} from "@lodestar/types"; export enum StateArchiveMode { Frequency = "frequency", - // Specify only existing strategy + // New strategy to be implemented + // WIP: https://github.com/ChainSafe/lodestar/pull/7005 // Differential = "diff", } diff --git a/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts b/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts index 8ef3503a0a6..a701da5b22e 100644 --- a/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts +++ b/packages/beacon-node/src/chain/archiver/strategies/frequencyStateArchiveStrategy.ts @@ -10,7 +10,12 @@ import {serializeState} from "../../serializeState.js"; import {AllocSource, BufferPool} from "../../../util/bufferPool.js"; import {Metrics} from "../../../metrics/metrics.js"; import {StateArchiveStrategy, StatesArchiverOpts} from "../interface.js"; -import {PERSIST_TEMP_STATE_EVERY_EPOCHS} from "../constants.js"; + +/** + * Minimum number of epochs between single temp archived states + * These states will be pruned once a new state is persisted + */ +export const PERSIST_TEMP_STATE_EVERY_EPOCHS = 32; /** * Archives finalized states from active bucket to archive bucket. diff --git a/packages/beacon-node/src/chain/options.ts b/packages/beacon-node/src/chain/options.ts index dadefd4bac0..fb14da79c2b 100644 --- a/packages/beacon-node/src/chain/options.ts +++ b/packages/beacon-node/src/chain/options.ts @@ -7,7 +7,7 @@ import {ShufflingCacheOpts} from "./shufflingCache.js"; import {DEFAULT_MAX_BLOCK_STATES, FIFOBlockStateCacheOpts} from "./stateCache/fifoBlockStateCache.js"; import {PersistentCheckpointStateCacheOpts} from "./stateCache/persistentCheckpointsCache.js"; import {DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY} from "./stateCache/persistentCheckpointsCache.js"; -import {DEFAULT_STATE_ARCHIVE_MODE} from "./archiver/constants.js"; +import {DEFAULT_STATE_ARCHIVE_MODE} from "./archiver/archiver.js"; export {StateArchiveMode} from "./archiver/interface.js"; export type IChainOptions = BlockProcessOpts & diff --git a/packages/cli/src/options/beaconNodeOptions/chain.ts b/packages/cli/src/options/beaconNodeOptions/chain.ts index 2c9af973514..c5f907804a8 100644 --- a/packages/cli/src/options/beaconNodeOptions/chain.ts +++ b/packages/cli/src/options/beaconNodeOptions/chain.ts @@ -1,5 +1,5 @@ import * as path from "node:path"; -import {StateArchiveMode, defaultOptions, IBeaconNodeOptions} from "@lodestar/beacon-node"; +import {StateArchiveMode, defaultOptions, IBeaconNodeOptions, DEFAULT_STATE_ARCHIVE_MODE} from "@lodestar/beacon-node"; import {CliCommandOptions} from "@lodestar/utils"; export type ChainArgs = { @@ -215,7 +215,7 @@ Will double processing times. Use only for debugging purposes.", "chain.stateArchiveMode": { hidden: true, choices: Object.values(StateArchiveMode), - description: "Strategy to manage archive states", + description: `Strategy to manage archive states, only support ${DEFAULT_STATE_ARCHIVE_MODE} at this time`, default: defaultOptions.chain.stateArchiveMode, type: "string", group: "chain",