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

Commit

Permalink
Adapt to new CryptoStore api
Browse files Browse the repository at this point in the history
companion PR for paritytech/substrate#8619
  • Loading branch information
Falco Hirschenberger authored and hirschenberger committed Apr 14, 2021
1 parent 2daf65c commit c158049
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
12 changes: 5 additions & 7 deletions node/network/availability-distribution/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,11 @@ impl Runtime {
///
/// Returns: None if we are not a validator.
async fn get_our_index(&self, validators: &[ValidatorId]) -> Option<ValidatorIndex> {
for (i, v) in validators.iter().enumerate() {
if CryptoStore::has_keys(&*self.keystore, &[(v.to_raw_vec(), ValidatorId::ID)])
.await
{
return Some(ValidatorIndex(i as u32));
}
}
let keys: Vec<_> = validators.iter().map(|v| (v.to_raw_vec(), ValidatorId::ID)).collect();
CryptoStore::has_keys(&*self.keystore, &keys).await.into_found().next().and_then(|i| {
return Some(ValidatorIndex(i as u32));
});

None
}
}
12 changes: 5 additions & 7 deletions node/network/availability-distribution/src/session_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,11 @@ impl SessionCache {
///
/// Returns: None if we are not a validator.
async fn get_our_index(&self, validators: Vec<ValidatorId>) -> Option<ValidatorIndex> {
for (i, v) in validators.iter().enumerate() {
if CryptoStore::has_keys(&*self.keystore, &[(v.to_raw_vec(), ValidatorId::ID)])
.await
{
return Some(ValidatorIndex(i as u32));
}
}
let keys: Vec<_> = validators.iter().map(|v| (v.to_raw_vec(), ValidatorId::ID)).collect();
CryptoStore::has_keys(&*self.keystore, &keys).await.into_found().next().and_then(|i| {
return Some(ValidatorIndex(i as u32));
});

None
}
}
11 changes: 5 additions & 6 deletions node/network/gossip-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,12 @@ async fn ensure_i_am_an_authority(
keystore: &SyncCryptoStorePtr,
authorities: &[AuthorityDiscoveryId],
) -> Result<(), util::Error> {
for v in authorities {
if CryptoStore::has_keys(&**keystore, &[(v.to_raw_vec(), AuthorityDiscoveryId::ID)])
.await
{
return Ok(());
}
let keys: Vec<_> = authorities.iter().map(|v| (v.to_raw_vec(), AuthorityDiscoveryId::ID)).collect();
if CryptoStore::has_keys(&**keystore, &keys).await.found_any()
{
return Ok(());
}

Err(util::Error::NotAValidator)
}

Expand Down
10 changes: 5 additions & 5 deletions node/subsystem-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ pub async fn signing_key(validators: &[ValidatorId], keystore: &SyncCryptoStoreP
pub async fn signing_key_and_index(validators: &[ValidatorId], keystore: &SyncCryptoStorePtr)
-> Option<(ValidatorId, ValidatorIndex)>
{
for (i, v) in validators.iter().enumerate() {
if CryptoStore::has_keys(&**keystore, &[(v.to_raw_vec(), ValidatorId::ID)]).await {
return Some((v.clone(), ValidatorIndex(i as _)));
}
}
let keys: Vec<_> = validators.iter().map(|v| (v.to_raw_vec(), ValidatorId::ID)).collect();
CryptoStore::has_keys(&**keystore, &keys).await.into_found().next().and_then(|i| {
return Some((validators[i].clone(), ValidatorIndex(i as _)));
});

None
}

Expand Down

0 comments on commit c158049

Please sign in to comment.