Skip to content

Commit

Permalink
fix-subxt-dyn-register-para
Browse files Browse the repository at this point in the history
  • Loading branch information
pepoviola committed Oct 5, 2023
1 parent cba3654 commit 0d5273d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
19 changes: 12 additions & 7 deletions crates/orchestrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ where
.iter_mut()
.map(|node| spawner::spawn_node(node, global_files_to_inject.clone(), &ctx));

// Initiate the node_ws_uel which will be later used in the Parachain_with_extrinsic config
let mut node_ws_url: String = "".to_string();

// Calculate the bootnodes addr from the running nodes
let mut bootnodes_addr: Vec<String> = vec![];
for node in futures::future::try_join_all(spawning_tasks).await? {
Expand All @@ -248,23 +251,22 @@ where
&node.spec.p2p_cert_hash,
)?,
);

// Is used in the register_para_options (We need to get this from the relay and not the collators)
if node_ws_url.is_empty() { node_ws_url = node.ws_uri.clone() }

// Add the node to the `Network` instance
network.add_running_node(node, None);
}

ctx.bootnodes_addr = &bootnodes_addr;

// Initiate the node_ws_uel which will be later used in the Parachain_with_extrinsic config
let mut node_ws_url: String = "".to_string();

// spawn the rest of the nodes (TODO: in batches)
let spawning_tasks = relaynodes
.iter()
.map(|node| spawner::spawn_node(node, global_files_to_inject.clone(), &ctx));
for node in futures::future::try_join_all(spawning_tasks).await? {
// Is used in the register_para_options (We need to get this from the relay and not the collators)
node_ws_url = node.ws_uri.clone();

for node in futures::future::try_join_all(spawning_tasks).await? {
// Add the node to the `Network` instance
network.add_running_node(node, None);
}
Expand Down Expand Up @@ -332,6 +334,10 @@ where
}
}

// TODO: we should wait until node is ready!
if !para_to_register_with_extrinsic.is_empty() {
tokio::time::sleep(Duration::from_secs(10)).await;
}
// Now we need to register the paras with extrinsic from the Vec collected before;
for para in para_to_register_with_extrinsic {
let register_para_options: RegisterParachainOptions = RegisterParachainOptions {
Expand All @@ -357,7 +363,6 @@ where
finalization: false, // TODO: Seed is passed by?
};

println!("{:#?}", register_para_options);
let _ = Parachain::register::<T>(register_para_options, &scoped_fs).await?;
}

Expand Down
43 changes: 25 additions & 18 deletions crates/orchestrator/src/network/parachain.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::path::{Path, PathBuf};

use subxt::{dynamic::Value, OnlineClient, SubstrateConfig};
use subxt_signer::{ bip39::Mnemonic, sr25519::Keypair };
use subxt_signer::{sr25519::Keypair, SecretUri };
use std::str::FromStr;

use support::fs::FileSystem;

// use crate::generators::key::generate_pair;
// use sp_core::{sr25519, Pair};
use super::node::NetworkNode;
use crate::{
shared::types::{ParachainGenesisArgs, RegisterParachainOptions},
shared::types::RegisterParachainOptions,
ScopedFilesystem,
};

Expand Down Expand Up @@ -57,9 +58,8 @@ impl Parachain {
if let Some(possible_seed) = options.seed {
sudo = Keypair::from_seed(possible_seed).expect("seed should return a Keypair.");
} else {
let phrase = "bottom drive obey lake curtain smoke basket hold race lonely fit walk";
let mnemonic = Mnemonic::parse(phrase)?;
sudo = Keypair::from_phrase(&mnemonic, None)?;
let uri = SecretUri::from_str("//Alice")?;
sudo = Keypair::from_uri(&uri)?;
}

let genesis_state = scoped_fs
Expand All @@ -71,34 +71,41 @@ impl Parachain {
.await
.expect("Wasm Path should be ok by this point.");

let parachain_genesis_value: ParachainGenesisArgs = ParachainGenesisArgs {
genesis_head: genesis_state,
validation_code: wasm_data,
parachain: options.onboard_as_para,
};

let api = OnlineClient::<SubstrateConfig>::from_url(options.node_ws_url).await?;

// // based on subXT docs: The public key bytes are equivalent to a Substrate `AccountId32`;
let account_id = sudo.public_key();

let schedule_para = subxt::dynamic::tx(
"ParasSudoWrapperCall",
"ParasSudoWrapper",
"sudo_schedule_para_initialize",
vec![
Value::from_bytes(account_id),
Value::from_bytes(parachain_genesis_value),
Value::primitive(options.id.into()),
Value::named_composite([
("genesis_head", Value::from_bytes(hex::decode(&genesis_state[2..])?)),
("validation_code", Value::from_bytes(hex::decode(&wasm_data[2..])?)),
("para_kind", Value::bool(true)),
])
],
);



let sudo_call = subxt::dynamic::tx(
"Sudo",
"sudo",
vec![schedule_para.into_value()]
);


// TODO: uncomment below and fix the sign and submit (and follow afterwards until
// finalized block) to register the parachain
let result = api
.tx()
.sign_and_submit_then_watch_default(&schedule_para, &sudo)
.sign_and_submit_then_watch_default(&sudo_call, &sudo)
.await?;

println!("{:#?}", result);

let result = result.wait_for_in_block().await?;
println!("In block: {:#?}", result.block_hash());
Ok(())
}
}

0 comments on commit 0d5273d

Please sign in to comment.