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

Commit 14e0a0b

Browse files
davxyskunert
andauthored
Relax Send/Sync/Clone requirements for Pair (#14647)
* Relax Send/Sync requirements for not instanced generic Pair * Remove leftover * Apply review suggestion Co-authored-by: Sebastian Kunert <skunert49@gmail.com> * Further cleanup * Trigger CI --------- Co-authored-by: Sebastian Kunert <skunert49@gmail.com>
1 parent cb450b6 commit 14e0a0b

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

client/consensus/aura/src/import_queue.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
authorities, standalone::SealVerificationError, AuthorityId, CompatibilityMode, Error,
2323
LOG_TARGET,
2424
};
25-
use codec::{Codec, Decode, Encode};
25+
use codec::Codec;
2626
use log::{debug, info, trace};
2727
use prometheus_endpoint::Registry;
2828
use sc_client_api::{backend::AuxStore, BlockOf, UsageProvider};
@@ -44,7 +44,7 @@ use sp_runtime::{
4444
traits::{Block as BlockT, Header, NumberFor},
4545
DigestItem,
4646
};
47-
use std::{fmt::Debug, hash::Hash, marker::PhantomData, sync::Arc};
47+
use std::{fmt::Debug, marker::PhantomData, sync::Arc};
4848

4949
/// check a header has been signed by the right key. If the slot is too far in the future, an error
5050
/// will be returned. If it's successful, returns the pre-header and the digest item
@@ -60,9 +60,9 @@ fn check_header<C, B: BlockT, P: Pair>(
6060
check_for_equivocation: CheckForEquivocation,
6161
) -> Result<CheckedHeader<B::Header, (Slot, DigestItem)>, Error<B>>
6262
where
63+
P::Public: Codec,
6364
P::Signature: Codec,
6465
C: sc_client_api::backend::AuxStore,
65-
P::Public: Encode + Decode + PartialEq + Clone,
6666
{
6767
let check_result =
6868
crate::standalone::check_header_slot_and_seal::<B, P>(slot_now, header, authorities);
@@ -101,11 +101,11 @@ where
101101
/// A verifier for Aura blocks.
102102
pub struct AuraVerifier<C, P, CIDP, N> {
103103
client: Arc<C>,
104-
phantom: PhantomData<P>,
105104
create_inherent_data_providers: CIDP,
106105
check_for_equivocation: CheckForEquivocation,
107106
telemetry: Option<TelemetryHandle>,
108107
compatibility_mode: CompatibilityMode<N>,
108+
_phantom: PhantomData<fn() -> P>,
109109
}
110110

111111
impl<C, P, CIDP, N> AuraVerifier<C, P, CIDP, N> {
@@ -122,14 +122,13 @@ impl<C, P, CIDP, N> AuraVerifier<C, P, CIDP, N> {
122122
check_for_equivocation,
123123
telemetry,
124124
compatibility_mode,
125-
phantom: PhantomData,
125+
_phantom: PhantomData,
126126
}
127127
}
128128
}
129129

