Batch signature verification (#5023)

* create parallel tasks extension

* make type system happy

* basic externalities

* test for dynamic extensions

* batching test

* remove premature verify_batch

* shnschnorrkel batch

* alter test

* shnschnorrkel test

* executive batching

* some docs

* also multi/any signatgures

* error propagation

* styling

* make verification extension optional

* experimental ed25519 parallelization

* some merge fallout

* utilize task executor

* merge fallout

* utilize task executor more

* another merge fallout

* feature-gate sp-io

* arrange toml

* fix no-std

* sr25519 batching and refactoring

* add docs

* fix name

* add newline

* fix block import test

* long sr25519 test

* blocking instead of parking

* move everything in crypto

* return batch_verify to check :)

* use condvars

* use multi-threaded executor for benches

* don't call via host interface

* try no spawning

* add true

* cleanup

* straighten batching

* remove signature check from this test (?)

* remove now pointless test

* remove another now useless test

* fix warnings

* Revert "remove another now useless test"

This reverts commit bbdec24bb67ed4373072daef7c863e1a8825bd8b.

* rethink the sp-io-part

* Revert "remove now pointless test"

This reverts commit 4d553066322e65782264caa6053d4cd5538df977.

* fix wording

* add  wording

* add todo and fix

* return check and fix

* add logging in sp-io

* Update primitives/io/src/batch_verifier.rs

Co-Authored-By: cheme <emericchevalier.pro@gmail.com>

* address review and use std condvar

* account for early exit

* address reivew

* address review

* more suggestions

* add docs for batch verification

* remove unused

* more review suggestions

* move to sp-runtime

* add expects

* remove blocks

* use entry

* Update primitives/io/src/batch_verifier.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update primitives/externalities/src/extensions.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* update overlooked note

* remove stupid return

* Update primitives/io/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update primitives/io/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* fix wording

* bump spec_version

Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Nikolay Volf
2020-04-16 22:40:04 +03:00
committed by GitHub
parent 36243068bd
commit 372f8b2c7e
21 changed files with 711 additions and 47 deletions
+1 -1
View File
@@ -127,7 +127,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// and set impl_version to 0. If only runtime
// implementation changes and behavior does not, then leave spec_version as
// is and increment impl_version.
spec_version: 241,
spec_version: 242,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
};
+1
View File
@@ -50,6 +50,7 @@ sp-blockchain = { version = "2.0.0-dev", path = "../../../primitives/blockchain"
log = "0.4.8"
tempfile = "3.1.0"
fs_extra = "1"
futures = "0.3.1"
[dev-dependencies]
criterion = "0.3.0"
+35 -4
View File
@@ -47,7 +47,7 @@ use node_runtime::{
AccountId,
Signature,
};
use sp_core::{ExecutionContext, blake2_256};
use sp_core::{ExecutionContext, blake2_256, traits::CloneableSpawn};
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_inherents::InherentData;
@@ -57,6 +57,7 @@ use sc_client_api::{
};
use sp_core::{Pair, Public, sr25519, ed25519};
use sc_block_builder::BlockBuilderProvider;
use futures::{executor, task};
/// Keyring full of accounts for benching.
///
@@ -142,6 +143,36 @@ impl BlockType {
}
}
/// Benchmarking task executor.
///
/// Uses multiple threads as the regular executable.
#[derive(Debug, Clone)]
pub struct TaskExecutor {
pool: executor::ThreadPool,
}
impl TaskExecutor {
fn new() -> Self {
Self {
pool: executor::ThreadPool::new()
.expect("Failed to create task executor")
}
}
}
impl task::Spawn for TaskExecutor {
fn spawn_obj(&self, future: task::FutureObj<'static, ()>)
-> Result<(), task::SpawnError> {
self.pool.spawn_obj(future)
}
}
impl CloneableSpawn for TaskExecutor {
fn clone(&self) -> Box<dyn CloneableSpawn> {
Box::new(Clone::clone(self))
}
}
impl BenchDb {
/// New immutable benchmarking database.
///
@@ -168,8 +199,8 @@ impl BenchDb {
/// and keep it there until struct is dropped.
///
/// You can `clone` this database or you can `create_context` from it
/// (which also do `clone`) to run actual operation against new database
/// which will be identical to this.
/// (which also does `clone`) to run actual operation against new database
/// which will be identical to the original.
pub fn new(keyring_length: usize) -> Self {
Self::with_key_types(keyring_length, KeyTypes::Sr25519)
}
@@ -197,7 +228,7 @@ impl BenchDb {
None,
None,
ExecutionExtensions::new(profile.into_execution_strategies(), None),
sp_core::tasks::executor(),
Box::new(TaskExecutor::new()),
None,
).expect("Should not fail");