Skip to content

Commit

Permalink
chore: clean checkpoint_states folder in nHistoricalStates e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
twoeths committed Jan 5, 2024
1 parent 6969f19 commit 8f8fe75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ packages/cli/.git-data.json
dictionary.dic

temp/

checkpoint_states/
6 changes: 4 additions & 2 deletions packages/beacon-node/src/chain/stateCache/datastore/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ensureDir, readFile, readFileNames, removeFile, writeIfNotExist} from ".
import {CPStateDatastore, DatastoreKey} from "./types.js";

export const CHECKPOINT_STATES_FOLDER = "./checkpoint_states";
const CHECKPOINT_FILE_NAME_LENGTH = 82;

/**
* Implementation of CPStatePersistentApis using file system, this is beneficial for debugging.
Expand Down Expand Up @@ -39,7 +40,8 @@ export class FileCPStateDatastore implements CPStateDatastore {

async readKeys(): Promise<DatastoreKey[]> {
const fileNames = await readFileNames(this.folderPath);
// TODO: filter file names with fixed size
return fileNames.map((fileName) => fromHexString(fileName));
return fileNames
.filter((fileName) => fileName.startsWith("0x") && fileName.length === CHECKPOINT_FILE_NAME_LENGTH)
.map((fileName) => fromHexString(fileName));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {describe, it, afterEach, expect} from "vitest";
import fs from "node:fs";
import {describe, it, afterEach, beforeEach, expect} from "vitest";
import {Gauge, Histogram} from "prom-client";
import {ChainConfig} from "@lodestar/config";
import {Slot, phase0} from "@lodestar/types";
Expand All @@ -13,6 +14,7 @@ import {ChainEvent, ReorgEventData} from "../../../../src/chain/emitter.js";
import {ReorgedForkChoice} from "../../../utils/mocks/forkchoice.js";
import {connect} from "../../../utils/network.js";
import {CacheItemType} from "../../../../src/chain/stateCache/types.js";
import {CHECKPOINT_STATES_FOLDER} from "../../../../src/chain/stateCache/datastore/file.js";

/**
* Test different reorg scenarios to make sure the StateCache implementations are correct.
Expand All @@ -26,6 +28,10 @@ describe(
SECONDS_PER_SLOT: 2,
};

beforeEach(async () => {
await fs.promises.rm(CHECKPOINT_STATES_FOLDER, {recursive: true, force: true});
});

const afterEachCallbacks: (() => Promise<unknown> | void)[] = [];
afterEach(async () => {
while (afterEachCallbacks.length > 0) {
Expand Down

0 comments on commit 8f8fe75

Please sign in to comment.