@aztec/aztec 0.0.1-commit.9b94fc1 → 0.0.1-commit.9ee6fcc6

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 (141) hide show
  1. package/dest/bin/index.js +12 -5
  2. package/dest/cli/admin_api_key_store.d.ts +45 -0
  3. package/dest/cli/admin_api_key_store.d.ts.map +1 -0
  4. package/dest/cli/admin_api_key_store.js +98 -0
  5. package/dest/cli/aztec_start_action.d.ts +1 -1
  6. package/dest/cli/aztec_start_action.d.ts.map +1 -1
  7. package/dest/cli/aztec_start_action.js +65 -19
  8. package/dest/cli/aztec_start_options.d.ts +1 -1
  9. package/dest/cli/aztec_start_options.d.ts.map +1 -1
  10. package/dest/cli/aztec_start_options.js +41 -36
  11. package/dest/cli/cli.d.ts +1 -1
  12. package/dest/cli/cli.d.ts.map +1 -1
  13. package/dest/cli/cli.js +4 -37
  14. package/dest/cli/cmds/compile.d.ts +4 -0
  15. package/dest/cli/cmds/compile.d.ts.map +1 -0
  16. package/dest/cli/cmds/compile.js +166 -0
  17. package/dest/cli/cmds/migrate_ha_db.d.ts +3 -0
  18. package/dest/cli/cmds/migrate_ha_db.d.ts.map +1 -0
  19. package/dest/cli/cmds/migrate_ha_db.js +27 -0
  20. package/dest/cli/cmds/profile.d.ts +4 -0
  21. package/dest/cli/cmds/profile.d.ts.map +1 -0
  22. package/dest/cli/cmds/profile.js +8 -0
  23. package/dest/cli/cmds/profile_flamegraph.d.ts +4 -0
  24. package/dest/cli/cmds/profile_flamegraph.d.ts.map +1 -0
  25. package/dest/cli/cmds/profile_flamegraph.js +52 -0
  26. package/dest/cli/cmds/profile_gates.d.ts +4 -0
  27. package/dest/cli/cmds/profile_gates.d.ts.map +1 -0
  28. package/dest/cli/cmds/profile_gates.js +58 -0
  29. package/dest/cli/cmds/profile_utils.d.ts +18 -0
  30. package/dest/cli/cmds/profile_utils.d.ts.map +1 -0
  31. package/dest/cli/cmds/profile_utils.js +50 -0
  32. package/dest/cli/cmds/standby.d.ts +32 -0
  33. package/dest/cli/cmds/standby.d.ts.map +1 -0
  34. package/dest/cli/cmds/standby.js +97 -0
  35. package/dest/cli/cmds/start_archiver.d.ts +2 -2
  36. package/dest/cli/cmds/start_archiver.d.ts.map +1 -1
  37. package/dest/cli/cmds/start_archiver.js +12 -14
  38. package/dest/cli/cmds/start_bot.d.ts +3 -3
  39. package/dest/cli/cmds/start_bot.d.ts.map +1 -1
  40. package/dest/cli/cmds/start_bot.js +10 -6
  41. package/dest/cli/cmds/start_node.d.ts +3 -2
  42. package/dest/cli/cmds/start_node.d.ts.map +1 -1
  43. package/dest/cli/cmds/start_node.js +85 -29
  44. package/dest/cli/cmds/start_p2p_bootstrap.d.ts +2 -2
  45. package/dest/cli/cmds/start_p2p_bootstrap.d.ts.map +1 -1
  46. package/dest/cli/cmds/start_p2p_bootstrap.js +2 -3
  47. package/dest/cli/cmds/start_prover_agent.d.ts +1 -1
  48. package/dest/cli/cmds/start_prover_agent.d.ts.map +1 -1
  49. package/dest/cli/cmds/start_prover_agent.js +4 -4
  50. package/dest/cli/cmds/start_prover_broker.d.ts +1 -1
  51. package/dest/cli/cmds/start_prover_broker.d.ts.map +1 -1
  52. package/dest/cli/cmds/start_prover_broker.js +15 -9
  53. package/dest/cli/cmds/utils/artifacts.d.ts +21 -0
  54. package/dest/cli/cmds/utils/artifacts.d.ts.map +1 -0
  55. package/dest/cli/cmds/utils/artifacts.js +24 -0
  56. package/dest/cli/cmds/utils/needs_recompile.d.ts +10 -0
  57. package/dest/cli/cmds/utils/needs_recompile.d.ts.map +1 -0
  58. package/dest/cli/cmds/utils/needs_recompile.js +134 -0
  59. package/dest/cli/cmds/utils/spawn.d.ts +3 -0
  60. package/dest/cli/cmds/utils/spawn.d.ts.map +1 -0
  61. package/dest/cli/cmds/utils/spawn.js +16 -0
  62. package/dest/cli/util.d.ts +9 -20
  63. package/dest/cli/util.d.ts.map +1 -1
  64. package/dest/cli/util.js +51 -87
  65. package/dest/examples/token.js +9 -9
  66. package/dest/examples/util.d.ts +2 -2
  67. package/dest/examples/util.d.ts.map +1 -1
  68. package/dest/local-network/banana_fpc.d.ts +1 -1
  69. package/dest/local-network/banana_fpc.d.ts.map +1 -1
  70. package/dest/local-network/banana_fpc.js +4 -4
  71. package/dest/local-network/local-network.d.ts +13 -14
  72. package/dest/local-network/local-network.d.ts.map +1 -1
  73. package/dest/local-network/local-network.js +86 -43
  74. package/dest/testing/anvil_test_watcher.d.ts +10 -2
  75. package/dest/testing/anvil_test_watcher.d.ts.map +1 -1
  76. package/dest/testing/anvil_test_watcher.js +54 -17
  77. package/dest/testing/cheat_codes.d.ts +3 -1
  78. package/dest/testing/cheat_codes.d.ts.map +1 -1
  79. package/dest/testing/cheat_codes.js +1 -1
  80. package/dest/testing/epoch_test_settler.d.ts +19 -0
  81. package/dest/testing/epoch_test_settler.d.ts.map +1 -0
  82. package/dest/testing/epoch_test_settler.js +61 -0
  83. package/dest/testing/index.d.ts +3 -1
  84. package/dest/testing/index.d.ts.map +1 -1
  85. package/dest/testing/index.js +2 -0
  86. package/dest/testing/token_allowed_setup.d.ts +7 -0
  87. package/dest/testing/token_allowed_setup.d.ts.map +1 -0
  88. package/dest/testing/token_allowed_setup.js +20 -0
  89. package/package.json +37 -35
  90. package/scripts/add_crate.sh +102 -0
  91. package/scripts/aztec.sh +22 -13
  92. package/scripts/init.sh +23 -19
  93. package/scripts/new.sh +48 -24
  94. package/scripts/setup_workspace.sh +68 -0
  95. package/src/bin/index.ts +13 -5
  96. package/src/cli/admin_api_key_store.ts +128 -0
  97. package/src/cli/aztec_start_action.ts +63 -14
  98. package/src/cli/aztec_start_options.ts +42 -35
  99. package/src/cli/cli.ts +4 -37
  100. package/src/cli/cmds/compile.ts +191 -0
  101. package/src/cli/cmds/migrate_ha_db.ts +43 -0
  102. package/src/cli/cmds/profile.ts +25 -0
  103. package/src/cli/cmds/profile_flamegraph.ts +64 -0
  104. package/src/cli/cmds/profile_gates.ts +68 -0
  105. package/src/cli/cmds/profile_utils.ts +58 -0
  106. package/src/cli/cmds/standby.ts +132 -0
  107. package/src/cli/cmds/start_archiver.ts +8 -19
  108. package/src/cli/cmds/start_bot.ts +9 -6
  109. package/src/cli/cmds/start_node.ts +85 -35
  110. package/src/cli/cmds/start_p2p_bootstrap.ts +3 -3
  111. package/src/cli/cmds/start_prover_agent.ts +4 -12
  112. package/src/cli/cmds/start_prover_broker.ts +20 -16
  113. package/src/cli/cmds/utils/artifacts.ts +44 -0
  114. package/src/cli/cmds/utils/needs_recompile.ts +151 -0
  115. package/src/cli/cmds/utils/spawn.ts +16 -0
  116. package/src/cli/util.ts +60 -98
  117. package/src/examples/token.ts +10 -10
  118. package/src/examples/util.ts +1 -1
  119. package/src/local-network/banana_fpc.ts +12 -8
  120. package/src/local-network/local-network.ts +120 -85
  121. package/src/testing/anvil_test_watcher.ts +62 -18
  122. package/src/testing/cheat_codes.ts +4 -3
  123. package/src/testing/epoch_test_settler.ts +70 -0
  124. package/src/testing/index.ts +2 -0
  125. package/src/testing/token_allowed_setup.ts +19 -0
  126. package/dest/cli/cmds/start_blob_sink.d.ts +0 -3
  127. package/dest/cli/cmds/start_blob_sink.d.ts.map +0 -1
  128. package/dest/cli/cmds/start_blob_sink.js +0 -33
  129. package/dest/cli/cmds/start_prover_node.d.ts +0 -7
  130. package/dest/cli/cmds/start_prover_node.d.ts.map +0 -1
  131. package/dest/cli/cmds/start_prover_node.js +0 -108
  132. package/dest/cli/release_version.d.ts +0 -2
  133. package/dest/cli/release_version.d.ts.map +0 -1
  134. package/dest/cli/release_version.js +0 -14
  135. package/scripts/compile.sh +0 -44
  136. package/scripts/extract_function.js +0 -47
  137. package/scripts/flamegraph.sh +0 -59
  138. package/scripts/setup_project.sh +0 -31
  139. package/src/cli/cmds/start_blob_sink.ts +0 -57
  140. package/src/cli/cmds/start_prover_node.ts +0 -124
  141. package/src/cli/release_version.ts +0 -21
