Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Store trie nodes in DB (#157)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rphmeier authored and gavofyork committed May 16, 2018
1 parent 58223b0 commit 9736c50
Show file tree
Hide file tree
Showing 15 changed files with 434 additions and 231 deletions.
159 changes: 64 additions & 95 deletions Cargo.lock

Large diffs are not rendered by default.

55 changes: 23 additions & 32 deletions polkadot/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ macro_rules! with_runtime {

$client.state_at(parent).map_err(Error::from).and_then(|state| {
let mut changes = Default::default();
let mut ext = state_machine::Ext {
overlay: &mut changes,
backend: &state,
};
let mut ext = state_machine::Ext::new(&mut changes, &state);

::substrate_executor::with_native_environment(&mut ext, || {
::runtime::Executive::initialise_block(&header);
Expand Down Expand Up @@ -278,51 +275,48 @@ pub struct ClientBlockBuilder<S> {
impl<S: state_machine::Backend> ClientBlockBuilder<S>
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<()> {
let mut ext = state_machine::Ext {
overlay: &mut self.changes,
backend: &self.state,
let result = {
let mut ext = state_machine::Ext::new(&mut self.changes, &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 {
Ok(_) => {
ext.overlay.commit_prospective();
self.changes.commit_prospective();
Ok(())
}
Err(e) => {
ext.overlay.discard_prospective();
self.changes.discard_prospective();
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<()> {
let mut ext = state_machine::Ext {
overlay: &mut self.changes,
backend: &self.state,
};
let result = {
let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);

let result = ::substrate_executor::with_native_environment(
&mut ext,
move || runtime::Executive::apply_extrinsic(extrinsic),
).map_err(Into::into);
::substrate_executor::with_native_environment(
&mut ext,
move || runtime::Executive::apply_extrinsic(extrinsic),
).map_err(Into::into)
};

match result {
Ok(_) => {
ext.overlay.commit_prospective();
self.changes.commit_prospective();
Ok(())
}
Err(e) => {
ext.overlay.discard_prospective();
self.changes.discard_prospective();
Err(e)
}
}
Expand All @@ -344,10 +338,7 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
}

fn bake(mut self) -> Block {
let mut ext = state_machine::Ext {
overlay: &mut self.changes,
backend: &self.state,
};
let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);

let final_header = ::substrate_executor::with_native_environment(
&mut ext,
Expand Down
4 changes: 4 additions & 0 deletions substrate/client/db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ parking_lot = "0.4"
log = "0.3"
kvdb = { git = "https://github.com/paritytech/parity.git" }
kvdb-rocksdb = { git = "https://github.com/paritytech/parity.git" }
ethereum-types = "0.3"
hashdb = { git = "https://github.com/paritytech/parity.git" }
patricia-trie = { git = "https://github.com/paritytech/parity.git" }
memorydb = { git = "https://github.com/paritytech/parity.git" }
substrate-primitives = { path = "../../../substrate/primitives" }
substrate-client = { path = "../../../substrate/client" }
substrate-state-machine = { path = "../../../substrate/state-machine" }
Expand Down
Loading

0 comments on commit 9736c50

Please sign in to comment.