Skip to content

Commit

Permalink
Merge pull request #290 from savudani8/feature/metadata-match-check
Browse files Browse the repository at this point in the history
feat: fail to start on metadata mismatch
  • Loading branch information
sander2 authored May 10, 2022
2 parents e78daf1 + 5806174 commit b8f7d7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions runtime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub enum Error {
InsufficientFunds,
#[error("Client does not support spec_version: expected {0}, got {1}")]
InvalidSpecVersion(u32, u32),
#[error("Client metadata is different from parachain metadata: expected {0}, got {1}")]
ParachainMetadataMismatch(String, String),
#[error("Failed to load credentials from file: {0}")]
KeyLoadingFailure(#[from] KeyLoadingError),
#[error("Error serializing: {0}")]
Expand Down
16 changes: 16 additions & 0 deletions runtime/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use codec::Encode;
use futures::{future::join_all, stream::StreamExt, FutureExt, SinkExt};
use module_oracle_rpc_runtime_api::BalanceWrapper;
use primitives::UnsignedFixedPoint;
use serde_json::{Map, Value};
use sp_runtime::FixedPointNumber;
use std::{collections::BTreeSet, future::Future, sync::Arc, time::Duration};
use subxt::{
Expand All @@ -30,15 +31,19 @@ const TRANSACTION_TIMEOUT: Duration = Duration::from_secs(300); // 5 minute time
cfg_if::cfg_if! {
if #[cfg(feature = "standalone-metadata")] {
const DEFAULT_SPEC_VERSION: u32 = 1;
const DEFAULT_SPEC_NAME: &str = "interbtc-standalone";
pub const SS58_PREFIX: u16 = 42;
} else if #[cfg(feature = "parachain-metadata-interlay")] {
const DEFAULT_SPEC_VERSION: u32 = 3;
const DEFAULT_SPEC_NAME: &str = "interlay-parachain";
pub const SS58_PREFIX: u16 = 2032;
} else if #[cfg(feature = "parachain-metadata-kintsugi")] {
const DEFAULT_SPEC_VERSION: u32 = 15;
const DEFAULT_SPEC_NAME: &str = "kintsugi-parachain";
pub const SS58_PREFIX: u16 = 2092;
} else if #[cfg(feature = "parachain-metadata-testnet")] {
const DEFAULT_SPEC_VERSION: u32 = 6;
const DEFAULT_SPEC_NAME: &str = "testnet-parachain";
pub const SS58_PREFIX: u16 = 42;
}
}
Expand Down Expand Up @@ -69,6 +74,17 @@ impl InterBtcParachain {
let api: RuntimeApi = ext_client.clone().to_runtime_api();

let runtime_version = ext_client.rpc().runtime_version(None).await?;
let default_spec_name = &Value::default();
let spec_name = runtime_version.other.get("specName").unwrap_or(default_spec_name);
if spec_name == DEFAULT_SPEC_NAME {
log::info!("spec_name={}", spec_name);
} else {
return Err(Error::ParachainMetadataMismatch(
DEFAULT_SPEC_NAME.into(),
spec_name.as_str().unwrap_or_default().into(),
));
}

if runtime_version.spec_version == DEFAULT_SPEC_VERSION {
log::info!("spec_version={}", runtime_version.spec_version);
log::info!("transaction_version={}", runtime_version.transaction_version);
Expand Down

0 comments on commit b8f7d7f

Please sign in to comment.