Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Clean up data configuration #9973

Merged
merged 43 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
aed5bce
WIP
PhilWindle Oct 29, 2024
0894c13
Updated logging
PhilWindle Oct 29, 2024
36f53d4
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Oct 29, 2024
68f2c25
Removed erroneous code
PhilWindle Oct 29, 2024
f91d91e
Merge branch 'master' into pw/world-state-cleanup
ludamad Oct 30, 2024
4962d96
Detect if trees are out of sync
PhilWindle Oct 30, 2024
8d46f2c
Merge branch 'pw/world-state-cleanup' of github.com:AztecProtocol/azt…
PhilWindle Oct 31, 2024
6511d8a
WIP
PhilWindle Oct 31, 2024
e536a59
WIP
PhilWindle Nov 11, 2024
5019a35
WIP
PhilWindle Nov 11, 2024
22e1a14
Merge remote-tracking branch 'origin/master' into pw/world-state-cleanup
PhilWindle Nov 11, 2024
478296e
Merge remote-tracking branch 'origin/master' into pw/world-state-cleanup
PhilWindle Nov 11, 2024
0c62a94
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Nov 11, 2024
70ec05a
Merge remote-tracking branch 'origin/master' into pw/world-state-cleanup
PhilWindle Nov 12, 2024
eb72f4f
WIP
PhilWindle Nov 12, 2024
c24b940
WIP
PhilWindle Nov 13, 2024
75e8472
WIP
PhilWindle Nov 13, 2024
14fa37b
WIP
PhilWindle Nov 13, 2024
21a5a1c
WIP
PhilWindle Nov 13, 2024
0ad1bdb
WIP
PhilWindle Nov 13, 2024
5cc95c5
Fixes
PhilWindle Nov 13, 2024
0ac899f
Formatting
PhilWindle Nov 13, 2024
ed8be9f
Additional test case
PhilWindle Nov 13, 2024
c7e64bb
Log formatting
PhilWindle Nov 13, 2024
b0b25bc
More log formatting
PhilWindle Nov 13, 2024
6224fa8
Formatting
PhilWindle Nov 13, 2024
4db7059
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Nov 13, 2024
e9968b7
Merge branch 'master' into pw/world-state-cleanup
PhilWindle Nov 13, 2024
4704900
Data directory config
PhilWindle Nov 14, 2024
7a0ed9b
WIP
PhilWindle Nov 14, 2024
5d229eb
WIP
PhilWindle Nov 14, 2024
62d9a9a
Changed default value
PhilWindle Nov 15, 2024
5dc7e55
Merge remote-tracking branch 'origin/master' into pw/data-config
PhilWindle Nov 17, 2024
192b4dc
Merge branch 'master' into pw/data-config
PhilWindle Nov 18, 2024
9bfb0d7
Merge branch 'master' into pw/data-config
PhilWindle Nov 18, 2024
b0b6057
Fixes
PhilWindle Nov 18, 2024
34ee499
Fixes
PhilWindle Nov 19, 2024
cf757f5
Fix
PhilWindle Nov 19, 2024
d69b3fd
Test fixes
PhilWindle Nov 19, 2024
5683889
Merge branch 'master' into pw/data-config
PhilWindle Nov 19, 2024
5b14855
Fixed prover coordination test
PhilWindle Nov 19, 2024
5aba28e
Disable uniswap test
PhilWindle Nov 19, 2024
70fec90
Documentation
PhilWindle Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"ierc",
"indexeddb",
"initialise",
"initialising",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🇬🇧

