Update to work with async keystore – Companion PR for #7000 (#1740)

* Fix keystore types

* Use SyncCryptoStorePtr

* Borrow keystore

* Fix unused imports

* Fix polkadot service

* Fix bitfield-distribution tests

* Fix indentation

* Fix backing tests

* Fix tests

* Fix provisioner tests

* Removed SyncCryptoStorePtr

* Fix services

* Address PR feedback

* Address PR feedback - 2

* Update CryptoStorePtr imports to be from sp_keystore

* Typo

* Fix CryptoStore import

* Document the reason behind using filesystem keystore

* Remove VALIDATORS

* Fix duplicate dependency

* Mark sp-keystore as optional

* Fix availability distribution

* Fix call to sign_with

* Fix keystore usage

* Remove tokio and fix parachains Cargo config

* Typos

* Fix keystore dereferencing

* Fix CryptoStore import

* Fix provisioner

* Fix node backing

* Update services

* Cleanup dependencies

* Use sync_keystore

* Fix node service

* Fix node service - 2

* Fix node service - 3

* Rename CryptoStorePtr to SyncCryptoStorePtr

* "Update Substrate"

* Apply suggestions from code review

* Update node/core/backing/Cargo.toml

* Update primitives/src/v0.rs

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

* Fix wasm build

* Update Cargo.lock

Co-authored-by: parity-processbot <>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Rakan Alhneiti
2020-10-09 12:54:03 +02:00
committed by GitHub
parent a2044bb87e
commit bd75a4ce18
23 changed files with 663 additions and 395 deletions
@@ -25,12 +25,8 @@
use codec::{Decode, Encode};
use futures::{channel::oneshot, FutureExt};
use keystore::KeyStorePtr;
use sp_core::{
crypto::Public,
traits::BareCryptoStore,
};
use sc_keystore as keystore;
use sp_core::crypto::Public;
use sp_keystore::{CryptoStore, SyncCryptoStorePtr};
use log::{trace, warn};
use polkadot_erasure_coding::branch_hash;
@@ -293,7 +289,7 @@ impl ProtocolState {
/// which depends on the message type received.
async fn handle_network_msg<Context>(
ctx: &mut Context,
keystore: KeyStorePtr,
keystore: &SyncCryptoStorePtr,
state: &mut ProtocolState,
metrics: &Metrics,
bridge_message: NetworkBridgeEvent<protocol_v1::AvailabilityDistributionMessage>,
@@ -332,7 +328,7 @@ where
/// Handle the changes necessary when our view changes.
async fn handle_our_view_change<Context>(
ctx: &mut Context,
keystore: KeyStorePtr,
keystore: &SyncCryptoStorePtr,
state: &mut ProtocolState,
view: View,
metrics: &Metrics,
@@ -353,7 +349,7 @@ where
let validator_index = obtain_our_validator_index(
&validators,
keystore.clone(),
);
).await;
state.add_relay_parent(ctx, added, validators, validator_index).await?;
}
@@ -579,18 +575,16 @@ where
/// Obtain the first key which has a signing key.
/// Returns the index within the validator set as `ValidatorIndex`, if there exists one,
/// otherwise, `None` is returned.
fn obtain_our_validator_index(
async fn obtain_our_validator_index(
validators: &[ValidatorId],
keystore: KeyStorePtr,
keystore: SyncCryptoStorePtr,
) -> Option<ValidatorIndex> {
let keystore = keystore.read();
validators.iter().enumerate().find_map(|(idx, validator)| {
if keystore.has_keys(&[(validator.to_raw_vec(), PARACHAIN_KEY_TYPE_ID)]) {
Some(idx as ValidatorIndex)
} else {
None
for (idx, validator) in validators.iter().enumerate() {
if CryptoStore::has_keys(&*keystore, &[(validator.to_raw_vec(), PARACHAIN_KEY_TYPE_ID)]).await {
return Some(idx as ValidatorIndex)
}
})
}
None
}
/// Handle an incoming message from a peer.
@@ -712,7 +706,7 @@ where
/// The bitfield distribution subsystem.
pub struct AvailabilityDistributionSubsystem {
/// Pointer to a keystore, which is required for determining this nodes validator index.
keystore: KeyStorePtr,
keystore: SyncCryptoStorePtr,
/// Prometheus metrics.
metrics: Metrics,
}
@@ -722,7 +716,7 @@ impl AvailabilityDistributionSubsystem {
const K: usize = 3;
/// Create a new instance of the availability distribution.
pub fn new(keystore: KeyStorePtr, metrics: Metrics) -> Self {
pub fn new(keystore: SyncCryptoStorePtr, metrics: Metrics) -> Self {
Self { keystore, metrics }
}
@@ -741,7 +735,7 @@ impl AvailabilityDistributionSubsystem {
} => {
if let Err(e) = handle_network_msg(
&mut ctx,
self.keystore.clone(),
&self.keystore.clone(),
&mut state,
&self.metrics,
event,