Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/executor/src/wasm_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 1)]),
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 1)]),
};

let version = decode_version(&old_runtime_version.encode()).unwrap();
Expand All @@ -507,7 +507,7 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 3)]),
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
};

decode_version(&old_runtime_version.encode()).unwrap_err();
Expand All @@ -521,7 +521,7 @@ mod tests {
authoring_version: 1,
spec_version: 1,
impl_version: 1,
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 3)]),
apis: sp_api::create_apis_vec!([(<dyn Core::<Block>>::ID, 3)]),
transaction_version: 3,
};

Expand Down
2 changes: 1 addition & 1 deletion frame/merkle-mountain-range/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ decl_storage! {
decl_module! {
/// A public part of the pallet.
pub struct Module<T: Config<I>, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {
fn on_initialize(n: T::BlockNumber) -> Weight {
fn on_initialize(_n: T::BlockNumber) -> Weight {
use primitives::LeafDataProvider;
let leaves = Self::mmr_leaves();
let peaks_before = mmr::utils::NodesUtils::new(leaves).number_of_peaks();
Expand Down
2 changes: 0 additions & 2 deletions frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ macro_rules! parameter_types {
}

#[cfg(not(feature = "std"))]
#[doc(inline)]
#[macro_export]
macro_rules! parameter_types_impl_thread_local {
( $( $any:tt )* ) => {
Expand All @@ -406,7 +405,6 @@ macro_rules! parameter_types_impl_thread_local {
}

#[cfg(feature = "std")]
#[doc(inline)]
#[macro_export]
macro_rules! parameter_types_impl_thread_local {
(
Expand Down
8 changes: 4 additions & 4 deletions frame/utility/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ pub mod example {

decl_module! {
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
#[weight = *weight]
fn noop(_origin, weight: Weight) { }
#[weight = *_weight]
fn noop(_origin, _weight: Weight) { }

#[weight = *start_weight]
#[weight = *_start_weight]
fn foobar(
origin,
err: bool,
start_weight: Weight,
_start_weight: Weight,
end_weight: Option<Weight>,
) -> DispatchResultWithPostInfo {
let _ = ensure_signed(origin)?;
Expand Down
12 changes: 6 additions & 6 deletions primitives/api/test/tests/decl_and_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ fn test_client_side_function_signature() {

#[test]
fn check_runtime_api_info() {
assert_eq!(&Api::<Block>::ID, &runtime_decl_for_Api::ID);
assert_eq!(Api::<Block>::VERSION, runtime_decl_for_Api::VERSION);
assert_eq!(Api::<Block>::VERSION, 1);
assert_eq!(&<dyn Api::<Block>>::ID, &runtime_decl_for_Api::ID);
assert_eq!(<dyn Api::<Block>>::VERSION, runtime_decl_for_Api::VERSION);
assert_eq!(<dyn Api::<Block>>::VERSION, 1);

assert_eq!(
ApiWithCustomVersion::<Block>::VERSION,
<dyn ApiWithCustomVersion::<Block>>::VERSION,
runtime_decl_for_ApiWithCustomVersion::VERSION,
);
assert_eq!(
&ApiWithCustomVersion::<Block>::ID,
&<dyn ApiWithCustomVersion::<Block>>::ID,
&runtime_decl_for_ApiWithCustomVersion::ID,
);
assert_eq!(ApiWithCustomVersion::<Block>::VERSION, 2);
assert_eq!(<dyn ApiWithCustomVersion::<Block>>::VERSION, 2);
}

fn check_runtime_api_versions_contains<T: RuntimeApiInfo + ?Sized>() {
Expand Down
113 changes: 78 additions & 35 deletions primitives/core/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.



#[macro_use]
extern crate criterion;

use criterion::{Criterion, black_box, Bencher, Fun};
use std::time::Duration;
use criterion::{Criterion, black_box, Bencher, BenchmarkId};
use sp_core::crypto::Pair as _;
use sp_core::hashing::{twox_128, blake2_128};

Expand Down Expand Up @@ -49,87 +46,133 @@ fn bench_twox_128(b: &mut Bencher, key: &Vec<u8>) {
}

fn bench_hash_128_fix_size(c: &mut Criterion) {
let mut group = c.benchmark_group("fix size hashing");

let key = get_key(MAX_KEY_SIZE);
let blake_fn = Fun::new("blake2_128", bench_blake2_128);
let twox_fn = Fun::new("twox_128", bench_twox_128);
let fns = vec![blake_fn, twox_fn];

c.bench_functions("fixed size hashing", fns, key);
group.bench_with_input("blake2_128", &key, bench_blake2_128);
group.bench_with_input("twox_128", &key, bench_twox_128);

group.finish();
}

fn bench_hash_128_dyn_size(c: &mut Criterion) {
let mut keys = Vec::new();
let mut group = c.benchmark_group("dyn size hashing");

for i in (2..MAX_KEY_SIZE).step_by(4) {
keys.push(get_key(i).clone())
let key = get_key(i);

group.bench_with_input(
BenchmarkId::new("blake2_128", format!("{}", i)),
&key,
bench_blake2_128,
);
group.bench_with_input(
BenchmarkId::new("twox_128", format!("{}", i)),
&key,
bench_twox_128,
);
}

c.bench_function_over_inputs("dyn size hashing - blake2", |b, key| bench_blake2_128(b, &key), keys.clone());
c.bench_function_over_inputs("dyn size hashing - twox", |b, key| bench_twox_128(b, &key), keys);
group.finish();
}

fn bench_ed25519(c: &mut Criterion) {
c.bench_function_over_inputs("signing - ed25519", |b, &msg_size| {
let mut group = c.benchmark_group("ed25519");

for msg_size in vec![32, 1024, 1024 * 1024] {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = sp_core::ed25519::Pair::generate().0;
b.iter(|| key.sign(&msg))
}, vec![32, 1024, 1024 * 1024]);
group.bench_function(
BenchmarkId::new("signing", format!("{}", msg_size)),
|b| b.iter(|| key.sign(&msg)),
);
}

c.bench_function_over_inputs("verifying - ed25519", |b, &msg_size| {
for msg_size in vec![32, 1024, 1024 * 1024] {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = sp_core::ed25519::Pair::generate().0;
let sig = key.sign(&msg);
let public = key.public();
b.iter(|| sp_core::ed25519::Pair::verify(&sig, &msg, &public))
}, vec![32, 1024, 1024 * 1024]);
group.bench_function(
BenchmarkId::new("verifying", format!("{}", msg_size)),
|b| b.iter(|| sp_core::ed25519::Pair::verify(&sig, &msg, &public)),
);
}

group.finish();
}

fn bench_sr25519(c: &mut Criterion) {
c.bench_function_over_inputs("signing - sr25519", |b, &msg_size| {
let mut group = c.benchmark_group("ed25519");
Comment thread
shawntabrizi marked this conversation as resolved.
Outdated

for msg_size in vec![32, 1024, 1024 * 1024] {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = sp_core::sr25519::Pair::generate().0;
b.iter(|| key.sign(&msg))
}, vec![32, 1024, 1024 * 1024]);
group.bench_function(
BenchmarkId::new("signing", format!("{}", msg_size)),
|b| b.iter(|| key.sign(&msg)),
);
}

c.bench_function_over_inputs("verifying - sr25519", |b, &msg_size| {
for msg_size in vec![32, 1024, 1024 * 1024] {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = sp_core::sr25519::Pair::generate().0;
let sig = key.sign(&msg);
let public = key.public();
b.iter(|| sp_core::sr25519::Pair::verify(&sig, &msg, &public))
}, vec![32, 1024, 1024 * 1024]);
group.bench_function(
BenchmarkId::new("verifying", format!("{}", msg_size)),
|b| b.iter(|| sp_core::sr25519::Pair::verify(&sig, &msg, &public)),
);
}

group.finish();
}

fn bench_ecdsa(c: &mut Criterion) {
c.bench_function_over_inputs("signing - ecdsa", |b, &msg_size| {
let mut group = c.benchmark_group("ed25519");
Comment thread
shawntabrizi marked this conversation as resolved.
Outdated

for msg_size in vec![32, 1024, 1024 * 1024] {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = sp_core::ecdsa::Pair::generate().0;
b.iter(|| key.sign(&msg))
}, vec![32, 1024, 1024 * 1024]);
group.bench_function(
BenchmarkId::new("signing", format!("{}", msg_size)),
|b| b.iter(|| key.sign(&msg)),
);
}

c.bench_function_over_inputs("verifying - ecdsa", |b, &msg_size| {
for msg_size in vec![32, 1024, 1024 * 1024] {
let msg = (0..msg_size)
.map(|_| rand::random::<u8>())
.collect::<Vec<_>>();
let key = sp_core::ecdsa::Pair::generate().0;
let sig = key.sign(&msg);
let public = key.public();
b.iter(|| sp_core::ecdsa::Pair::verify(&sig, &msg, &public))
}, vec![32, 1024, 1024 * 1024]);
}
group.bench_function(
BenchmarkId::new("verifying", format!("{}", msg_size)),
|b| b.iter(|| sp_core::ecdsa::Pair::verify(&sig, &msg, &public)),
);
}

criterion_group!{
name = benches;
config = Criterion::default().warm_up_time(Duration::from_millis(500)).without_plots();
targets = bench_hash_128_fix_size, bench_hash_128_dyn_size, bench_ed25519, bench_sr25519, bench_ecdsa
group.finish();
}

criterion_group!(
benches,
bench_hash_128_fix_size,
bench_hash_128_dyn_size,
bench_ed25519,
bench_sr25519,
bench_ecdsa,
);
criterion_main!(benches);