diff --git a/docs/src/database-snapshot-guide.md b/docs/src/database-snapshot-guide.md new file mode 100644 index 000000000..4def42482 --- /dev/null +++ b/docs/src/database-snapshot-guide.md @@ -0,0 +1,39 @@ +# Database snapshot guide + +For this guide we will be taking a snapshot of a parachain and relay chain. Please note we are using a local chain here `rococo_local_testnet` and `local_testnet`. Live chains will have different values + +*Please ensure that the database is not in current use, i.e no nodes are writing to it* + +# How to prepare database for a relaychain +To prepare snapshot for a relay chain we need to copy the database. + +``` +mkdir -p relaychain-snapshot/alice/data/chains/rococo_local_testnet/db/ + +cp -r chain-data/alice/data/chains/rococo_local_testnet/db/ relaychain-snapshot/alice/data/chains/rococo_local_testnet/db/ + +tar -C relaychain-snapshot/alice/ -czf relaychain.tgz data +``` +# How to prepare database for a parachain + +To prepare snapshot for a parachain we need to copy the database for both the collator node (parachain data) and validator (relay data) + +``` +#Parachain data +mkdir -p parachain-snapshot/charlie/data/chains/local_testnet/db/ + +# Relay data +mkdir -p parachain-snapshot/charlie/relay-data/chains/rococo_local_testnet/db/ + + +cp -r chain-data/charlie/data/chains/local_testnet/db/ parachain-snapshot/charlie/data/chains/local_testnet/db/ + + +cp -r chain-data/charlie/relay-data/chains/rococo_local_testnet/db/ parachain-snapshot/charlie/relay-data/chains/rococo_local_testnet/db/ + +tar -C parachain-snapshot/charlie/ -czf parachain.tgz data relay-data +``` + +# Restoring a snapshot +Zombienet will automatically download the `*.tgz` file to the respective folder for a run. However you can also download it manually, just ensure you extract the tar file in the correct directory, i.e. the root directory +`chain-data/charlie/` \ No newline at end of file diff --git a/javascript/packages/orchestrator/src/configGenerator.ts b/javascript/packages/orchestrator/src/configGenerator.ts index a2805ae7e..1267edc65 100644 --- a/javascript/packages/orchestrator/src/configGenerator.ts +++ b/javascript/packages/orchestrator/src/configGenerator.ts @@ -530,6 +530,7 @@ async function getCollatorNodeFromConfig( overrides: [], zombieRole: cumulusBased ? "cumulus-collator" : "collator", parachainId: para_id, + dbSnapshot: collatorConfig.db_snapshot, imagePullPolicy: networkSpec.settings.image_pull_policy || "Always", ...ports, externalPorts, diff --git a/javascript/packages/orchestrator/src/orchestrator.ts b/javascript/packages/orchestrator/src/orchestrator.ts index 0274501d6..a26d88322 100644 --- a/javascript/packages/orchestrator/src/orchestrator.ts +++ b/javascript/packages/orchestrator/src/orchestrator.ts @@ -261,6 +261,38 @@ export async function start( const chainSpecContent = require(chainSpecFullPathPlain); client.chainId = chainSpecContent.id; + const parachainFilesPromiseGenerator = async (parachain: Parachain) => { + const parachainFilesPath = `${tmpDir.path}/${parachain.name}`; + await makeDir(parachainFilesPath); + await generateParachainFiles( + namespace, + tmpDir.path, + parachainFilesPath, + chainName, + parachain, + ); + }; + + const parachainPromiseGenerators = networkSpec.parachains.map( + (parachain: Parachain) => { + return () => parachainFilesPromiseGenerator(parachain); + }, + ); + + await series(parachainPromiseGenerators, opts.spawnConcurrency); + for (const parachain of networkSpec.parachains) { + const parachainFilesPath = `${tmpDir.path}/${parachain.name}`; + const stateLocalFilePath = `${parachainFilesPath}/${GENESIS_STATE_FILENAME}`; + const wasmLocalFilePath = `${parachainFilesPath}/${GENESIS_WASM_FILENAME}`; + if (parachain.addToGenesis) + await addParachainToGenesis( + chainSpecFullPathPlain, + parachain.id.toString(), + stateLocalFilePath, + wasmLocalFilePath, + ); + } + if (!chainSpecContent.genesis.raw) { // Chain spec customization logic const relayChainSpec = readAndParseChainSpec(chainSpecFullPathPlain); @@ -314,37 +346,6 @@ export async function start( ); } - const parachainFilesPromiseGenerator = async (parachain: Parachain) => { - const parachainFilesPath = `${tmpDir.path}/${parachain.name}`; - await makeDir(parachainFilesPath); - await generateParachainFiles( - namespace, - tmpDir.path, - parachainFilesPath, - chainName, - parachain, - ); - }; - const parachainPromiseGenerators = networkSpec.parachains.map( - (parachain: Parachain) => { - return () => parachainFilesPromiseGenerator(parachain); - }, - ); - - await series(parachainPromiseGenerators, opts.spawnConcurrency); - for (const parachain of networkSpec.parachains) { - const parachainFilesPath = `${tmpDir.path}/${parachain.name}`; - const stateLocalFilePath = `${parachainFilesPath}/${GENESIS_STATE_FILENAME}`; - const wasmLocalFilePath = `${parachainFilesPath}/${GENESIS_WASM_FILENAME}`; - if (parachain.addToGenesis) - await addParachainToGenesis( - chainSpecFullPathPlain, - parachain.id.toString(), - stateLocalFilePath, - wasmLocalFilePath, - ); - } - if (networkSpec.hrmp_channels) { await addHrmpChannelsToGenesis( chainSpecFullPathPlain, diff --git a/javascript/packages/orchestrator/src/providers/native/nativeClient.ts b/javascript/packages/orchestrator/src/providers/native/nativeClient.ts index 3c5d92f7f..79d318586 100644 --- a/javascript/packages/orchestrator/src/providers/native/nativeClient.ts +++ b/javascript/packages/orchestrator/src/providers/native/nativeClient.ts @@ -278,12 +278,12 @@ export class NativeClient extends Client { if (dbSnapshot) { // we need to get the snapshot from a public access // and extract to /data - await makeDir(`${podDef.spec.dataPath}/chains`, true); + await makeDir(`${podDef.spec.dataPath}`, true); - await downloadFile(dbSnapshot, `${podDef.spec.dataPath}/chains/db.tgz`); + await downloadFile(dbSnapshot, `${podDef.spec.dataPath}/db.tgz`); await this.runCommand([ "-c", - `cd ${podDef.spec.dataPath}/chains && tar -xzvf db.tgz`, + `cd ${podDef.spec.dataPath}/.. && tar -xzvf data/db.tgz`, ]); } diff --git a/javascript/packages/orchestrator/src/providers/podman/podmanClient.ts b/javascript/packages/orchestrator/src/providers/podman/podmanClient.ts index 8ac63e841..55f02c5a7 100644 --- a/javascript/packages/orchestrator/src/providers/podman/podmanClient.ts +++ b/javascript/packages/orchestrator/src/providers/podman/podmanClient.ts @@ -377,10 +377,10 @@ export class PodmanClient extends Client { // and extract to /data await makeDir(`${dataPath.hostPath.path}/chains`, true); - await downloadFile(dbSnapshot, `${dataPath.hostPath.path}/chains/db.tgz`); + await downloadFile(dbSnapshot, `${dataPath.hostPath.path}/db.tgz`); await execa("bash", [ "-c", - `cd ${dataPath.hostPath.path}/chains && tar -xzvf db.tgz`, + `cd ${dataPath.hostPath.path}/.. && tar -xzvf data/db.tgz`, ]); }