-
Notifications
You must be signed in to change notification settings - Fork 2.6k
BREAKING Overlay transaction support. #3263
Changes from 85 commits
ef20f40
a218162
4e8f6a7
917e26b
8b93ab7
ae8e880
c716f95
808a409
e481952
d9f3e50
cc0aa37
2bc2af0
0c8235e
5b98b4b
cade913
fd26b2a
3245968
8550ad9
41483b5
44f5173
00326b2
fc2100d
e38fc7b
b8564e6
21aa65d
c8938d3
d1d947b
f4fb1e1
2836808
968ba35
d703ee4
ee52917
249675e
0100d70
da093d5
af4cceb
4e68123
75fd798
1fb154e
46de531
80f4c2b
8dbd48d
9203e25
ea028ec
c69e258
0ab789e
8d45d31
9488ca1
09a24e0
b596b52
5cc5fd0
117388e
1647084
838cd3b
5437981
fe38b30
b7dcd6d
616fc2a
7001e8c
b534b3d
a84b8db
9787a97
d9d2118
887f95b
1074c8c
076623d
937655f
ff4bcb0
45dc935
d7c9f8a
6c9abda
89b4f26
2ab0da3
6673ce1
cdd1c3e
e076d12
b877213
fc66ecd
dcdd32c
6a153e5
32e6268
cf943e2
4a439af
c71e2c5
71c4012
4ca0b40
47b8867
d9a0fb5
1c06ce1
c399c58
106d84b
6b5aeea
8738b30
594ce64
7546e6a
2e6fa4c
cd7113b
a995150
789af78
1a12715
6625ab8
2d91b89
61dba1e
6334c10
1b9ff7b
55cacc1
4920da4
4a1fb7f
a995e18
fb01856
ef0bcda
e265ad1
9904c4f
0a98033
5f82305
494ad42
f7b9594
55d112a
741d420
19b1014
a2bab20
4b90775
a81fb12
d9ff813
fa0ec93
e0b580e
efa05f1
e0a6243
281344b
2676397
fbdbd34
80c55c6
5597bf3
9c09b78
28413a7
1e1e790
827441c
ac424ac
6d3e10f
19733c5
f7a1193
0f8bee6
106b1f7
fd262d9
8f79592
d1554ec
92d5184
81f5c90
57a2ddd
70946d1
dc4462a
0004cf4
2a5b816
d00f3e8
7bc1c6c
7a99509
256f3a5
80f3d38
c9873b8
4f0c633
b3014ae
412fba4
4f4fed6
9dee523
f055f3b
441d5ca
96f9662
b3078a7
9f01802
92c99af
5614176
f18f4d3
26cfd0f
ab272e3
e93097e
2970099
ec7f683
68b9678
6b14213
8cc64bb
6227baf
be9811d
e69fd24
47f117a
5f26869
09539d4
ea1fe4f
b109130
2533b04
1db0bec
121e64b
1e2497a
46e54c8
1e8cd7b
1667f18
5df5e51
0d29a09
4d6af74
6242ebc
683abcb
0c8d9e7
e620a05
45d5c7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,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(); | ||
|
@@ -131,6 +130,23 @@ fn use_trie_function() { | |
assert_eq!(runtime_api.use_trie(&block_id).unwrap(), 2); | ||
} | ||
|
||
#[test] | ||
fn use_history_data() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both of these tests should be live somewhere else. |
||
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!(runtime_api.use_history_data(&block_id).is_ok()); | ||
} | ||
|
||
#[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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// 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(); | ||
}); | ||
} | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not add this to the main workspace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fuzz generated cargo.toml isolate it from a workspace explicitly, I am not sure if there is any good reason for it, "cargo test" behaving oddly on the project can be one.