@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.
- package/dest/actions/snapshot-sync.d.ts +2 -1
- package/dest/actions/snapshot-sync.d.ts.map +1 -1
- package/dest/actions/snapshot-sync.js +89 -54
- package/dest/config/index.d.ts +2 -2
- package/dest/config/index.d.ts.map +1 -1
- package/dest/config/index.js +8 -3
- package/package.json +19 -19
- package/src/actions/snapshot-sync.ts +101 -62
- package/src/config/index.ts +12 -5
|
@@ -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'
|
|
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,
|
|
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,
|
|
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 (!
|
|
26
|
-
log.verbose('Snapshot sync is disabled. No snapshots
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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 (
|
|
87
|
-
log.verbose(`No
|
|
125
|
+
if (snapshotCandidates.length === 0) {
|
|
126
|
+
log.verbose(`No valid snapshots found from any URL. Skipping snapshot sync.`, {
|
|
88
127
|
...indexMetadata,
|
|
89
|
-
|
|
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
|
-
|
|
109
|
-
|
|
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
|
-
|
|
139
|
+
snapshotsUrl: url
|
|
112
140
|
});
|
|
113
|
-
|
|
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
|
-
|
|
116
|
-
|
|
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
|
|
163
|
+
return false;
|
|
129
164
|
}
|
|
130
165
|
/**
|
|
131
166
|
* Downloads the given snapshot replacing any local data stores.
|
package/dest/config/index.d.ts
CHANGED
|
@@ -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
|
|
10
|
-
|
|
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,
|
|
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"}
|
package/dest/config/index.js
CHANGED
|
@@ -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
|
-
|
|
19
|
-
env: '
|
|
20
|
-
description: 'Base
|
|
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.
|
|
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.
|
|
58
|
-
"@aztec/bb-prover": "3.0.0-nightly.
|
|
59
|
-
"@aztec/blob-sink": "3.0.0-nightly.
|
|
60
|
-
"@aztec/constants": "3.0.0-nightly.
|
|
61
|
-
"@aztec/epoch-cache": "3.0.0-nightly.
|
|
62
|
-
"@aztec/ethereum": "3.0.0-nightly.
|
|
63
|
-
"@aztec/foundation": "3.0.0-nightly.
|
|
64
|
-
"@aztec/kv-store": "3.0.0-nightly.
|
|
65
|
-
"@aztec/merkle-tree": "3.0.0-nightly.
|
|
66
|
-
"@aztec/p2p": "3.0.0-nightly.
|
|
67
|
-
"@aztec/protocol-contracts": "3.0.0-nightly.
|
|
68
|
-
"@aztec/prover-client": "3.0.0-nightly.
|
|
69
|
-
"@aztec/sequencer-client": "3.0.0-nightly.
|
|
70
|
-
"@aztec/simulator": "3.0.0-nightly.
|
|
71
|
-
"@aztec/stdlib": "3.0.0-nightly.
|
|
72
|
-
"@aztec/telemetry-client": "3.0.0-nightly.
|
|
73
|
-
"@aztec/validator-client": "3.0.0-nightly.
|
|
74
|
-
"@aztec/world-state": "3.0.0-nightly.
|
|
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'
|
|
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,
|
|
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 (!
|
|
49
|
-
log.verbose('Snapshot sync is disabled. No snapshots
|
|
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
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
99
|
+
// Fetch latest snapshot from each URL
|
|
100
|
+
type SnapshotCandidate = { snapshot: SnapshotMetadata; url: string; fileStore: ReadOnlyFileStore };
|
|
101
|
+
const snapshotCandidates: SnapshotCandidate[] = [];
|
|
120
102
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
)
|
|
126
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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 (
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
156
|
-
|
|
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
|
/**
|
package/src/config/index.ts
CHANGED
|
@@ -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
|
|
11
|
-
|
|
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
|
-
|
|
40
|
-
env: '
|
|
41
|
-
description: 'Base
|
|
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',
|