@@ -1,30 +1,36 @@
1
- import { getInitialTestAccountsData } from '@aztec/accounts/testing';
2
1
  import { type AztecNodeConfig, aztecNodeConfigMappings, getConfigEnvVars } from '@aztec/aztec-node';
3
2
  import { Fr } from '@aztec/aztec.js/fields';
4
- import { getSponsoredFPCAddress } from '@aztec/cli/cli-utils';
5
3
  import { getL1Config } from '@aztec/cli/config';
6
- import { getPublicClient } from '@aztec/ethereum';
7
- import { SecretValue } from '@aztec/foundation/config';
4
+ import { getPublicClient } from '@aztec/ethereum/client';
5
+ import { getGenesisStateConfigEnvVars } from '@aztec/ethereum/config';
6
+ import { type NetworkNames, SecretValue } from '@aztec/foundation/config';
8
7
  import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
8
+ import { Agent, makeUndiciFetch } from '@aztec/foundation/json-rpc/undici';
9
9
  import type { LogFn } from '@aztec/foundation/log';
10
+ import { getVKTreeRoot } from '@aztec/noir-protocol-circuits-types/vk-tree';
11
+ import { protocolContractsHash } from '@aztec/protocol-contracts';
12
+ import { ProvingJobConsumerSchema, createProvingJobBrokerClient } from '@aztec/prover-client/broker';
10
13
  import { type CliPXEOptions, type PXEConfig, allPxeConfigMappings } from '@aztec/pxe/config';