"interruptible",
"isequal",
"ivpk",
Expand Down Expand Up @@ -154,6 +155,7 @@
"monomorphize",
"mplex",
"msgpack",
"msgpackr",
"muldiv",
"multiaddr",
"multiaddrs",
Expand All @@ -163,6 +165,7 @@
"muxers",
"nada",
"namespacing",
"napi",
"Nargo",
"nixpkgs",
"nodebuffer",
Expand Down
11 changes: 1 addition & 10 deletions yarn-project/archiver/src/archiver/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ export type ArchiverConfig = {
*/
l1Contracts: L1ContractAddresses;

/**
* Optional dir to store data. If omitted will store in memory.
*/
dataDirectory: string | undefined;

/** The max number of logs that can be obtained in 1 "getUnencryptedLogs" call. */
maxLogs?: number;
} & L1ReaderConfig &
Expand All @@ -57,11 +52,7 @@ export const archiverConfigMappings: ConfigMappingsType<ArchiverConfig> = {
archiverPollingIntervalMS: {
env: 'ARCHIVER_POLLING_INTERVAL_MS',
description: 'The polling interval in ms for retrieving new L2 blocks and encrypted logs.',
...numberConfigHelper(1000),
},
dataDirectory: {
env: 'DATA_DIRECTORY',
description: 'Optional dir to store data. If omitted will store in memory.',
...numberConfigHelper(1_000),
},
maxLogs: {
env: 'ARCHIVER_MAX_LOGS',
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/archiver/src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type ArchiverApi, type Service } from '@aztec/circuit-types';
import { type ContractClassPublic } from '@aztec/circuits.js';
import { createDebugLogger } from '@aztec/foundation/log';
import { type Maybe } from '@aztec/foundation/types';
import { type DataStoreConfig } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/utils';
import { getCanonicalProtocolContract, protocolContractNames } from '@aztec/protocol-contracts';
import { type TelemetryClient } from '@aztec/telemetry-client';
Expand All @@ -13,7 +14,7 @@ import { KVArchiverDataStore } from './archiver/index.js';
import { createArchiverClient } from './rpc/index.js';

export async function createArchiver(
config: ArchiverConfig,
config: ArchiverConfig & DataStoreConfig,
telemetry: TelemetryClient = new NoopTelemetryClient(),
opts: { blockUntilSync: boolean } = { blockUntilSync: true },
): Promise<ArchiverApi & Maybe<Service>> {
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/aztec-node/src/aztec-node/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type ArchiverConfig, archiverConfigMappings } from '@aztec/archiver';
import { type ConfigMappingsType, booleanConfigHelper, getConfigFromMappings } from '@aztec/foundation/config';
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
import { type P2PConfig, p2pConfigMappings } from '@aztec/p2p';
import { type ProverClientConfig, proverClientConfigMappings } from '@aztec/prover-client';
import { type SequencerClientConfig, sequencerClientConfigMappings } from '@aztec/sequencer-client';
Expand All @@ -24,7 +25,7 @@ export type AztecNodeConfig = ArchiverConfig &
P2PConfig & {
/** Whether the validator is disabled for this node */
disableValidator: boolean;
};
} & DataStoreConfig;

