diff --git a/yarn-project/aztec-node/package.json b/yarn-project/aztec-node/package.json index a2e602a03fff..2c0dd26296cb 100644 --- a/yarn-project/aztec-node/package.json +++ b/yarn-project/aztec-node/package.json @@ -47,17 +47,11 @@ "@aztec/world-state": "workspace:^", "koa": "^2.14.2", "koa-router": "^12.0.0", - "levelup": "^5.1.1", - "lmdb": "^2.9.1", - "memdown": "^6.1.1", "tslib": "^2.4.0" }, "devDependencies": { "@jest/globals": "^29.5.0", "@types/jest": "^29.5.0", - "@types/leveldown": "^4.0.4", - "@types/levelup": "^5.1.2", - "@types/memdown": "^3.0.0", "@types/node": "^18.7.23", "jest": "^29.5.0", "ts-jest": "^29.1.0", diff --git a/yarn-project/aztec-node/src/aztec-node/db.ts b/yarn-project/aztec-node/src/aztec-node/db.ts deleted file mode 100644 index 9b5be428781a..000000000000 --- a/yarn-project/aztec-node/src/aztec-node/db.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { LogFn } from '@aztec/foundation/log'; - -import { LevelDown, default as leveldown } from 'leveldown'; -import { LevelUp, default as levelup } from 'levelup'; -import { RootDatabase, open } from 'lmdb'; -import { MemDown, default as memdown } from 'memdown'; -import { mkdir } from 'node:fs/promises'; -import { join } from 'node:path'; - -import { AztecNodeConfig } from './config.js'; - -export const createMemDown = () => (memdown as any)() as MemDown; -export const createLevelDown = (path: string) => (leveldown as any)(path) as LevelDown; - -const DB_SUBDIR = 'aztec-node-db'; -const WORLD_STATE_SUBDIR = 'aztec-world-state-db'; -const NODE_METADATA_KEY = '@@aztec_node_metadata'; - -/** - * The metadata for an aztec node. - */ -type NodeMetadata = { - /** - * The address of the rollup contract on L1 - */ - rollupContractAddress: string; -}; - -/** - * Opens the database for the aztec node. If a data directory is specified, then this attempts to create it. - * @param config - The configuration to be used by the aztec node. - * @throws If `config.dataDirectory` is set and the directory cannot be created. - * @returns The database for the aztec node. - */ -export async function openDb( - config: AztecNodeConfig, - log: LogFn, -): Promise<[nodeDb: RootDatabase, worldStateDb: LevelUp]> { - const nodeMetadata: NodeMetadata = { - rollupContractAddress: config.l1Contracts.rollupAddress.toString(), - }; - - let nodeDb: RootDatabase; - let worldStateDb: LevelUp; - - if (config.dataDirectory) { - const nodeDir = join(config.dataDirectory, DB_SUBDIR); - const worldStateDir = join(config.dataDirectory, WORLD_STATE_SUBDIR); - // this throws if we don't have permissions to create the directory - await mkdir(nodeDir, { recursive: true }); - await mkdir(worldStateDir, { recursive: true }); - - log(`Opening aztec-node database at ${nodeDir}`); - nodeDb = open(nodeDir, {}); - - log(`Opening world-state database at ${worldStateDir}`); - worldStateDb = levelup(createLevelDown(worldStateDir)); - } else { - log('Opening temporary databases'); - // not passing a path will use a temp file that gets deleted when the process exits - nodeDb = open({}); - worldStateDb = levelup(createMemDown()); - } - - await checkNodeMetadataAndClear(nodeDb, worldStateDb, nodeMetadata, log); - return [nodeDb, worldStateDb]; -} - -/** - * Checks the node metadata and clears the database if the rollup contract address has changed. - * @param nodeDb - The database for the aztec node. - * @param nodeMetadata - The metadata for the aztec node. - */ -async function checkNodeMetadataAndClear( - nodeDb: RootDatabase, - worldStateDb: LevelUp, - nodeMetadata: NodeMetadata, - log: LogFn, -): Promise { - const metadataDB = nodeDb.openDB('metadata', {}); - try { - const existing = metadataDB.get(NODE_METADATA_KEY); - // if the rollup addresses are different, wipe the local database and start over - if (!existing || existing.rollupContractAddress !== nodeMetadata.rollupContractAddress) { - log('Rollup contract address has changed, clearing databases'); - await Promise.all([nodeDb.clearAsync(), worldStateDb.clear()]); - } - await metadataDB.put(NODE_METADATA_KEY, nodeMetadata); - } finally { - await metadataDB.close(); - } -} diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 51d169e86e3e..a418e13b858d 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -181,16 +181,10 @@ __metadata: "@aztec/world-state": "workspace:^" "@jest/globals": ^29.5.0 "@types/jest": ^29.5.0 - "@types/leveldown": ^4.0.4 - "@types/levelup": ^5.1.2 - "@types/memdown": ^3.0.0 "@types/node": ^18.7.23 jest: ^29.5.0 koa: ^2.14.2 koa-router: ^12.0.0 - levelup: ^5.1.1 - lmdb: ^2.9.1 - memdown: ^6.1.1 ts-jest: ^29.1.0 ts-node: ^10.9.1 tslib: ^2.4.0 @@ -3490,16 +3484,6 @@ __metadata: languageName: node linkType: hard -"@types/leveldown@npm:^4.0.4": - version: 4.0.4 - resolution: "@types/leveldown@npm:4.0.4" - dependencies: - "@types/abstract-leveldown": "*" - "@types/node": "*" - checksum: 630b2d2d1c48f83d14ab0f6c03ad2af1c427675c3692873c4fd3d673bde4140eabc028ce5736ad3d76aeea20769cf53df6f83468a4f0cf28f6d04dbb435edf48 - languageName: node - linkType: hard - "@types/levelup@npm:^5.1.2": version: 5.1.2 resolution: "@types/levelup@npm:5.1.2"