-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add runtime_upgrade for releaychain (#259)
Added: - Helper to perform a runtime upgrade on the relaychain ```rust let wasm = "file_path__or__url_to_*.compact.compressed.wasm"; network .relaychain() .runtime_upgrade(RuntimeUpgradeOptions::new(wasm.into())) .await?; ```
- Loading branch information
Showing
9 changed files
with
193 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod register_para; | ||
pub mod validator_actions; | ||
// pub mod register_para; | ||
// pub mod validator_actions; | ||
pub mod runtime_upgrade; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use subxt::{dynamic::Value, tx::TxStatus, OnlineClient, SubstrateConfig}; | ||
use subxt_signer::sr25519::Keypair; | ||
use tracing::{debug, info}; | ||
|
||
pub async fn upgrade( | ||
// options: RuntimeUpgradeOptions, | ||
ws_url: &str, | ||
wasm_data: &[u8], | ||
sudo: &Keypair, | ||
// scoped_fs: &ScopedFilesystem<'_, impl FileSystem>, | ||
) -> Result<(), anyhow::Error> { | ||
debug!("Upgrading runtime, using {} as endpoint ", ws_url); | ||
let api = OnlineClient::<SubstrateConfig>::from_url(ws_url).await?; | ||
|
||
let upgrade = subxt::dynamic::tx( | ||
"System", | ||
"set_code_without_checks", | ||
vec![Value::from_bytes(wasm_data)], | ||
); | ||
|
||
let sudo_call = subxt::dynamic::tx( | ||
"Sudo", | ||
"sudo_unchecked_weight", | ||
vec![ | ||
upgrade.into_value(), | ||
Value::named_composite([ | ||
("ref_time", Value::primitive(1.into())), | ||
("proof_size", Value::primitive(1.into())), | ||
]), | ||
], | ||
); | ||
|
||
let mut tx = api | ||
.tx() | ||
.sign_and_submit_then_watch_default(&sudo_call, sudo) | ||
.await?; | ||
|
||
// Below we use the low level API to replicate the `wait_for_in_block` behaviour | ||
// which was removed in subxt 0.33.0. See https://github.com/paritytech/subxt/pull/1237. | ||
while let Some(status) = tx.next().await { | ||
let status = status?; | ||
match &status { | ||
TxStatus::InBestBlock(tx_in_block) | TxStatus::InFinalizedBlock(tx_in_block) => { | ||
let _result = tx_in_block.wait_for_success().await?; | ||
let block_status = if status.as_finalized().is_some() { | ||
"Finalized" | ||
} else { | ||
"Best" | ||
}; | ||
info!( | ||
"[{}] In block: {:#?}", | ||
block_status, | ||
tx_in_block.block_hash() | ||
); | ||
}, | ||
TxStatus::Error { message } | ||
| TxStatus::Invalid { message } | ||
| TxStatus::Dropped { message } => { | ||
return Err(anyhow::format_err!("Error submitting tx: {message}")); | ||
}, | ||
_ => continue, | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters