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

BREAKING Overlay transaction support. #3263

Closed
wants to merge 203 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
ef20f40
init some bench
cheme Jul 9, 2019
a218162
Init implementing.
cheme Jul 9, 2019
4e8f6a7
Initial implementation of prospective with unbound layer.
cheme Jul 11, 2019
917e26b
Remove size counter
cheme Jul 11, 2019
8b93ab7
fix ix.
cheme Jul 11, 2019
ae8e880
code for transactional layers: TODO testing!!
cheme Jul 12, 2019
c716f95
Regain perfs (-15%) by using a couple of static memory for
cheme Jul 30, 2019
808a409
Fix tx logic and basic tx test.
cheme Jul 30, 2019
e481952
with_transaction function and high level test.
cheme Jul 30, 2019
d9f3e50
state was useless in overlayed change (allways the last ix of history).
cheme Jul 30, 2019
cc0aa37
Cleaning comments and names.
cheme Jul 30, 2019
2bc2af0
Merge branch 'master' into overlay_change
cheme Jul 30, 2019
0c8235e
Rename Externalities primitives to 'storage_' + old name.
cheme Jul 31, 2019
5b98b4b
Merge branch 'master' into overlay_change
cheme Jul 31, 2019
cade913
name fields instead of tuble.
cheme Jul 31, 2019
fd26b2a
Update srml/support/src/storage/mod.rs
cheme Jul 31, 2019
3245968
Use more efficient smallvec.
cheme Aug 1, 2019
8550ad9
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Aug 1, 2019
41483b5
Missing spaces.
cheme Aug 1, 2019
44f5173
slice and slice to_vec from ptr to vec.
cheme Aug 1, 2019
00326b2
Init some fuzzing (only look for panic).
cheme Aug 1, 2019
fc2100d
Implement simplier inefficient overlay to fuzz compare.
cheme Aug 1, 2019
e38fc7b
Update core/state-machine/src/overlayed_changes.rs
cheme Aug 1, 2019
b8564e6
implement overlay garbage collection.
cheme Aug 5, 2019
21aa65d
Trigger gc based on constant rule.
cheme Aug 5, 2019
c8938d3
Managing a configuration for gc of overlay. This commit will be revert
cheme Aug 5, 2019
d1d947b
Revert "Managing a configuration for gc of overlay. This commit will …
cheme Aug 5, 2019
f4fb1e1
Merge branch 'master' into overlay_change
cheme Aug 6, 2019
2836808
Merge branch 'master' into overlay_change
cheme Aug 8, 2019
968ba35
Merge branch 'master' into overlay_change
cheme Aug 8, 2019
d703ee4
Merge branch 'master' into overlay_change
cheme Aug 15, 2019
ee52917
Direct iterator on children, not that the fact that it is owned does not
cheme Aug 15, 2019
249675e
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Aug 15, 2019
0100d70
Merge branch 'master' into overlay_change
cheme Aug 22, 2019
da093d5
Merge branch 'master' into overlay_change
cheme Aug 26, 2019
af4cceb
warning fix
cheme Aug 26, 2019
4e68123
Extracting transaction history and states plus logics to its own
cheme Aug 26, 2019
75fd798
Make history buffer parametric (to allow encoding efficient
cheme Aug 26, 2019
1fb154e
Removed history trait, to go to the more pragmatic macro approach (after
cheme Aug 27, 2019
46de531
macroed code (trait would be better but not at this point).
cheme Aug 28, 2019
80f4c2b
Fix basis code.
cheme Aug 28, 2019
8dbd48d
Remove serialized variant.
cheme Aug 28, 2019
9203e25
change some variables name, try to document gc.
cheme Aug 28, 2019
ea028ec
Change operation cost proto, add into_pending method and few formatting
cheme Aug 28, 2019
c69e258
Merge branch 'master' into overlay_change
cheme Aug 28, 2019
0ab789e
Doc and renaming 'force_push' to 'unsafe_push' (this function being
cheme Aug 29, 2019
8d45d31
Merge branch 'master' into overlay_change
cheme Aug 29, 2019
9488ca1
Merge branch 'master' into overlay_change
cheme Sep 2, 2019
09a24e0
Merge branch 'overlay_change' of github.com:cheme/substrate into over…
cheme Sep 2, 2019
b596b52
Merge branch 'master' into overlay_change
cheme Sep 4, 2019
5cc5fd0
Merge branch 'master' into overlay_change
cheme Sep 5, 2019
117388e
bump spec version
cheme Sep 5, 2019
1647084
Merge branch 'master' into overlay_change
cheme Sep 11, 2019
838cd3b
Addressing some nits, adding fuzz check into ci benches target.
cheme Sep 12, 2019
5437981
Merge branch 'master' into overlay_change
cheme Sep 12, 2019
fe38b30
Update iter docs, bump runtime version.
cheme Sep 13, 2019
b7dcd6d
Merge branch 'master' into overlay_change
cheme Sep 13, 2019
616fc2a
Simplify top and child iter into a single function.
cheme Sep 13, 2019
7001e8c
Restore access to iter for fuzzer.
cheme Sep 13, 2019
b534b3d
Merge branch 'master' into overlay_change
cheme Sep 16, 2019
a84b8db
rename gc for liner to get_mut_pruning, rename unsafe_push to
cheme Sep 16, 2019
9787a97
switch tuple to historiedvalue struct.
cheme Sep 16, 2019
d9d2118
use len instead of internal_item_counts
cheme Sep 16, 2019
887f95b
historied value on get and get mut to.
cheme Sep 17, 2019
1074c8c
Merge branch 'master' into overlay_change
Demi-Marie Sep 17, 2019
076623d
Merge branch 'master' into overlay_change
cheme Sep 18, 2019
937655f
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Sep 18, 2019
ff4bcb0
proper rand on bench
cheme Sep 18, 2019
45dc935
Update core/utils/historied-data/README.md
cheme Sep 20, 2019
d7c9f8a
Update core/utils/historied-data/src/lib.rs
cheme Sep 20, 2019
6c9abda
Update core/utils/historied-data/src/linear.rs
cheme Sep 20, 2019
89b4f26
Switching runtime test to panic instead of returning result.
cheme Sep 20, 2019
2ab0da3
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Sep 20, 2019
6673ce1
Merge branch 'master' into overlay_change
cheme Oct 2, 2019
cdd1c3e
Merge branch 'master' into overlay_change
cheme Oct 10, 2019
e076d12
Avoid clone explicitely in some case (the clone with this PR is
cheme Oct 10, 2019
b877213
remove it from parameter.
cheme Oct 10, 2019
fc66ecd
Merge branch 'master' into overlay_change
cheme Oct 18, 2019
dcdd32c
Merge branch 'master' into overlay_change
cheme Oct 21, 2019
6a153e5
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Oct 21, 2019
32e6268
fix merge.
cheme Oct 21, 2019
cf943e2
Apply suggestions from code review
cheme Oct 21, 2019
4a439af
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Oct 21, 2019
c71e2c5
Smallvec is compatible with no_std.
cheme Oct 21, 2019
71c4012
fix fuzz, rename 'test' feature to more substratish 'test-helpers'.
cheme Oct 21, 2019
4ca0b40
Implement with less state.
cheme Oct 21, 2019
47b8867
revert to no gc of commited data
cheme Oct 23, 2019
d9a0fb5
renaming some history variables and field to states.
cheme Oct 23, 2019
1c06ce1
satisfactory get_mut, pruning need changes.
cheme Oct 23, 2019
c399c58
Fix gc (fuzz seems ok), a bit more work on avoiding redundancy in
cheme Oct 23, 2019
106d84b
remove a bit of code redundancy.
cheme Oct 24, 2019
6b5aeea
rename historied to historical
cheme Oct 24, 2019
8738b30
Merge branch 'master' into overlay_change
cheme Oct 24, 2019
594ce64
removing dubious as_ref_mut method (intermediate tuple is not optimized
cheme Oct 24, 2019
7546e6a
Named field for States.
cheme Oct 24, 2019
2e6fa4c
change find_previous_transaction to use an in memory state.
cheme Oct 24, 2019
cd7113b
update runtime versions.
cheme Oct 24, 2019
a995150
Merge branch 'master' into overlay_change
cheme Oct 24, 2019
789af78
Merge branch 'master' into overlay_change, and few english nits.
cheme Oct 28, 2019
1a12715
Merge branch 'master' into overlay_change
cheme Oct 30, 2019
6625ab8
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Oct 30, 2019
2d91b89
fix some documentation nits.
cheme Oct 30, 2019
61dba1e
Documentation.
cheme Nov 1, 2019
6334c10
favor for expression when possible.
cheme Nov 1, 2019
1b9ff7b
use 'get_unchecked_pending' for a recurrent pattern matching.
cheme Nov 1, 2019
55cacc1
Reorganize historical crate and documentation.
cheme Nov 1, 2019
4920da4
fix import.
cheme Nov 1, 2019
4a1fb7f
Preparing refactor.
cheme Nov 11, 2019
a995e18
setting up linear synch historical data.
cheme Nov 12, 2019
fb01856
quick implementation before fuzzing.
cheme Nov 12, 2019
ef0bcda
code fix and overlay implemetation, before deletion of old code.
cheme Nov 13, 2019
e265ad1
New implementation accounts for a 17 and 20% lost on existing bench.
cheme Nov 13, 2019
9904c4f
Remove unuse code. Test failings.
cheme Nov 14, 2019
0a98033
Merge branch 'master' into overlay_change
cheme Nov 14, 2019
5f82305
Fix broken tests (obviously cloning only state do not work anymore).
cheme Nov 14, 2019
494ad42
Removing trailing spaces.
cheme Nov 14, 2019
f7b9594
rename 'ensure_runing' to 'finalize_discard' as it is only really needed
cheme Nov 14, 2019
55d112a
renaming PruneResult to CleaningResult.
cheme Nov 14, 2019
741d420
fix compilation issue
cheme Nov 14, 2019
19b1014
Field name for states.
cheme Nov 15, 2019
a2bab20
Merge branch 'master' into overlay_change
cheme Nov 15, 2019
4b90775
Fix conflicts.
cheme Nov 15, 2019
a81fb12
fix ci for checking fuzz
cheme Nov 15, 2019
d9ff813
No sense in having new ext in deprecated interface.
cheme Nov 19, 2019
fa0ec93
Ensure discard prospective.
cheme Nov 19, 2019
e0b580e
Merge branch 'master' into overlay_change
cheme Nov 21, 2019
efa05f1
Merge branch 'master' into overlay_change
cheme Nov 23, 2019
e0a6243
Merge branch 'master' into overlay_change
cheme Nov 27, 2019
281344b
Merge branch 'master' into overlay_change
cheme Nov 29, 2019
2676397
Merge branch 'master' into overlay_change
cheme Nov 29, 2019
fbdbd34
Merge branch 'master' into overlay_change
cheme Dec 2, 2019
80c55c6
Merge branch 'overlay_change' of github.com:cheme/substrate into over…
cheme Dec 2, 2019
5597bf3
update cargo.lock
cheme Dec 2, 2019
9c09b78
fix crate names for bench and fuzz
cheme Dec 6, 2019
28413a7
Merge branch 'master' into overlay_change
cheme Dec 8, 2019
1e1e790
Address nits: remove test-helpers specific derive, make 'len' function
cheme Dec 9, 2019
827441c
Merge branch 'master' into overlay_change
cheme Dec 9, 2019
ac424ac
Merge branch 'master' into overlay_change
cheme Dec 10, 2019
6d3e10f
Merge branch 'master' into overlay_change
cheme Dec 11, 2019
19733c5
fix merge (runtime-io to sp-io)
cheme Dec 11, 2019
f7a1193
Merge branch 'master' into overlay_change
cheme Dec 11, 2019
0f8bee6
Move historical-data crate to primitives.
cheme Dec 11, 2019
106b1f7
Merge branch 'master' into overlay_change
cheme Dec 13, 2019
fd262d9
Historical values documentation update.
cheme Dec 14, 2019
8f79592
Merge branch 'master' into overlay_change
cheme Dec 14, 2019
d1554ec
Documentation change on overlay_change
cheme Dec 14, 2019
92d5184
Merge branch 'master' into overlay_change
cheme Dec 17, 2019
81f5c90
adding cargo.lock to overlay fuzzing
cheme Dec 17, 2019
57a2ddd
Merge branch 'master' into overlay_change
cheme Jan 1, 2020
70946d1
rewrite readme, rename historicalvalue to historicalentry
cheme Jan 2, 2020
dc4462a
spelling an slight documentation change.
cheme Jan 2, 2020
0004cf4
Merge branch 'master' into overlay_change
cheme Jan 6, 2020
2a5b816
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Jan 6, 2020
d00f3e8
Merge branch 'master' into overlay_change
cheme Jan 6, 2020
7bc1c6c
Fix runtime tests.
cheme Jan 6, 2020
7a99509
apply update-copyright.sh
cheme Jan 7, 2020
256f3a5
move transaction to its own transaction runtime module.
cheme Jan 7, 2020
80f3d38
synch_linear_transaction renamed to sync_linear_transaction
cheme Jan 7, 2020
c9873b8
unused dependency to sp-std
cheme Jan 7, 2020
4f0c633
nits.
cheme Jan 7, 2020
b3014ae
Comments for `apply_commit_transaction` internals.
cheme Jan 7, 2020
412fba4
Use 'COMMITTED_LAYER' const to make code clearer.
cheme Jan 7, 2020
4f4fed6
Fix refacto error.
cheme Jan 7, 2020
9dee523
Discard transaction is same as truncate.
cheme Jan 7, 2020
f055f3b
Move helpers implementations.
cheme Jan 7, 2020
441d5ca
Declare transaction host function for wasm
cheme Jan 8, 2020
96f9662
renaming prior to removal of historical-data
cheme Jan 10, 2020
b3078a7
Flattern historical data crate & fix discard transaction latest commit
cheme Jan 10, 2020
9f01802
Move transaction code in its own module.
cheme Jan 10, 2020
92c99af
Move fuzzer base code to sp-state-machine to add non regression
cheme Jan 10, 2020
5614176
Merge branch 'master' into overlay_change
cheme Jan 10, 2020
f18f4d3
Merge branch 'master' into overlay_change
cheme Jan 13, 2020
26cfd0f
fix `where` formatting and some documentation from pr review.
cheme Jan 13, 2020
ab272e3
Simplify logic for commit transaction.
cheme Jan 14, 2020
e93097e
Merge branch 'master' into overlay_change
cheme Jan 15, 2020
2970099
provious lazy design for transaction.
cheme Jan 15, 2020
ec7f683
Switch overlay_change primitives.
cheme Jan 16, 2020
68b9678
Switch to mutable for storage, child storage and similar.
cheme Jan 16, 2020
6b14213
Merge branch 'master' into overlay_change
cheme Jan 16, 2020
8cc64bb
Merge branch 'overlay_change' into overlay_change_lazy
cheme Jan 16, 2020
6227baf
Merge branch 'overlay_change_lazy' into overlay_change_lazy_mut
cheme Jan 16, 2020
be9811d
Merge branch 'master' into overlay_change
cheme Jan 20, 2020
e69fd24
Merge branch 'overlay_change' into overlay_change_lazy_mut
cheme Jan 20, 2020
47f117a
Fix some doc, mark loop enhancement to test.
cheme Jan 20, 2020
5f26869
best loop condition, and manage deleted offset out of actual deletion.
cheme Jan 20, 2020
09539d4
fix benches.
cheme Jan 21, 2020
ea1fe4f
Merge branch 'master' into overlay_change
cheme Jan 27, 2020
b109130
Fixing line lengths.
cheme Jan 30, 2020
2533b04
Merge branch 'master' into overlay_change
cheme Jan 30, 2020
1db0bec
increment spec version
cheme Jan 30, 2020
121e64b
storage transaction host module name.
cheme Jan 30, 2020
1e2497a
3 new function, switching index of missing one in wasmtime test.
cheme Jan 30, 2020
46e54c8
another hardcoded wasmtime index in test.
cheme Jan 30, 2020
1e8cd7b
Merge branch 'master' into overlay_change
cheme Feb 5, 2020
1667f18
Merge branch 'master' into overlay_change
cheme Feb 12, 2020
5df5e51
Merge branch 'master' into overlay_change
cheme Feb 12, 2020
0d29a09
Merge branch 'master' into overlay_change
cheme Feb 28, 2020
4d6af74
Added a descriptive test of internal state. This does not intend to
cheme Mar 2, 2020
6242ebc
Merge branch 'master' into overlay_change
cheme Mar 10, 2020
683abcb
update fuzzer cargo.lock
cheme Mar 10, 2020
0c8d9e7
Merge branch 'master' into overlay_change
cheme Mar 17, 2020
e620a05
Merge branch 'master' into overlay_change
cheme Apr 14, 2020
45d5c7c
fix bench
cheme Apr 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions core/executor/src/wasm_executor.rs
Expand Up @@ -1247,6 +1247,18 @@ impl_function_executor!(this: FunctionExecutor<'e, E>,
this.sandbox_store.memory_teardown(memory_idx)?;
Ok(())
},
ext_storage_start_transaction() => {
this.ext.storage_start_transaction();
Ok(())
},
ext_storage_discard_transaction() => {
this.ext.storage_discard_transaction();
Ok(())
},
ext_storage_commit_transaction() => {
this.ext.storage_commit_transaction();
Ok(())
},
=> <'e, E: Externalities<Blake2Hasher> + 'e>
);

Expand Down
10 changes: 9 additions & 1 deletion core/sr-api-macros/tests/runtime_calls.rs
Expand Up @@ -103,7 +103,6 @@ fn calling_with_both_strategy_and_fail_on_native_should_work() {
assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1);
}


#[test]
fn calling_with_native_else_wasm_and_fail_on_wasm_should_work() {
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeElseWasm).build();
Expand All @@ -128,6 +127,15 @@ fn use_trie_function() {
assert_eq!(runtime_api.use_trie(&block_id).unwrap(), 2);
}

#[test]
fn test_transactions() {
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.info().chain.best_number);
assert_eq!(runtime_api.use_transactions(&block_id).unwrap(), 1);
}


#[test]
fn initialize_block_works() {
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
Expand Down
9 changes: 9 additions & 0 deletions core/sr-io/src/lib.rs
Expand Up @@ -151,6 +151,15 @@ export_api! {
/// "Commit" all existing operations and get the resultant storage change root.
fn storage_changes_root(parent_hash: [u8; 32]) -> Option<[u8; 32]>;

/// Start a new transaction.
fn storage_start_transaction();

/// Discard a transactional layer.
fn storage_discard_transaction();

/// Commit a transactional layer.
fn storage_commit_transaction();

/// A trie root formed from the enumerated items.
/// TODO [#2382] remove (just use `ordered_trie_root` (NOTE currently not implemented for without_std))
fn enumerated_trie_root<H>(input: &[&[u8]]) -> H::Out
Expand Down
12 changes: 12 additions & 0 deletions core/sr-io/with_std.rs
Expand Up @@ -164,6 +164,18 @@ impl StorageApi for () {
).unwrap_or(Ok(None)).expect("Invalid parent hash passed to storage_changes_root")
}

fn storage_start_transaction() {
ext::with(|ext| ext.storage_start_transaction());
}

fn storage_discard_transaction() {
ext::with(|ext| ext.storage_discard_transaction());
}

fn storage_commit_transaction() {
ext::with(|ext| ext.storage_commit_transaction());
}

fn enumerated_trie_root<H>(input: &[&[u8]]) -> H::Out
where
H: Hasher,
Expand Down
36 changes: 35 additions & 1 deletion core/sr-io/without_std.rs
Expand Up @@ -90,7 +90,7 @@ pub mod ext {
/// # Returns
///
/// Returns the original implementation wrapped in [`RestoreImplementation`].
pub fn replace_implementation(&'static self, new_impl: T) -> RestoreImplementation<T> {
pub fn replace_implementation(&'static self, new_impl: T) -> RestoreImplementation<T> {
if let ExchangeableFunctionState::Replaced = self.0.get().1 {
panic!("Trying to replace an already replaced implementation!")
}
Expand Down Expand Up @@ -624,7 +624,22 @@ pub mod ext {
buffer_len: u32,
deadline: u64
) -> u32;

//================================
// Transactional Context
//================================

/// Open a new transactional storage layer.
fn ext_storage_start_transaction();

/// Close and dismiss current transactional storage layer.
fn ext_storage_discard_transaction();

/// Close and commit current transactional storage layer.
fn ext_storage_commit_transaction();

}

}

pub use self::ext::*;
Expand Down Expand Up @@ -805,6 +820,25 @@ impl StorageApi for () {
>(_input: I) -> H::Out {
unimplemented!()
}

fn storage_start_transaction() {
unsafe {
ext_storage_start_transaction.get()()
}
}

fn storage_discard_transaction() {
unsafe {
ext_storage_discard_transaction.get()()
}
}

fn storage_commit_transaction() {
unsafe {
ext_storage_commit_transaction.get()()
}
}

}

impl OtherApi for () {
Expand Down
6 changes: 6 additions & 0 deletions core/state-machine/Cargo.toml
Expand Up @@ -19,3 +19,9 @@ num-traits = "0.2"

[dev-dependencies]
hex-literal = "0.2.0"
criterion = "0.2"
rand = "0.6"

[[bench]]
name = "bench"
harness = false
118 changes: 118 additions & 0 deletions core/state-machine/benches/bench.rs
@@ -0,0 +1,118 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use criterion::{Criterion, black_box, Bencher};
use criterion::{criterion_group, criterion_main};
use substrate_state_machine::OverlayedChanges;

const CONTENT_KEY_SIZE: usize = 32;

fn get_content(seed: u64, len: usize) -> Vec<u8> {
use rand::SeedableRng;
use rand::RngCore;
let mut rng = rand::rngs::SmallRng::seed_from_u64(seed);
let mut data = vec![0u8; len];
rng.fill_bytes(&mut data[..]);
data
}

fn key_val(
mut inp: &[u8],
len_key: usize,
len_val: usize,
) -> Vec<(Vec<u8>, Vec<u8>)> {
let mut result = Vec::new();
loop {
let key = if inp.len() >= len_key {
inp[..len_key].to_vec()
} else { break };
inp = &inp[len_key..];
let val = if inp.len() >= len_val {
inp[..len_val].to_vec()
} else { break };
inp = &inp[len_val..];
result.push((key, val));
}
result
}

fn commit_drop_commit(b: &mut Bencher, input: &Vec<u8>) {
let key_vals = key_val(&input[..], 32, 32);
b.iter(move || {
let mut overlayed = OverlayedChanges::default();
for i in key_vals.iter() {
overlayed.set_storage(i.0.clone(), Some(i.1.clone()));
}
overlayed.commit_prospective();
for i in key_vals.iter() {
overlayed.set_storage(i.0.clone(), Some(i.1.clone()));
}
overlayed.discard_prospective();
for i in key_vals.iter() {
overlayed.set_storage(i.0.clone(), Some(i.1.clone()));
}
overlayed.commit_prospective();
});
}

fn commit_drop_commit_and_get(b: &mut Bencher, input: &Vec<u8>) {
let key_vals = key_val(&input[..], 32, 32);
b.iter(move || {
let mut overlayed = OverlayedChanges::default();
for i in key_vals.iter() {
overlayed.set_storage(i.0.clone(), Some(i.1.clone()));
}
for i in key_vals.iter() {
black_box(overlayed.storage(&i.0));
}
overlayed.commit_prospective();
for i in key_vals.iter() {
overlayed.set_storage(i.0.clone(), Some(i.1.clone()));
}
for i in key_vals.iter() {
black_box(overlayed.storage(&i.0));
}
overlayed.discard_prospective();
for i in key_vals.iter() {
black_box(overlayed.storage(&i.0));
}
for i in key_vals.iter() {
overlayed.set_storage(i.0.clone(), Some(i.1.clone()));
}
overlayed.commit_prospective();
});
}


pepyakin marked this conversation as resolved.
Show resolved Hide resolved


fn bench_overlay_commit_drop_commit(c: &mut Criterion) {
let inp = get_content(12, CONTENT_KEY_SIZE * 100);
let inps = vec![inp];
c.bench_function_over_inputs("commit_drop_commit", commit_drop_commit, inps);
}
fn bench_overlay_commit_drop_commit_get(c: &mut Criterion) {
let inp = get_content(12, CONTENT_KEY_SIZE * 100);
let inps = vec![inp];
c.bench_function_over_inputs("commit_drop_commit_get", commit_drop_commit_and_get, inps);
}


criterion_group!(benches,
bench_overlay_commit_drop_commit,
bench_overlay_commit_drop_commit_get,
);
criterion_main!(benches);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is not run by default, is it? Can we integrate it in our building process, at least for cargo check otherwise it will rot pretty fast

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is checked by the existing cargo check target, I need to add the fuzzing code still (I will add it to the check bench target as it seems to have similar purpose).

13 changes: 13 additions & 0 deletions core/state-machine/src/basic.rs
Expand Up @@ -170,6 +170,19 @@ impl<H: Hasher> Externalities<H> for BasicExternalities where H::Out: Ord {
warn!("Call to non-existent out offchain externalities set.");
None
}

fn storage_start_transaction(&mut self) {
warn!("No support for storage transaction");
}

fn storage_discard_transaction(&mut self) {
panic!("No support for storage transaction");
}

fn storage_commit_transaction(&mut self) {
// no need to fail in this case
}

}

#[cfg(test)]
Expand Down