Skip to content

Commit d1fd257

Browse files
authored
feat: fetch polkadot-omni-node with pop up command (#684)
1 parent a4cd6a4 commit d1fd257

File tree

9 files changed

+185
-151
lines changed

9 files changed

+185
-151
lines changed

crates/pop-chains/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ mod generator;
2020
mod new_chain;
2121
/// Tools for creating new runtime pallets.
2222
mod new_pallet;
23+
/// Provides functionality for running runtime-only parachains.
24+
pub mod omni_node;
2325
/// A registry of parachains.
2426
pub mod registry;
2527
/// Relay chain interaction and management.

crates/pop-chains/src/omni_node.rs

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
use pop_common::{
2+
Error,
3+
git::GitHub,
4+
polkadot_sdk::sort_by_latest_semantic_version,
5+
sourcing::{
6+
ArchiveFileSpec, Binary,
7+
GitHub::*,
8+
Source,
9+
filters::prefix,
10+
traits::{
11+
Source as SourceT,
12+
enums::{Source as _, *},
13+
},
14+
},
15+
target,
16+
};
17+
use std::path::PathBuf;
18+
use strum_macros::EnumProperty;
19+
20+
/// CLI enum for managing Polkadot Omni Node binary sources and configuration.
21+
/// Provides repository information and binary specifications for fetching and managing the node.
22+
#[derive(Debug, EnumProperty, PartialEq)]
23+
pub enum PolkadotOmniNodeCli {
24+
#[strum(props(
25+
Repository = "https://github.com/r0gue-io/polkadot",
26+
Binary = "polkadot-omni-node",
27+
TagPattern = "polkadot-{version}",
28+
Fallback = "stable2506-2"
29+
))]
30+
/// Polkadot Omni Node binary. Used to bootstrap parachains without node.
31+
PolkadotOmniNode,
32+
}
33+
34+
impl SourceT for PolkadotOmniNodeCli {
35+
type Error = Error;
36+
/// Creates a Source configuration for fetching the Polkadot Omni Node binary from GitHub.
37+
fn source(&self) -> Result<Source, Error> {
38+
// Source from GitHub release asset
39+
let repo = GitHub::parse(self.repository())?;
40+
let binary = self.binary();
41+
Ok(Source::GitHub(ReleaseArchive {
42+
owner: repo.org,
43+
repository: repo.name,
44+
tag: None,
45+
tag_pattern: self.tag_pattern().map(|t| t.into()),
46+
prerelease: false,
47+
version_comparator: sort_by_latest_semantic_version,
48+
fallback: self.fallback().into(),
49+
archive: format!("{binary}-{}.tar.gz", target()?),
50+
contents: vec![ArchiveFileSpec::new(binary.into(), Some(binary.into()), true)],
51+
latest: None,
52+
}))
53+
}
54+
}
55+
56+
/// Generate the source of the `polkadot-omni-node` binary on the remote repository.
57+
///
58+
/// # Arguments
59+
/// * `cache` - The path to the directory where the binary should be cached.
60+
/// * `version` - An optional version string. If `None`, the latest available version is used.
61+
pub async fn polkadot_omni_node_generator(
62+
cache: PathBuf,
63+
version: Option<&str>,
64+
) -> Result<Binary, Error> {
65+
let cli = PolkadotOmniNodeCli::PolkadotOmniNode;
66+
let name = cli.binary().to_string();
67+
let source = cli
68+
.source()?
69+
.resolve(&name, version, cache.as_path(), |f| prefix(f, &name))
70+
.await
71+
.into();
72+
let binary = Binary::Source { name, source, cache: cache.to_path_buf() };
73+
Ok(binary)
74+
}
75+
76+
#[cfg(test)]
77+
mod tests {
78+
use super::*;
79+
use pop_common::sourcing::TagPattern;
80+
use strum::EnumProperty;
81+
82+
#[test]
83+
fn polkadot_omni_node_cli_properties_work() {
84+
let cli = PolkadotOmniNodeCli::PolkadotOmniNode;
85+
86+
// Test enum properties
87+
assert_eq!(cli.get_str("Repository"), Some("https://github.com/r0gue-io/polkadot"));
88+
assert_eq!(cli.get_str("Binary"), Some("polkadot-omni-node"));
89+
assert_eq!(cli.get_str("TagPattern"), Some("polkadot-{version}"));
90+
assert_eq!(cli.get_str("Fallback"), Some("stable2506-2"));
91+
}
92+
93+
#[test]
94+
fn polkadot_omni_node_cli_source_works() -> anyhow::Result<()> {
95+
let cli = PolkadotOmniNodeCli::PolkadotOmniNode;
96+
let source = cli.source()?;
97+
98+
// Verify source is GitHub variant
99+
match source {
100+
Source::GitHub(ReleaseArchive {
101+
owner,
102+
repository,
103+
tag,
104+
tag_pattern,
105+
prerelease,
106+
fallback,
107+
archive,
108+
contents,
109+
..
110+
}) => {
111+
assert_eq!(owner, "r0gue-io");
112+
assert_eq!(repository, "polkadot");
113+
assert_eq!(tag, None);
114+
assert_eq!(tag_pattern, Some(TagPattern::new("polkadot-{version}")));
115+
assert!(!prerelease);
116+
assert_eq!(fallback, "stable2506-2");
117+
assert!(archive.starts_with("polkadot-omni-node-"));
118+
assert!(archive.ends_with(".tar.gz"));
119+
assert_eq!(contents.len(), 1);
120+
assert_eq!(contents[0].name, "polkadot-omni-node");
121+
assert!(contents[0].required);
122+
},
123+
_ => panic!("Expected GitHub ReleaseArchive source variant"),
124+
}
125+
126+
Ok(())
127+
}
128+
129+
#[tokio::test]
130+
async fn polkadot_omni_node_generator_works() -> anyhow::Result<()> {
131+
let cache = tempfile::tempdir()?;
132+
let binary = polkadot_omni_node_generator(cache.path().to_path_buf(), None).await?;
133+
134+
match binary {
135+
Binary::Source { name, source, cache: cache_path } => {
136+
assert_eq!(name, "polkadot-omni-node");
137+
assert_eq!(cache_path, cache.path());
138+
// Source should be a ResolvedRelease
139+
match *source {
140+
Source::GitHub(github) =>
141+
if let ReleaseArchive { archive, .. } = github {
142+
assert!(archive.contains("polkadot-omni-node"));
143+
},
144+
_ => panic!("Expected GitHub variant"),
145+
}
146+
},
147+
_ => panic!("Expected Binary::Source variant"),
148+
}
149+
150+
Ok(())
151+
}
152+
}

