@aztec/aztec 0.0.1-commit.96dac018d → 0.0.1-commit.9a89641

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.
Files changed (135) hide show
  1. package/dest/bin/index.js +4 -2
  2. package/dest/cli/aztec_start_action.d.ts +1 -1
  3. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  4. package/dest/cli/aztec_start_action.js +26 -25
  5. package/dest/cli/aztec_start_options.d.ts +2 -2
  6. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_options.js +16 -17
  8. package/dest/cli/cli.js +3 -3
  9. package/dest/cli/cmds/compile.d.ts +1 -1
  10. package/dest/cli/cmds/compile.d.ts.map +1 -1
  11. package/dest/cli/cmds/compile.js +35 -21
  12. package/dest/cli/cmds/profile.d.ts +1 -1
  13. package/dest/cli/cmds/profile.d.ts.map +1 -1
  14. package/dest/cli/cmds/profile.js +1 -1
  15. package/dest/cli/cmds/profile_flamegraph.d.ts +1 -1
  16. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -1
  17. package/dest/cli/cmds/profile_flamegraph.js +2 -1
  18. package/dest/cli/cmds/profile_gates.d.ts +2 -2
  19. package/dest/cli/cmds/profile_gates.d.ts.map +1 -1
  20. package/dest/cli/cmds/profile_gates.js +23 -4
  21. package/dest/cli/cmds/prover.d.ts +4 -0
  22. package/dest/cli/cmds/prover.d.ts.map +1 -0
  23. package/dest/cli/cmds/prover.js +24 -0
  24. package/dest/cli/cmds/standby.d.ts +56 -0
  25. package/dest/cli/cmds/standby.d.ts.map +1 -0
  26. package/dest/cli/cmds/standby.js +140 -0
  27. package/dest/cli/cmds/start_bot.d.ts +1 -1
  28. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  29. package/dest/cli/cmds/start_bot.js +8 -4
  30. package/dest/cli/cmds/start_node.d.ts +3 -2
  31. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  32. package/dest/cli/cmds/start_node.js +37 -58
  33. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  34. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  35. package/dest/cli/cmds/start_prover_agent.js +5 -17
  36. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  37. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  38. package/dest/cli/cmds/start_prover_broker.js +22 -13
  39. package/dest/cli/cmds/start_txe.d.ts +2 -2
  40. package/dest/cli/cmds/start_txe.d.ts.map +1 -1
  41. package/dest/cli/cmds/start_txe.js +6 -5
  42. package/dest/cli/cmds/utils/artifacts.d.ts +6 -1
  43. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -1
  44. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts +21 -0
  45. package/dest/cli/cmds/utils/collect_crate_dirs.d.ts.map +1 -0
  46. package/dest/cli/cmds/utils/collect_crate_dirs.js +114 -0
  47. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  48. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  49. package/dest/cli/cmds/utils/needs_recompile.js +90 -0
  50. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts +4 -0
  51. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.d.ts.map +1 -0
  52. package/dest/cli/cmds/utils/warn_if_aztec_version_mismatch.js +61 -0
  53. package/dest/cli/util.d.ts +9 -6
  54. package/dest/cli/util.d.ts.map +1 -1
  55. package/dest/cli/util.js +29 -97
  56. package/dest/examples/token.js +7 -7
  57. package/dest/local-network/auth_registry.d.ts +5 -0
  58. package/dest/local-network/auth_registry.d.ts.map +1 -0
  59. package/dest/local-network/auth_registry.js +17 -0
  60. package/dest/local-network/banana_fpc.d.ts +3 -2
  61. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  62. package/dest/local-network/banana_fpc.js +12 -8
  63. package/dest/local-network/local-network.d.ts +10 -32
  64. package/dest/local-network/local-network.d.ts.map +1 -1
  65. package/dest/local-network/local-network.js +68 -76
  66. package/dest/testing/cheat_codes.d.ts +17 -23
  67. package/dest/testing/cheat_codes.d.ts.map +1 -1
  68. package/dest/testing/cheat_codes.js +17 -43
  69. package/dest/testing/epoch_test_settler.d.ts +2 -2
  70. package/dest/testing/epoch_test_settler.d.ts.map +1 -1
  71. package/dest/testing/epoch_test_settler.js +6 -26
  72. package/dest/testing/index.d.ts +3 -2
  73. package/dest/testing/index.d.ts.map +1 -1
  74. package/dest/testing/index.js +2 -1
  75. package/dest/testing/local-network.d.ts +51 -0
  76. package/dest/testing/local-network.d.ts.map +1 -0
  77. package/dest/testing/local-network.js +60 -0
  78. package/dest/testing/token_allowed_setup.d.ts +12 -0
  79. package/dest/testing/token_allowed_setup.d.ts.map +1 -0
  80. package/dest/testing/token_allowed_setup.js +24 -0
  81. package/package.json +35 -34
  82. package/scripts/add_crate.sh +53 -0
  83. package/scripts/aztec.sh +10 -3
  84. package/scripts/init.sh +18 -24
  85. package/scripts/new.sh +45 -22
  86. package/scripts/setup_workspace.sh +12 -67
  87. package/scripts/templates/blank/contract/Nargo.toml +6 -0
  88. package/scripts/templates/blank/contract/src/main.nr +10 -0
  89. package/scripts/templates/blank/test/Nargo.toml +7 -0
  90. package/scripts/templates/blank/test/src/lib.nr +11 -0
  91. package/scripts/templates/counter/contract/Nargo.toml +7 -0
  92. package/scripts/templates/counter/contract/src/main.nr +48 -0
  93. package/scripts/templates/counter/test/Nargo.toml +7 -0
  94. package/scripts/templates/counter/test/src/lib.nr +32 -0
  95. package/src/bin/index.ts +4 -2
  96. package/src/cli/aztec_start_action.ts +22 -21
  97. package/src/cli/aztec_start_options.ts +23 -25
  98. package/src/cli/cli.ts +3 -3
  99. package/src/cli/cmds/compile.ts +41 -20
  100. package/src/cli/cmds/profile.ts +2 -1
  101. package/src/cli/cmds/profile_flamegraph.ts +2 -1
  102. package/src/cli/cmds/profile_gates.ts +22 -5
  103. package/src/cli/cmds/prover.ts +42 -0
  104. package/src/cli/cmds/standby.ts +184 -0
  105. package/src/cli/cmds/start_bot.ts +9 -6
  106. package/src/cli/cmds/start_node.ts +51 -53
  107. package/src/cli/cmds/start_prover_agent.ts +5 -8
  108. package/src/cli/cmds/start_prover_broker.ts +23 -24
  109. package/src/cli/cmds/start_txe.ts +7 -5
  110. package/src/cli/cmds/utils/artifacts.ts +5 -0
  111. package/src/cli/cmds/utils/collect_crate_dirs.ts +118 -0
  112. package/src/cli/cmds/utils/needs_recompile.ts +98 -0
  113. package/src/cli/cmds/utils/warn_if_aztec_version_mismatch.ts +76 -0
  114. package/src/cli/util.ts +28 -102
  115. package/src/examples/token.ts +17 -7
  116. package/src/local-network/auth_registry.ts +19 -0
  117. package/src/local-network/banana_fpc.ts +13 -9
  118. package/src/local-network/local-network.ts +73 -85
  119. package/src/testing/cheat_codes.ts +18 -49
  120. package/src/testing/epoch_test_settler.ts +8 -32
  121. package/src/testing/index.ts +2 -1
  122. package/src/testing/local-network.ts +97 -0
  123. package/src/testing/token_allowed_setup.ts +26 -0
  124. package/dest/cli/cmds/start_archiver.d.ts +0 -9
  125. package/dest/cli/cmds/start_archiver.d.ts.map +0 -1
  126. package/dest/cli/cmds/start_archiver.js +0 -48
  127. package/dest/cli/release_version.d.ts +0 -2
  128. package/dest/cli/release_version.d.ts.map +0 -1
  129. package/dest/cli/release_version.js +0 -14
  130. package/dest/testing/anvil_test_watcher.d.ts +0 -42
  131. package/dest/testing/anvil_test_watcher.d.ts.map +0 -1
  132. package/dest/testing/anvil_test_watcher.js +0 -181
  133. package/src/cli/cmds/start_archiver.ts +0 -50
  134. package/src/cli/release_version.ts +0 -21
  135. package/src/testing/anvil_test_watcher.ts +0 -210
