Companion for #13683 (#6944)

* Companion for #13683

* Wraps trait is not required

* update lockfile for {"substrate"}

---------

Co-authored-by: parity-processbot <>
This commit is contained in:
Davide Galassi
2023-03-24 15:43:21 +01:00
committed by GitHub
parent bd209c2d70
commit 260d073658
14 changed files with 228 additions and 247 deletions
+183 -183
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -34,7 +34,7 @@ use polkadot_primitives::{
CandidateDescriptor, CollatorId, GroupRotationInfo, HeadData, PersistedValidationData, CandidateDescriptor, CollatorId, GroupRotationInfo, HeadData, PersistedValidationData,
PvfExecTimeoutKind, ScheduledCore, PvfExecTimeoutKind, ScheduledCore,
}; };
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
use sp_keystore::Keystore; use sp_keystore::Keystore;
use sp_tracing as _; use sp_tracing as _;
@@ -45,7 +45,7 @@ use polkadot_node_subsystem::{
use polkadot_node_subsystem_util::TimeoutExt; use polkadot_node_subsystem_util::TimeoutExt;
use sc_keystore::LocalKeystore; use sc_keystore::LocalKeystore;
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_core::{sr25519::Pair, testing::TaskExecutor, Pair as PairT}; use sp_core::{sr25519::Pair, testing::TaskExecutor, Pair as PairT};
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
use sp_keystore::{Keystore, KeystorePtr}; use sp_keystore::{Keystore, KeystorePtr};
@@ -562,18 +562,18 @@ impl TestState {
let validator_id = self.validators[index.0 as usize].public(); let validator_id = self.validators[index.0 as usize].public();
let payload = ApprovalVote(candidate_hash).signing_payload(session); let payload = ApprovalVote(candidate_hash).signing_payload(session);
let signature = let signature = keystore
Keystore::sign_with(&*keystore, ValidatorId::ID, &validator_id.into(), &payload[..]) .sr25519_sign(ValidatorId::ID, &validator_id, &payload)
.ok() .ok()
.flatten() .flatten()
.unwrap(); .unwrap();
SignedDisputeStatement::new_unchecked_from_trusted_source( SignedDisputeStatement::new_unchecked_from_trusted_source(
DisputeStatement::Valid(ValidDisputeStatementKind::ApprovalChecking), DisputeStatement::Valid(ValidDisputeStatementKind::ApprovalChecking),
candidate_hash, candidate_hash,
session, session,
validator_id.into(), validator_id.into(),
signature.try_into().unwrap(), signature.into(),
) )
} }
+1 -1
View File
@@ -57,7 +57,7 @@ pub fn scheduled_core(id: u32) -> ScheduledCore {
mod select_availability_bitfields { mod select_availability_bitfields {
use super::{super::*, default_bitvec, occupied_core}; use super::{super::*, default_bitvec, occupied_core};
use polkadot_primitives::{ScheduledCore, SigningContext, ValidatorId, ValidatorIndex}; use polkadot_primitives::{ScheduledCore, SigningContext, ValidatorId, ValidatorIndex};
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_keystore::{testing::MemoryKeystore, Keystore, KeystorePtr}; use sp_keystore::{testing::MemoryKeystore, Keystore, KeystorePtr};
use std::sync::Arc; use std::sync::Arc;
+1 -1
View File
@@ -29,7 +29,7 @@ use polkadot_primitives::{
BlockNumber, Hash, Header, PvfCheckStatement, SessionIndex, ValidationCode, ValidationCodeHash, BlockNumber, Hash, Header, PvfCheckStatement, SessionIndex, ValidationCode, ValidationCodeHash,
ValidatorId, ValidatorId,
}; };
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_core::testing::TaskExecutor; use sp_core::testing::TaskExecutor;
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
use sp_keystore::Keystore; use sp_keystore::Keystore;
@@ -33,7 +33,7 @@ use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_node_subsystem_util::TimeoutExt; use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::{AvailabilityBitfield, Signed, ValidatorIndex}; use polkadot_primitives::{AvailabilityBitfield, Signed, ValidatorIndex};
use rand_chacha::ChaCha12Rng; use rand_chacha::ChaCha12Rng;
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_authority_discovery::AuthorityPair as AuthorityDiscoveryPair; use sp_authority_discovery::AuthorityPair as AuthorityDiscoveryPair;
use sp_core::Pair as PairT; use sp_core::Pair as PairT;
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
@@ -28,7 +28,7 @@ use lazy_static::lazy_static;
use polkadot_node_network_protocol::{authority_discovery::AuthorityDiscovery, PeerId}; use polkadot_node_network_protocol::{authority_discovery::AuthorityDiscovery, PeerId};
use sc_keystore::LocalKeystore; use sc_keystore::LocalKeystore;
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
use sp_keystore::{Keystore, KeystorePtr}; use sp_keystore::{Keystore, KeystorePtr};
@@ -36,7 +36,7 @@ use rand::{seq::SliceRandom as _, SeedableRng};
use rand_chacha::ChaCha20Rng; use rand_chacha::ChaCha20Rng;
use sc_network::Multiaddr; use sc_network::Multiaddr;
use sp_application_crypto::{AppKey, ByteArray}; use sp_application_crypto::{AppCrypto, ByteArray};
use sp_keystore::{Keystore, KeystorePtr}; use sp_keystore::{Keystore, KeystorePtr};
use polkadot_node_network_protocol::{ use polkadot_node_network_protocol::{
@@ -42,7 +42,7 @@ use polkadot_primitives_test_helpers::{
dummy_committed_candidate_receipt, dummy_hash, AlwaysZeroRng, dummy_committed_candidate_receipt, dummy_hash, AlwaysZeroRng,
}; };
use sc_keystore::LocalKeystore; use sc_keystore::LocalKeystore;
use sp_application_crypto::{sr25519::Pair, AppKey, Pair as TraitPair}; use sp_application_crypto::{sr25519::Pair, AppCrypto, Pair as TraitPair};
use sp_authority_discovery::AuthorityPair; use sp_authority_discovery::AuthorityPair;
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
use sp_keystore::{Keystore, KeystorePtr}; use sp_keystore::{Keystore, KeystorePtr};
+12 -22
View File
@@ -21,8 +21,8 @@ use std::collections::{
use parity_scale_codec::{Decode, Encode}; use parity_scale_codec::{Decode, Encode};
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_keystore::{Error as KeystoreError, Keystore, KeystorePtr}; use sp_keystore::{Error as KeystoreError, KeystorePtr};
use super::{Statement, UncheckedSignedFullStatement}; use super::{Statement, UncheckedSignedFullStatement};
use polkadot_primitives::{ use polkadot_primitives::{
@@ -221,26 +221,16 @@ impl SignedDisputeStatement {
}; };
let data = dispute_statement.payload_data(candidate_hash, session_index); let data = dispute_statement.payload_data(candidate_hash, session_index);
let signature = Keystore::sign_with( let signature = keystore
&**keystore, .sr25519_sign(ValidatorId::ID, validator_public.as_ref(), &data)?
ValidatorId::ID, .map(|sig| Self {
&validator_public.clone().into(), dispute_statement,
&data, candidate_hash,
)?; validator_public,
validator_signature: sig.into(),
let signature = match signature { session_index,
Some(sig) => });
sig.try_into().map_err(|_| KeystoreError::KeyNotSupported(ValidatorId::ID))?, Ok(signature)
None => return Ok(None),
};
Ok(Some(Self {
dispute_statement,
candidate_hash,
validator_public,
validator_signature: signature,
session_index,
}))
} }
/// Access the underlying dispute statement /// Access the underlying dispute statement
@@ -17,7 +17,7 @@
use std::sync::Arc; use std::sync::Arc;
use sc_keystore::LocalKeystore; use sc_keystore::LocalKeystore;
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_keyring::Sr25519Keyring; use sp_keyring::Sr25519Keyring;
use sp_keystore::{Keystore, KeystorePtr}; use sp_keystore::{Keystore, KeystorePtr};
+7 -10
View File
@@ -49,9 +49,9 @@ use polkadot_primitives::{
ValidatorSignature, ValidatorSignature,
}; };
pub use rand; pub use rand;
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_core::ByteArray; use sp_core::ByteArray;
use sp_keystore::{Error as KeystoreError, Keystore, KeystorePtr}; use sp_keystore::{Error as KeystoreError, KeystorePtr};
use std::time::Duration; use std::time::Duration;
use thiserror::Error; use thiserror::Error;
@@ -276,7 +276,7 @@ pub fn signing_key_and_index(
keystore: &KeystorePtr, keystore: &KeystorePtr,
) -> Option<(ValidatorId, ValidatorIndex)> { ) -> Option<(ValidatorId, ValidatorIndex)> {
for (i, v) in validators.iter().enumerate() { for (i, v) in validators.iter().enumerate() {
if Keystore::has_keys(&**keystore, &[(v.to_raw_vec(), ValidatorId::ID)]) { if keystore.has_keys(&[(v.to_raw_vec(), ValidatorId::ID)]) {
return Some((v.clone(), ValidatorIndex(i as _))) return Some((v.clone(), ValidatorIndex(i as _)))
} }
} }
@@ -292,13 +292,10 @@ pub fn sign(
key: &ValidatorId, key: &ValidatorId,
data: &[u8], data: &[u8],
) -> Result<Option<ValidatorSignature>, KeystoreError> { ) -> Result<Option<ValidatorSignature>, KeystoreError> {
let signature = Keystore::sign_with(&**keystore, ValidatorId::ID, &key.into(), &data)?; let signature = keystore
.sr25519_sign(ValidatorId::ID, key.as_ref(), data)?
match signature { .map(|sig| sig.into());
Some(sig) => Ok(signature)
Ok(Some(sig.try_into().map_err(|_| KeystoreError::KeyNotSupported(ValidatorId::ID))?)),
None => Ok(None),
}
} }
/// Find the validator group the given validator index belongs to. /// Find the validator group the given validator index belongs to.
@@ -21,7 +21,7 @@ use std::num::NonZeroUsize;
use lru::LruCache; use lru::LruCache;
use parity_scale_codec::Encode; use parity_scale_codec::Encode;
use sp_application_crypto::AppKey; use sp_application_crypto::AppCrypto;
use sp_core::crypto::ByteArray; use sp_core::crypto::ByteArray;
use sp_keystore::{Keystore, KeystorePtr}; use sp_keystore::{Keystore, KeystorePtr};
+10 -16
View File
@@ -18,9 +18,9 @@ use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo; use scale_info::TypeInfo;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use application_crypto::AppKey; use application_crypto::AppCrypto;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use sp_keystore::{Error as KeystoreError, Keystore, KeystorePtr}; use sp_keystore::{Error as KeystoreError, KeystorePtr};
use sp_std::prelude::Vec; use sp_std::prelude::Vec;
use primitives::RuntimeDebug; use primitives::RuntimeDebug;
@@ -252,20 +252,14 @@ impl<Payload: EncodeAs<RealPayload>, RealPayload: Encode> UncheckedSigned<Payloa
key: &ValidatorId, key: &ValidatorId,
) -> Result<Option<Self>, KeystoreError> { ) -> Result<Option<Self>, KeystoreError> {
let data = Self::payload_data(&payload, context); let data = Self::payload_data(&payload, context);
let signature = Keystore::sign_with(&**keystore, ValidatorId::ID, &key.into(), &data)?; let signature =
keystore.sr25519_sign(ValidatorId::ID, key.as_ref(), &data)?.map(|sig| Self {
let signature = match signature { payload,
Some(sig) => validator_index,
sig.try_into().map_err(|_| KeystoreError::KeyNotSupported(ValidatorId::ID))?, signature: sig.into(),
None => return Ok(None), real_payload: std::marker::PhantomData,
}; });
Ok(signature)
Ok(Some(Self {
payload,
validator_index,
signature,
real_payload: std::marker::PhantomData,
}))
} }
/// Validate the payload given the context and public key /// Validate the payload given the context and public key