crates/pop-chains/src/up/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// SPDX-License-Identifier: GPL-3.0
22

3-
use crate::{errors::Error, registry::traits::Rollup, up::chain_specs::Runtime};
3+
use crate::{
4+
errors::Error, omni_node::PolkadotOmniNodeCli::PolkadotOmniNode, registry::traits::Rollup,
5+
up::chain_specs::Runtime,
6+
};
47
pub use chain_specs::Runtime as Relay;
58
use glob::glob;
69
use indexmap::IndexMap;
10+
use pop_common::sourcing::traits::{Source as _, enums::Source as _};
711
pub use pop_common::{
812
Profile,
913
git::{GitHub, Repository},
@@ -209,6 +213,12 @@ impl Zombienet {
209213
}
210214
return Err(Error::MissingBinary(command));
211215
}
216+
217+
if command.starts_with(PolkadotOmniNode.binary()) {
218+
paras.insert(id, Chain::from_omni_node(id, cache)?);
219+
continue 'outer;
220+
}
221+
212222
return Err(Error::MissingBinary(command));
213223
}
214224
Ok(paras)
@@ -779,6 +789,19 @@ impl Chain {
779789
})
780790
}
781791
}
792+
793+
fn from_omni_node(id: u32, cache: &Path) -> Result<Chain, Error> {
794+
Ok(Chain {
795+
id,
796+
binary: Binary::Source {
797+
name: PolkadotOmniNode.binary().to_string(),
798+
source: Box::new(PolkadotOmniNode.source()?),
799+
cache: cache.to_path_buf(),
800+
},
801+
chain: None,
802+
chain_spec_generator: None,
803+
})
804+
}
782805
}
783806

784807
/// Attempts to resolve the package manifest from the specified path.

crates/pop-cli/src/common/bench.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{
88
};
99
use cliclack::ProgressBar;
1010
use pop_chains::omni_bencher_generator;
11-
use pop_common::sourcing::Binary;
1211
use std::{
1312
self,
1413
cmp::Ordering,

crates/pop-cli/src/common/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ macro_rules! impl_binary_generator {
116116

117117
impl BinaryGenerator for $generator_name {
118118
async fn generate(
119-
cache_path: PathBuf,
119+
cache_path: std::path::PathBuf,
120120
version: Option<&str>,
121-
) -> Result<Binary, pop_common::Error> {
121+
) -> Result<pop_common::sourcing::Binary, pop_common::Error> {
122122
$generate_fn(cache_path, version).await
123123
}
124124
}

crates/pop-cli/src/common/contracts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
impl_binary_generator,
77
};
88
use cliclack::ProgressBar;
9-
use pop_common::{manifest::from_path, sourcing::Binary};
9+
use pop_common::manifest::from_path;
1010
use pop_contracts::{ContractFunction, contracts_node_generator};
1111
use std::{
1212
path::{Path, PathBuf},

crates/pop-cli/src/common/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod chain;
1212
pub mod contracts;
1313
#[cfg(any(feature = "chain", feature = "wasm-contracts", feature = "polkavm-contracts"))]
1414
pub mod helpers;
15+
/// Contains omni-node utilities.
1516
#[cfg(feature = "chain")]
1617
pub mod omni_node;
1718
/// Contains utilities for interacting with the CLI prompt.

0 commit comments

Comments
 (0)