zombienet_orchestrator/network/
relaychain.rs1use std::path::PathBuf;
2
3use anyhow::anyhow;
4use async_trait::async_trait;
5use serde::Serialize;
6
7use super::node::NetworkNode;
8use crate::{network::chain_upgrade::ChainUpgrade, shared::types::RuntimeUpgradeOptions};
9
10#[derive(Debug, Serialize)]
11pub struct Relaychain {
12 pub(crate) chain: String,
13 pub(crate) chain_id: String,
14 pub(crate) chain_spec_path: PathBuf,
15 pub(crate) nodes: Vec<NetworkNode>,
16}
17
18#[async_trait]
19impl ChainUpgrade for Relaychain {
20 async fn runtime_upgrade(&self, options: RuntimeUpgradeOptions) -> Result<(), anyhow::Error> {
21 let node = if let Some(node_name) = &options.node_name {
23 if let Some(node) = self
24 .nodes()
25 .into_iter()
26 .find(|node| node.name() == node_name)
27 {
28 node
29 } else {
30 return Err(anyhow!(
31 "Node: {} is not part of the set of nodes",
32 node_name
33 ));
34 }
35 } else {
36 if let Some(node) = self.nodes().first() {
38 node
39 } else {
40 return Err(anyhow!("chain doesn't have any node!"));
41 }
42 };
43
44 self.perform_runtime_upgrade(node, options).await
45 }
46}
47
48impl Relaychain {
49 pub(crate) fn new(chain: String, chain_id: String, chain_spec_path: PathBuf) -> Self {
50 Self {
51 chain,
52 chain_id,
53 chain_spec_path,
54 nodes: Default::default(),
55 }
56 }
57
58 pub fn nodes(&self) -> Vec<&NetworkNode> {
60 self.nodes.iter().collect()
61 }
62
63 pub fn chain(&self) -> &str {
65 &self.chain
66 }
67}