Skip to content

Commit

Permalink
Remove RawGenesisConfig
Browse files Browse the repository at this point in the history
Not needed after new genesis builder code
  • Loading branch information
tmpolaczyk committed Nov 21, 2024
1 parent 2760888 commit e94c263
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
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

0 comments on commit e94c263

Please sign in to comment.