Commit 9439c55b authored by asynchronous rob's avatar asynchronous rob Committed by Gav Wood
Browse files

Store trie nodes in DB (#157)

* move responsibility of storage_root calculation to state backend

* have `storage_root` produce a memoizable transaction

* store trie nodes in kvdb

* fix up test fallout

* remove stray newline

* Fix comment

* test for setting and checking state data

* fiddle with dependencies

* all parity deps on same commit hash

* fix network protocol registration
parent 788757e4
...@@ -168,10 +168,7 @@ macro_rules! with_runtime { ...@@ -168,10 +168,7 @@ macro_rules! with_runtime {
$client.state_at(parent).map_err(Error::from).and_then(|state| { $client.state_at(parent).map_err(Error::from).and_then(|state| {
let mut changes = Default::default(); let mut changes = Default::default();
let mut ext = state_machine::Ext { let mut ext = state_machine::Ext::new(&mut changes, &state);
overlay: &mut changes,
backend: &state,
};
::substrate_executor::with_native_environment(&mut ext, || { ::substrate_executor::with_native_environment(&mut ext, || {
::runtime::Executive::initialise_block(&header); ::runtime::Executive::initialise_block(&header);
...@@ -278,51 +275,48 @@ pub struct ClientBlockBuilder<S> { ...@@ -278,51 +275,48 @@ pub struct ClientBlockBuilder<S> {
impl<S: state_machine::Backend> ClientBlockBuilder<S> impl<S: state_machine::Backend> ClientBlockBuilder<S>
where S::Error: Into<client::error::Error> where S::Error: Into<client::error::Error>
{ {
// executes a extrinsic, inherent or otherwise, without appending to the list // initialises a block ready to allow extrinsics to be applied.
fn initialise_block(&mut self) -> Result<()> { fn initialise_block(&mut self) -> Result<()> {
let mut ext = state_machine::Ext { let result = {
overlay: &mut self.changes, let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);
backend: &self.state, let h = self.header.clone();
::substrate_executor::with_native_environment(
&mut ext,
|| runtime::Executive::initialise_block(&h),
).map_err(Into::into)
}; };
let h = self.header.clone();
let result = ::substrate_executor::with_native_environment(
&mut ext,
|| runtime::Executive::initialise_block(&h),
).map_err(Into::into);
match result { match result {
Ok(_) => { Ok(_) => {
ext.overlay.commit_prospective(); self.changes.commit_prospective();
Ok(()) Ok(())
} }
Err(e) => { Err(e) => {
ext.overlay.discard_prospective(); self.changes.discard_prospective();
Err(e) Err(e)
} }
} }
} }
// executes a extrinsic, inherent or otherwise, without appending to the list // executes a extrinsic, inherent or otherwise, without appending to the list.
fn apply_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> { fn apply_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
let mut ext = state_machine::Ext { let result = {
overlay: &mut self.changes, let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);
backend: &self.state,
};
let result = ::substrate_executor::with_native_environment( ::substrate_executor::with_native_environment(
&mut ext, &mut ext,
move || runtime::Executive::apply_extrinsic(extrinsic), move || runtime::Executive::apply_extrinsic(extrinsic),
).map_err(Into::into); ).map_err(Into::into)
};
match result { match result {
Ok(_) => { Ok(_) => {
ext.overlay.commit_prospective(); self.changes.commit_prospective();
Ok(()) Ok(())
} }
Err(e) => { Err(e) => {
ext.overlay.discard_prospective(); self.changes.discard_prospective();
Err(e) Err(e)
} }
} }
...@@ -344,10 +338,7 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S> ...@@ -344,10 +338,7 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
} }
fn bake(mut self) -> Block { fn bake(mut self) -> Block {
let mut ext = state_machine::Ext { let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);
overlay: &mut self.changes,
backend: &self.state,
};
let final_header = ::substrate_executor::with_native_environment( let final_header = ::substrate_executor::with_native_environment(
&mut ext, &mut ext,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment