Skip to content

Commit

Permalink
sc-chainspec: Switch to assimilate_storage (paritytech#12720)
Browse files Browse the repository at this point in the history
Before it was using `build_storage` and `assimilate_storage` was returning an error. However, there
was no real reason for `assimilate_storage` to return an error. This pr implements
`assimilate_storage` and uses the default `build_storage` of the trait.
  • Loading branch information
bkchr authored and ark0f committed Feb 27, 2023
1 parent 4c161b0 commit 04dfcb9
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions client/chain-spec/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,28 @@ impl<G: RuntimeGenesis> GenesisSource<G> {
}

impl<G: RuntimeGenesis, E> BuildStorage for ChainSpec<G, E> {
fn build_storage(&self) -> Result<Storage, String> {
fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> {
match self.genesis.resolve()? {
Genesis::Runtime(gc) => gc.build_storage(),
Genesis::Raw(RawGenesis { top: map, children_default: children_map }) => Ok(Storage {
top: map.into_iter().map(|(k, v)| (k.0, v.0)).collect(),
children_default: children_map
.into_iter()
.map(|(storage_key, child_content)| {
let child_info = ChildInfo::new_default(storage_key.0.as_slice());
(
storage_key.0,
StorageChild {
data: child_content.into_iter().map(|(k, v)| (k.0, v.0)).collect(),
child_info,
},
)
})
.collect(),
}),
Genesis::Runtime(gc) => gc.assimilate_storage(storage),
Genesis::Raw(RawGenesis { top: map, children_default: children_map }) => {
storage.top.extend(map.into_iter().map(|(k, v)| (k.0, v.0)));
children_map.into_iter().for_each(|(k, v)| {
let child_info = ChildInfo::new_default(k.0.as_slice());
storage
.children_default
.entry(k.0)
.or_insert_with(|| StorageChild { data: Default::default(), child_info })
.data
.extend(v.into_iter().map(|(k, v)| (k.0, v.0)));
});
Ok(())
},
// The `StateRootHash` variant exists as a way to keep note that other clients support
// it, but Substrate itself isn't capable of loading chain specs with just a hash at the
// moment.
Genesis::StateRootHash(_) => Err("Genesis storage in hash format not supported".into()),
}
}

fn assimilate_storage(&self, _: &mut Storage) -> Result<(), String> {
Err("`assimilate_storage` not implemented for `ChainSpec`.".into())
}
}

pub type GenesisStorage = BTreeMap<StorageKey, StorageData>;
Expand Down

0 comments on commit 04dfcb9

Please sign in to comment.