130130
impl<C, P, CIDP, N> AuraVerifier<C, P, CIDP, N>
131131
where
132-
P: Send + Sync + 'static,
133132
CIDP: Send,
134133
{
135134
async fn check_inherents<B: BlockT>(
@@ -168,9 +167,9 @@ impl<B: BlockT, C, P, CIDP> Verifier<B> for AuraVerifier<C, P, CIDP, NumberFor<B
168167
where
169168
C: ProvideRuntimeApi<B> + Send + Sync + sc_client_api::backend::AuxStore,
170169
C::Api: BlockBuilderApi<B> + AuraApi<B, AuthorityId<P>> + ApiExt<B>,
171-
P: Pair + Send + Sync + 'static,
172-
P::Public: Send + Sync + Hash + Eq + Clone + Decode + Encode + Debug + 'static,
173-
P::Signature: Encode + Decode,
170+
P: Pair,
171+
P::Public: Codec + Debug,
172+
P::Signature: Codec,
174173
CIDP: CreateInherentDataProviders<B, ()> + Send + Sync,
175174
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,
176175
{
@@ -365,9 +364,9 @@ where
365364
+ Send
366365
+ Sync
367366
+ 'static,
368-
P: Pair + Send + Sync + 'static,
369-
P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode,
370-
P::Signature: Encode + Decode,
367+
P: Pair + 'static,
368+
P::Public: Codec + Debug,
369+
P::Signature: Codec,
371370
S: sp_core::traits::SpawnEssentialNamed,
372371
CIDP: CreateInherentDataProviders<Block, ()> + Sync + Send + 'static,
373372
CIDP::InherentDataProviders: InherentDataProviderExt + Send + Sync,

client/consensus/aura/src/lib.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030
//!
3131
//! NOTE: Aura itself is designed to be generic over the crypto used.
3232
#![forbid(missing_docs, unsafe_code)]
33-
use std::{fmt::Debug, hash::Hash, marker::PhantomData, pin::Pin, sync::Arc};
33+
use std::{fmt::Debug, marker::PhantomData, pin::Pin, sync::Arc};
3434

35+
use codec::Codec;
3536
use futures::prelude::*;
3637

37-
use codec::{Codec, Decode, Encode};
38-
3938
use sc_client_api::{backend::AuxStore, BlockOf};
4039
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, StateAction};
4140
use sc_consensus_slots::{
@@ -48,7 +47,7 @@ use sp_application_crypto::AppPublic;
4847
use sp_blockchain::HeaderBackend;
4948
use sp_consensus::{BlockOrigin, Environment, Error as ConsensusError, Proposer, SelectChain};
5049
use sp_consensus_slots::Slot;
51-
use sp_core::crypto::{Pair, Public};
50+
use sp_core::crypto::Pair;
5251
use sp_inherents::CreateInherentDataProviders;
5352
use sp_keystore::KeystorePtr;
5453
use sp_runtime::traits::{Block as BlockT, Header, Member, NumberFor};
@@ -172,9 +171,9 @@ pub fn start_aura<P, B, C, SC, I, PF, SO, L, CIDP, BS, Error>(
172171
}: StartAuraParams<C, SC, I, PF, SO, L, CIDP, BS, NumberFor<B>>,
173172
) -> Result<impl Future<Output = ()>, ConsensusError>
174173
where
175-
P: Pair + Send + Sync,
176-
P::Public: AppPublic + Hash + Member + Encode + Decode,
177-
P::Signature: TryFrom<Vec<u8>> + Hash + Member + Encode + Decode,
174+
P: Pair,
175+
P::Public: AppPublic + Member,
176+
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
178177
B: BlockT,
179178
C: ProvideRuntimeApi<B> + BlockOf + AuxStore + HeaderBackend<B> + Send + Sync,
180179
C::Api: AuraApi<B, AuthorityId<P>>,
@@ -281,9 +280,9 @@ where
281280
C::Api: AuraApi<B, AuthorityId<P>>,
282281
PF: Environment<B, Error = Error> + Send + Sync + 'static,
283282
PF::Proposer: Proposer<B, Error = Error, Transaction = sp_api::TransactionFor<C, B>>,
284-
P: Pair + Send + Sync,
285-
P::Public: AppPublic + Hash + Member + Encode + Decode,
286-
P::Signature: TryFrom<Vec<u8>> + Hash + Member + Encode + Decode,
283+
P: Pair,
284+
P::Public: AppPublic + Member,
285+
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
287286
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync + 'static,
288287
Error: std::error::Error + Send + From<ConsensusError> + 'static,
289288
SO: SyncOracle + Send + Sync + Clone,
@@ -303,7 +302,7 @@ where
303302
block_proposal_slot_portion,
304303
max_block_proposal_slot_portion,
305304
compatibility_mode,
306-
_key_type: PhantomData::<P>,
305+
_phantom: PhantomData::<fn() -> P>,
307306
}
308307
}
309308