11
14
  import { AztecNodeAdminApiSchema, AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client';
12
- import { P2PApiSchema } from '@aztec/stdlib/interfaces/server';
15
+ import { P2PApiSchema, ProverNodeApiSchema, type ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
13
16
  import {
14
17
  type TelemetryClientConfig,
15
18
  initTelemetryClient,
19
+ makeTracedFetch,
16
20
  telemetryClientConfigMappings,
17
21
  } from '@aztec/telemetry-client';
18
- import { TestWallet } from '@aztec/test-wallet/server';
19
- import { getGenesisValues } from '@aztec/world-state/testing';
22
+ import { EmbeddedWallet } from '@aztec/wallets/embedded';
20
23
 
21
24
  import { createAztecNode } from '../../local-network/index.js';
22
25
  import {
23
26
  extractNamespacedOptions,
24
27
  extractRelevantOptions,
25
28
  preloadCrsDataForVerifying,
26
- setupUpdateMonitor,
29
+ setupVersionChecker,
27
30
  } from '../util.js';
31
+ import { getVersions } from '../versioning.js';
32
+ import { computeExpectedGenesisRoot, waitForCompatibleRollup } from './standby.js';
33
+ import { startProverBroker } from './start_prover_broker.js';
28
34
 
29
35
  export async function startNode(
30
36
  options: any,
@@ -32,6 +38,7 @@ export async function startNode(
32
38
  services: NamespacedApiHandlers,
33
39
  adminServices: NamespacedApiHandlers,
34
40
  userLog: LogFn,
41
+ networkName: NetworkNames,
35
42
  ): Promise<{ config: AztecNodeConfig }> {
36
43
  // All options set from environment variables
37
44
  const configFromEnvVars = getConfigEnvVars();
@@ -45,22 +52,38 @@ export async function startNode(
45
52
  ...relevantOptions,
46
53
  };
47
54
 
55
+ // Prover node configuration and broker setup
56
+ // REFACTOR: Move the broker setup out of here and into the prover-node factory
57
+ let broker: ProvingJobBroker | undefined = undefined;
48
58
  if (options.proverNode) {
49
- userLog(`Running a Prover Node within a Node is not yet supported`);
50
- process.exit(1);
59
+ nodeConfig.enableProverNode = true;
60
+ if (nodeConfig.proverAgentCount === 0) {
61
+ userLog(
62
+ `Running prover node without local prover agent. Connect prover agents or pass --proverAgent.proverAgentCount`,
63
+ );
64
+ }
65
+ if (nodeConfig.proverBrokerUrl) {
66
+ // at 1TPS we'd enqueue ~1k chonk verifier proofs and ~1k AVM proofs immediately
67
+ // set a lower connection limit such that we don't overload the server
68
+ // Keep retrying up to 30s
69
+ const fetch = makeTracedFetch(
70
+ [1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
71
+ false,
72
+ makeUndiciFetch(new Agent({ connections: 100 })),
73
+ );
74
+ broker = createProvingJobBrokerClient(nodeConfig.proverBrokerUrl, getVersions(nodeConfig), fetch);
75
+ } else if (options.proverBroker) {
76
+ ({ broker } = await startProverBroker(options, signalHandlers, services, userLog));
77
+ } else {
78
+ userLog(`--prover-broker-url or --prover-broker is required to start a Prover Node`);
79
+ process.exit(1);
80
+ }
51
81
  }
52
82
 
53
83
  await preloadCrsDataForVerifying(nodeConfig, userLog);
54
84
 
55
- const testAccounts = nodeConfig.testAccounts ? (await getInitialTestAccountsData()).map(a => a.address) : [];
56
- const sponsoredFPCAccounts = nodeConfig.sponsoredFPC ? [await getSponsoredFPCAddress()] : [];
57
- const initialFundedAccounts = testAccounts.concat(sponsoredFPCAccounts);
58
-
59
- userLog(`Initial funded accounts: ${initialFundedAccounts.map(a => a.toString()).join(', ')}`);
60
-
61
- const { genesisArchiveRoot, prefilledPublicData } = await getGenesisValues(initialFundedAccounts);
62
-
63
- userLog(`Genesis archive root: ${genesisArchiveRoot.toString()}`);
85
+ const genesisConfig = getGenesisStateConfigEnvVars();
86
+ const { genesisArchiveRoot, prefilledPublicData } = await computeExpectedGenesisRoot(genesisConfig, userLog);
64
87
 
65
88
  const followsCanonicalRollup =
66
89
  typeof nodeConfig.rollupVersion !== 'number' || (nodeConfig.rollupVersion as unknown as string) === 'canonical';
@@ -68,6 +91,16 @@ export async function startNode(
68
91
  if (!nodeConfig.l1Contracts.registryAddress || nodeConfig.l1Contracts.registryAddress.isZero()) {
69
92
  throw new Error('L1 registry address is required to start Aztec Node');
70
93
  }
94
+
95
+ // Wait for a compatible rollup before proceeding with full L1 config fetch.
96
+ // This prevents crashes when the canonical rollup hasn't been upgraded yet.
97
+ await waitForCompatibleRollup(
98
+ nodeConfig,
99
+ { genesisArchiveRoot, vkTreeRoot: getVKTreeRoot(), protocolContractsHash },
100
+ options.port,
101
+ userLog,
102
+ );
103
+
71
104
  const { addresses, config } = await getL1Config(
72
105
  nodeConfig.l1Contracts.registryAddress,
73
106
  nodeConfig.l1RpcUrls,
@@ -101,12 +134,17 @@ export async function startNode(
101
134
  ...extractNamespacedOptions(options, 'sequencer'),
102
135
  };
103
136
  // If no publisher private keys have been given, use the first validator key
104
- if (sequencerConfig.publisherPrivateKeys === undefined || !sequencerConfig.publisherPrivateKeys.length) {
137
+ if (
138
+ sequencerConfig.sequencerPublisherPrivateKeys === undefined ||
139
+ !sequencerConfig.sequencerPublisherPrivateKeys.length
140
+ ) {
105
141
  if (sequencerConfig.validatorPrivateKeys?.getValue().length) {
106
- sequencerConfig.publisherPrivateKeys = [new SecretValue(sequencerConfig.validatorPrivateKeys.getValue()[0])];
142
+ sequencerConfig.sequencerPublisherPrivateKeys = [
143
+ new SecretValue(sequencerConfig.validatorPrivateKeys.getValue()[0]),
144
+ ];
107
145
  }
108
146
  }
109
- nodeConfig.publisherPrivateKeys = sequencerConfig.publisherPrivateKeys;
147
+ nodeConfig.sequencerPublisherPrivateKeys = sequencerConfig.sequencerPublisherPrivateKeys;
110
148
  }
111
149
 
112
150
  if (nodeConfig.p2pEnabled) {
@@ -117,16 +155,25 @@ export async function startNode(
117
155
  }
118
156
 
119
157
  const telemetryConfig = extractRelevantOptions<TelemetryClientConfig>(options, telemetryClientConfigMappings, 'tel');
120
- const telemetry = initTelemetryClient(telemetryConfig);
158
+ const telemetry = await initTelemetryClient(telemetryConfig);
121
159
 
122
160
  // Create and start Aztec Node
123
- const node = await createAztecNode(nodeConfig, { telemetry }, { prefilledPublicData });
161
+ const node = await createAztecNode(nodeConfig, { telemetry, proverBroker: broker }, { prefilledPublicData });
124
162
 
125
163
  // Add node and p2p to services list
126
164
  services.node = [node, AztecNodeApiSchema];
127
165
  services.p2p = [node.getP2P(), P2PApiSchema];
128
166
  adminServices.nodeAdmin = [node, AztecNodeAdminApiSchema];
129
167
 
168
+ // Register prover-node services if the prover node subsystem is running
169
+ const proverNode = node.getProverNode();
170
+ if (proverNode) {
171
+ services.prover = [proverNode, ProverNodeApiSchema];
172
+ if (!nodeConfig.proverBrokerUrl) {
173
+ services.provingJobSource = [proverNode.getProver().getProvingJobSource(), ProvingJobConsumerSchema];
174
+ }
175
+ }
176
+
130
177
  // Add node stop function to signal handlers
131
178
  signalHandlers.push(node.stop.bind(node));
132
179
 
@@ -135,21 +182,24 @@ export async function startNode(
135
182
  const { addBot } = await import('./start_bot.js');
136
183
 
137
184
  const pxeConfig = extractRelevantOptions<PXEConfig & CliPXEOptions>(options, allPxeConfigMappings, 'pxe');
138
- const wallet = await TestWallet.create(node, pxeConfig);
185
+ const wallet = await EmbeddedWallet.create(node, { pxeConfig });
139
186
 
140
187
  await addBot(options, signalHandlers, services, wallet, node, telemetry, undefined);
141
188
  }
142
189
 
143
- if (nodeConfig.autoUpdate !== 'disabled' && nodeConfig.autoUpdateUrl) {
144
- await setupUpdateMonitor(
145
- nodeConfig.autoUpdate,
146
- new URL(nodeConfig.autoUpdateUrl),
147
- followsCanonicalRollup,
148
- getPublicClient(nodeConfig!),
149
- nodeConfig.l1Contracts.registryAddress,
150
- signalHandlers,
151
- async config => node.setConfig((await AztecNodeAdminApiSchema.setConfig.parameters().parseAsync([config]))[0]),
152
- );
190
+ if (nodeConfig.enableVersionCheck && networkName !== 'local') {
191
+ const cacheDir = process.env.DATA_DIRECTORY ? `${process.env.DATA_DIRECTORY}/cache` : undefined;
192
+ try {
193
+ await setupVersionChecker(
194
+ networkName,
195
+ followsCanonicalRollup,
196
+ getPublicClient(nodeConfig!),
197
+ signalHandlers,
198
+ cacheDir,
199
+ );
200
+ } catch {
201
+ /* no-op */
202
+ }
153
203
  }
154
204
 
155
205
  return { config: nodeConfig };
@@ -1,6 +1,6 @@
1
1
  import { jsonStringify } from '@aztec/foundation/json-rpc';
2
2
  import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server';
3
- import { type LogFn, createLogger } from '@aztec/foundation/log';
3
+ import type { LogFn } from '@aztec/foundation/log';
4
4
  import { createStore } from '@aztec/kv-store/lmdb-v2';
5
5
  import { type BootnodeConfig, BootstrapNode, bootnodeConfigMappings } from '@aztec/p2p';
6
6
  import { emptyChainConfig } from '@aztec/stdlib/config';
@@ -25,9 +25,9 @@ export async function startP2PBootstrap(
25
25
  userLog(`Starting P2P bootstrap node with config: ${jsonStringify(safeConfig)}`);
26
26
 
27
27
  const telemetryConfig = extractRelevantOptions<TelemetryClientConfig>(options, telemetryClientConfigMappings, 'tel');
28
- const telemetryClient = initTelemetryClient(telemetryConfig);
28
+ const telemetryClient = await initTelemetryClient(telemetryConfig);
29
29
 
30
- const store = await createStore('p2p-bootstrap', 1, config, createLogger('p2p:bootstrap:store'));
30
+ const store = await createStore('p2p-bootstrap', 1, config);
31
31
  const node = new BootstrapNode(store, telemetryClient);
32
32
  await node.start(config);
33
33
  signalHandlers.push(() => node.stop());
@@ -4,9 +4,9 @@ import { Agent, makeUndiciFetch } from '@aztec/foundation/json-rpc/undici';
4
4
  import type { LogFn } from '@aztec/foundation/log';
5
5
  import { buildServerCircuitProver } from '@aztec/prover-client';
6
6
  import {
7
- InlineProofStore,
8
7
  type ProverAgentConfig,
9
8
  ProvingAgent,
9
+ createProofStore,
10
10
  createProvingJobBrokerClient,
11
11
  proverAgentConfigMappings,
12
12
  } from '@aztec/prover-client/broker';
@@ -53,20 +53,12 @@ export async function startProverAgent(
53
53
  );
54
54
  const broker = createProvingJobBrokerClient(config.proverBrokerUrl, getVersions(), fetch);
55
55
 
56
- const telemetry = initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
56
+ const telemetry = await initTelemetryClient(extractRelevantOptions(options, telemetryClientConfigMappings, 'tel'));
57
57
  const prover = await buildServerCircuitProver(config, telemetry);
58
- const proofStore = new InlineProofStore();
58
+ const proofStore = await createProofStore(config.proofStore);
59
59
  const agents = times(
60
60
  config.proverAgentCount,
61
- () =>
62
- new ProvingAgent(
63
- broker,
64
- proofStore,
65
- prover,
66
- config.proverAgentProofTypes,
67
- config.proverAgentPollIntervalMs,
68
- telemetry,
69
- ),
61
+ () => new ProvingAgent(broker, proofStore, prover, config.proverAgentProofTypes, config.proverAgentPollIntervalMs),
70
62
  );
71
63
 
72
64
  // expose all agents as individual services
@@ -1,10 +1,13 @@
1
1
  import { getL1Config } from '@aztec/cli/config';
2
- import { getPublicClient } from '@aztec/ethereum';
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,
10
+ ProvingJobBrokerSchemaWithDebug,
8
11
  createAndStartProvingBroker,
9
12
  proverBrokerConfigMappings,
10
13
  } from '@aztec/prover-client/broker';
@@ -12,7 +15,8 @@ import { getProverNodeBrokerConfigFromEnv } from '@aztec/prover-node';
12
15
  import type { ProvingJobBroker } from '@aztec/stdlib/interfaces/server';
13
16
  import { getConfigEnvVars as getTelemetryClientConfig, initTelemetryClient } from '@aztec/telemetry-client';
14
17
 
15
- import { extractRelevantOptions, setupUpdateMonitor } from '../util.js';
18
+ import { extractRelevantOptions } from '../util.js';
19
+ import { computeExpectedGenesisRoot, waitForCompatibleRollup } from './standby.js';
16
20
 
17
21
  export async function startProverBroker(
18
22
  options: any,
@@ -34,7 +38,15 @@ export async function startProverBroker(
34
38
  throw new Error('L1 registry address is required to start Aztec Node without --deploy-aztec-contracts option');
35
39
  }
36
40
 
37
- const followsCanonicalRollup = typeof config.rollupVersion !== 'number';
41
+ const genesisConfig = getGenesisStateConfigEnvVars();
42
+ const { genesisArchiveRoot } = await computeExpectedGenesisRoot(genesisConfig, userLog);
43
+ await waitForCompatibleRollup(
44
+ config,
45
+ { genesisArchiveRoot, vkTreeRoot: getVKTreeRoot(), protocolContractsHash },
46
+ options.port,
47
+ userLog,
48
+ );
49
+
38
50
  const { addresses, config: rollupConfig } = await getL1Config(
39
51
  config.l1Contracts.registryAddress,
40
52
  config.l1RpcUrls,
@@ -45,21 +57,13 @@ export async function startProverBroker(
45
57
  config.l1Contracts = addresses;
46
58
  config.rollupVersion = rollupConfig.rollupVersion;
47
59
 
48
- const client = initTelemetryClient(getTelemetryClientConfig());
60
+ const client = await initTelemetryClient(getTelemetryClientConfig());
49
61
  const broker = await createAndStartProvingBroker(config, client);
50
62
 
51
- if (options.autoUpdate !== 'disabled' && options.autoUpdateUrl) {
52
- await setupUpdateMonitor(
53
- options.autoUpdate,
54
- new URL(options.autoUpdateUrl),
55
- followsCanonicalRollup,
56
- getPublicClient(config),
57
- config.l1Contracts.registryAddress,
58
- signalHandlers,
59
- );
60
- }
61
-
62
- services.proverBroker = [broker, ProvingJobBrokerSchema];
63
+ services.proverBroker = [
64
+ broker,
65
+ config.proverBrokerDebugReplayEnabled ? ProvingJobBrokerSchemaWithDebug : ProvingJobBrokerSchema,
66
+ ];
63
67
  signalHandlers.push(() => broker.stop());
64
68
 
65
69
  return { broker, config };
@@ -0,0 +1,44 @@
1
+ import { readFile, readdir } from 'fs/promises';
2
+ import { join } from 'path';
3
+
4
+ export interface CompiledArtifact {
5
+ noir_version: string;
6
+ file_map: unknown;
7
+ functions: ContractFunction[];
8
+ bytecode?: string;
9
+ }
10
+
11
+ export interface ContractFunction {
12
+ name: string;
13
+ abi: unknown;
14
+ bytecode: string;
15
+ debug_symbols: unknown;
16
+ is_unconstrained?: boolean;
17
+ }
18
+
19
+ export interface ArtifactFile {
20
+ name: string;
21
+ filePath: string;
22
+ content: CompiledArtifact;
23
+ }
24
+
25
+ /** Reads all JSON artifact files from a target directory and returns their parsed contents. */
26
+ export async function readArtifactFiles(targetDir: string): Promise<ArtifactFile[]> {
27
+ let entries: string[];
28
+ try {
29
+ entries = (await readdir(targetDir)).filter(f => f.endsWith('.json'));
30
+ } catch (err: any) {
31
+ if (err?.code === 'ENOENT') {
32
+ throw new Error(`Target directory '${targetDir}' does not exist. Compile first with 'aztec compile'.`);
33
+ }
34
+ throw err;
35
+ }
36
+
37
+ const artifacts: ArtifactFile[] = [];
38
+ for (const file of entries) {
39
+ const filePath = join(targetDir, file);
40
+ const content = JSON.parse(await readFile(filePath, 'utf-8')) as CompiledArtifact;
41
+ artifacts.push({ name: file.replace('.json', ''), filePath, content });
42
+ }
43
+ return artifacts;
44
+ }
@@ -0,0 +1,151 @@
1
+ import TOML from '@iarna/toml';
2
+ import { readFile, readdir, stat } from 'fs/promises';
3
+ import { join, resolve } from 'path';
4
+
5
+ /**
6
+ * Returns true if recompilation is needed: either no artifacts exist in target/ or any .nr or Nargo.toml source file
7
+ * (including path-based dependencies) is newer than the oldest artifact. We compare against the oldest artifact so
8
+ * that a source change between the oldest and newest compilation (e.g. in a multi-contract workspace) still triggers
9
+ * a recompile.
10
+ *
11
+ * Note: The above implies that if there is a random json file in the target dir we would be always recompiling.
12
+ */
13
+ export async function needsRecompile(): Promise<boolean> {
14
+ const oldestArtifactMs = await getOldestArtifactModificationTime('target');
15
+ if (oldestArtifactMs === undefined) {
16
+ return true;
17
+ }
18
+
19
+ const crateDirs = await collectCrateDirs('.');
20
+ return hasNewerSourceFile(crateDirs, oldestArtifactMs);
21
+ }
22
+
23
+ /**
24
+ * Returns the last modification time (timestamp in ms) of the oldest .json artifact in targetDir, or undefined if
25
+ * none exist.
26
+ */
27
+ async function getOldestArtifactModificationTime(targetDir: string): Promise<number | undefined> {
28
+ let entries: string[];
29
+ try {
30
+ entries = (await readdir(targetDir)).filter(f => f.endsWith('.json'));
31
+ } catch (err: any) {
32
+ if (err?.code === 'ENOENT') {
33
+ return undefined;
34
+ }
35
+ throw err;
36
+ }
37
+
38
+ if (entries.length === 0) {
39
+ return undefined;
40
+ }
41
+
42
+ let oldest = Infinity;
43
+ for (const entry of entries) {
44
+ const s = await stat(join(targetDir, entry));
45
+ if (s.mtimeMs < oldest) {
46
+ oldest = s.mtimeMs;
47
+ }
48
+ }
49
+ return oldest;
50
+ }
51
+
52
+ /**
53
+ * Recursively collects crate directories starting from startCrateDir by following path-based dependencies declared in
54
+ * Nargo.toml files. Git-based deps are ignored (they only change when Nargo.toml itself is modified since the deps are
55
+ * tagged).
56
+ */
57
+ async function collectCrateDirs(startCrateDir: string): Promise<string[]> {
58
+ // We have a set of visited dirs we check against when entering a new dir because we could stumble upon a directory
59
+ // multiple times in case multiple deps shared a dep (e.g. dep A and dep B both sharing dep C).
60
+ const visited = new Set<string>();
61
+
62
+ async function visit(crateDir: string): Promise<void> {
63
+ const absDir = resolve(crateDir);
64
+ if (visited.has(absDir)) {
65
+ return;
66
+ }
67
+ visited.add(absDir);
68
+
69
+ // Every dep is its own crate and every crate needs to have Nargo.toml defined in the root so we try to load it and
70
+ // error out if it's not the case.
71
+ const tomlPath = join(absDir, 'Nargo.toml');
72
+ const content = await readFile(tomlPath, 'utf-8').catch(() => {
73
+ throw new Error(`Incorrectly defined dependency. Nargo.toml not found in ${absDir}`);
74
+ });
75
+
76
+ const parsed = TOML.parse(content) as Record<string, any>;
77
+
78
+ const members = (parsed.workspace as Record<string, any>)?.members as string[] | undefined;
79
+
80
+ // A Nargo.toml is either a workspace root (has workspace.members) or a single crate (has dependencies).
81
+ if (Array.isArray(members)) {
82
+ // The crate is a workspace root and has members defined so we visit the members
83
+ for (const member of members) {
84
+ const memberPath = resolve(absDir, member);
85
+ await visit(memberPath);
86
+ }
87
+ } else {
88
+ // The crate is not a workspace root so we check for dependencies
89
+ const deps = (parsed.dependencies as Record<string, any>) ?? {};
90
+ for (const dep of Object.values(deps)) {
91
+ if (dep && typeof dep === 'object' && typeof dep.path === 'string') {
92
+ const depPath = resolve(absDir, dep.path);
93
+ const s = await stat(depPath);
94
+ if (!s.isDirectory()) {
95
+ throw new Error(
96
+ `Dependency path "${dep.path}" in ${tomlPath} resolves to ${depPath} which is not a directory`,
97
+ );
98
+ }
99
+ await visit(depPath);
100
+ }
101
+ }
102
+ }
103
+ }
104
+
105
+ await visit(startCrateDir);
106
+ return [...visited];
107
+ }
108
+
109
+ /**
110
+ * Walks crate dirs looking for .nr and Nargo.toml files newer than thresholdMs. Short-circuits on the first match.
111
+ */
112
+ async function hasNewerSourceFile(crateDirs: string[], thresholdMs: number): Promise<boolean> {
113
+ // Returns true if it find a new file than thresholdMs, false otherwise
114
+ async function walkForNewer(dir: string): Promise<boolean> {
115
+ let entries;
116
+ try {
117
+ entries = await readdir(dir, { withFileTypes: true });
118
+ } catch {
119
+ return false;
120
+ }
121
+
122
+ // We iterate over the entries in the dir
123
+ for (const entry of entries) {
124
+ const fullPath = join(dir, entry.name);
125
+ if (entry.isDirectory()) {
126
+ // If the entry is a dir and it's not called `target` we recursively enter it
127
+ if (entry.name === 'target') {
128
+ continue;
129
+ }
130
+ if (await walkForNewer(fullPath)) {
131
+ return true;
132
+ }
133
+ } else if (entry.name === 'Nargo.toml' || entry.name.endsWith('.nr')) {
134
+ // The entry is a Nargo.toml file or *.nr file so we check the timestamp
135
+ const s = await stat(fullPath);
136
+ if (s.mtimeMs > thresholdMs) {
137
+ return true;
138
+ }
139
+ }
140
+ }
141
+ return false;
142
+ }
143
+
144
+ // We search through the crate dirs
145
+ for (const dir of crateDirs) {
146
+ if (await walkForNewer(dir)) {
147
+ return true;
148
+ }
149
+ }
150
+ return false;
151
+ }
@@ -0,0 +1,16 @@
1
+ import { spawn } from 'child_process';
2
+
3
+ /** Spawns a command with inherited stdio and rejects on non-zero exit. */
4
+ export function run(cmd: string, args: string[]): Promise<void> {
5
+ return new Promise((resolve, reject) => {
6
+ const child = spawn(cmd, args, { stdio: 'inherit' });
7
+ child.on('error', reject);
8
+ child.on('close', code => {
9
+ if (code !== 0) {
10
+ reject(new Error(`${cmd} exited with code ${code}`));
11
+ } else {
12
+ resolve();
13
+ }
14
+ });
15
+ });
16
+ }