Skip to content
Draft
Changes from 1 commit
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
114 changes: 114 additions & 0 deletions sketch.rs
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,
Copy link
Copy Markdown

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Collaborator

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 Shareable as default?
Thx!

Copy link
Copy Markdown
Contributor Author

@michalkucharczyk michalkucharczyk May 25, 2026

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:

  • snapshot contain the keystore and networking directory,
  • the same snapshot was used for alice and bob nodes,
  • this led to problems with the liveliness of the network (basically network was not progressing).

This approach was incorrect.

So when generating the snapshot we can take two approaches:

  • we always snapshot DB directory only, and always re-generated the keys (consensus + p2p),
    OR:
  • we also allow to take a "full" snapshot for every node individually and then replicate the nodes from the snapshot (so we have per-node snapshot). This could provide some means for scenarios when we want to have full control over the node's directory content.

For now we only have use-cases for shared snapshots.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe set Shareable as default?

0a04d26

Copy link
Copy Markdown
Collaborator

@pepoviola pepoviola May 25, 2026

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)

Copy link
Copy Markdown
Contributor Author

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?

/// 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>;
Comment thread
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,
}
Loading