Skip to content

Commit 212547b

Browse files
authored
Merge 7b5ee68 into 4a35371
2 parents 4a35371 + 7b5ee68 commit 212547b

File tree

7 files changed

+19
-6
lines changed

7 files changed

+19
-6
lines changed

packages/beacon-node/src/chain/chain.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ export class BeaconChain implements IBeaconChain {
184184
{
185185
config,
186186
db,
187+
dataDir,
187188
logger,
188189
processShutdownCallback,
189190
clock,
@@ -196,6 +197,7 @@ export class BeaconChain implements IBeaconChain {
196197
}: {
197198
config: BeaconConfig;
198199
db: IBeaconDb;
200+
dataDir: string;
199201
logger: Logger;
200202
processShutdownCallback: ProcessShutdownCallback;
201203
/** Used for testing to supply fake clock */
@@ -284,7 +286,7 @@ export class BeaconChain implements IBeaconChain {
284286
this.pubkey2index = cachedState.epochCtx.pubkey2index;
285287
this.index2pubkey = cachedState.epochCtx.index2pubkey;
286288

287-
const fileDataStore = opts.nHistoricalStatesFileDataStore ?? false;
289+
const fileDataStore = opts.nHistoricalStatesFileDataStore ?? true;
288290
const blockStateCache = this.opts.nHistoricalStates
289291
? new FIFOBlockStateCache(this.opts, {metrics})
290292
: new BlockStateCacheImpl({metrics});
@@ -301,7 +303,7 @@ export class BeaconChain implements IBeaconChain {
301303
bufferPool: this.bufferPool,
302304
datastore: fileDataStore
303305
? // debug option if we want to investigate any issues with the DB
304-
new FileCPStateDatastore()
306+
new FileCPStateDatastore(dataDir)
305307
: // production option
306308
new DbCPStateDatastore(this.db),
307309
},

packages/beacon-node/src/chain/options.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ export const defaultChainOptions: IChainOptions = {
117117
// since this batch attestation work is designed to work with useWorker=true, make this the lowest value
118118
minSameMessageSignatureSetsToBatch: 2,
119119
nHistoricalStates: true,
120-
nHistoricalStatesFileDataStore: false,
120+
// as of Feb 2025, this option turned out to be very useful:
121+
// - it allows to share a persisted checkpoint state to other nodes
122+
// - users can prune the persisted checkpoint state files manually to save disc space
123+
// - it helps debug easier when network is unfinalized
124+
nHistoricalStatesFileDataStore: true,
121125
maxBlockStates: DEFAULT_MAX_BLOCK_STATES,
122126
maxCPStateEpochsInMemory: DEFAULT_MAX_CP_STATE_EPOCHS_IN_MEMORY,
123127
};

packages/beacon-node/src/chain/stateCache/datastore/file.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ const CHECKPOINT_FILE_NAME_LENGTH = 82;
1313
export class FileCPStateDatastore implements CPStateDatastore {
1414
private readonly folderPath: string;
1515

16-
constructor(parentDir = ".") {
17-
// by default use the beacon folder `/beacon/checkpoint_states`
18-
this.folderPath = path.join(parentDir, CHECKPOINT_STATES_FOLDER);
16+
constructor(dataDir: string) {
17+
// service deployment: `/beacon/checkpoint_states`
18+
// docker deployment: `/data/checkpoint_states`
19+
this.folderPath = path.join(dataDir, CHECKPOINT_STATES_FOLDER);
1920
}
2021

2122
async init(): Promise<void> {

packages/beacon-node/src/node/nodejs.ts

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export type BeaconNodeInitModules = {
5252
logger: LoggerNode;
5353
processShutdownCallback: ProcessShutdownCallback;
5454
peerId: PeerId;
55+
dataDir: string;
5556
peerStoreDir?: string;
5657
anchorState: BeaconStateAllForks;
5758
wsCheckpoint?: phase0.Checkpoint;
@@ -149,6 +150,7 @@ export class BeaconNode {
149150
logger,
150151
processShutdownCallback,
151152
peerId,
153+
dataDir,
152154
peerStoreDir,
153155
anchorState,
154156
wsCheckpoint,
@@ -224,6 +226,7 @@ export class BeaconNode {
224226
const chain = new BeaconChain(opts.chain, {
225227
config,
226228
clock,
229+
dataDir,
227230
db,
228231
logger: logger.child({module: LoggerModule.chain}),
229232
processShutdownCallback,

packages/beacon-node/test/spec/presets/fork_choice.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const forkChoiceTest =
111111
{
112112
config: createBeaconConfig(config, state.genesisValidatorsRoot),
113113
db: getMockedBeaconDb(),
114+
dataDir: ".",
114115
logger,
115116
processShutdownCallback: () => {},
116117
clock,

packages/beacon-node/test/utils/node/beacon.ts

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export async function getDevBeaconNode(
9494
logger,
9595
processShutdownCallback: () => {},
9696
peerId,
97+
dataDir: ".",
9798
peerStoreDir,
9899
anchorState,
99100
wsCheckpoint: opts.wsCheckpoint,

packages/cli/src/cmds/beacon/handler.ts

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export async function beaconHandler(args: BeaconArgs & GlobalArgs): Promise<void
8686
logger,
8787
processShutdownCallback,
8888
peerId,
89+
dataDir: beaconPaths.dataDir,
8990
peerStoreDir: beaconPaths.peerStoreDir,
9091
anchorState,
9192
wsCheckpoint,

0 commit comments

Comments
 (0)