@aztec/node-lib 3.0.0-nightly.20250930 → 3.0.0-nightly.20251002

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.
@@ -6,7 +6,8 @@ import type { DataStoreConfig } from '@aztec/kv-store/config';
6
6
  import type { ChainConfig } from '@aztec/stdlib/config';
7
7
  import { type SnapshotMetadata } from '@aztec/stdlib/snapshots';
8
8
  import type { SharedNodeConfig } from '../config/index.js';
9
- type SnapshotSyncConfig = Pick<SharedNodeConfig, 'syncMode' | 'snapshotsUrl'> & Pick<ChainConfig, 'l1ChainId' | 'rollupVersion'> & Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & Required<DataStoreConfig> & EthereumClientConfig & {
9
+ type SnapshotSyncConfig = Pick<SharedNodeConfig, 'syncMode'> & Pick<ChainConfig, 'l1ChainId' | 'rollupVersion'> & Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> & Required<DataStoreConfig> & EthereumClientConfig & {
10
+ snapshotsUrls?: string[];
10
11
  minL1BlocksToTriggerReplace?: number;
11
12
  };
12
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"snapshot-sync.d.ts","sourceRoot":"","sources":["../../src/actions/snapshot-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,KAAK,cAAc,EAAuB,MAAM,iBAAiB,CAAC;AAErH,OAAO,EAAE,KAAK,oBAAoB,EAAmB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,EACL,KAAK,gBAAgB,EAKtB,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAK3D,KAAK,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,cAAc,CAAC,GAC3E,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,CAAC,GAChD,IAAI,CAAC,cAAc,EAAE,wBAAwB,GAAG,SAAS,CAAC,GAC1D,QAAQ,CAAC,eAAe,CAAC,GACzB,oBAAoB,GAAG;IACrB,2BAA2B,CAAC,EAAE,MAAM,CAAC;CACtC,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,oBA2H5E;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC5C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,UAAU,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,iBAqDnF"}
1
+ {"version":3,"file":"snapshot-sync.d.ts","sourceRoot":"","sources":["../../src/actions/snapshot-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,KAAK,cAAc,EAAuB,MAAM,iBAAiB,CAAC;AAErH,OAAO,EAAE,KAAK,oBAAoB,EAAmB,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,EACL,KAAK,gBAAgB,EAKtB,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAK3D,KAAK,kBAAkB,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAC1D,IAAI,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,CAAC,GAChD,IAAI,CAAC,cAAc,EAAE,wBAAwB,GAAG,SAAS,CAAC,GAC1D,QAAQ,CAAC,eAAe,CAAC,GACzB,oBAAoB,GAAG;IACrB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,2BAA2B,CAAC,EAAE,MAAM,CAAC;CACtC,CAAC;AAEJ;;;GAGG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,oBAiK5E;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,EAC5C,GAAG,EAAE,MAAM,EACX,MAAM,EAAE;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,UAAU,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,iBAqDnF"}
@@ -15,29 +15,22 @@ const MIN_L1_BLOCKS_TO_TRIGGER_REPLACE = 86400 / 2 / 12;
15
15
  * Connects to a remote snapshot index and downloads the latest snapshot if the local archiver is behind.
16
16
  * Behaviour depends on syncing mode.
17
17
  */ export async function trySnapshotSync(config, log) {
18
- const { syncMode, snapshotsUrl, dataDirectory, l1ChainId, rollupVersion, l1Contracts } = config;
18
+ const { syncMode, snapshotsUrls, dataDirectory, l1ChainId, rollupVersion, l1Contracts } = config;
19
19
  if (syncMode === 'full') {
20
20
  log.debug('Snapshot sync is disabled. Running full sync.', {
21
21
  syncMode: syncMode
22
22
  });
23
23
  return false;
24
24
  }
25
- if (!snapshotsUrl) {
26
- log.verbose('Snapshot sync is disabled. No snapshots URL provided.');
25
+ if (!snapshotsUrls || snapshotsUrls.length === 0) {
26
+ log.verbose('Snapshot sync is disabled. No snapshots URLs provided.');
27
27
  return false;
28
28
  }
29
29
  if (!dataDirectory) {
30
30
  log.verbose('Snapshot sync is disabled. No local data directory defined.');
31
31
  return false;
32
32
  }
33
- let fileStore;
34
- try {
35
- fileStore = await createReadOnlyFileStore(snapshotsUrl, log);
36
- } catch (err) {
37
- log.error(`Invalid config for downloading snapshots`, err);
38
- return false;
39
- }
40
- // Create an archiver store to check the current state
33
+ // Create an archiver store to check the current state (do this only once)
41
34
  log.verbose(`Creating temporary archiver data store`);
42
35
  const archiverStore = await createArchiverStore(config);
43
36
  let archiverL1BlockNumber;
@@ -73,59 +66,101 @@ const MIN_L1_BLOCKS_TO_TRIGGER_REPLACE = 86400 / 2 / 12;
73
66
  rollupVersion,
74
67
  rollupAddress: l1Contracts.rollupAddress
75
68
  };
76
- let snapshot;
77
- try {
78
- snapshot = await getLatestSnapshotMetadata(indexMetadata, fileStore);
79
- } catch (err) {
80
- log.error(`Failed to get latest snapshot metadata. Skipping snapshot sync.`, err, {
81
- ...indexMetadata,
82
- snapshotsUrl
69
+ const snapshotCandidates = [];
70
+ for (const snapshotsUrl of snapshotsUrls){
71
+ let fileStore;
72
+ try {
73
+ fileStore = await createReadOnlyFileStore(snapshotsUrl, log);
74
+ } catch (err) {
75
+ log.error(`Invalid config for downloading snapshots from ${snapshotsUrl}`, err);
76
+ continue;
77
+ }
78
+ let snapshot;
79
+ try {
80
+ snapshot = await getLatestSnapshotMetadata(indexMetadata, fileStore);
81
+ } catch (err) {
82
+ log.error(`Failed to get latest snapshot metadata from ${snapshotsUrl}. Skipping this URL.`, err, {
83
+ ...indexMetadata,
84
+ snapshotsUrl
85
+ });
86
+ continue;
87
+ }
88
+ if (!snapshot) {
89
+ log.verbose(`No snapshot found at ${snapshotsUrl}. Skipping this URL.`, {
90
+ ...indexMetadata,
91
+ snapshotsUrl
92
+ });
93
+ continue;
94
+ }
95
+ if (snapshot.schemaVersions.archiver !== ARCHIVER_DB_VERSION) {
96
+ log.warn(`Skipping snapshot from ${snapshotsUrl} as it has schema version ${snapshot.schemaVersions.archiver} but expected ${ARCHIVER_DB_VERSION}.`, snapshot);
97
+ continue;
98
+ }
99
+ if (snapshot.schemaVersions.worldState !== WORLD_STATE_DB_VERSION) {
100
+ log.warn(`Skipping snapshot from ${snapshotsUrl} as it has world state schema version ${snapshot.schemaVersions.worldState} but we expected ${WORLD_STATE_DB_VERSION}.`, snapshot);
101
+ continue;
102
+ }
103
+ if (archiverL1BlockNumber && snapshot.l1BlockNumber < archiverL1BlockNumber) {
104
+ log.verbose(`Skipping snapshot from ${snapshotsUrl} since local archiver is at L1 block ${archiverL1BlockNumber} which is further than snapshot at ${snapshot.l1BlockNumber}`, {
105
+ snapshot,
106
+ archiverL1BlockNumber,
107
+ snapshotsUrl
108
+ });
109
+ continue;
110
+ }
111
+ if (archiverL1BlockNumber && snapshot.l1BlockNumber - Number(archiverL1BlockNumber) < minL1BlocksToTriggerReplace) {
112
+ log.verbose(`Skipping snapshot from ${snapshotsUrl} as archiver is less than ${snapshot.l1BlockNumber - Number(archiverL1BlockNumber)} L1 blocks behind this snapshot.`, {
113
+ snapshot,
114
+ archiverL1BlockNumber,
115
+ snapshotsUrl
116
+ });
117
+ continue;
118
+ }
119
+ snapshotCandidates.push({
120
+ snapshot,
121
+ url: snapshotsUrl,
122
+ fileStore
83
123
  });
84
- return false;
85
124
  }
86
- if (!snapshot) {
87
- log.verbose(`No snapshot found. Skipping snapshot sync.`, {
125
+ if (snapshotCandidates.length === 0) {
126
+ log.verbose(`No valid snapshots found from any URL. Skipping snapshot sync.`, {
88
127
  ...indexMetadata,
89
- snapshotsUrl
90
- });
91
- return false;
92
- }
93
- if (snapshot.schemaVersions.archiver !== ARCHIVER_DB_VERSION) {
94
- log.warn(`Skipping snapshot sync as last snapshot has schema version ${snapshot.schemaVersions.archiver} but expected ${ARCHIVER_DB_VERSION}.`, snapshot);
95
- return false;
96
- }
97
- if (snapshot.schemaVersions.worldState !== WORLD_STATE_DB_VERSION) {
98
- log.warn(`Skipping snapshot sync as last snapshot has world state schema version ${snapshot.schemaVersions.worldState} but we expected ${WORLD_STATE_DB_VERSION}.`, snapshot);
99
- return false;
100
- }
101
- if (archiverL1BlockNumber && snapshot.l1BlockNumber < archiverL1BlockNumber) {
102
- log.verbose(`Skipping snapshot sync since local archiver is at L1 block ${archiverL1BlockNumber} which is further than last snapshot at ${snapshot.l1BlockNumber}`, {
103
- snapshot,
104
- archiverL1BlockNumber
128
+ snapshotsUrls
105
129
  });
106
130
  return false;
107
131
  }
108
- if (archiverL1BlockNumber && snapshot.l1BlockNumber - Number(archiverL1BlockNumber) < minL1BlocksToTriggerReplace) {
109
- log.verbose(`Skipping snapshot sync as archiver is less than ${snapshot.l1BlockNumber - Number(archiverL1BlockNumber)} L1 blocks behind latest snapshot.`, {
132
+ // Sort candidates by L1 block number (highest first)
133
+ snapshotCandidates.sort((a, b)=>b.snapshot.l1BlockNumber - a.snapshot.l1BlockNumber);
134
+ // Try each candidate in order until one succeeds
135
+ for (const { snapshot, url } of snapshotCandidates){
136
+ const { l1BlockNumber, l2BlockNumber } = snapshot;
137
+ log.info(`Attempting to sync from snapshot at L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, {
110
138
  snapshot,
111
- archiverL1BlockNumber
139
+ snapshotsUrl: url
112
140
  });
113
- return false;
141
+ try {
142
+ await snapshotSync(snapshot, log, {
143
+ dataDirectory: config.dataDirectory,
144
+ rollupAddress: config.l1Contracts.rollupAddress,
145
+ snapshotsUrl: url
146
+ });
147
+ log.info(`Snapshot synced to L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, {
148
+ snapshot,
149
+ snapshotsUrl: url
150
+ });
151
+ return true;
152
+ } catch (err) {
153
+ log.error(`Failed to download snapshot from ${url}. Trying next candidate.`, err, {
154
+ snapshot,
155
+ snapshotsUrl: url
156
+ });
157
+ continue;
158
+ }
114
159
  }
115
- const { l1BlockNumber, l2BlockNumber } = snapshot;
116
- log.info(`Syncing from snapshot at L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, {
117
- snapshot,
118
- snapshotsUrl
119
- });
120
- await snapshotSync(snapshot, log, {
121
- dataDirectory: config.dataDirectory,
122
- rollupAddress: config.l1Contracts.rollupAddress,
123
- snapshotsUrl
124
- });
125
- log.info(`Snapshot synced to L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, {
126
- snapshot
160
+ log.error(`Failed to download snapshot from all URLs.`, {
161
+ snapshotsUrls
127
162
  });
128
- return true;
163
+ return false;
129
164
  }
130
165
  /**
131
166
  * Downloads the given snapshot replacing any local data stores.
@@ -6,8 +6,8 @@ export type SharedNodeConfig = {
6
6
  sponsoredFPC: boolean;
7
7
  /** Sync mode: full to always sync via L1, snapshot to download a snapshot if there is no local data, force-snapshot to download even if there is local data. */
8
8
  syncMode: 'full' | 'snapshot' | 'force-snapshot';
9
- /** Base URL for snapshots index. Index file will be searched at `SNAPSHOTS_BASE_URL/aztec-L1_CHAIN_ID-VERSION-ROLLUP_ADDRESS/index.json` */
10
- snapshotsUrl?: string;
9
+ /** Base URLs for snapshots index. Index file will be searched at `SNAPSHOTS_BASE_URL/aztec-L1_CHAIN_ID-VERSION-ROLLUP_ADDRESS/index.json` */
10
+ snapshotsUrls?: string[];
11
11
  /** Auto update mode: disabled - to completely ignore remote signals to update the node. enabled - to respect the signals (potentially shutting this node down). log - check for updates but log a warning instead of applying them*/
12
12
  autoUpdate?: 'disabled' | 'notify' | 'config' | 'config-and-version';
13
13
  /** The base URL against which to check for updates */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAuB,MAAM,0BAA0B,CAAC;AAExF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,yFAAyF;IACzF,YAAY,EAAE,OAAO,CAAC;IACtB,yFAAyF;IACzF,YAAY,EAAE,OAAO,CAAC;IACtB,gKAAgK;IAChK,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,gBAAgB,CAAC;IACjD,4IAA4I;IAC5I,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,qOAAqO;IACrO,UAAU,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,oBAAoB,CAAC;IACrE,sDAAsD;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,kBAAkB,CAAC,gBAAgB,CAmCzE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAuB,MAAM,0BAA0B,CAAC;AAExF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,yFAAyF;IACzF,YAAY,EAAE,OAAO,CAAC;IACtB,yFAAyF;IACzF,YAAY,EAAE,OAAO,CAAC;IACtB,gKAAgK;IAChK,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,gBAAgB,CAAC;IACjD,6IAA6I;IAC7I,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IAEzB,qOAAqO;IACrO,UAAU,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,oBAAoB,CAAC;IACrE,sDAAsD;IACtD,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,kBAAkB,CAAC,gBAAgB,CA0CzE,CAAC"}
@@ -15,9 +15,14 @@ export const sharedNodeConfigMappings = {
15
15
  description: 'Set sync mode to `full` to always sync via L1, `snapshot` to download a snapshot if there is no local data, `force-snapshot` to download even if there is local data.',
16
16
  defaultValue: 'snapshot'
17
17
  },
18
- snapshotsUrl: {
19
- env: 'SYNC_SNAPSHOTS_URL',
20
- description: 'Base URL for snapshots index.'
18
+ snapshotsUrls: {
19
+ env: 'SYNC_SNAPSHOTS_URLS',
20
+ description: 'Base URLs for snapshots index, comma-separated.',
21
+ parseEnv: (val)=>val.split(',').map((url)=>url.trim()).filter((url)=>url.length > 0),
22
+ fallback: [
23
+ 'SYNC_SNAPSHOTS_URL'
24
+ ],
25
+ defaultValue: []
21
26
  },
22
27
  autoUpdate: {
23
28
  env: 'AUTO_UPDATE',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/node-lib",
3
- "version": "3.0.0-nightly.20250930",
3
+ "version": "3.0.0-nightly.20251002",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./actions": "./dest/actions/index.js",
@@ -54,24 +54,24 @@
54
54
  ]
55
55
  },
56
56
  "dependencies": {
57
- "@aztec/archiver": "3.0.0-nightly.20250930",
58
- "@aztec/bb-prover": "3.0.0-nightly.20250930",
59
- "@aztec/blob-sink": "3.0.0-nightly.20250930",
60
- "@aztec/constants": "3.0.0-nightly.20250930",
61
- "@aztec/epoch-cache": "3.0.0-nightly.20250930",
62
- "@aztec/ethereum": "3.0.0-nightly.20250930",
63
- "@aztec/foundation": "3.0.0-nightly.20250930",
64
- "@aztec/kv-store": "3.0.0-nightly.20250930",
65
- "@aztec/merkle-tree": "3.0.0-nightly.20250930",
66
- "@aztec/p2p": "3.0.0-nightly.20250930",
67
- "@aztec/protocol-contracts": "3.0.0-nightly.20250930",
68
- "@aztec/prover-client": "3.0.0-nightly.20250930",
69
- "@aztec/sequencer-client": "3.0.0-nightly.20250930",
70
- "@aztec/simulator": "3.0.0-nightly.20250930",
71
- "@aztec/stdlib": "3.0.0-nightly.20250930",
72
- "@aztec/telemetry-client": "3.0.0-nightly.20250930",
73
- "@aztec/validator-client": "3.0.0-nightly.20250930",
74
- "@aztec/world-state": "3.0.0-nightly.20250930",
57
+ "@aztec/archiver": "3.0.0-nightly.20251002",
58
+ "@aztec/bb-prover": "3.0.0-nightly.20251002",
59
+ "@aztec/blob-sink": "3.0.0-nightly.20251002",
60
+ "@aztec/constants": "3.0.0-nightly.20251002",
61
+ "@aztec/epoch-cache": "3.0.0-nightly.20251002",
62
+ "@aztec/ethereum": "3.0.0-nightly.20251002",
63
+ "@aztec/foundation": "3.0.0-nightly.20251002",
64
+ "@aztec/kv-store": "3.0.0-nightly.20251002",
65
+ "@aztec/merkle-tree": "3.0.0-nightly.20251002",
66
+ "@aztec/p2p": "3.0.0-nightly.20251002",
67
+ "@aztec/protocol-contracts": "3.0.0-nightly.20251002",
68
+ "@aztec/prover-client": "3.0.0-nightly.20251002",
69
+ "@aztec/sequencer-client": "3.0.0-nightly.20251002",
70
+ "@aztec/simulator": "3.0.0-nightly.20251002",
71
+ "@aztec/stdlib": "3.0.0-nightly.20251002",
72
+ "@aztec/telemetry-client": "3.0.0-nightly.20251002",
73
+ "@aztec/validator-client": "3.0.0-nightly.20251002",
74
+ "@aztec/world-state": "3.0.0-nightly.20251002",
75
75
  "tslib": "^2.4.0"
76
76
  },
77
77
  "devDependencies": {
@@ -26,11 +26,12 @@ import type { SharedNodeConfig } from '../config/index.js';
26
26
  // Half day worth of L1 blocks
27
27
  const MIN_L1_BLOCKS_TO_TRIGGER_REPLACE = 86400 / 2 / 12;
28
28
 
29
- type SnapshotSyncConfig = Pick<SharedNodeConfig, 'syncMode' | 'snapshotsUrl'> &
29
+ type SnapshotSyncConfig = Pick<SharedNodeConfig, 'syncMode'> &
30
30
  Pick<ChainConfig, 'l1ChainId' | 'rollupVersion'> &
31
31
  Pick<ArchiverConfig, 'archiverStoreMapSizeKb' | 'maxLogs'> &
32
32
  Required<DataStoreConfig> &
33
33
  EthereumClientConfig & {
34
+ snapshotsUrls?: string[];
34
35
  minL1BlocksToTriggerReplace?: number;
35
36
  };
36
37
 
@@ -39,14 +40,14 @@ type SnapshotSyncConfig = Pick<SharedNodeConfig, 'syncMode' | 'snapshotsUrl'> &
39
40
  * Behaviour depends on syncing mode.
40
41
  */
41
42
  export async function trySnapshotSync(config: SnapshotSyncConfig, log: Logger) {
42
- const { syncMode, snapshotsUrl, dataDirectory, l1ChainId, rollupVersion, l1Contracts } = config;
43
+ const { syncMode, snapshotsUrls, dataDirectory, l1ChainId, rollupVersion, l1Contracts } = config;
43
44
  if (syncMode === 'full') {
44
45
  log.debug('Snapshot sync is disabled. Running full sync.', { syncMode: syncMode });
45
46
  return false;
46
47
  }
47
48
 
48
- if (!snapshotsUrl) {
49
- log.verbose('Snapshot sync is disabled. No snapshots URL provided.');
49
+ if (!snapshotsUrls || snapshotsUrls.length === 0) {
50
+ log.verbose('Snapshot sync is disabled. No snapshots URLs provided.');
50
51
  return false;
51
52
  }
52
53
 
@@ -55,15 +56,7 @@ export async function trySnapshotSync(config: SnapshotSyncConfig, log: Logger) {
55
56
  return false;
56
57
  }
57
58
 
58
- let fileStore: ReadOnlyFileStore;
59
- try {
60
- fileStore = await createReadOnlyFileStore(snapshotsUrl, log);
61
- } catch (err) {
62
- log.error(`Invalid config for downloading snapshots`, err);
63
- return false;
64
- }
65
-
66
- // Create an archiver store to check the current state
59
+ // Create an archiver store to check the current state (do this only once)
67
60
  log.verbose(`Creating temporary archiver data store`);
68
61
  const archiverStore = await createArchiverStore(config);
69
62
  let archiverL1BlockNumber: bigint | undefined;
@@ -102,65 +95,111 @@ export async function trySnapshotSync(config: SnapshotSyncConfig, log: Logger) {
102
95
  rollupVersion,
103
96
  rollupAddress: l1Contracts.rollupAddress,
104
97
  };
105
- let snapshot: SnapshotMetadata | undefined;
106
- try {
107
- snapshot = await getLatestSnapshotMetadata(indexMetadata, fileStore);
108
- } catch (err) {
109
- log.error(`Failed to get latest snapshot metadata. Skipping snapshot sync.`, err, {
110
- ...indexMetadata,
111
- snapshotsUrl,
112
- });
113
- return false;
114
- }
115
98
 
116
- if (!snapshot) {
117
- log.verbose(`No snapshot found. Skipping snapshot sync.`, { ...indexMetadata, snapshotsUrl });
118
- return false;
119
- }
99
+ // Fetch latest snapshot from each URL
100
+ type SnapshotCandidate = { snapshot: SnapshotMetadata; url: string; fileStore: ReadOnlyFileStore };
101
+ const snapshotCandidates: SnapshotCandidate[] = [];
120
102
 
121
- if (snapshot.schemaVersions.archiver !== ARCHIVER_DB_VERSION) {
122
- log.warn(
123
- `Skipping snapshot sync as last snapshot has schema version ${snapshot.schemaVersions.archiver} but expected ${ARCHIVER_DB_VERSION}.`,
124
- snapshot,
125
- );
126
- return false;
127
- }
103
+ for (const snapshotsUrl of snapshotsUrls) {
104
+ let fileStore: ReadOnlyFileStore;
105
+ try {
106
+ fileStore = await createReadOnlyFileStore(snapshotsUrl, log);
107
+ } catch (err) {
108
+ log.error(`Invalid config for downloading snapshots from ${snapshotsUrl}`, err);
109
+ continue;
110
+ }
128
111
 
129
- if (snapshot.schemaVersions.worldState !== WORLD_STATE_DB_VERSION) {
130
- log.warn(
131
- `Skipping snapshot sync as last snapshot has world state schema version ${snapshot.schemaVersions.worldState} but we expected ${WORLD_STATE_DB_VERSION}.`,
132
- snapshot,
133
- );
134
- return false;
112
+ let snapshot: SnapshotMetadata | undefined;
113
+ try {
114
+ snapshot = await getLatestSnapshotMetadata(indexMetadata, fileStore);
115
+ } catch (err) {
116
+ log.error(`Failed to get latest snapshot metadata from ${snapshotsUrl}. Skipping this URL.`, err, {
117
+ ...indexMetadata,
118
+ snapshotsUrl,
119
+ });
120
+ continue;
121
+ }
122
+
123
+ if (!snapshot) {
124
+ log.verbose(`No snapshot found at ${snapshotsUrl}. Skipping this URL.`, { ...indexMetadata, snapshotsUrl });
125
+ continue;
126
+ }
127
+
128
+ if (snapshot.schemaVersions.archiver !== ARCHIVER_DB_VERSION) {
129
+ log.warn(
130
+ `Skipping snapshot from ${snapshotsUrl} as it has schema version ${snapshot.schemaVersions.archiver} but expected ${ARCHIVER_DB_VERSION}.`,
131
+ snapshot,
132
+ );
133
+ continue;
134
+ }
135
+
136
+ if (snapshot.schemaVersions.worldState !== WORLD_STATE_DB_VERSION) {
137
+ log.warn(
138
+ `Skipping snapshot from ${snapshotsUrl} as it has world state schema version ${snapshot.schemaVersions.worldState} but we expected ${WORLD_STATE_DB_VERSION}.`,
139
+ snapshot,
140
+ );
141
+ continue;
142
+ }
143
+
144
+ if (archiverL1BlockNumber && snapshot.l1BlockNumber < archiverL1BlockNumber) {
145
+ log.verbose(
146
+ `Skipping snapshot from ${snapshotsUrl} since local archiver is at L1 block ${archiverL1BlockNumber} which is further than snapshot at ${snapshot.l1BlockNumber}`,
147
+ { snapshot, archiverL1BlockNumber, snapshotsUrl },
148
+ );
149
+ continue;
150
+ }
151
+
152
+ if (archiverL1BlockNumber && snapshot.l1BlockNumber - Number(archiverL1BlockNumber) < minL1BlocksToTriggerReplace) {
153
+ log.verbose(
154
+ `Skipping snapshot from ${snapshotsUrl} as archiver is less than ${
155
+ snapshot.l1BlockNumber - Number(archiverL1BlockNumber)
156
+ } L1 blocks behind this snapshot.`,
157
+ { snapshot, archiverL1BlockNumber, snapshotsUrl },
158
+ );
159
+ continue;
160
+ }
161
+
162
+ snapshotCandidates.push({ snapshot, url: snapshotsUrl, fileStore });
135
163
  }
136
164
 
137
- if (archiverL1BlockNumber && snapshot.l1BlockNumber < archiverL1BlockNumber) {
138
- log.verbose(
139
- `Skipping snapshot sync since local archiver is at L1 block ${archiverL1BlockNumber} which is further than last snapshot at ${snapshot.l1BlockNumber}`,
140
- { snapshot, archiverL1BlockNumber },
141
- );
165
+ if (snapshotCandidates.length === 0) {
166
+ log.verbose(`No valid snapshots found from any URL. Skipping snapshot sync.`, { ...indexMetadata, snapshotsUrls });
142
167
  return false;
143
168
  }
144
169
 
145
- if (archiverL1BlockNumber && snapshot.l1BlockNumber - Number(archiverL1BlockNumber) < minL1BlocksToTriggerReplace) {
146
- log.verbose(
147
- `Skipping snapshot sync as archiver is less than ${
148
- snapshot.l1BlockNumber - Number(archiverL1BlockNumber)
149
- } L1 blocks behind latest snapshot.`,
150
- { snapshot, archiverL1BlockNumber },
151
- );
152
- return false;
170
+ // Sort candidates by L1 block number (highest first)
171
+ snapshotCandidates.sort((a, b) => b.snapshot.l1BlockNumber - a.snapshot.l1BlockNumber);
172
+
173
+ // Try each candidate in order until one succeeds
174
+ for (const { snapshot, url } of snapshotCandidates) {
175
+ const { l1BlockNumber, l2BlockNumber } = snapshot;
176
+ log.info(`Attempting to sync from snapshot at L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, {
177
+ snapshot,
178
+ snapshotsUrl: url,
179
+ });
180
+
181
+ try {
182
+ await snapshotSync(snapshot, log, {
183
+ dataDirectory: config.dataDirectory!,
184
+ rollupAddress: config.l1Contracts.rollupAddress,
185
+ snapshotsUrl: url,
186
+ });
187
+ log.info(`Snapshot synced to L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, {
188
+ snapshot,
189
+ snapshotsUrl: url,
190
+ });
191
+ return true;
192
+ } catch (err) {
193
+ log.error(`Failed to download snapshot from ${url}. Trying next candidate.`, err, {
194
+ snapshot,
195
+ snapshotsUrl: url,
196
+ });
197
+ continue;
198
+ }
153
199
  }
154
200
 
155
- const { l1BlockNumber, l2BlockNumber } = snapshot;
156
- log.info(`Syncing from snapshot at L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, { snapshot, snapshotsUrl });
157
- await snapshotSync(snapshot, log, {
158
- dataDirectory: config.dataDirectory!,
159
- rollupAddress: config.l1Contracts.rollupAddress,
160
- snapshotsUrl,
161
- });
162
- log.info(`Snapshot synced to L1 block ${l1BlockNumber} L2 block ${l2BlockNumber}`, { snapshot });
163
- return true;
201
+ log.error(`Failed to download snapshot from all URLs.`, { snapshotsUrls });
202
+ return false;
164
203
  }
165
204
 
166
205
  /**
@@ -7,8 +7,8 @@ export type SharedNodeConfig = {
7
7
  sponsoredFPC: boolean;
8
8
  /** Sync mode: full to always sync via L1, snapshot to download a snapshot if there is no local data, force-snapshot to download even if there is local data. */
9
9
  syncMode: 'full' | 'snapshot' | 'force-snapshot';
10
- /** Base URL for snapshots index. Index file will be searched at `SNAPSHOTS_BASE_URL/aztec-L1_CHAIN_ID-VERSION-ROLLUP_ADDRESS/index.json` */
11
- snapshotsUrl?: string;
10
+ /** Base URLs for snapshots index. Index file will be searched at `SNAPSHOTS_BASE_URL/aztec-L1_CHAIN_ID-VERSION-ROLLUP_ADDRESS/index.json` */
11
+ snapshotsUrls?: string[];
12
12
 
13
13
  /** Auto update mode: disabled - to completely ignore remote signals to update the node. enabled - to respect the signals (potentially shutting this node down). log - check for updates but log a warning instead of applying them*/
14
14
  autoUpdate?: 'disabled' | 'notify' | 'config' | 'config-and-version';
@@ -36,9 +36,16 @@ export const sharedNodeConfigMappings: ConfigMappingsType<SharedNodeConfig> = {
36
36
  'Set sync mode to `full` to always sync via L1, `snapshot` to download a snapshot if there is no local data, `force-snapshot` to download even if there is local data.',
37
37
  defaultValue: 'snapshot',
38
38
  },
39
- snapshotsUrl: {
40
- env: 'SYNC_SNAPSHOTS_URL',
41
- description: 'Base URL for snapshots index.',
39
+ snapshotsUrls: {
40
+ env: 'SYNC_SNAPSHOTS_URLS',
41
+ description: 'Base URLs for snapshots index, comma-separated.',
42
+ parseEnv: (val: string) =>
43
+ val
44
+ .split(',')
45
+ .map(url => url.trim())
46
+ .filter(url => url.length > 0),
47
+ fallback: ['SYNC_SNAPSHOTS_URL'],
48
+ defaultValue: [],
42
49
  },
43
50
  autoUpdate: {
44
51
  env: 'AUTO_UPDATE',