@@ -0,0 +1,184 @@
1
+ import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
+ import type { Fr } from '@aztec/aztec.js/fields';
3
+ import { getSponsoredFPCAddress } from '@aztec/cli/cli-utils';
4
+ import { getPublicClient } from '@aztec/ethereum/client';
5
+ import type { GenesisStateConfig } from '@aztec/ethereum/config';
6
+ import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts';
7
+ import type { EthAddress } from '@aztec/foundation/eth-address';
8
+ import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
9
+ import { type LogFn, createLogger } from '@aztec/foundation/log';
10
+ import { retryUntil } from '@aztec/foundation/retry';
11
+ import { AztecAddress } from '@aztec/stdlib/aztec-address';
12
+ import type { VersionCheck } from '@aztec/stdlib/update-checker';
13
+ import { getGenesisValues } from '@aztec/world-state/testing';
14
+
15
+ import Koa from 'koa';
16
+
17
+ import { isShuttingDown, softShutdown } from '../util.js';
18
+
19
+ const ROLLUP_POLL_INTERVAL_S = 60;
20
+
21
+ /**
22
+ * Computes the expected genesis archive root from the genesis state config.
23
+ * Reads test accounts and sponsored FPC addresses as specified, then computes
24
+ * the genesis values including the archive root and prefilled public data.
25
+ */
26
+ export async function computeExpectedGenesisRoot(config: GenesisStateConfig, userLog: LogFn) {
27
+ const testAccounts = config.testAccounts ? (await getInitialTestAccountsData()).map(a => a.address) : [];
28
+ const sponsoredFPCAccounts = config.sponsoredFPC ? [await getSponsoredFPCAddress()] : [];
29
+ const prefundAddresses = (config.prefundAddresses ?? []).map(a => AztecAddress.fromStringUnsafe(a));
30
+ const initialFundedAccounts = testAccounts.concat(sponsoredFPCAccounts).concat(prefundAddresses);
31
+
32
+ userLog(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
33
+
34
+ const { genesisArchiveRoot, genesis } = await getGenesisValues(initialFundedAccounts);
35
+
36
+ userLog(`Genesis archive root: ${genesisArchiveRoot.toString()}`);
37
+
38
+ return { genesisArchiveRoot, genesis };
39
+ }
40
+
41
+ /**
42
+ * Compares the rollup's on-chain protocol constants (genesis archive root, VK tree root, protocol
43
+ * contracts hash) against the node's expected local values. Returns a list of human-readable mismatch
44
+ * descriptions, empty if the rollup is compatible.
45
+ */
46
+ export async function checkRollupCompatibility(
47
+ rollup: RollupContract,
48
+ expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
49
+ ): Promise<string[]> {
50
+ const mismatches: string[] = [];
51
+ const [l1Genesis, l1Vk, l1Protocol] = await Promise.all([
52
+ rollup.getGenesisArchiveTreeRoot(),
53
+ rollup.getVkTreeRoot(),
54
+ rollup.getProtocolContractsHash(),
55
+ ]);
56
+ if (!l1Genesis.equals(expected.genesisArchiveRoot)) {
57
+ mismatches.push(`genesis archive root (expected ${expected.genesisArchiveRoot}, got ${l1Genesis})`);
58
+ }
59
+ if (!l1Vk.equals(expected.vkTreeRoot)) {
60
+ mismatches.push(`VK tree root (expected ${expected.vkTreeRoot}, got ${l1Vk})`);
61
+ }
62
+ if (!l1Protocol.equals(expected.protocolContractsHash)) {
63
+ mismatches.push(`protocol contracts hash (expected ${expected.protocolContractsHash}, got ${l1Protocol})`);
64
+ }
65
+ return mismatches;
66
+ }
67
+
68
+ /**
69
+ * Waits until the canonical rollup's genesis archive root, VK tree root, and protocol contracts hash
70
+ * all match the expected local values. If the rollup is not yet compatible (e.g. during L1 contract upgrades),
71
+ * enters standby mode: starts a lightweight HTTP server for K8s liveness probes and polls every 60s
72
+ * until a compatible rollup appears.
73
+ */
74
+ export async function waitForCompatibleRollup(
75
+ config: {
76
+ l1RpcUrls: string[];
77
+ l1ChainId: number;
78
+ registryAddress: EthAddress;
79
+ rollupVersion?: number;
80
+ },
81
+ expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
82
+ port: number | undefined,
83
+ userLog: LogFn,
84
+ ): Promise<void> {
85
+ const publicClient = getPublicClient(config);
86
+ const rollupVersion: number | 'canonical' = config.rollupVersion ?? 'canonical';
87
+
88
+ const registry = new RegistryContract(publicClient, config.registryAddress);
89
+ const rollupAddress = await registry.getRollupAddress(rollupVersion);
90
+ const rollup = new RollupContract(publicClient, rollupAddress.toString());
91
+
92
+ let mismatches: string[];
93
+ try {
94
+ mismatches = await checkRollupCompatibility(rollup, expected);
95
+ } catch (err: any) {
96
+ throw new Error(`Could not retrieve rollup config from canonical rollup at ${rollupAddress}: ${err.message}`);
97
+ }
98
+
99
+ if (mismatches.length === 0) {
100
+ return;
101
+ }
102
+
103
+ userLog(
104
+ `Rollup at ${rollupAddress} is incompatible: ${mismatches.join('; ')}. ` +
105
+ `Entering standby mode. Will poll every ${ROLLUP_POLL_INTERVAL_S}s for a compatible rollup...`,
106
+ );
107
+
108
+ const standbyServer = await startHttpRpcServer({ getApp: () => new Koa(), isHealthy: () => true }, { port });
109
+ userLog(`Standby status server listening on port ${standbyServer.port}`);
110
+
111
+ try {
112
+ await retryUntil(
113
+ async () => {
114
+ const currentRollupAddress = await registry.getRollupAddress(rollupVersion);
115
+ const currentRollup = new RollupContract(publicClient, currentRollupAddress.toString());
116
+
117
+ let currentMismatches: string[];
118
+ try {
119
+ currentMismatches = await checkRollupCompatibility(currentRollup, expected);
120
+ } catch {
121
+ userLog(`Failed to fetch rollup config from rollup at ${currentRollupAddress}. Retrying...`);
122
+ return undefined;
123
+ }
124
+
125
+ if (currentMismatches.length === 0) {
126
+ userLog(`Compatible rollup found at ${currentRollupAddress}. Exiting standby mode.`);
127
+ return true;
128
+ }
129
+
130
+ userLog(`Still waiting. Rollup at ${currentRollupAddress}: ${currentMismatches.join('; ')}.`);
131
+ return undefined;
132
+ },
133
+ 'compatible rollup',
134
+ 0,
135
+ ROLLUP_POLL_INTERVAL_S,
136
+ );
137
+ } finally {
138
+ await new Promise<void>((resolve, reject) => standbyServer.close(err => (err ? reject(err) : resolve())));
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Polls the canonical rollup's protocol constants every 10 minutes and soft-shuts-down the node once they
144
+ * diverge from the node's expected local values (i.e. an incompatible rollup has become canonical on L1).
145
+ * The HTTP health server is left running so K8s probes keep passing on the wound-down pod. This is the
146
+ * inverse of {@link waitForCompatibleRollup}; it should only be set up for nodes following the canonical
147
+ * rollup. Reuses the {@link checkRollupCompatibility} diff and the generic VersionChecker poll primitive.
148
+ */
149
+ export async function setupAutoShutdown(
150
+ config: { l1RpcUrls: string[]; l1ChainId: number },
151
+ registryAddress: EthAddress,
152
+ rollupVersion: number | 'canonical',
153
+ expected: { genesisArchiveRoot: Fr; vkTreeRoot: Fr; protocolContractsHash: Fr },
154
+ signalHandlers: Array<() => Promise<void>>,
155
+ ): Promise<void> {
156
+ const { VersionChecker } = await import('@aztec/stdlib/update-checker');
157
+
158
+ const logger = createLogger('auto_shutdown');
159
+ const publicClient = getPublicClient(config);
160
+ const registry = new RegistryContract(publicClient, registryAddress);
161
+
162
+ const check: VersionCheck = {
163
+ name: 'rollup',
164
+ currentVersion: 'compatible',
165
+ getLatestVersion: async () => {
166
+ const rollupAddress = await registry.getRollupAddress(rollupVersion);
167
+ const rollup = new RollupContract(publicClient, rollupAddress.toString());
168
+ const mismatches = await checkRollupCompatibility(rollup, expected);
169
+ return mismatches.length === 0 ? 'compatible' : `incompatible: ${mismatches.join('; ')}`;
170
+ },
171
+ };
172
+
173
+ const checker = new VersionChecker([check], 600_000, logger);
174
+ checker.on('newVersion', ({ latestVersion }) => {
175
+ if (isShuttingDown()) {
176
+ return;
177
+ }
178
+ logger.warn('Canonical rollup is no longer compatible; auto-shutting down node', { latestVersion });
179
+ // softShutdown never rejects (it awaits handlers via allSettled); fire-and-forget from the listener.
180
+ void softShutdown(logger.info.bind(logger), signalHandlers);
181
+ });
182
+ checker.start();
183
+ signalHandlers.push(() => checker.stop());
184
+ }
@@ -21,11 +21,9 @@ export async function startBot(
21
21
  services: NamespacedApiHandlers,
22
22
  userLog: LogFn,
23
23
  ) {
24
- const { proverNode, archiver, sequencer, p2pBootstrap, txe, prover } = options;
25
- if (proverNode || archiver || sequencer || p2pBootstrap || txe || prover) {
26
- userLog(
27
- `Starting a bot with --prover-node, --prover, --archiver, --sequencer, --p2p-bootstrap, or --txe is not supported.`,
28
- );
24
+ const { proverNode, sequencer, p2pBootstrap, txe, prover } = options;
25
+ if (proverNode || sequencer || p2pBootstrap || txe || prover) {
26
+ userLog(`Starting a bot with --prover-node, --prover, --sequencer, --p2p-bootstrap, or --txe is not supported.`);
29
27
  process.exit(1);
30
28
  }
31
29
 
@@ -58,6 +56,11 @@ export async function addBot(
58
56
  const config = extractRelevantOptions<BotConfig>(options, botConfigMappings, 'bot');
59
57
  userLog?.(`Starting bot with config ${stringifyConfig(config)}`);
60
58
 
59
+ // The bot wallet's embedded PXE syncs to this tip (see start_bot.ts/start_node.ts which build the wallet from the
60
+ // same options). L1-to-L2 readiness checks must be evaluated at this tip rather than at 'latest', or the bot can
61
+ // consider a message ready while the PXE simulation anchors to an older block that cannot prove its membership yet.
62
+ const { syncChainTip } = extractRelevantOptions<PXEConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');
63
+
61
64
  const db = await (config.dataDirectory
62
65
  ? createStore('bot', BotStore.SCHEMA_VERSION, config)
63
66
  : openTmpStore('bot', true, config.dataStoreMapSizeKb));
@@ -65,7 +68,7 @@ export async function addBot(
65
68
  const store = new BotStore(db);
66
69
  await store.cleanupOldClaims();
67
70
 
68
- const botRunner = new BotRunner(config, wallet, aztecNode, telemetry, aztecNodeAdmin, store);
71
+ const botRunner = new BotRunner(config, wallet, aztecNode, telemetry, aztecNodeAdmin, store, syncChainTip);
69
72
  if (!config.noStart) {
70
73
  void botRunner.start(); // Do not block since bot setup takes time
71
74
  }
@@ -1,17 +1,25 @@
1
- import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
- import { type AztecNodeConfig, aztecNodeConfigMappings, getConfigEnvVars } from '@aztec/aztec-node';
1
+ import {
2
+ type AztecNodeConfig,
3
+ aztecNodeConfigMappings,
4
+ getConfigEnvVars,
5
+ registerAztecNodeRpcHandlers,
6
+ } from '@aztec/aztec-node';
3
7
  import { Fr } from '@aztec/aztec.js/fields';
4
- import { getSponsoredFPCAddress } from '@aztec/cli/cli-utils';
5
8
  import { getL1Config } from '@aztec/cli/config';
6
- import { getPublicClient } from '@aztec/ethereum/client';
7
- import { SecretValue } from '@aztec/foundation/config';
9
+ import { getGenesisStateConfigEnvVars } from '@aztec/ethereum/config';
10
+ import { type NetworkNames, SecretValue } from '@aztec/foundation/config';
8
11
  import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
9
12
  import { Agent, makeUndiciFetch } from '@aztec/foundation/json-rpc/undici';
10
13
  import type { LogFn } from '@aztec/foundation/log';
11
- import { ProvingJobConsumerSchema, createProvingJobBrokerClient } from '@aztec/prover-client/broker';
14
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
15
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
16
+ import {
17
+ ProvingJobConsumerSchema,
18
+ createProvingJobBrokerClient,
19
+ proverBrokerBackoff,
20
+ } from '@aztec/prover-client/broker';
12
21
  import { type CliPXEOptions, type PXEConfig, allPxeConfigMappings } from '@aztec/pxe/config';
13
- import { AztecNodeAdminApiSchema, AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
14
- import { P2PApiSchema, ProverNodeApiSchema, type ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
22
+ import { ProverNodeApiSchema, type ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
15
23
  import {
16
24
  type TelemetryClientConfig,
17
25
  initTelemetryClient,
@@ -19,16 +27,11 @@ import {
19
27
  telemetryClientConfigMappings,
20
28
  } from '@aztec/telemetry-client';
21
29
  import { EmbeddedWallet } from '@aztec/wallets/embedded';
22
- import { getGenesisValues } from '@aztec/world-state/testing';
23
30
 
24
31
  import { createAztecNode } from '../../local-network/index.js';
25
- import {
26
- extractNamespacedOptions,
27
- extractRelevantOptions,
28
- preloadCrsDataForVerifying,
29
- setupUpdateMonitor,
30
- } from '../util.js';
32
+ import { extractNamespacedOptions, extractRelevantOptions, preloadCrsDataForVerifying } from '../util.js';
31
33
  import { getVersions } from '../versioning.js';
34
+ import { computeExpectedGenesisRoot, setupAutoShutdown, waitForCompatibleRollup } from './standby.js';
32
35
  import { startProverBroker } from './start_prover_broker.js';
33
36
 
34
37
  export async function startNode(
@@ -37,6 +40,7 @@ export async function startNode(
37
40
  services: NamespacedApiHandlers,
38
41
  adminServices: NamespacedApiHandlers,
39
42
  userLog: LogFn,
43
+ networkName: NetworkNames,
40
44
  ): Promise<{ config: AztecNodeConfig }> {
41
45
  // All options set from environment variables
42
46
  const configFromEnvVars = getConfigEnvVars();
@@ -63,12 +67,8 @@ export async function startNode(
63
67
  if (nodeConfig.proverBrokerUrl) {
64
68
  // at 1TPS we'd enqueue ~1k chonk verifier proofs and ~1k AVM proofs immediately
65
69
  // set a lower connection limit such that we don't overload the server
66
- // Keep retrying up to 30s
67
- const fetch = makeTracedFetch(
68
- [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
69
- false,
70
- makeUndiciFetch(new Agent({ connections: 100 })),
71
- );
70
+ // Retry indefinitely until the epoch proving times out and the chain reorgs
71
+ const fetch = makeTracedFetch(proverBrokerBackoff, false, makeUndiciFetch(new Agent({ connections: 100 })));
72
72
  broker = createProvingJobBrokerClient(nodeConfig.proverBrokerUrl, getVersions(nodeConfig), fetch);
73
73
  } else if (options.proverBroker) {
74
74
  ({ broker } = await startProverBroker(options, signalHandlers, services, userLog));
@@ -80,24 +80,27 @@ export async function startNode(
80
80
 
81
81
  await preloadCrsDataForVerifying(nodeConfig, userLog);
82
82
 
83
- const testAccounts = nodeConfig.testAccounts ? (await getInitialTestAccountsData()).map(a => a.address) : [];
84
- const sponsoredFPCAccounts = nodeConfig.sponsoredFPC ? [await getSponsoredFPCAddress()] : [];
85
- const initialFundedAccounts = testAccounts.concat(sponsoredFPCAccounts);
86
-
87
- userLog(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
88
-
89
- const { genesisArchiveRoot, prefilledPublicData } = await getGenesisValues(initialFundedAccounts);
90
-
91
- userLog(`Genesis archive root: ${genesisArchiveRoot.toString()}`);
83
+ const genesisConfig = getGenesisStateConfigEnvVars();
84
+ const { genesisArchiveRoot, genesis } = await computeExpectedGenesisRoot(genesisConfig, userLog);
92
85
 
93
86
  const followsCanonicalRollup =
94
87
  typeof nodeConfig.rollupVersion !== 'number' || (nodeConfig.rollupVersion as unknown as string) === 'canonical';
95
88
 
96
- if (!nodeConfig.l1Contracts.registryAddress || nodeConfig.l1Contracts.registryAddress.isZero()) {
89
+ if (!nodeConfig.registryAddress || nodeConfig.registryAddress.isZero()) {
97
90
  throw new Error('L1 registry address is required to start Aztec Node');
98
91
  }
92
+
93
+ // Wait for a compatible rollup before proceeding with full L1 config fetch.
94
+ // This prevents crashes when the canonical rollup hasn't been upgraded yet.
95
+ await waitForCompatibleRollup(
96
+ nodeConfig,
97
+ { genesisArchiveRoot, vkTreeRoot: getVKTreeRoot(), protocolContractsHash },
98
+ options.port,
99
+ userLog,
100
+ );
101
+
99
102
  const { addresses, config } = await getL1Config(
100
- nodeConfig.l1Contracts.registryAddress,
103
+ nodeConfig.registryAddress,
101
104
  nodeConfig.l1RpcUrls,
102
105
  nodeConfig.l1ChainId,
103
106
  nodeConfig.rollupVersion,
@@ -111,13 +114,9 @@ export async function startNode(
111
114
  );
112
115
  }
113
116
 
114
- // TODO(#12272): will clean this up.
115
117
  nodeConfig = {
116
118
  ...nodeConfig,
117
- l1Contracts: {
118
- ...addresses,
119
- slashFactoryAddress: nodeConfig.l1Contracts.slashFactoryAddress,
120
- },
119
+ ...addresses,
121
120
  ...config,
122
121
  };
123
122
 
@@ -153,17 +152,14 @@ export async function startNode(
153
152
  const telemetry = await initTelemetryClient(telemetryConfig);
154
153
 
155
154
  // Create and start Aztec Node
156
- const node = await createAztecNode(nodeConfig, { telemetry, proverBroker: broker }, { prefilledPublicData });
155
+ const node = await createAztecNode(nodeConfig, { telemetry, proverBroker: broker }, { genesis });
157
156
 
158
- // Add node and p2p to services list
159
- services.node = [node, AztecNodeApiSchema];
160
- services.p2p = [node.getP2P(), P2PApiSchema];
161
- adminServices.nodeAdmin = [node, AztecNodeAdminApiSchema];
157
+ registerAztecNodeRpcHandlers(node, services, adminServices, { debug: options.nodeDebug });
162
158
 
163
159
  // Register prover-node services if the prover node subsystem is running
164
160
  const proverNode = node.getProverNode();
165
161
  if (proverNode) {
166
- services.prover = [proverNode, ProverNodeApiSchema];
162
+ adminServices.prover = [proverNode, ProverNodeApiSchema];
167
163
  if (!nodeConfig.proverBrokerUrl) {
168
164
  services.provingJobSource = [proverNode.getProver().getProvingJobSource(), ProvingJobConsumerSchema];
169
165
  }
@@ -182,16 +178,18 @@ export async function startNode(
182
178
  await addBot(options, signalHandlers, services, wallet, node, telemetry, undefined);
183
179
  }
184
180
 
185
- if (nodeConfig.autoUpdate !== 'disabled' && nodeConfig.autoUpdateUrl) {
186
- await setupUpdateMonitor(
187
- nodeConfig.autoUpdate,
188
- new URL(nodeConfig.autoUpdateUrl),
189
- followsCanonicalRollup,
190
- getPublicClient(nodeConfig!),
191
- nodeConfig.l1Contracts.registryAddress,
192
- signalHandlers,
193
- async config => node.setConfig((await AztecNodeAdminApiSchema.setConfig.parameters().parseAsync([config]))[0]),
194
- );
181
+ if (nodeConfig.enableAutoShutdown && networkName !== 'local' && followsCanonicalRollup) {
182
+ try {
183
+ await setupAutoShutdown(
184
+ nodeConfig,
185
+ nodeConfig.registryAddress,
186
+ (nodeConfig.rollupVersion as number | 'canonical') ?? 'canonical',
187
+ { genesisArchiveRoot, vkTreeRoot: getVKTreeRoot(), protocolContractsHash },
188
+ signalHandlers,
189
+ );
190
+ } catch {
191
+ /* no-op */
192
+ }
195
193
  }
196
194
 
197
195
  return { config: nodeConfig };
@@ -9,6 +9,7 @@ import {
9
9
  createProofStore,
10
10
  createProvingJobBrokerClient,
11
11
  proverAgentConfigMappings,
12
+ proverBrokerBackoff,
12
13
  } from '@aztec/prover-client/broker';
13
14
  import { getProverNodeAgentConfigFromEnv } from '@aztec/prover-node';
14
15
  import { ProverAgentApiSchema } from '@aztec/stdlib/interfaces/server';
@@ -23,8 +24,8 @@ export async function startProverAgent(
23
24
  services: NamespacedApiHandlers,
24
25
  userLog: LogFn,
25
26
  ) {
26
- if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
27
- userLog(`Starting a prover agent with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
27
+ if (options.node || options.sequencer || options.p2pBootstrap || options.txe) {
28
+ userLog(`Starting a prover agent with --node, --sequencer, --p2p-bootstrap, or --txe is not supported.`);
28
29
  process.exit(1);
29
30
  }
30
31
 
@@ -45,12 +46,8 @@ export async function startProverAgent(
45
46
 
46
47
  await preloadCrsDataForServerSideProving(config, userLog);
47
48
 
48
- const fetch = makeTracedFetch(
49
- // retry connections every 3s, up to 30s before giving up
50
- [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
51
- false,
52
- makeUndiciFetch(new Agent({ connections: 10 })),
53
- );
49
+ // Retry indefinitely until the epoch proving times out and the chain reorgs
50
+ const fetch = makeTracedFetch(proverBrokerBackoff, false, makeUndiciFetch(new Agent({ connections: 10 })));
54
51
  const broker = createProvingJobBrokerClient(config.proverBrokerUrl, getVersions(), fetch);
55
52
 
56
53
  const telemetry = await initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
@@ -1,7 +1,9 @@
1
1
  import { getL1Config } from '@aztec/cli/config';
2
- import { getPublicClient } from '@aztec/ethereum/client';
2
+ import { getGenesisStateConfigEnvVars } from '@aztec/ethereum/config';
3
3
  import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
4
4
  import type { LogFn } from '@aztec/foundation/log';
5
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
6
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
5
7
  import {
6
8
  type ProverBrokerConfig,
7
9
  ProvingJobBrokerSchema,
@@ -13,7 +15,8 @@ import { getProverNodeBrokerConfigFromEnv } from '@aztec/prover-node';
13
15
  import type { ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
14
16
  import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
15
17
 
16
- import { extractRelevantOptions, setupUpdateMonitor } from '../util.js';
18
+ import { extractRelevantOptions } from '../util.js';
19
+ import { computeExpectedGenesisRoot, waitForCompatibleRollup } from './standby.js';
17
20
 
18
21
  export async function startProverBroker(
19
22
  options: any,
@@ -21,45 +24,41 @@ export async function startProverBroker(
21
24
  services: NamespacedApiHandlers,
22
25
  userLog: LogFn,
23
26
  ): Promise<{ broker: ProvingJobBroker; config: ProverBrokerConfig }> {
24
- if (options.node || options.sequencer || options.pxe || options.p2pBootstrap || options.txe) {
25
- userLog(`Starting a prover broker with --node, --sequencer, --pxe, --p2p-bootstrap, or --txe is not supported.`);
27
+ if (options.node || options.sequencer || options.p2pBootstrap || options.txe) {
28
+ userLog(`Starting a prover broker with --node, --sequencer, --p2p-bootstrap, or --txe is not supported.`);
26
29
  process.exit(1);
27
30
  }
28
31
 
29
- const config: ProverBrokerConfig = {
32
+ const baseConfig: ProverBrokerConfig = {
30
33
  ...getProverNodeBrokerConfigFromEnv(), // get default config from env
31
34
  ...extractRelevantOptions<ProverBrokerConfig>(options, proverBrokerConfigMappings, 'proverBroker'), // override with command line options
32
35
  };
33
36
 
34
- if (!config.l1Contracts.registryAddress || config.l1Contracts.registryAddress.isZero()) {
37
+ if (!baseConfig.registryAddress || baseConfig.registryAddress.isZero()) {
35
38
  throw new Error('L1 registry address is required to start Aztec Node without --deploy-aztec-contracts option');
36
39
  }
37
40
 
38
- const followsCanonicalRollup = typeof config.rollupVersion !== 'number';
41
+ const genesisConfig = getGenesisStateConfigEnvVars();
42
+ const { genesisArchiveRoot } = await computeExpectedGenesisRoot(genesisConfig, userLog);
43
+ await waitForCompatibleRollup(
44
+ baseConfig,
45
+ { genesisArchiveRoot, vkTreeRoot: getVKTreeRoot(), protocolContractsHash },
46
+ options.port,
47
+ userLog,
48
+ );
49
+
39
50
  const { addresses, config: rollupConfig } = await getL1Config(
40
- config.l1Contracts.registryAddress,
41
- config.l1RpcUrls,
42
- config.l1ChainId,
43
- config.rollupVersion,
51
+ baseConfig.registryAddress,
52
+ baseConfig.l1RpcUrls,
53
+ baseConfig.l1ChainId,
54
+ baseConfig.rollupVersion,
44
55
  );
45
56
 
46
- config.l1Contracts = addresses;
47
- config.rollupVersion = rollupConfig.rollupVersion;
57
+ const config: ProverBrokerConfig = { ...baseConfig, ...addresses, rollupVersion: rollupConfig.rollupVersion };
48
58
 
49
59
  const client = await initTelemetryClient(getTelemetryClientConfig());
50
60
  const broker = await createAndStartProvingBroker(config, client);
51
61
 
52
- if (options.autoUpdate !== 'disabled' && options.autoUpdateUrl) {
53
- await setupUpdateMonitor(
54
- options.autoUpdate,
55
- new URL(options.autoUpdateUrl),
56
- followsCanonicalRollup,
57
- getPublicClient(config),
58
- config.l1Contracts.registryAddress,
59
- signalHandlers,
60
- );
61
- }
62
-
63
62
  services.proverBroker = [
64
63
  broker,
65
64
  config.proverBrokerDebugReplayEnabled ? ProvingJobBrokerSchemaWithDebug : ProvingJobBrokerSchema,
@@ -1,15 +1,17 @@
1
1
  import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
2
2
  import type { Logger } from '@aztec/foundation/log';
3
- import { createTXERpcServer } from '@aztec/txe';
3
+ import { createTXERpcServer } from '@aztec/txe/server';
4
4
 
5
- export async function startTXE(options: any, debugLogger: Logger) {
5
+ export async function startTXE(options: any, signalHandlers: Array<() => Promise<void>>, debugLogger: Logger) {
6
6
  debugLogger.info(`Setting up TXE...`);
7
7
 
8
- const txeServer = createTXERpcServer(debugLogger);
9
- const { port } = await startHttpRpcServer(txeServer, {
8
+ const txeServer = await createTXERpcServer(debugLogger);
9
+ const httpServer = await startHttpRpcServer(txeServer, {
10
10
  port: options.port,
11
11
  timeoutMs: 1e3 * 60 * 5,
12
12
  });
13
13
 
14
- debugLogger.info(`TXE listening on port ${port}`);
14
+ signalHandlers.push(() => new Promise<void>(resolve => httpServer.close(() => resolve())));
15
+
16
+ debugLogger.info(`TXE listening on port ${httpServer.port}`);
15
17
  }
@@ -6,6 +6,11 @@ export interface CompiledArtifact {
6
6
  file_map: unknown;
7
7
  functions: ContractFunction[];
8
8
  bytecode?: string;
9
+ /**
10
+ * Set to true by the AVM transpiler (invoked via `bb aztec_process`) once the contract has been transpiled and its
11
+ * verification keys generated. Absent on raw `nargo compile` output, hence optional.
12
+ */
13
+ transpiled?: boolean;
9
14
  }
10
15
 
11
16
  export interface ContractFunction {