Skip to content

Commit

Permalink
src/chain_spec: remove code_substitutes hack
Browse files Browse the repository at this point in the history
and amend the field's docs
Closes #1844
  • Loading branch information
melekes committed Mar 8, 2022
1 parent 00ba3c8 commit 9b0caaa
Showing 1 changed file with 6 additions and 44 deletions.
50 changes: 6 additions & 44 deletions src/chain_spec/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,15 @@ pub(super) struct ClientSpec {
#[serde(default)]
pub(super) chain_type: ChainType,

/// Each key is a block hash. Values are a hex-encoded runtime code (normally found in the
/// `:code` storage key). The descendants of the block with the given hash that share the same
/// [`crate::executor::CoreVersionRef::spec_version`] as the Wasm runtime code in the value
/// should instead use that Wasm runtime code. In other words, the substitution stops when
/// the `spec_version` is modified.
/// The block with that hash uses its unmodified runtime code. Only its children can be
/// affected.
/// Mapping from a block number to a hex-encoded wasm runtime code (normally found in the
/// `:code` storage key).
///
/// This can be used in order to substitute faulty runtimes with functioning ones.
///
/// See also <https://github.com/paritytech/substrate/pull/8898>.
/// The given runtime code will be used to substitute the on-chain runtime code starting with
/// the given block number until the `spec_version`
/// ([`crate::executor::CoreVersionRef::spec_version`]) on chain changes.
#[serde(default)]
// TODO: make use of this
pub(super) code_substitutes: HashMap<NumberAsString, HexString, fnv::FnvBuildHasher>,
pub(super) code_substitutes: HashMap<u64, HexString, fnv::FnvBuildHasher>,
pub(super) boot_nodes: Vec<String>,
pub(super) telemetry_endpoints: Option<Vec<(String, u8)>>,
pub(super) protocol_id: Option<String>,
Expand Down Expand Up @@ -143,39 +138,6 @@ impl<'a> serde::Deserialize<'a> for HexString {
}
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(super) struct NumberAsString(pub(super) u64);

impl serde::Serialize for NumberAsString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.serialize(serializer)
}
}

impl<'a> serde::Deserialize<'a> for NumberAsString {
fn deserialize<D>(deserializer: D) -> Result<NumberAsString, D::Error>
where
D: serde::Deserializer<'a>,
{
let string = String::deserialize(deserializer)?;

if let Some(hex) = string.strip_prefix("0x") {
// TODO: the hexadecimal format support is just a complete hack during a transition period for https://github.com/paritytech/substrate/pull/10600 ; must be removed before we actually make use of the code substitutes
let _bytes = hex::decode(&hex).map_err(serde::de::Error::custom)?;
Ok(NumberAsString(0))
} else if let Ok(num) = string.parse() {
Ok(NumberAsString(num))
} else {
Err(serde::de::Error::custom(
"block number is neither hexadecimal nor decimal",
))
}
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
Expand Down

0 comments on commit 9b0caaa

Please sign in to comment.