export const aztecNodeConfigMappings: ConfigMappingsType<AztecNodeConfig> = {
...archiverConfigMappings,
Expand All @@ -33,6 +34,7 @@ export const aztecNodeConfigMappings: ConfigMappingsType<AztecNodeConfig> = {
...proverClientConfigMappings,
...worldStateConfigMappings,
...p2pConfigMappings,
...dataConfigMappings,
disableValidator: {
env: 'VALIDATOR_DISABLED',
description: 'Whether the validator is disabled for this node.',
Expand Down
6 changes: 0 additions & 6 deletions yarn-project/aztec/src/cli/aztec_start_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ export const aztecStartOptions: { [key: string]: AztecStartOption[] } = {
defaultValue: undefined,
envVar: undefined,
},
{
flag: '--pxe.dataDirectory <value>',
description: 'Where to store PXE data. If not set, will store in memory',
defaultValue: undefined,
envVar: 'PXE_DATA_DIRECTORY',
},
...getOptions('pxe', allPxeConfigMappings),
],
ARCHIVER: [
Expand Down
10 changes: 9 additions & 1 deletion yarn-project/aztec/src/cli/cmds/start_archiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Archiver, type ArchiverConfig, KVArchiverDataStore, archiverConfigMappi
import { createDebugLogger } from '@aztec/aztec.js';
import { ArchiverApiSchema } from '@aztec/circuit-types';
import { type NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/utils';
import {
createAndStartTelemetryClient,
Expand All @@ -16,7 +17,14 @@ export async function startArchiver(
signalHandlers: (() => Promise<void>)[],
services: NamespacedApiHandlers,
) {
const archiverConfig = extractRelevantOptions<ArchiverConfig>(options, archiverConfigMappings, 'archiver');
const archiverConfig = extractRelevantOptions<ArchiverConfig & DataStoreConfig>(
options,
{
...archiverConfigMappings,
...dataConfigMappings,
},
'archiver',
);

const storeLog = createDebugLogger('aztec:archiver:lmdb');
const store = await createStore('archiver', archiverConfig, storeLog);
Expand Down
25 changes: 13 additions & 12 deletions yarn-project/end-to-end/src/benchmarks/bench_prover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BBCircuitVerifier } from '@aztec/bb-prover';
import { CompleteAddress, Fq, Fr, GasSettings } from '@aztec/circuits.js';
import { FPCContract, FeeJuiceContract, TestContract, TokenContract } from '@aztec/noir-contracts.js';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import { type PXEService, createPXEService } from '@aztec/pxe';
import { type PXEService, type PXEServiceConfig, createPXEService } from '@aztec/pxe';

import { jest } from '@jest/globals';

Expand Down Expand Up @@ -142,17 +142,18 @@ describe('benchmarks/proving', () => {
ctx.logger.info('Starting PXEs configured with real proofs');
provingPxes = [];
for (let i = 0; i < 4; i++) {
const pxe = await createPXEService(
ctx.aztecNode,
{
proverEnabled: true,
bbBinaryPath: bbConfig.bbBinaryPath,
bbWorkingDirectory: bbConfig.bbWorkingDirectory,
l2BlockPollingIntervalMS: 1000,
l2StartingBlock: 1,
},
`proving-pxe-${i}`,
);
const l1Contracts = await ctx.aztecNode.getL1ContractAddresses();
const pxeConfig = {
proverEnabled: true,
bbBinaryPath: bbConfig.bbBinaryPath,
bbWorkingDirectory: bbConfig.bbWorkingDirectory,
l2BlockPollingIntervalMS: 1000,
l2StartingBlock: 1,
dataDirectory: undefined,
dataStoreMapSizeKB: 1024 * 1024,
l1Contracts,
} as PXEServiceConfig;
const pxe = await createPXEService(ctx.aztecNode, pxeConfig, `proving-pxe-${i}`);

await getSchnorrAccount(pxe, schnorrWalletEncKey, schnorrWalletSigningKey, schnorrWalletSalt).register();
await pxe.registerContract(initialTokenContract);
Expand Down
13 changes: 9 additions & 4 deletions yarn-project/end-to-end/src/benchmarks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type AztecNode, BatchCall, INITIAL_L2_BLOCK_NUM, type SentTx, retryUnti
import { times } from '@aztec/foundation/collection';
import { randomInt } from '@aztec/foundation/crypto';
import { BenchmarkingContract } from '@aztec/noir-contracts.js/Benchmarking';
import { type PXEService, createPXEService } from '@aztec/pxe';
import { type PXEService, type PXEServiceConfig, createPXEService } from '@aztec/pxe';

import { mkdirpSync } from 'fs-extra';
import { globSync } from 'glob';
Expand Down Expand Up @@ -102,10 +102,15 @@ export async function waitNewPXESynced(
contract: BenchmarkingContract,
startingBlock: number = INITIAL_L2_BLOCK_NUM,
): Promise<PXEService> {
const pxe = await createPXEService(node, {
l2BlockPollingIntervalMS: 100,
const l1Contracts = await node.getL1ContractAddresses();
const pxeConfig = {
l2StartingBlock: startingBlock,
});
l2BlockPollingIntervalMS: 100,
dataDirectory: undefined,
dataStoreMapSizeKB: 1024 * 1024,
l1Contracts,
} as PXEServiceConfig;
const pxe = await createPXEService(node, pxeConfig);
await pxe.registerContract(contract);
await retryUntil(() => pxe.isGlobalStateSynchronized(), 'pxe-global-sync');
return pxe;
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type EnvVar =
| 'BOT_STOP_WHEN_UNHEALTHY'
| 'COINBASE'
| 'DATA_DIRECTORY'
| 'DATA_STORE_MAP_SIZE_KB'
| 'DEBUG'
| 'DEPLOY_AZTEC_CONTRACTS_SALT'
| 'DEPLOY_AZTEC_CONTRACTS'
Expand Down Expand Up @@ -112,7 +113,6 @@ export type EnvVar =
| 'PROVER_REQUIRED_CONFIRMATIONS'
| 'PROVER_TEST_DELAY_MS'
| 'PXE_BLOCK_POLLING_INTERVAL_MS'
| 'PXE_DATA_DIRECTORY'
| 'PXE_L2_STARTING_BLOCK'
| 'PXE_PROVER_ENABLED'
| 'QUOTE_PROVIDER_BASIS_POINT_FEE'
Expand Down Expand Up @@ -152,6 +152,7 @@ export type EnvVar =
| 'PROVER_VIEM_POLLING_INTERVAL_MS'
| 'SEQ_VIEM_POLLING_INTERVAL_MS'
| 'WS_DB_MAP_SIZE_KB'
| 'WS_DATA_DIRECTORY'
| 'ETHEREUM_SLOT_DURATION'
| 'AZTEC_SLOT_DURATION'
| 'AZTEC_EPOCH_DURATION'
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/kv-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"exports": {
".": "./dest/interfaces/index.js",
"./lmdb": "./dest/lmdb/index.js",
"./utils": "./dest/utils.js"
"./utils": "./dest/utils.js",
"./config": "./dest/config.js"
},
"scripts": {
"build": "yarn clean && tsc -b",
Expand Down Expand Up @@ -55,6 +56,7 @@
]
},
"dependencies": {
"@aztec/ethereum": "workspace:^",
"@aztec/foundation": "workspace:^",
"lmdb": "^3.0.6"
},
Expand Down
34 changes: 34 additions & 0 deletions yarn-project/kv-store/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { l1ContractAddressesMapping } from '@aztec/ethereum';
import { type ConfigMappingsType, getConfigFromMappings, numberConfigHelper } from '@aztec/foundation/config';
import { type EthAddress } from '@aztec/foundation/eth-address';

export type DataStoreConfig = {
dataDirectory: string | undefined;
dataStoreMapSizeKB: number;
l1Contracts: { rollupAddress: EthAddress };
};

export const dataConfigMappings: ConfigMappingsType<DataStoreConfig> = {
dataDirectory: {
env: 'DATA_DIRECTORY',
description: 'Optional dir to store data. If omitted will store in memory.',
},
dataStoreMapSizeKB: {
env: 'DATA_STORE_MAP_SIZE_KB',
description: 'DB mapping size to be applied to all key/value stores',
...numberConfigHelper(128 * 1_024 * 1_024), // Defaulted to 128 GB
},
l1Contracts: {
description: 'The deployed L1 contract addresses',
defaultValue: l1ContractAddressesMapping,
},
};

/**
* Returns the archiver configuration from the environment variables.
* Note: If an environment variable is not set, the default value is used.
* @returns The archiver configuration.
*/
export function getDataConfigFromEnv(): DataStoreConfig {
return getConfigFromMappings<DataStoreConfig>(dataConfigMappings);
}
8 changes: 5 additions & 3 deletions yarn-project/kv-store/src/lmdb/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { join } from 'path';

import { AztecLmdbStore } from './store.js';

const defaultMapSize = 1024 * 1024 * 1024 * 10;

describe('AztecLmdbStore', () => {
const itForks = async (store: AztecLmdbStore) => {
const singleton = store.openSingleton('singleton');
Expand All @@ -21,17 +23,17 @@ describe('AztecLmdbStore', () => {

it('forks a persistent store', async () => {
const path = await mkdtemp(join(tmpdir(), 'aztec-store-test-'));
const store = AztecLmdbStore.open(path, false);
const store = AztecLmdbStore.open(path, defaultMapSize, false);
await itForks(store);
});

it('forks a persistent store with no path', async () => {
const store = AztecLmdbStore.open(undefined, false);
const store = AztecLmdbStore.open(undefined, defaultMapSize, false);
await itForks(store);
});

it('forks an ephemeral store', async () => {
const store = AztecLmdbStore.open(undefined, true);
const store = AztecLmdbStore.open(undefined, defaultMapSize, true);
await itForks(store);
});
});
6 changes: 4 additions & 2 deletions yarn-project/kv-store/src/lmdb/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ export class AztecLmdbStore implements AztecKVStore {
*/
static open(
path?: string,
mapSizeKb = 1 * 1024 * 1024, // defaults to 1 GB map size
ephemeral: boolean = false,
log = createDebugLogger('aztec:kv-store:lmdb'),
): AztecLmdbStore {
log.debug(`Opening LMDB database at ${path || 'temporary location'}`);
if (path) {
mkdirSync(path, { recursive: true });
}
const rootDb = open({ path, noSync: ephemeral });
const mapSize = 1024 * mapSizeKb;
log.debug(`Opening LMDB database at ${path || 'temporary location'} with map size ${mapSize}`);
const rootDb = open({ path, noSync: ephemeral, mapSize });
return new AztecLmdbStore(rootDb, ephemeral, path);
}

Expand Down
16 changes: 10 additions & 6 deletions yarn-project/kv-store/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { type Logger, createDebugLogger } from '@aztec/foundation/log';

import { join } from 'path';

import { type DataStoreConfig } from './config.js';
import { type AztecKVStore } from './interfaces/store.js';
import { AztecLmdbStore } from './lmdb/store.js';

export type DataStoreConfig = { dataDirectory: string | undefined; l1Contracts: { rollupAddress: EthAddress } };

export function createStore(name: string, config: DataStoreConfig, log: Logger = createDebugLogger('aztec:kv-store')) {
let { dataDirectory } = config;
if (typeof dataDirectory !== 'undefined') {
Expand All @@ -16,10 +15,14 @@ export function createStore(name: string, config: DataStoreConfig, log: Logger =

log.info(
dataDirectory
? `Creating ${name} data store at directory ${dataDirectory}`
: `Creating ${name} ephemeral data store`,
? `Creating ${name} data store at directory ${dataDirectory} with map size ${config.dataStoreMapSizeKB} KB`
: `Creating ${name} ephemeral data store with map size ${config.dataStoreMapSizeKB} KB`,
);
return initStoreForRollup(
AztecLmdbStore.open(dataDirectory, config.dataStoreMapSizeKB, false),
config.l1Contracts.rollupAddress,
log,
);
return initStoreForRollup(AztecLmdbStore.open(dataDirectory, false), config.l1Contracts.rollupAddress, log);
}

/**
Expand Down Expand Up @@ -60,5 +63,6 @@ async function initStoreForRollup<T extends AztecKVStore>(
* @returns A new store
*/
export function openTmpStore(ephemeral: boolean = false): AztecKVStore {
return AztecLmdbStore.open(undefined, ephemeral);
const mapSize = 1024 * 1024 * 10; // 10 GB map size
return AztecLmdbStore.open(undefined, mapSize, ephemeral);
}
3 changes: 3 additions & 0 deletions yarn-project/kv-store/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"references": [
{
"path": "../foundation"
},
{
"path": "../ethereum"
}
],
"include": ["src"]
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/p2p/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ClientProtocolCircuitVerifier, L2BlockSource, WorldStateSynchronizer } from '@aztec/circuit-types';
import { createDebugLogger } from '@aztec/foundation/log';
import { type AztecKVStore } from '@aztec/kv-store';
import { type DataStoreConfig, createStore } from '@aztec/kv-store/utils';
import { type DataStoreConfig } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/utils';
import { type TelemetryClient } from '@aztec/telemetry-client';
import { NoopTelemetryClient } from '@aztec/telemetry-client/noop';

Expand Down
Loading
Loading