-
Notifications
You must be signed in to change notification settings - Fork 16
[sketch] API for snapshot generation #542
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
Draft
michalkucharczyk
wants to merge
2
commits into
main
Choose a base branch
from
mku-snapshot-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // crates/orchestrator/src/network/node.rs | ||
|
|
||
| impl NetworkNode { | ||
| /// Tar this node's database into `out_path` (gzip). Archive layout: | ||
| /// `data/` at the top, plus `relay-data/` for cumulus collators | ||
| /// (auto-detected from the node's context). Directly consumable by | ||
| /// `with_db_snapshot` on a sibling node. | ||
| /// | ||
| /// The caller is responsible for pausing the node before calling this; | ||
| /// snapshotting a running node risks a torn RocksDB state. | ||
| /// | ||
| /// `kind` controls whether per-node identity (`keystore/`, `network/`) | ||
| /// is included — see [`SnapshotKind`]. | ||
| pub async fn snapshot_db( | ||
| &self, | ||
| out_path: impl AsRef<Path>, | ||
| kind: SnapshotKind, | ||
| ) -> Result<NodeSnapshot, anyhow::Error>; | ||
| } | ||
|
|
||
| /// Identity-handling policy for [`NetworkNode::snapshot_db`]. | ||
| pub enum SnapshotKind { | ||
| /// Includes `keystore/` and `network/`. Safe to load back into a | ||
| /// single node. If consumed by multiple sibling nodes the shared | ||
| /// session keys cause equivocation and the libp2p identity causes | ||
| /// peer-id collisions. | ||
| Full, | ||
| /// Strips `keystore/` and `network/`. Safe to load on any number of | ||
| /// sibling nodes; zombienet re-injects per-node keys at startup via | ||
| /// `author_insertKey`. | ||
| Shareable, | ||
| } | ||
|
|
||
| /// Result of [`NetworkNode::snapshot_db`]. | ||
| pub struct NodeSnapshot { | ||
| /// Absolute path to the produced `.tgz`. | ||
| pub path: PathBuf, | ||
| /// Hex-encoded SHA-256 of the archive contents. | ||
| pub sha256: String, | ||
| /// Size of the archive in bytes. | ||
| pub size: u64, | ||
| /// Name of the node this snapshot was taken from. | ||
| pub node_name: String, | ||
| } | ||
|
|
||
|
|
||
| // crates/orchestrator/src/network.rs | ||
|
|
||
| impl<FS> Network<FS> { | ||
| /// Pause every node in the network (SIGSTOP). Issued in parallel. | ||
| pub async fn pause(&self) -> Result<(), anyhow::Error>; | ||
|
|
||
| /// Resume every node in the network (SIGCONT). Issued in parallel. | ||
| pub async fn resume(&self) -> Result<(), anyhow::Error>; | ||
| } | ||
|
|
||
|
|
||
| // crates/sdk/src/snapshot.rs (new module, re-exported as zombienet_sdk::snapshot) | ||
|
|
||
| /// Assembles a single `bundle.tar.gz` from one or more [`NodeSnapshot`]s | ||
| /// plus a JSON `user_data` blob. The bundle is the unit of upload. | ||
| /// | ||
| /// Layout inside the bundle: | ||
| /// ```text | ||
| /// <archive1>.tgz | ||
| /// <archive2>.tgz | ||
| /// ... | ||
| /// manifest.json // schema: SnapshotManifest | ||
| /// ``` | ||
| pub struct BundleBuilder { /* … */ } | ||
|
|
||
| impl BundleBuilder { | ||
| pub fn new() -> Self; | ||
|
|
||
| /// Add a per-node archive produced by [`NetworkNode::snapshot_db`]. | ||
| pub fn add(self, snap: NodeSnapshot) -> Self; | ||
|
|
||
| /// Attach an arbitrary serializable blob. Stored as JSON under | ||
| /// `user_data` in the manifest. Test authors put block heights, | ||
| /// CIDs, release tags, "number of collators", etc. here. | ||
| pub fn user_data<T: serde::Serialize>(self, data: T) -> Self; | ||
|
|
||
| /// Produce `out_path` (gzipped tarball). Fails if no archives were | ||
| /// added. | ||
| pub fn build(self, out_path: impl AsRef<Path>) -> Result<Bundle, anyhow::Error>; | ||
|
michalkucharczyk marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| /// Result of [`BundleBuilder::build`]. | ||
| pub struct Bundle { | ||
| pub path: PathBuf, | ||
| pub sha256: String, | ||
| pub size: u64, | ||
| } | ||
|
|
||
| /// Schema of `manifest.json` inside the bundle. Versioned — | ||
| /// `schema_version` bumps are breaking changes. | ||
| #[derive(serde::Serialize, serde::Deserialize)] | ||
| pub struct SnapshotManifest { | ||
| pub schema_version: u32, | ||
| /// RFC 3339 timestamp at bundle-build time. | ||
| pub created_at: String, | ||
| pub archives: Vec<ArchiveEntry>, | ||
| /// Caller-provided payload from [`BundleBuilder::user_data`]. | ||
| pub user_data: serde_json::Value, | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize)] | ||
| pub struct ArchiveEntry { | ||
| /// Basename inside the bundle (e.g. `"relaychain-db.tgz"`). | ||
| pub file: String, | ||
| pub sha256: String, | ||
| pub size: u64, | ||
| pub node_name: String, | ||
| } | ||
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.
Do you have a specific use-case in mind for this? I think for existing tests I have not encountered this yet.
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.
No. But I can imagine that such scenario (replicating 1:1 entire source network) will be needed. API can be ready for this.
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.
In general we always inject the keystore (derived from the node name), but we can also add support to not doit iff we have this kind of snap. Maybe set
Shareableas default?Thx!
Uh oh!
There was an error while loading. Please reload this page.
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.
One more comment expaining why I proposed Shared / Full:
The problem with snapshot that was fixed by paritytech/smoldot#3264 was as follows:
This approach was incorrect.
So when generating the snapshot we can take two approaches:
OR:
For now we only have use-cases for shared snapshots.
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.
0a04d26
Uh oh!
There was an error while loading. Please reload this page.
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 think the issue (in smoldot), was a bug on the native provider (https://github.com/paritytech/zombienet-sdk/blob/main/crates/provider/src/native/node.rs#L189-L195), since we are unpacking the snap as last step before initialize the process. In the other providers (docker/k8s), we first unpack the snap and then apply the _startup files (e.g keystore).
I will fix this and ping you.
(#543)
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.
But still - the keys should not be there in the snapshot. We should only have DB there if we don't plan to use keys/networking.
We can also skip the snapshot type in the API. What would be your take on this?