Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RawGenesisConfig #758

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions client/service-container-chain/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,11 @@
use {
sc_chain_spec::{ChainSpecExtension, ChainSpecGroup},
serde::{Deserialize, Serialize},
std::collections::BTreeMap,
};

/// Specialized `ChainSpec` for container chains that only allows raw genesis format.
pub type RawChainSpec = sc_service::GenericChainSpec<Extensions>;

/// Helper type that implements the traits needed to be used as a "GenesisConfig",
/// but whose implementation panics because we only expect it to be used with raw ChainSpecs,
/// so it will never be serialized or deserialized.
/// This is because container chains must use raw chain spec files where the "genesis"
/// field only has one field: "raw".
pub struct RawGenesisConfig {
pub storage_raw: BTreeMap<Vec<u8>, Vec<u8>>,
}

impl Serialize for RawGenesisConfig {
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
panic!("RawGenesisConfigDummy should never be serialized")
}
}

impl<'de> Deserialize<'de> for RawGenesisConfig {
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
panic!("Attempted to read a non-raw ContainerChain ChainSpec.\nHelp: add `--raw` flag to `build-spec` command to generate a raw chain spec")
}
}

impl sp_runtime::BuildStorage for RawGenesisConfig {
fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> {
storage
.top
.extend(self.storage_raw.iter().map(|(k, v)| (k.clone(), v.clone())));

Ok(())
}
}

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
Expand Down
6 changes: 1 addition & 5 deletions client/service-container-chain/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>

use {
crate::chain_spec::RawGenesisConfig,
cumulus_client_cli::{CollatorOptions, RelayChainMode},
dc_orchestrator_chain_interface::ContainerChainGenesisData,
dp_container_chain_genesis_data::json::properties_to_map,
Expand Down Expand Up @@ -181,9 +180,6 @@ impl ContainerChainCli {
relay_chain,
para_id,
};
let raw_genesis_config = RawGenesisConfig {
storage_raw: storage_raw.clone(),
};

let chain_spec = crate::chain_spec::RawChainSpec::builder(
// This code is not used, we override it in `set_storage` below
Expand All @@ -210,7 +206,7 @@ impl ContainerChainCli {
let mut chain_spec = chain_spec.build();

chain_spec.set_storage(Storage {
top: raw_genesis_config.storage_raw,
top: storage_raw,
children_default: Default::default(),
});

Expand Down
Loading