Skip to content
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

Restore snapshots to parachains #673

Merged
merged 16 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/src/database-snapshot-guide.md
Original file line number Diff line number Diff line change
@@ -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/`
1 change: 1 addition & 0 deletions javascript/packages/orchestrator/src/configGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 32 additions & 31 deletions javascript/packages/orchestrator/src/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,38 @@ export async function start(
const chainSpecContent = require(chainSpecFullPathPlain);
client.chainId = chainSpecContent.id;

const parachainFilesPromiseGenerator = async (parachain: Parachain) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a reorder in the code, or I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a reorder because we need to generate the parachain files, and since the relay chain we provided isnt raw, these codeblock does not run and the cumulus parachains fail to get created

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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
]);
}

Expand Down