@@ -320,7 +319,7 @@ struct AuraWorker<C, E, I, P, SO, L, BS, N> {
320319
max_block_proposal_slot_portion: Option<SlotProportion>,
321320
telemetry: Option<TelemetryHandle>,
322321
compatibility_mode: CompatibilityMode<N>,
323-
_key_type: PhantomData<P>,
322+
_phantom: PhantomData<fn() -> P>,
324323
}
325324

326325
#[async_trait::async_trait]
@@ -333,9 +332,9 @@ where
333332
E: Environment<B, Error = Error> + Send + Sync,
334333
E::Proposer: Proposer<B, Error = Error, Transaction = sp_api::TransactionFor<C, B>>,
335334
I: BlockImport<B, Transaction = sp_api::TransactionFor<C, B>> + Send + Sync + 'static,
336-
P: Pair + Send + Sync,
337-
P::Public: AppPublic + Public + Member + Encode + Decode + Hash,
338-
P::Signature: TryFrom<Vec<u8>> + Member + Encode + Decode + Hash + Debug,
335+
P: Pair,
336+
P::Public: AppPublic + Member,
337+
P::Signature: TryFrom<Vec<u8>> + Member + Codec,
339338
SO: SyncOracle + Send + Clone + Sync,
340339
L: sc_consensus::JustificationSyncLink<B>,
341340
BS: BackoffAuthoringBlocksStrategy<NumberFor<B>> + Send + Sync + 'static,
@@ -806,10 +805,10 @@ mod tests {
806805
force_authoring: false,
807806
backoff_authoring_blocks: Some(BackoffAuthoringOnFinalizedHeadLagging::default()),
808807
telemetry: None,
809-
_key_type: PhantomData::<AuthorityPair>,
810808
block_proposal_slot_portion: SlotProportion::new(0.5),
811809
max_block_proposal_slot_portion: None,
812810
compatibility_mode: Default::default(),
811+
_phantom: PhantomData::<fn() -> AuthorityPair>,
813812
};
814813

815814
let head = Header::new(
@@ -856,10 +855,10 @@ mod tests {
856855
force_authoring: false,
857856
backoff_authoring_blocks: Option::<()>::None,
858857
telemetry: None,
859-
_key_type: PhantomData::<AuthorityPair>,
860858
block_proposal_slot_portion: SlotProportion::new(0.5),
861859
max_block_proposal_slot_portion: None,
862860
compatibility_mode: Default::default(),
861+
_phantom: PhantomData::<fn() -> AuthorityPair>,
863862
};
864863

865864
let head = client.expect_header(client.info().genesis_hash).unwrap();

client/consensus/common/src/import_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct IncomingBlock<B: BlockT> {
9595

9696
/// Verify a justification of a block
9797
#[async_trait::async_trait]
98-
pub trait Verifier<B: BlockT>: Send + Sync {
98+
pub trait Verifier<B: BlockT>: Send {
9999
/// Verify the given block data and return the `BlockImportParams` to
100100
/// continue the block import process.
101101
async fn verify(

primitives/core/src/crypto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ pub trait ByteArray: AsRef<[u8]> + AsMut<[u8]> + for<'a> TryFrom<&'a [u8], Error
486486
}
487487

488488
/// Trait suitable for typical cryptographic key public type.
489-
pub trait Public: ByteArray + Derive + CryptoType + PartialEq + Eq + Clone + Send + Sync {}
489+
pub trait Public: CryptoType + ByteArray + Derive + PartialEq + Eq + Clone + Send {}
490490

491491
/// An opaque 32-byte cryptographic identifier.
492492
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, TypeInfo)]
@@ -834,7 +834,7 @@ impl sp_std::str::FromStr for SecretUri {
834834
///
835835
/// For now it just specifies how to create a key from a phrase and derivation path.
836836
#[cfg(feature = "full_crypto")]
837-
pub trait Pair: CryptoType + Sized + Clone + Send + Sync + 'static {
837+
pub trait Pair: CryptoType + Sized {
838838
/// The type which is used to encode a public key.
839839
type Public: Public + Hash;
840840

0 commit comments

Comments
 (0)