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

Wire between Orchestrator - Provider #101

Merged
merged 100 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
776226e
wip, refactor provider trait
pepoviola Aug 8, 2023
5ff367e
fmt
pepoviola Aug 8, 2023
f99f009
wip
l0r1s Aug 14, 2023
95816cb
wip, add from_config to NetworkSpec
pepoviola Aug 24, 2023
92f6ccc
config reorgs
pepoviola Aug 24, 2023
a8bce1d
add logic for create NetworkSpec
pepoviola Aug 24, 2023
b20050e
feat: refactored FileSystem trait and errors
l0r1s Aug 28, 2023
6a7c8de
chore: removed unused local_file, stdout will be hardcoded in provide…
l0r1s Aug 28, 2023
9b010bb
feat: moved MockFileSystem to InMemoryFileSystem, files too, and adde…
l0r1s Aug 28, 2023
7549c71
feat: added new method append to FileSystem trait
l0r1s Aug 29, 2023
12371a2
feat: implemented new append method on InMemoryFileSystem
l0r1s Aug 29, 2023
4a02844
feat: added anyhow dependencies to support crate
l0r1s Aug 31, 2023
7aa5d07
feat: refactored FileSystem trait to expose only a single wrapped error
l0r1s Aug 31, 2023
b9004ff
feat: refacto InMemoryFileSystem following FileSystem trait refacto
l0r1s Aug 31, 2023
ca9932a
feat: added conversion between io::Error and FileSystemError
l0r1s Sep 1, 2023
08e2571
feat: added implementation of LocalFileSystem using tokio::fs
l0r1s Sep 1, 2023
cf5e9ba
feat: added nix crate dependency to workspace and provider crate
l0r1s Sep 2, 2023
061abe2
feat: added uuid with v4 as dev-dependencies for testing in support c…
l0r1s Sep 2, 2023
c9ee23c
feat: added unit tests for LocalFileSystem
l0r1s Sep 2, 2023
e993090
feat: updated Provider, ProviderNamespace and ProviderNode traits and…
l0r1s Sep 3, 2023
d0657c0
feat: added anyhow as dependency to provider crate
l0r1s Sep 3, 2023
b773d9d
feat: updated ProviderError
l0r1s Sep 3, 2023
9ff812a
feat: work on NativeProvider with individual Node, Namespace and Prov…
l0r1s Sep 3, 2023
0910156
feat: rename some provider constants
l0r1s Sep 3, 2023
19846cb
Merge pull request #99 from paritytech/refactor/provider-trait-l0r1s
l0r1s Sep 3, 2023
665a447
wip
pepoviola Sep 5, 2023
0f28ee7
feat: added uuid with v4 features as normal dependency
l0r1s Sep 6, 2023
8f69cee
feat: added new set_mode method on FileSystem trait to modify permiss…
l0r1s Sep 6, 2023
81a3046
feat: added builder for options types used in provider traits methods…
l0r1s Sep 6, 2023
c2173da
feat: added modified implementation of run_script/run_command/copy_fr…
l0r1s Sep 6, 2023
8b4bd1e
feat: moved filesystem, capabilities and tmp_dir out of NativeProvide…
l0r1s Sep 9, 2023
e1596d1
wip on network spec creation
pepoviola Sep 11, 2023
03862e5
move chain_spec to generators
pepoviola Sep 11, 2023
dee3140
change defaults for validator/invulnerable settings
pepoviola Sep 11, 2023
279373c
Add test and clean-ups
pepoviola Sep 11, 2023
3326479
nits and clean
pepoviola Sep 11, 2023
002ab11
fmt
pepoviola Sep 11, 2023
7fd3ee6
fmt
pepoviola Sep 11, 2023
a3a9da5
fix docs/clippy
pepoviola Sep 11, 2023
200361d
fixes from clippy
pepoviola Sep 11, 2023
8ff4cf0
add TODO and allow dead_code for now
pepoviola Sep 11, 2023
e80205c
fmt
pepoviola Sep 11, 2023
0ad56a5
more nits
pepoviola Sep 11, 2023
5ba4baf
fmt
pepoviola Sep 11, 2023
a7b7660
Merge branch 'refactor/provider-trait' into feat/glue/network-spec_pr…
pepoviola Sep 11, 2023
705aaa7
feat: make constructors and fields public for testing on InMemoryFile…
l0r1s Sep 12, 2023
9c801a3
feat: removed unused types atm and added TransferedFile
l0r1s Sep 12, 2023
d6bedff
feat: updated types for Provider methods output, updated non needed a…
l0r1s Sep 12, 2023
7adb937
feat: added generate_files implementation on namespace using temporar…
l0r1s Sep 12, 2023
d9ee632
feat: removed comment
l0r1s Sep 12, 2023
d656be7
feat: refactored provider types and added builders
l0r1s Sep 12, 2023
8df6de3
Merge branch 'refactor/provider-trait' into feat/glue/network-spec_pr…
pepoviola Sep 13, 2023
9de861e
feat(orchestrator) add generators
pepoviola Sep 19, 2023
24dc439
feat(orchestrator) add logic to compute the network spec
pepoviola Sep 19, 2023
a7c7da1
small changes in provider trait and native impl
pepoviola Sep 19, 2023
b430982
wip, example to drive exec
pepoviola Sep 19, 2023
b4124fc
make paras working, first design draft of network public api
pepoviola Sep 23, 2023
20ad6a8
cleanups
pepoviola Sep 23, 2023
417469a
add spawner
pepoviola Sep 25, 2023
2e62848
add logic to add new nodes to running network and methods on nodes
pepoviola Sep 25, 2023
5306c5b
modify example
pepoviola Sep 25, 2023
de6a502
fmt
pepoviola Sep 25, 2023
9b9baa8
allow to add collators to a running network
pepoviola Sep 25, 2023
20fae90
modify example
pepoviola Sep 25, 2023
037df74
move Network related structs
pepoviola Sep 25, 2023
5e7124c
reorg code
pepoviola Sep 25, 2023
e7ed8f5
fmt
pepoviola Sep 25, 2023
6253202
resolve and merge main
pepoviola Sep 26, 2023
128734f
fixes and clean-up
pepoviola Sep 26, 2023
fd57449
removed commented code
pepoviola Sep 26, 2023
62c6f15
clippy
pepoviola Sep 26, 2023
92e21d5
fmt
pepoviola Sep 26, 2023
359b520
clippy
pepoviola Sep 27, 2023
ff8ed13
fmt
pepoviola Sep 27, 2023
45ced02
clippy in example
pepoviola Sep 27, 2023
1e86d19
fix validator/invulnerable true as default
pepoviola Sep 27, 2023
f85ac13
fmt
pepoviola Sep 27, 2023
3a70d05
fix base_dir for mac/linux compat
pepoviola Sep 27, 2023
f215d2a
fix, allow generate files with fullpaths (encapsualate as part of the…
pepoviola Sep 27, 2023
61089fb
Add todos
pepoviola Sep 27, 2023
0f7c960
fix p2p port for full_node in collator
pepoviola Sep 27, 2023
709e0cc
fix p2p port for full_node in collator
pepoviola Sep 27, 2023
5ea2b1a
clippy
pepoviola Sep 27, 2023
545d2ac
fmt
pepoviola Sep 27, 2023
bc89de2
Update crates/orchestrator/src/network_spec/node.rs
pepoviola Sep 27, 2023
ce91dc5
Update crates/orchestrator/src/network_spec/relaychain.rs
pepoviola Sep 27, 2023
8fccef7
Update crates/orchestrator/src/generators/chain_spec.rs
pepoviola Sep 27, 2023
04aab70
Update crates/examples/examples/small_network_with_default.rs
pepoviola Sep 27, 2023
369b8ae
Update crates/orchestrator/src/generators/bootnode_addr.rs
pepoviola Sep 27, 2023
a6aabee
Update crates/orchestrator/src/network_spec/node.rs
pepoviola Sep 27, 2023
336d3e5
Update crates/orchestrator/src/network_spec/node.rs
pepoviola Sep 27, 2023
6f4893f
Update crates/orchestrator/src/network_spec/relaychain.rs
pepoviola Sep 27, 2023
86980c6
changes from feedback
pepoviola Sep 27, 2023
bbaa0b0
reorg deps
pepoviola Sep 27, 2023
cbab02f
clippy/fmt
pepoviola Sep 27, 2023
b856930
reorg generators and add some unittest
pepoviola Sep 28, 2023
292292e
more unittest and cleans
pepoviola Sep 28, 2023
692453a
fmt/clippy
pepoviola Sep 28, 2023
7b72636
fmt/clippy
pepoviola Sep 28, 2023
9d7a107
add TODOs from feedback
pepoviola Sep 29, 2023
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
2 changes: 1 addition & 1 deletion crates/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod utils;
pub use global_settings::{GlobalSettings, GlobalSettingsBuilder};
pub use hrmp_channel::{HrmpChannelConfig, HrmpChannelConfigBuilder};
pub use network::{NetworkConfig, NetworkConfigBuilder};
pub use parachain::{ParachainConfig, ParachainConfigBuilder};
pub use parachain::{ParachainConfig, ParachainConfigBuilder, RegistrationStrategy};
pub use relaychain::{RelaychainConfig, RelaychainConfigBuilder};
// re-export shared
pub use shared::{node::NodeConfig, types};
18 changes: 12 additions & 6 deletions crates/configuration/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,15 +753,11 @@ mod tests {
.with_default_command("polkadot")
.with_default_image("docker.io/parity/polkadot:latest")
.with_default_args(vec![("-lparachain", "debug").into()])
.with_node(|node| {
node.with_name("alice")
.validator(true)
.invulnerable(true)
.validator(true)
})
.with_node(|node| node.with_name("alice").validator(true))
.with_node(|node| {
node.with_name("bob")
.validator(true)
.invulnerable(false)
.bootnode(true)
.with_args(vec![("--database", "paritydb-experimental").into()])
})
Expand Down Expand Up @@ -822,6 +818,7 @@ mod tests {
.with_collator(|collator| {
collator
.with_name("charles")
.validator(false)
.bootnode(true)
.invulnerable(true)
.with_initial_balance(0)
Expand All @@ -830,6 +827,7 @@ mod tests {
collator
.with_name("frank")
.validator(true)
.invulnerable(false)
.bootnode(true)
.with_initial_balance(1_000_000_000)
})
Expand All @@ -850,6 +848,7 @@ mod tests {
.with_collator(|collator| {
collator
.with_name("georges")
.validator(false)
.bootnode(true)
.invulnerable(true)
.with_initial_balance(0)
Expand All @@ -858,6 +857,7 @@ mod tests {
collator
.with_name("victor")
.validator(true)
.invulnerable(false)
.bootnode(true)
.with_initial_balance(1_000_000_000)
})
Expand Down Expand Up @@ -947,6 +947,7 @@ mod tests {
.with_collator(|collator| {
collator
.with_name("charles")
.validator(false)
.bootnode(true)
.invulnerable(true)
.with_initial_balance(0)
Expand Down Expand Up @@ -1088,13 +1089,15 @@ mod tests {
collator
.with_name("charles")
.bootnode(true)
.validator(false)
.invulnerable(true)
.with_initial_balance(0)
})
.with_collator(|collator| {
collator
.with_name("frank")
.validator(true)
.invulnerable(false)
.bootnode(true)
.with_initial_balance(1_000_000_000)
})
Expand All @@ -1116,13 +1119,15 @@ mod tests {
collator
.with_name("georges")
.bootnode(true)
.validator(false)
.invulnerable(true)
.with_initial_balance(0)
})
.with_collator(|collator| {
collator
.with_name("victor")
.validator(true)
.invulnerable(false)
.bootnode(true)
.with_initial_balance(1_000_000_000)
})
Expand Down Expand Up @@ -1323,6 +1328,7 @@ mod tests {
collator
.with_name("charles")
.bootnode(true)
.validator(false)
.invulnerable(true)
.with_initial_balance(0)
})
Expand Down
17 changes: 10 additions & 7 deletions crates/configuration/src/shared/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ use super::{
resources::ResourcesBuilder,
types::{AssetLocation, ChainDefaultContext, Command, Image, ValidationContext, U128},
};
use crate::shared::{
resources::Resources,
types::{Arg, Port},
use crate::{
shared::{
resources::Resources,
types::{Arg, Port},
},
utils::default_as_true,
};

/// An environment variable with a name and a value.
Expand Down Expand Up @@ -59,9 +62,9 @@ pub struct NodeConfig {
pub(crate) command: Option<Command>,
#[serde(default)]
args: Vec<Arg>,
#[serde(alias = "validator")]
#[serde(alias = "validator", default = "default_as_true")]
pub(crate) is_validator: bool,
#[serde(alias = "invulnerable")]
#[serde(alias = "invulnerable", default = "default_as_true")]
pub(crate) is_invulnerable: bool,
#[serde(alias = "bootnode")]
pub(crate) is_bootnode: bool,
Expand Down Expand Up @@ -263,8 +266,8 @@ impl Default for NodeConfigBuilder<Initial> {
image: None,
command: None,
args: vec![],
is_validator: false,
is_invulnerable: false,
is_validator: true,
is_invulnerable: true,
pepoviola marked this conversation as resolved.
Show resolved Hide resolved
is_bootnode: false,
initial_balance: 2_000_000_000_000.into(),
env: vec![],
Expand Down
2 changes: 1 addition & 1 deletion crates/configuration/src/shared/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ impl Command {
/// let url_location2: AssetLocation = "https://mycloudstorage.com/path/to/my/file.tgz".into();
/// let path_location: AssetLocation = PathBuf::from_str("/tmp/path/to/my/file").unwrap().into();
/// let path_location2: AssetLocation = "/tmp/path/to/my/file".into();
///
///
/// assert!(matches!(url_location, AssetLocation::Url(value) if value.as_str() == "https://mycloudstorage.com/path/to/my/file.tgz"));
/// assert!(matches!(url_location2, AssetLocation::Url(value) if value.as_str() == "https://mycloudstorage.com/path/to/my/file.tgz"));
/// assert!(matches!(path_location, AssetLocation::FilePath(value) if value.to_str().unwrap() == "/tmp/path/to/my/file"));
Expand Down
6 changes: 6 additions & 0 deletions crates/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ edition = "2021"

[dependencies]
configuration = { path = "../configuration" }
orchestrator = { path = "../orchestrator" }
provider = { path = "../provider" }
# TODO: we shouldn't need to pull from support, we need
# to review the exports for neeeded types
support = { path = "../support" }
Copy link
Collaborator Author

@pepoviola pepoviola Sep 26, 2023

Choose a reason for hiding this comment

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

Support types needed by external users should be re-exported by the orchestrator.
we should add a //TODO to track this.

Copy link
Contributor

@l0r1s l0r1s Sep 27, 2023

Choose a reason for hiding this comment

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

Maybe having a wrapper "zombienet" crate organizing all re-exports and features could be good, wdyt ? We could use it like this:

zombienet = { version = "0.1", features = ["k8s-provider"] }

or

zombienet = { version = "0.1", features = ["native-provider" }

And at the beginning, we can defined "local-fs", "logging", and some others options as default-features

tokio = { workspace = true }
60 changes: 56 additions & 4 deletions crates/examples/examples/small_network_with_default.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,66 @@
use std::time::Duration;

use configuration::NetworkConfigBuilder;
use orchestrator::{AddNodeOpts, Orchestrator};
use provider::NativeProvider;
use support::fs::local::LocalFileSystem;

fn main() {
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = NetworkConfigBuilder::new()
.with_relaychain(|r| {
r.with_chain("rococo-local")
.with_default_command("polkadot")
.with_node(|node| node.with_name("alice"))
.with_node(|node| node.with_name("name"))
.with_node(|node| node.with_name("bob"))
})
.with_parachain(|p| {
p.with_id(100).cumulus_based(true).with_collator(|n| {
n.with_name("collator").with_command("polkadot-parachain")
//.with_command("adder-collator")
pepoviola marked this conversation as resolved.
Show resolved Hide resolved
})
})
.build();
.build()
.unwrap();

println!("{:?}", &config);
pepoviola marked this conversation as resolved.
Show resolved Hide resolved

let fs = LocalFileSystem;
let provider = NativeProvider::new(fs.clone());
let orchestrator = Orchestrator::new(fs, provider);
let mut network = orchestrator.spawn(config).await?;
println!("🚀🚀🚀🚀 network deployed");
// add a new node
let opts = AddNodeOpts {
rpc_port: Some(9444),
is_validator: true,
..Default::default()
};
Comment on lines +31 to +35
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should define a impl AddNodeOpts to build is without having to call Default::default()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this will be an external API so we can add some builder for AddNodeOpts. (could be in a following pr)


// TODO: add check to ensure if unique
network.add_node("new1", opts, None).await?;

tokio::time::sleep(Duration::from_secs(5)).await;

// pause the node
network.pause_node("new1").await?;
println!("node new1 paused!");
pepoviola marked this conversation as resolved.
Show resolved Hide resolved

tokio::time::sleep(Duration::from_secs(5)).await;

network.resume_node("new1").await?;
println!("node new1 resumed!");
pepoviola marked this conversation as resolved.
Show resolved Hide resolved

let col_opts = AddNodeOpts {
command: Some("polkadot-parachain".try_into()?),
..Default::default()
};
network.add_node("new-col-1", col_opts, Some(100)).await?;
println!("new collator deployed!");

// For now let just loop....
#[allow(clippy::empty_loop)]
loop {}
Comment on lines +60 to +62
Copy link
Contributor

@l0r1s l0r1s Sep 27, 2023

Choose a reason for hiding this comment

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

We need to fix this in some way, I have ideas about exposing a .wait method on ProviderNode and have differents implementations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, this is just an example entrypoint that should be replaced by the cli in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean add some wait for each node? you also need to think that in k8s/podman we will not have a running process as we have in native. I think this is more an exploration we need to do as part of the cli crate.


println!("{:?}", config.unwrap());
// Ok(())
}
16 changes: 16 additions & 0 deletions crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
configuration = { path = "../configuration" }
support = { path = "../support" }
provider = { path = "../provider" }
tokio = { workspace = true, features = ["time"] }
thiserror = { workspace = true }
# TODO: add logger in a new pr.
#log = { workspace = true }
multiaddr = { workspace = true }
rand = "0.8"
sha2 = { version = "0.10.2", default-features = false }
hex = "0.4"
sp-core = "22.0.0"
serde_json = { workspace = true }
futures = { workspace = true }
libp2p = { version = "0.52" }
Copy link
Contributor

@l0r1s l0r1s Sep 27, 2023

Choose a reason for hiding this comment

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

We should probably hoist all dependencies to workspace Cargo.toml to enable other crates to have synchronized versions, it doesn't cost anything and make things cleaner imho, wdyt ? That way, when we need to update dependencies, we only have a single source of truth

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we should move it to the main Cargo.toml and use only the needed here. I will change it today.

anyhow = { workspace = true }
27 changes: 27 additions & 0 deletions crates/orchestrator/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//! Zombienet Orchestrator error definitions.

use provider::ProviderError;
use support::fs::FileSystemError;

use crate::generators;

#[derive(Debug, thiserror::Error)]
pub enum OrchestratorError {
// TODO: improve invalid config reporting
#[error("Invalid network configuration: {0}")]
InvalidConfig(String),
#[error("Invalid configuration for node: {0}, field: {1}")]
InvalidNodeConfig(String, String),
#[error("Invariant not fulfilled {0}")]
InvariantError(&'static str),
#[error("Global network spawn timeout: {0} secs")]
GlobalTimeOut(u32),
#[error("Generator error")]
GeneratorError(#[from] generators::errors::GeneratorError),
#[error("Provider error")]
ProviderError(#[from] ProviderError),
#[error("FileSystem error")]
FileSystemError(#[from] FileSystemError),
#[error(transparent)]
SpawnerError(#[from] anyhow::Error),
}
9 changes: 9 additions & 0 deletions crates/orchestrator/src/generators.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub mod bootnode_addr;
pub mod chain_spec;
pub mod command;
pub mod errors;
pub mod identity;
pub mod key;
pub mod keystore;
pub mod para_artifact;
pub mod port;
34 changes: 34 additions & 0 deletions crates/orchestrator/src/generators/bootnode_addr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::net::IpAddr;

use super::errors::GeneratorError;

pub fn generate(
peer_id: &str,
ip: &IpAddr,
port: u16,
args: &[&String],
p2p_cert: &Option<String>,
) -> Result<String, GeneratorError> {
let addr = if let Some(index) = args.iter().position(|arg| (*arg).eq("--lister-addr")) {
pepoviola marked this conversation as resolved.
Show resolved Hide resolved
let listen_value = args
.get(index + 1)
.ok_or(GeneratorError::BootnodeAddrGeneration(
"can not generate bootnode address from args".into(),
))?;
let ip_str = ip.to_string();
let port_str = port.to_string();
let mut parts = listen_value.split('/').collect::<Vec<&str>>();
parts[2] = ip_str.as_str();
parts[4] = port_str.as_str();
let mut addr = parts.join("/");
if let Some(p2p_cert) = p2p_cert {
addr.push_str("/certhash/");
addr.push_str(p2p_cert)
}
addr
} else {
format!("/ip4/{ip}/tcp/{port}/ws")
};

Ok(format!("{addr}/p2p/{peer_id}"))
}
Loading