Fix genesis bug in bench db (#5253)

This commit is contained in:
Shawn Tabrizi
2020-03-15 21:19:01 +02:00
committed by GitHub
parent 45bb897ea1
commit b57fd17998
+5 -3
View File
@@ -51,6 +51,7 @@ impl<Block: BlockT> sp_state_machine::Storage<HashFor<Block>> for StorageDb<Bloc
pub struct BenchmarkingState<B: BlockT> {
path: PathBuf,
root: Cell<B::Hash>,
genesis_root: B::Hash,
state: RefCell<Option<DbState<B>>>,
db: Cell<Option<Arc<dyn KeyValueDB>>>,
genesis: <DbState<B> as StateBackend<HashFor<B>>>::Transaction,
@@ -74,6 +75,7 @@ impl<B: BlockT> BenchmarkingState<B> {
path,
root: Cell::new(root),
genesis: Default::default(),
genesis_root: Default::default(),
};
state.reopen()?;
@@ -82,11 +84,12 @@ impl<B: BlockT> BenchmarkingState<B> {
child_content.data.into_iter().map(|(k, v)| (k, Some(v))),
child_content.child_info
));
let (root, transaction) = state.state.borrow_mut().as_mut().unwrap().full_storage_root(
let (root, transaction): (B::Hash, _) = state.state.borrow_mut().as_mut().unwrap().full_storage_root(
genesis.top.into_iter().map(|(k, v)| (k, Some(v))),
child_delta,
);
state.genesis = transaction.clone();
state.genesis_root = root.clone();
state.commit(root, transaction)?;
Ok(state)
}
@@ -273,7 +276,7 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
fn wipe(&self) -> Result<(), Self::Error> {
self.kill()?;
self.reopen()?;
self.commit(self.root.get(), self.genesis.clone())?;
self.commit(self.genesis_root.clone(), self.genesis.clone())?;
Ok(())
}
}
@@ -283,4 +286,3 @@ impl<Block: BlockT> std::fmt::Debug for BenchmarkingState<Block> {
write!(f, "DB at {:?}", self.path)
}
}