-
Notifications
You must be signed in to change notification settings - Fork 598
feat(aztec): node enters standby mode on genesis root mismatch #20937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+86
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,14 @@ import { Fr } from '@aztec/aztec.js/fields'; | |
| import { getSponsoredFPCAddress } from '@aztec/cli/cli-utils'; | ||
| import { getL1Config } from '@aztec/cli/config'; | ||
| import { getPublicClient } from '@aztec/ethereum/client'; | ||
| import { RegistryContract, RollupContract } from '@aztec/ethereum/contracts'; | ||
| import { SecretValue } from '@aztec/foundation/config'; | ||
| import { EthAddress } from '@aztec/foundation/eth-address'; | ||
| import type { NamespacedApiHandlers } from '@aztec/foundation/json-rpc/server'; | ||
| import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server'; | ||
| import { Agent, makeUndiciFetch } from '@aztec/foundation/json-rpc/undici'; | ||
| import type { LogFn } from '@aztec/foundation/log'; | ||
| import { sleep } from '@aztec/foundation/sleep'; | ||
| import { ProvingJobConsumerSchema, createProvingJobBrokerClient } from '@aztec/prover-client/broker'; | ||
| import { type CliPXEOptions, type PXEConfig, allPxeConfigMappings } from '@aztec/pxe/config'; | ||
| import { AztecNodeAdminApiSchema, AztecNodeApiSchema } from '@aztec/stdlib/interfaces/client'; | ||
|
|
@@ -21,6 +25,8 @@ import { | |
| import { EmbeddedWallet } from '@aztec/wallets/embedded'; | ||
| import { getGenesisValues } from '@aztec/world-state/testing'; | ||
|
|
||
| import Koa from 'koa'; | ||
|
|
||
| import { createAztecNode } from '../../local-network/index.js'; | ||
| import { | ||
| extractNamespacedOptions, | ||
|
|
@@ -31,6 +37,72 @@ import { | |
| import { getVersions } from '../versioning.js'; | ||
| import { startProverBroker } from './start_prover_broker.js'; | ||
|
|
||
| const ROLLUP_POLL_INTERVAL_MS = 600_000; | ||
|
|
||
| /** | ||
| * Waits until the canonical rollup's genesis archive root matches the expected local genesis root. | ||
| * If the rollup is not yet compatible (e.g. during L1 contract upgrades), enters standby mode: | ||
| * starts a lightweight HTTP server for K8s liveness probes and polls until a compatible rollup appears. | ||
| */ | ||
| async function waitForCompatibleRollup( | ||
| publicClient: ReturnType<typeof getPublicClient>, | ||
| registryAddress: EthAddress, | ||
| rollupVersion: number | 'canonical', | ||
| expectedGenesisRoot: Fr, | ||
| port: number | undefined, | ||
| userLog: LogFn, | ||
| ): Promise<void> { | ||
| const registry = new RegistryContract(publicClient, registryAddress); | ||
| const rollupAddress = await registry.getRollupAddress(rollupVersion); | ||
| const rollup = new RollupContract(publicClient, rollupAddress.toString()); | ||
|
|
||
| let l1GenesisRoot: Fr; | ||
| try { | ||
| l1GenesisRoot = await rollup.getGenesisArchiveTreeRoot(); | ||
| } catch (err: any) { | ||
| throw new Error( | ||
| `Could not retrieve genesis archive root from canonical rollup at ${rollupAddress}: ${err.message}`, | ||
| ); | ||
| } | ||
|
|
||
| if (l1GenesisRoot.equals(expectedGenesisRoot)) { | ||
| return; | ||
| } | ||
|
|
||
| userLog( | ||
| `Genesis root mismatch: expected ${expectedGenesisRoot}, got ${l1GenesisRoot} from rollup at ${rollupAddress}. ` + | ||
| `Entering standby mode. Will poll every ${ROLLUP_POLL_INTERVAL_MS / 1000}s for a compatible rollup...`, | ||
| ); | ||
|
|
||
| const standbyServer = await startHttpRpcServer({ getApp: () => new Koa(), isHealthy: () => true }, { port }); | ||
| userLog(`Standby status server listening on port ${standbyServer.port}`); | ||
|
|
||
| try { | ||
| while (true) { | ||
| await sleep(ROLLUP_POLL_INTERVAL_MS); | ||
|
Comment on lines
+80
to
+82
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would use the |
||
|
|
||
| const currentRollupAddress = await registry.getRollupAddress(rollupVersion); | ||
| const currentRollup = new RollupContract(publicClient, currentRollupAddress.toString()); | ||
|
|
||
| try { | ||
| l1GenesisRoot = await currentRollup.getGenesisArchiveTreeRoot(); | ||
| } catch { | ||
| userLog(`Failed to fetch genesis root from rollup at ${currentRollupAddress}. Retrying...`); | ||
| continue; | ||
| } | ||
|
|
||
| if (l1GenesisRoot.equals(expectedGenesisRoot)) { | ||
| userLog(`Compatible rollup found at ${currentRollupAddress}. Exiting standby mode.`); | ||
| return; | ||
| } | ||
|
|
||
| userLog(`Still waiting. Rollup at ${currentRollupAddress} has genesis root ${l1GenesisRoot}.`); | ||
| } | ||
| } finally { | ||
| await new Promise<void>((resolve, reject) => standbyServer.close(err => (err ? reject(err) : resolve()))); | ||
| } | ||
| } | ||
|
|
||
| export async function startNode( | ||
| options: any, | ||
| signalHandlers: (() => Promise<void>)[], | ||
|
|
@@ -96,6 +168,20 @@ export async function startNode( | |
| if (!nodeConfig.l1Contracts.registryAddress || nodeConfig.l1Contracts.registryAddress.isZero()) { | ||
| throw new Error('L1 registry address is required to start Aztec Node'); | ||
| } | ||
|
|
||
| // Wait for a compatible rollup before proceeding with full L1 config fetch. | ||
| // This prevents crashes when the canonical rollup hasn't been upgraded yet. | ||
| const publicClient = getPublicClient(nodeConfig); | ||
| const rollupVersion: number | 'canonical' = nodeConfig.rollupVersion ?? 'canonical'; | ||
| await waitForCompatibleRollup( | ||
| publicClient, | ||
| nodeConfig.l1Contracts.registryAddress, | ||
| rollupVersion, | ||
| genesisArchiveRoot, | ||
| options.port, | ||
| userLog, | ||
| ); | ||
|
|
||
| const { addresses, config } = await getL1Config( | ||
| nodeConfig.l1Contracts.registryAddress, | ||
| nodeConfig.l1RpcUrls, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be in favour of reducing the interval to one minute. As it is nodes could potentially lose up to 25% of the first epoch (10 mins out of 38) depending on when they were started and when the switch over happens.