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

Commit 9736c50

Browse files
rphmeiergavofyork
authored andcommitted
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
1 parent 58223b0 commit 9736c50

File tree

15 files changed

+434
-231
lines changed

15 files changed

+434
-231
lines changed

Cargo.lock

Lines changed: 64 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/api/src/lib.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,7 @@ macro_rules! with_runtime {
168168

169169
$client.state_at(parent).map_err(Error::from).and_then(|state| {
170170
let mut changes = Default::default();
171-
let mut ext = state_machine::Ext {
172-
overlay: &mut changes,
173-
backend: &state,
174-
};
171+
let mut ext = state_machine::Ext::new(&mut changes, &state);
175172

176173
::substrate_executor::with_native_environment(&mut ext, || {
177174
::runtime::Executive::initialise_block(&header);
@@ -278,51 +275,48 @@ pub struct ClientBlockBuilder<S> {
278275
impl<S: state_machine::Backend> ClientBlockBuilder<S>
279276
where S::Error: Into<client::error::Error>
280277
{
281-
// executes a extrinsic, inherent or otherwise, without appending to the list
278+
// initialises a block ready to allow extrinsics to be applied.
282279
fn initialise_block(&mut self) -> Result<()> {
283-
let mut ext = state_machine::Ext {
284-
overlay: &mut self.changes,
285-
backend: &self.state,
280+
let result = {
281+
let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);
282+
let h = self.header.clone();
283+
284+
::substrate_executor::with_native_environment(
285+
&mut ext,
286+
|| runtime::Executive::initialise_block(&h),
287+
).map_err(Into::into)
286288
};
287289

288-
let h = self.header.clone();
289-
290-
let result = ::substrate_executor::with_native_environment(
291-
&mut ext,
292-
|| runtime::Executive::initialise_block(&h),
293-
).map_err(Into::into);
294-
295290
match result {
296291
Ok(_) => {
297-
ext.overlay.commit_prospective();
292+
self.changes.commit_prospective();
298293
Ok(())
299294
}
300295
Err(e) => {
301-
ext.overlay.discard_prospective();
296+
self.changes.discard_prospective();
302297
Err(e)
303298
}
304299
}
305300
}
306301

307-
// executes a extrinsic, inherent or otherwise, without appending to the list
302+
// executes a extrinsic, inherent or otherwise, without appending to the list.
308303
fn apply_extrinsic(&mut self, extrinsic: UncheckedExtrinsic) -> Result<()> {
309-
let mut ext = state_machine::Ext {
310-
overlay: &mut self.changes,
311-
backend: &self.state,
312-
};
304+
let result = {
305+
let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);
313306

314-
let result = ::substrate_executor::with_native_environment(
315-
&mut ext,
316-
move || runtime::Executive::apply_extrinsic(extrinsic),
317-
).map_err(Into::into);
307+
::substrate_executor::with_native_environment(
308+
&mut ext,
309+
move || runtime::Executive::apply_extrinsic(extrinsic),
310+
).map_err(Into::into)
311+
};
318312

319313
match result {
320314
Ok(_) => {
321-
ext.overlay.commit_prospective();
315+
self.changes.commit_prospective();
322316
Ok(())
323317
}
324318
Err(e) => {
325-
ext.overlay.discard_prospective();
319+
self.changes.discard_prospective();
326320
Err(e)
327321
}
328322
}
@@ -344,10 +338,7 @@ impl<S: state_machine::Backend> BlockBuilder for ClientBlockBuilder<S>
344338
}
345339

346340
fn bake(mut self) -> Block {
347-
let mut ext = state_machine::Ext {
348-
overlay: &mut self.changes,
349-
backend: &self.state,
350-
};
341+
let mut ext = state_machine::Ext::new(&mut self.changes, &self.state);
351342

352343
let final_header = ::substrate_executor::with_native_environment(
353344
&mut ext,

substrate/client/db/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ parking_lot = "0.4"
88
log = "0.3"
99
kvdb = { git = "https://github.com/paritytech/parity.git" }
1010
kvdb-rocksdb = { git = "https://github.com/paritytech/parity.git" }
11+
ethereum-types = "0.3"
12+
hashdb = { git = "https://github.com/paritytech/parity.git" }
13+
patricia-trie = { git = "https://github.com/paritytech/parity.git" }
14+
memorydb = { git = "https://github.com/paritytech/parity.git" }
1115
substrate-primitives = { path = "../../../substrate/primitives" }
1216
substrate-client = { path = "../../../substrate/client" }
1317
substrate-state-machine = { path = "../../../substrate/state-machine" }

0 commit comments

Comments
 (0)