@aztec/cli 2.0.3-rc.16 → 2.0.3-rc.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/config/cached_fetch.d.ts +18 -0
- package/dest/config/cached_fetch.d.ts.map +1 -0
- package/dest/config/cached_fetch.js +54 -0
- package/dest/config/chain_l2_config.d.ts.map +1 -1
- package/dest/config/chain_l2_config.js +14 -48
- package/dest/config/enrich_env.d.ts +4 -0
- package/dest/config/enrich_env.d.ts.map +1 -0
- package/dest/config/enrich_env.js +12 -0
- package/dest/config/index.d.ts +2 -0
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +2 -0
- package/dest/config/network_config.d.ts +19 -0
- package/dest/config/network_config.d.ts.map +1 -0
- package/dest/config/network_config.js +79 -0
- package/package.json +23 -23
- package/src/config/cached_fetch.ts +67 -0
- package/src/config/chain_l2_config.ts +12 -50
- package/src/config/enrich_env.ts +15 -0
- package/src/config/index.ts +2 -0
- package/src/config/network_config.ts +102 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface CachedFetchOptions {
|
|
2
|
+
/** Cache duration in milliseconds */
|
|
3
|
+
cacheDurationMs: number;
|
|
4
|
+
/** The cache file */
|
|
5
|
+
cacheFile?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Fetches data from a URL with file-based caching support.
|
|
9
|
+
* This utility can be used by both remote config and bootnodes fetching.
|
|
10
|
+
*
|
|
11
|
+
* @param url - The URL to fetch from
|
|
12
|
+
* @param networkName - Network name for cache directory structure
|
|
13
|
+
* @param options - Caching and error handling options
|
|
14
|
+
* @param cacheDir - Optional cache directory (defaults to no caching)
|
|
15
|
+
* @returns The fetched and parsed JSON data, or undefined if fetch fails and throwOnError is false
|
|
16
|
+
*/
|
|
17
|
+
export declare function cachedFetch<T = any>(url: string, options: CachedFetchOptions, fetch?: typeof globalThis.fetch, log?: import("@aztec/aztec.js").Logger): Promise<T | undefined>;
|
|
18
|
+
//# sourceMappingURL=cached_fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cached_fetch.d.ts","sourceRoot":"","sources":["../../src/config/cached_fetch.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAAC,CAAC,GAAG,GAAG,EACvC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,kBAAkB,EAC3B,KAAK,0BAAmB,EACxB,GAAG,mCAA+B,GACjC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAuCxB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js';
|
|
2
|
+
import { mkdir, readFile, stat, writeFile } from 'fs/promises';
|
|
3
|
+
import { dirname } from 'path';
|
|
4
|
+
/**
|
|
5
|
+
* Fetches data from a URL with file-based caching support.
|
|
6
|
+
* This utility can be used by both remote config and bootnodes fetching.
|
|
7
|
+
*
|
|
8
|
+
* @param url - The URL to fetch from
|
|
9
|
+
* @param networkName - Network name for cache directory structure
|
|
10
|
+
* @param options - Caching and error handling options
|
|
11
|
+
* @param cacheDir - Optional cache directory (defaults to no caching)
|
|
12
|
+
* @returns The fetched and parsed JSON data, or undefined if fetch fails and throwOnError is false
|
|
13
|
+
*/ export async function cachedFetch(url, options, fetch = globalThis.fetch, log = createLogger('cached_fetch')) {
|
|
14
|
+
const { cacheDurationMs, cacheFile } = options;
|
|
15
|
+
// Try to read from cache first
|
|
16
|
+
try {
|
|
17
|
+
if (cacheFile) {
|
|
18
|
+
const info = await stat(cacheFile);
|
|
19
|
+
if (info.mtimeMs + cacheDurationMs > Date.now()) {
|
|
20
|
+
const cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
|
|
21
|
+
return cachedData;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} catch {
|
|
25
|
+
log.trace('Failed to read data from cache');
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(url);
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
try {
|
|
35
|
+
if (cacheFile) {
|
|
36
|
+
await mkdir(dirname(cacheFile), {
|
|
37
|
+
recursive: true
|
|
38
|
+
});
|
|
39
|
+
await writeFile(cacheFile, JSON.stringify(data), 'utf-8');
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
log.warn('Failed to cache data on disk: ' + cacheFile, {
|
|
43
|
+
cacheFile,
|
|
44
|
+
err
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return data;
|
|
48
|
+
} catch (err) {
|
|
49
|
+
log.warn(`Failed to fetch from ${url}`, {
|
|
50
|
+
err
|
|
51
|
+
});
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain_l2_config.d.ts","sourceRoot":"","sources":["../../src/config/chain_l2_config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"chain_l2_config.d.ts","sourceRoot":"","sources":["../../src/config/chain_l2_config.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAQrE,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAC3C,IAAI,CAAC,SAAS,EAAE,2BAA2B,CAAC,GAC5C,IAAI,CAAC,aAAa,EAAE,sBAAsB,GAAG,uBAAuB,CAAC,GAAG;IACtE,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;IAGpC,eAAe,EAAE,OAAO,CAAC;CAC1B,CAAC;AAqCJ,eAAO,MAAM,4BAA4B,EAAE,aA4E1C,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,aAgDxC,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,aAmDlC,CAAC;AAIF,wBAAsB,YAAY,CAAC,WAAW,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,MAAM,gBAQ9E;AAED,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,YAAY,EACzB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAkBpC;AAMD,wBAAsB,gCAAgC,CAAC,WAAW,EAAE,YAAY,iBAyF/E"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
|
|
2
2
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import
|
|
4
|
-
import path, { dirname, join } from 'path';
|
|
3
|
+
import path, { join } from 'path';
|
|
5
4
|
import publicIncludeMetrics from '../../public_include_metric_prefixes.json' with {
|
|
6
5
|
type: 'json'
|
|
7
6
|
};
|
|
7
|
+
import { cachedFetch } from './cached_fetch.js';
|
|
8
|
+
import { enrichEthAddressVar, enrichVar } from './enrich_env.js';
|
|
8
9
|
const DefaultSlashConfig = {
|
|
9
10
|
/** Tally-style slashing */ slasherFlavor: 'tally',
|
|
10
11
|
/** Allow one round for vetoing */ slashingExecutionDelayInRounds: 1,
|
|
@@ -25,11 +26,12 @@ const DefaultSlashConfig = {
|
|
|
25
26
|
slashProposeInvalidAttestationsPenalty: DefaultL1ContractsConfig.slashAmountLarge,
|
|
26
27
|
slashAttestDescendantOfInvalidPenalty: DefaultL1ContractsConfig.slashAmountLarge,
|
|
27
28
|
slashUnknownPenalty: DefaultL1ContractsConfig.slashAmountSmall,
|
|
28
|
-
slashBroadcastedInvalidBlockPenalty:
|
|
29
|
+
slashBroadcastedInvalidBlockPenalty: 0n,
|
|
29
30
|
slashMaxPayloadSize: 50,
|
|
30
31
|
slashGracePeriodL2Slots: 32 * 2,
|
|
31
32
|
slashOffenseExpirationRounds: 8,
|
|
32
|
-
sentinelEnabled: true
|
|
33
|
+
sentinelEnabled: true,
|
|
34
|
+
slashExecuteRoundsLookBack: 4
|
|
33
35
|
};
|
|
34
36
|
export const stagingIgnitionL2ChainConfig = {
|
|
35
37
|
l1ChainId: 11155111,
|
|
@@ -87,11 +89,12 @@ export const stagingIgnitionL2ChainConfig = {
|
|
|
87
89
|
slashProposeInvalidAttestationsPenalty: 50_000n * 10n ** 18n,
|
|
88
90
|
slashAttestDescendantOfInvalidPenalty: 50_000n * 10n ** 18n,
|
|
89
91
|
slashUnknownPenalty: 2_000n * 10n ** 18n,
|
|
90
|
-
slashBroadcastedInvalidBlockPenalty:
|
|
92
|
+
slashBroadcastedInvalidBlockPenalty: 0n,
|
|
91
93
|
slashMaxPayloadSize: 50,
|
|
92
94
|
slashGracePeriodL2Slots: 32 * 4,
|
|
93
95
|
slashOffenseExpirationRounds: 8,
|
|
94
|
-
sentinelEnabled: true
|
|
96
|
+
sentinelEnabled: true,
|
|
97
|
+
slashExecuteRoundsLookBack: 4
|
|
95
98
|
};
|
|
96
99
|
export const stagingPublicL2ChainConfig = {
|
|
97
100
|
l1ChainId: 11155111,
|
|
@@ -172,34 +175,12 @@ export const testnetL2ChainConfig = {
|
|
|
172
175
|
};
|
|
173
176
|
const BOOTNODE_CACHE_DURATION_MS = 60 * 60 * 1000; // 1 hour;
|
|
174
177
|
export async function getBootnodes(networkName, cacheDir) {
|
|
175
|
-
const cacheFile = cacheDir ? join(cacheDir, networkName, 'bootnodes.json') : undefined;
|
|
176
|
-
try {
|
|
177
|
-
if (cacheFile) {
|
|
178
|
-
const info = await stat(cacheFile);
|
|
179
|
-
if (info.mtimeMs + BOOTNODE_CACHE_DURATION_MS > Date.now()) {
|
|
180
|
-
return JSON.parse(await readFile(cacheFile, 'utf-8'))['bootnodes'];
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
} catch {
|
|
184
|
-
// no-op. Get the remote-file
|
|
185
|
-
}
|
|
186
178
|
const url = `http://static.aztec.network/${networkName}/bootnodes.json`;
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
if (cacheFile) {
|
|
194
|
-
await mkdir(dirname(cacheFile), {
|
|
195
|
-
recursive: true
|
|
196
|
-
});
|
|
197
|
-
await writeFile(cacheFile, JSON.stringify(json), 'utf-8');
|
|
198
|
-
}
|
|
199
|
-
} catch {
|
|
200
|
-
// no-op
|
|
201
|
-
}
|
|
202
|
-
return json['bootnodes'];
|
|
179
|
+
const data = await cachedFetch(url, {
|
|
180
|
+
cacheDurationMs: BOOTNODE_CACHE_DURATION_MS,
|
|
181
|
+
cacheFile: cacheDir ? join(cacheDir, networkName, 'bootnodes.json') : undefined
|
|
182
|
+
});
|
|
183
|
+
return data?.bootnodes;
|
|
203
184
|
}
|
|
204
185
|
export async function getL2ChainConfig(networkName, cacheDir) {
|
|
205
186
|
let config;
|
|
@@ -226,21 +207,6 @@ export async function getL2ChainConfig(networkName, cacheDir) {
|
|
|
226
207
|
}
|
|
227
208
|
return config;
|
|
228
209
|
}
|
|
229
|
-
function enrichVar(envVar, value) {
|
|
230
|
-
// Don't override
|
|
231
|
-
if (process.env[envVar] || value === undefined) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
process.env[envVar] = value;
|
|
235
|
-
}
|
|
236
|
-
function enrichEthAddressVar(envVar, value) {
|
|
237
|
-
// EthAddress doesn't like being given empty strings
|
|
238
|
-
if (value === '') {
|
|
239
|
-
enrichVar(envVar, EthAddress.ZERO.toString());
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
enrichVar(envVar, value);
|
|
243
|
-
}
|
|
244
210
|
function getDefaultDataDir(networkName) {
|
|
245
211
|
return path.join(process.env.HOME || '~', '.aztec', networkName, 'data');
|
|
246
212
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrich_env.d.ts","sourceRoot":"","sources":["../../src/config/enrich_env.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,QAMlE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAGhE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js';
|
|
2
|
+
export function enrichVar(envVar, value) {
|
|
3
|
+
// Don't override
|
|
4
|
+
if (process.env[envVar] || value === undefined) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
process.env[envVar] = value;
|
|
8
|
+
}
|
|
9
|
+
export function enrichEthAddressVar(envVar, value) {
|
|
10
|
+
// EthAddress doesn't like being given empty strings
|
|
11
|
+
enrichVar(envVar, value || EthAddress.ZERO.toString());
|
|
12
|
+
}
|
package/dest/config/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
package/dest/config/index.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type NetworkConfig, type NetworkNames } from '@aztec/foundation/config';
|
|
2
|
+
/**
|
|
3
|
+
* Fetches remote network configuration from GitHub with caching support.
|
|
4
|
+
* Uses the reusable cachedFetch utility.
|
|
5
|
+
*
|
|
6
|
+
* @param networkName - The network name to fetch config for
|
|
7
|
+
* @param cacheDir - Optional cache directory for storing fetched config
|
|
8
|
+
* @returns Remote configuration for the specified network, or undefined if not found/error
|
|
9
|
+
*/
|
|
10
|
+
export declare function getNetworkConfig(networkName: NetworkNames, cacheDir?: string): Promise<NetworkConfig | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Enriches environment variables with remote network configuration.
|
|
13
|
+
* This function is called before node config initialization to set env vars
|
|
14
|
+
* from the remote config, following the same pattern as enrichEnvironmentWithChainConfig().
|
|
15
|
+
*
|
|
16
|
+
* @param networkName - The network name to fetch remote config for
|
|
17
|
+
*/
|
|
18
|
+
export declare function enrichEnvironmentWithNetworkConfig(networkName: NetworkNames): Promise<void>;
|
|
19
|
+
//# sourceMappingURL=network_config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network_config.d.ts","sourceRoot":"","sources":["../../src/config/network_config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAA0B,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAYzG;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CACpC,WAAW,EAAE,YAAY,EACzB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAiDpC;AAED;;;;;;GAMG;AACH,wBAAsB,kCAAkC,CAAC,WAAW,EAAE,YAAY,iBAoBjF"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { NetworkConfigMapSchema } from '@aztec/foundation/config';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { cachedFetch } from './cached_fetch.js';
|
|
5
|
+
import { enrichEthAddressVar, enrichVar } from './enrich_env.js';
|
|
6
|
+
const DEFAULT_CONFIG_URL = 'https://raw.githubusercontent.com/AztecProtocol/networks/refs/heads/main/network_config.json';
|
|
7
|
+
const NETWORK_CONFIG_CACHE_DURATION_MS = 60 * 60 * 1000; // 1 hour
|
|
8
|
+
/**
|
|
9
|
+
* Fetches remote network configuration from GitHub with caching support.
|
|
10
|
+
* Uses the reusable cachedFetch utility.
|
|
11
|
+
*
|
|
12
|
+
* @param networkName - The network name to fetch config for
|
|
13
|
+
* @param cacheDir - Optional cache directory for storing fetched config
|
|
14
|
+
* @returns Remote configuration for the specified network, or undefined if not found/error
|
|
15
|
+
*/ export async function getNetworkConfig(networkName, cacheDir) {
|
|
16
|
+
let url;
|
|
17
|
+
const configLocation = process.env.NETWORK_CONFIG_LOCATION || DEFAULT_CONFIG_URL;
|
|
18
|
+
if (!configLocation) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
if (configLocation.includes('://')) {
|
|
23
|
+
url = new URL(configLocation);
|
|
24
|
+
} else {
|
|
25
|
+
url = new URL(`file://${configLocation}`);
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
/* no-op */ }
|
|
29
|
+
if (!url) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
let rawConfig;
|
|
34
|
+
if (url.protocol === 'http:' || url.protocol === 'https:') {
|
|
35
|
+
rawConfig = await cachedFetch(url.href, {
|
|
36
|
+
cacheDurationMs: NETWORK_CONFIG_CACHE_DURATION_MS,
|
|
37
|
+
cacheFile: cacheDir ? join(cacheDir, networkName, 'network_config.json') : undefined
|
|
38
|
+
});
|
|
39
|
+
} else if (url.protocol === 'file:') {
|
|
40
|
+
rawConfig = JSON.parse(await readFile(url.pathname, 'utf-8'));
|
|
41
|
+
} else {
|
|
42
|
+
throw new Error('Unsupported Aztec network config protocol: ' + url.href);
|
|
43
|
+
}
|
|
44
|
+
if (!rawConfig) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const networkConfigMap = NetworkConfigMapSchema.parse(rawConfig);
|
|
48
|
+
if (networkName in networkConfigMap) {
|
|
49
|
+
return networkConfigMap[networkName];
|
|
50
|
+
} else {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Enriches environment variables with remote network configuration.
|
|
59
|
+
* This function is called before node config initialization to set env vars
|
|
60
|
+
* from the remote config, following the same pattern as enrichEnvironmentWithChainConfig().
|
|
61
|
+
*
|
|
62
|
+
* @param networkName - The network name to fetch remote config for
|
|
63
|
+
*/ export async function enrichEnvironmentWithNetworkConfig(networkName) {
|
|
64
|
+
if (networkName === 'local') {
|
|
65
|
+
return; // No remote config for local development
|
|
66
|
+
}
|
|
67
|
+
const cacheDir = process.env.DATA_DIRECTORY ? join(process.env.DATA_DIRECTORY, 'cache') : undefined;
|
|
68
|
+
const networkConfig = await getNetworkConfig(networkName, cacheDir);
|
|
69
|
+
if (!networkConfig) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
enrichVar('BOOTSTRAP_NODES', networkConfig.bootnodes.join(','));
|
|
73
|
+
enrichVar('L1_CHAIN_ID', String(networkConfig.l1ChainId));
|
|
74
|
+
enrichVar('SYNC_SNAPSHOTS_URL', networkConfig.snapshots.join(','));
|
|
75
|
+
enrichEthAddressVar('REGISTRY_CONTRACT_ADDRESS', networkConfig.registryAddress.toString());
|
|
76
|
+
if (networkConfig.feeAssetHandlerAddress) {
|
|
77
|
+
enrichEthAddressVar('FEE_ASSET_HANDLER_CONTRACT_ADDRESS', networkConfig.feeAssetHandlerAddress.toString());
|
|
78
|
+
}
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/cli",
|
|
3
|
-
"version": "2.0.3-rc.
|
|
3
|
+
"version": "2.0.3-rc.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./contracts": "./dest/cmds/contracts/index.js",
|
|
@@ -70,17 +70,17 @@
|
|
|
70
70
|
]
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@aztec/archiver": "2.0.3-rc.
|
|
74
|
-
"@aztec/aztec.js": "2.0.3-rc.
|
|
75
|
-
"@aztec/constants": "2.0.3-rc.
|
|
76
|
-
"@aztec/entrypoints": "2.0.3-rc.
|
|
77
|
-
"@aztec/ethereum": "2.0.3-rc.
|
|
78
|
-
"@aztec/foundation": "2.0.3-rc.
|
|
79
|
-
"@aztec/l1-artifacts": "2.0.3-rc.
|
|
80
|
-
"@aztec/node-lib": "2.0.3-rc.
|
|
81
|
-
"@aztec/p2p": "2.0.3-rc.
|
|
82
|
-
"@aztec/stdlib": "2.0.3-rc.
|
|
83
|
-
"@aztec/world-state": "2.0.3-rc.
|
|
73
|
+
"@aztec/archiver": "2.0.3-rc.18",
|
|
74
|
+
"@aztec/aztec.js": "2.0.3-rc.18",
|
|
75
|
+
"@aztec/constants": "2.0.3-rc.18",
|
|
76
|
+
"@aztec/entrypoints": "2.0.3-rc.18",
|
|
77
|
+
"@aztec/ethereum": "2.0.3-rc.18",
|
|
78
|
+
"@aztec/foundation": "2.0.3-rc.18",
|
|
79
|
+
"@aztec/l1-artifacts": "2.0.3-rc.18",
|
|
80
|
+
"@aztec/node-lib": "2.0.3-rc.18",
|
|
81
|
+
"@aztec/p2p": "2.0.3-rc.18",
|
|
82
|
+
"@aztec/stdlib": "2.0.3-rc.18",
|
|
83
|
+
"@aztec/world-state": "2.0.3-rc.18",
|
|
84
84
|
"@iarna/toml": "^2.2.5",
|
|
85
85
|
"@libp2p/peer-id-factory": "^3.0.4",
|
|
86
86
|
"commander": "^12.1.0",
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"viem": "2.23.7"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
|
-
"@aztec/accounts": "2.0.3-rc.
|
|
96
|
-
"@aztec/protocol-contracts": "2.0.3-rc.
|
|
95
|
+
"@aztec/accounts": "2.0.3-rc.18",
|
|
96
|
+
"@aztec/protocol-contracts": "2.0.3-rc.18",
|
|
97
97
|
"@jest/globals": "^30.0.0",
|
|
98
98
|
"@types/jest": "^30.0.0",
|
|
99
99
|
"@types/lodash.chunk": "^4.2.9",
|
|
@@ -109,15 +109,15 @@
|
|
|
109
109
|
"typescript": "^5.3.3"
|
|
110
110
|
},
|
|
111
111
|
"peerDependencies": {
|
|
112
|
-
"@aztec/accounts": "2.0.3-rc.
|
|
113
|
-
"@aztec/bb-prover": "2.0.3-rc.
|
|
114
|
-
"@aztec/ethereum": "2.0.3-rc.
|
|
115
|
-
"@aztec/l1-artifacts": "2.0.3-rc.
|
|
116
|
-
"@aztec/noir-contracts.js": "2.0.3-rc.
|
|
117
|
-
"@aztec/noir-protocol-circuits-types": "2.0.3-rc.
|
|
118
|
-
"@aztec/noir-test-contracts.js": "2.0.3-rc.
|
|
119
|
-
"@aztec/protocol-contracts": "2.0.3-rc.
|
|
120
|
-
"@aztec/stdlib": "2.0.3-rc.
|
|
112
|
+
"@aztec/accounts": "2.0.3-rc.18",
|
|
113
|
+
"@aztec/bb-prover": "2.0.3-rc.18",
|
|
114
|
+
"@aztec/ethereum": "2.0.3-rc.18",
|
|
115
|
+
"@aztec/l1-artifacts": "2.0.3-rc.18",
|
|
116
|
+
"@aztec/noir-contracts.js": "2.0.3-rc.18",
|
|
117
|
+
"@aztec/noir-protocol-circuits-types": "2.0.3-rc.18",
|
|
118
|
+
"@aztec/noir-test-contracts.js": "2.0.3-rc.18",
|
|
119
|
+
"@aztec/protocol-contracts": "2.0.3-rc.18",
|
|
120
|
+
"@aztec/stdlib": "2.0.3-rc.18"
|
|
121
121
|
},
|
|
122
122
|
"files": [
|
|
123
123
|
"dest",
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js';
|
|
2
|
+
|
|
3
|
+
import { mkdir, readFile, stat, writeFile } from 'fs/promises';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
|
|
6
|
+
export interface CachedFetchOptions {
|
|
7
|
+
/** Cache duration in milliseconds */
|
|
8
|
+
cacheDurationMs: number;
|
|
9
|
+
/** The cache file */
|
|
10
|
+
cacheFile?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetches data from a URL with file-based caching support.
|
|
15
|
+
* This utility can be used by both remote config and bootnodes fetching.
|
|
16
|
+
*
|
|
17
|
+
* @param url - The URL to fetch from
|
|
18
|
+
* @param networkName - Network name for cache directory structure
|
|
19
|
+
* @param options - Caching and error handling options
|
|
20
|
+
* @param cacheDir - Optional cache directory (defaults to no caching)
|
|
21
|
+
* @returns The fetched and parsed JSON data, or undefined if fetch fails and throwOnError is false
|
|
22
|
+
*/
|
|
23
|
+
export async function cachedFetch<T = any>(
|
|
24
|
+
url: string,
|
|
25
|
+
options: CachedFetchOptions,
|
|
26
|
+
fetch = globalThis.fetch,
|
|
27
|
+
log = createLogger('cached_fetch'),
|
|
28
|
+
): Promise<T | undefined> {
|
|
29
|
+
const { cacheDurationMs, cacheFile } = options;
|
|
30
|
+
|
|
31
|
+
// Try to read from cache first
|
|
32
|
+
try {
|
|
33
|
+
if (cacheFile) {
|
|
34
|
+
const info = await stat(cacheFile);
|
|
35
|
+
if (info.mtimeMs + cacheDurationMs > Date.now()) {
|
|
36
|
+
const cachedData = JSON.parse(await readFile(cacheFile, 'utf-8'));
|
|
37
|
+
return cachedData;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch {
|
|
41
|
+
log.trace('Failed to read data from cache');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const response = await fetch(url);
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
log.warn(`Failed to fetch from ${url}: ${response.status} ${response.statusText}`);
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
if (cacheFile) {
|
|
55
|
+
await mkdir(dirname(cacheFile), { recursive: true });
|
|
56
|
+
await writeFile(cacheFile, JSON.stringify(data), 'utf-8');
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
log.warn('Failed to cache data on disk: ' + cacheFile, { cacheFile, err });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return data;
|
|
63
|
+
} catch (err) {
|
|
64
|
+
log.warn(`Failed to fetch from ${url}`, { err });
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -5,10 +5,11 @@ import type { SharedNodeConfig } from '@aztec/node-lib/config';
|
|
|
5
5
|
import type { P2PConfig } from '@aztec/p2p/config';
|
|
6
6
|
import type { SlasherConfig } from '@aztec/stdlib/interfaces/server';
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import path, { dirname, join } from 'path';
|
|
8
|
+
import path, { join } from 'path';
|
|
10
9
|
|
|
11
10
|
import publicIncludeMetrics from '../../public_include_metric_prefixes.json' with { type: 'json' };
|
|
11
|
+
import { cachedFetch } from './cached_fetch.js';
|
|
12
|
+
import { enrichEthAddressVar, enrichVar } from './enrich_env.js';
|
|
12
13
|
|
|
13
14
|
export type L2ChainConfig = L1ContractsConfig &
|
|
14
15
|
Pick<P2PConfig, 'txPoolDeleteTxsAfterReorg'> &
|
|
@@ -63,11 +64,12 @@ const DefaultSlashConfig = {
|
|
|
63
64
|
slashProposeInvalidAttestationsPenalty: DefaultL1ContractsConfig.slashAmountLarge,
|
|
64
65
|
slashAttestDescendantOfInvalidPenalty: DefaultL1ContractsConfig.slashAmountLarge,
|
|
65
66
|
slashUnknownPenalty: DefaultL1ContractsConfig.slashAmountSmall,
|
|
66
|
-
slashBroadcastedInvalidBlockPenalty: DefaultL1ContractsConfig.
|
|
67
|
+
slashBroadcastedInvalidBlockPenalty: 0n, // DefaultL1ContractsConfig.slashAmountSmall // Disabled until further testing
|
|
67
68
|
slashMaxPayloadSize: 50,
|
|
68
69
|
slashGracePeriodL2Slots: 32 * 2, // Two epochs from genesis
|
|
69
70
|
slashOffenseExpirationRounds: 8,
|
|
70
71
|
sentinelEnabled: true,
|
|
72
|
+
slashExecuteRoundsLookBack: 4,
|
|
71
73
|
} satisfies Partial<L2ChainConfig>;
|
|
72
74
|
|
|
73
75
|
export const stagingIgnitionL2ChainConfig: L2ChainConfig = {
|
|
@@ -140,11 +142,12 @@ export const stagingIgnitionL2ChainConfig: L2ChainConfig = {
|
|
|
140
142
|
slashProposeInvalidAttestationsPenalty: 50_000n * 10n ** 18n,
|
|
141
143
|
slashAttestDescendantOfInvalidPenalty: 50_000n * 10n ** 18n,
|
|
142
144
|
slashUnknownPenalty: 2_000n * 10n ** 18n,
|
|
143
|
-
slashBroadcastedInvalidBlockPenalty: 10_000n * 10n ** 18n,
|
|
145
|
+
slashBroadcastedInvalidBlockPenalty: 0n, // 10_000n * 10n ** 18n, Disabled for now until further testing
|
|
144
146
|
slashMaxPayloadSize: 50,
|
|
145
147
|
slashGracePeriodL2Slots: 32 * 4, // One round from genesis
|
|
146
148
|
slashOffenseExpirationRounds: 8,
|
|
147
149
|
sentinelEnabled: true,
|
|
150
|
+
slashExecuteRoundsLookBack: 4,
|
|
148
151
|
};
|
|
149
152
|
|
|
150
153
|
export const stagingPublicL2ChainConfig: L2ChainConfig = {
|
|
@@ -253,37 +256,13 @@ export const testnetL2ChainConfig: L2ChainConfig = {
|
|
|
253
256
|
const BOOTNODE_CACHE_DURATION_MS = 60 * 60 * 1000; // 1 hour;
|
|
254
257
|
|
|
255
258
|
export async function getBootnodes(networkName: NetworkNames, cacheDir?: string) {
|
|
256
|
-
const cacheFile = cacheDir ? join(cacheDir, networkName, 'bootnodes.json') : undefined;
|
|
257
|
-
try {
|
|
258
|
-
if (cacheFile) {
|
|
259
|
-
const info = await stat(cacheFile);
|
|
260
|
-
if (info.mtimeMs + BOOTNODE_CACHE_DURATION_MS > Date.now()) {
|
|
261
|
-
return JSON.parse(await readFile(cacheFile, 'utf-8'))['bootnodes'];
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
} catch {
|
|
265
|
-
// no-op. Get the remote-file
|
|
266
|
-
}
|
|
267
|
-
|
|
268
259
|
const url = `http://static.aztec.network/${networkName}/bootnodes.json`;
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
const json = await response.json();
|
|
276
|
-
|
|
277
|
-
try {
|
|
278
|
-
if (cacheFile) {
|
|
279
|
-
await mkdir(dirname(cacheFile), { recursive: true });
|
|
280
|
-
await writeFile(cacheFile, JSON.stringify(json), 'utf-8');
|
|
281
|
-
}
|
|
282
|
-
} catch {
|
|
283
|
-
// no-op
|
|
284
|
-
}
|
|
260
|
+
const data = await cachedFetch(url, {
|
|
261
|
+
cacheDurationMs: BOOTNODE_CACHE_DURATION_MS,
|
|
262
|
+
cacheFile: cacheDir ? join(cacheDir, networkName, 'bootnodes.json') : undefined,
|
|
263
|
+
});
|
|
285
264
|
|
|
286
|
-
return
|
|
265
|
+
return data?.bootnodes;
|
|
287
266
|
}
|
|
288
267
|
|
|
289
268
|
export async function getL2ChainConfig(
|
|
@@ -309,23 +288,6 @@ export async function getL2ChainConfig(
|
|
|
309
288
|
return config;
|
|
310
289
|
}
|
|
311
290
|
|
|
312
|
-
function enrichVar(envVar: EnvVar, value: string | undefined) {
|
|
313
|
-
// Don't override
|
|
314
|
-
if (process.env[envVar] || value === undefined) {
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
process.env[envVar] = value;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function enrichEthAddressVar(envVar: EnvVar, value: string) {
|
|
321
|
-
// EthAddress doesn't like being given empty strings
|
|
322
|
-
if (value === '') {
|
|
323
|
-
enrichVar(envVar, EthAddress.ZERO.toString());
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
enrichVar(envVar, value);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
291
|
function getDefaultDataDir(networkName: NetworkNames): string {
|
|
330
292
|
return path.join(process.env.HOME || '~', '.aztec', networkName, 'data');
|
|
331
293
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EthAddress } from '@aztec/aztec.js';
|
|
2
|
+
import type { EnvVar } from '@aztec/foundation/config';
|
|
3
|
+
|
|
4
|
+
export function enrichVar(envVar: EnvVar, value: string | undefined) {
|
|
5
|
+
// Don't override
|
|
6
|
+
if (process.env[envVar] || value === undefined) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
process.env[envVar] = value;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function enrichEthAddressVar(envVar: EnvVar, value: string) {
|
|
13
|
+
// EthAddress doesn't like being given empty strings
|
|
14
|
+
enrichVar(envVar, value || EthAddress.ZERO.toString());
|
|
15
|
+
}
|
package/src/config/index.ts
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type NetworkConfig, NetworkConfigMapSchema, type NetworkNames } from '@aztec/foundation/config';
|
|
2
|
+
|
|
3
|
+
import { readFile } from 'fs/promises';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
import { cachedFetch } from './cached_fetch.js';
|
|
7
|
+
import { enrichEthAddressVar, enrichVar } from './enrich_env.js';
|
|
8
|
+
|
|
9
|
+
const DEFAULT_CONFIG_URL =
|
|
10
|
+
'https://raw.githubusercontent.com/AztecProtocol/networks/refs/heads/main/network_config.json';
|
|
11
|
+
const NETWORK_CONFIG_CACHE_DURATION_MS = 60 * 60 * 1000; // 1 hour
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Fetches remote network configuration from GitHub with caching support.
|
|
15
|
+
* Uses the reusable cachedFetch utility.
|
|
16
|
+
*
|
|
17
|
+
* @param networkName - The network name to fetch config for
|
|
18
|
+
* @param cacheDir - Optional cache directory for storing fetched config
|
|
19
|
+
* @returns Remote configuration for the specified network, or undefined if not found/error
|
|
20
|
+
*/
|
|
21
|
+
export async function getNetworkConfig(
|
|
22
|
+
networkName: NetworkNames,
|
|
23
|
+
cacheDir?: string,
|
|
24
|
+
): Promise<NetworkConfig | undefined> {
|
|
25
|
+
let url: URL | undefined;
|
|
26
|
+
const configLocation = process.env.NETWORK_CONFIG_LOCATION || DEFAULT_CONFIG_URL;
|
|
27
|
+
|
|
28
|
+
if (!configLocation) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
if (configLocation.includes('://')) {
|
|
34
|
+
url = new URL(configLocation);
|
|
35
|
+
} else {
|
|
36
|
+
url = new URL(`file://${configLocation}`);
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
/* no-op */
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!url) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
let rawConfig: any;
|
|
48
|
+
|
|
49
|
+
if (url.protocol === 'http:' || url.protocol === 'https:') {
|
|
50
|
+
rawConfig = await cachedFetch(url.href, {
|
|
51
|
+
cacheDurationMs: NETWORK_CONFIG_CACHE_DURATION_MS,
|
|
52
|
+
cacheFile: cacheDir ? join(cacheDir, networkName, 'network_config.json') : undefined,
|
|
53
|
+
});
|
|
54
|
+
} else if (url.protocol === 'file:') {
|
|
55
|
+
rawConfig = JSON.parse(await readFile(url.pathname, 'utf-8'));
|
|
56
|
+
} else {
|
|
57
|
+
throw new Error('Unsupported Aztec network config protocol: ' + url.href);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!rawConfig) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const networkConfigMap = NetworkConfigMapSchema.parse(rawConfig);
|
|
65
|
+
if (networkName in networkConfigMap) {
|
|
66
|
+
return networkConfigMap[networkName];
|
|
67
|
+
} else {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Enriches environment variables with remote network configuration.
|
|
77
|
+
* This function is called before node config initialization to set env vars
|
|
78
|
+
* from the remote config, following the same pattern as enrichEnvironmentWithChainConfig().
|
|
79
|
+
*
|
|
80
|
+
* @param networkName - The network name to fetch remote config for
|
|
81
|
+
*/
|
|
82
|
+
export async function enrichEnvironmentWithNetworkConfig(networkName: NetworkNames) {
|
|
83
|
+
if (networkName === 'local') {
|
|
84
|
+
return; // No remote config for local development
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const cacheDir = process.env.DATA_DIRECTORY ? join(process.env.DATA_DIRECTORY, 'cache') : undefined;
|
|
88
|
+
const networkConfig = await getNetworkConfig(networkName, cacheDir);
|
|
89
|
+
|
|
90
|
+
if (!networkConfig) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
enrichVar('BOOTSTRAP_NODES', networkConfig.bootnodes.join(','));
|
|
95
|
+
enrichVar('L1_CHAIN_ID', String(networkConfig.l1ChainId));
|
|
96
|
+
enrichVar('SYNC_SNAPSHOTS_URL', networkConfig.snapshots.join(','));
|
|
97
|
+
|
|
98
|
+
enrichEthAddressVar('REGISTRY_CONTRACT_ADDRESS', networkConfig.registryAddress.toString());
|
|
99
|
+
if (networkConfig.feeAssetHandlerAddress) {
|
|
100
|
+
enrichEthAddressVar('FEE_ASSET_HANDLER_CONTRACT_ADDRESS', networkConfig.feeAssetHandlerAddress.toString());
|
|
101
|
+
}
|
|
102
|
+
}
|