Remove an unnecessary clone in aura (#2163)

This commit is contained in:
Wei Tang
2019-04-01 23:35:48 +02:00
committed by GitHub
parent a0e6d96de0
commit a8b5fe145f
+7 -12
View File
@@ -79,9 +79,7 @@ pub trait Network: Clone {
} }
/// Get slot author for given block along with authorities. /// Get slot author for given block along with authorities.
fn slot_author<P: Pair>(slot_num: u64, authorities: &[AuthorityId<P>]) -> Option<AuthorityId<P>> fn slot_author<P: Pair>(slot_num: u64, authorities: &[AuthorityId<P>]) -> Option<&AuthorityId<P>> {
where P::Public: Clone,
{
if authorities.is_empty() { return None } if authorities.is_empty() { return None }
let idx = slot_num % (authorities.len() as u64); let idx = slot_num % (authorities.len() as u64);
@@ -90,10 +88,9 @@ fn slot_author<P: Pair>(slot_num: u64, authorities: &[AuthorityId<P>]) -> Option
let current_author = authorities.get(idx as usize) let current_author = authorities.get(idx as usize)
.expect("authorities not empty; index constrained to list length;\ .expect("authorities not empty; index constrained to list length;\
this is a valid index; qed") this is a valid index; qed");
.clone();
Some(current_author.clone()) Some(current_author)
} }
fn duration_now() -> Option<Duration> { fn duration_now() -> Option<Duration> {
@@ -235,13 +232,12 @@ pub fn start_aura<B, C, E, I, P, SO, Error, OnExit>(
E::Proposer: Proposer<B, Error=Error>, E::Proposer: Proposer<B, Error=Error>,
<<E::Proposer as Proposer<B>>::Create as IntoFuture>::Future: Send + 'static, <<E::Proposer as Proposer<B>>::Create as IntoFuture>::Future: Send + 'static,
I: BlockImport<B> + Send + Sync + 'static, I: BlockImport<B> + Send + Sync + 'static,
Error: From<I::Error>,
P: Pair + Send + Sync + 'static, P: Pair + Send + Sync + 'static,
P::Public: Hash + Eq + Send + Sync + Clone + Debug + Encode + Decode + 'static, P::Public: Hash + Eq + Send + Sync + Clone + Debug + Encode + Decode + 'static,
P::Signature: Encode, P::Signature: Encode,
SO: SyncOracle + Send + Sync + Clone, SO: SyncOracle + Send + Sync + Clone,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>, DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>,
Error: ::std::error::Error + Send + 'static + From<::consensus_common::Error>, Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
OnExit: Future<Item=(), Error=()>, OnExit: Future<Item=(), Error=()>,
{ {
let worker = AuraWorker { let worker = AuraWorker {
@@ -283,10 +279,9 @@ impl<B: Block, C, E, I, P, Error, SO> SlotWorker<B> for AuraWorker<C, E, I, P, S
P: Pair + Send + Sync + 'static, P: Pair + Send + Sync + 'static,
P::Public: Hash + Eq + Send + Sync + Clone + Debug + Encode + Decode + 'static, P::Public: Hash + Eq + Send + Sync + Clone + Debug + Encode + Decode + 'static,
P::Signature: Encode, P::Signature: Encode,
Error: From<I::Error>,
SO: SyncOracle + Send + Clone, SO: SyncOracle + Send + Clone,
DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>, DigestItemFor<B>: CompatibleDigestItem<P> + DigestItem<AuthorityId=AuthorityId<P>>,
Error: ::std::error::Error + Send + 'static + From<::consensus_common::Error>, Error: ::std::error::Error + Send + From<::consensus_common::Error> + From<I::Error> + 'static,
{ {
type OnSlot = Box<Future<Item=(), Error=consensus_common::Error> + Send>; type OnSlot = Box<Future<Item=(), Error=consensus_common::Error> + Send>;
@@ -336,7 +331,7 @@ impl<B: Block, C, E, I, P, Error, SO> SlotWorker<B> for AuraWorker<C, E, I, P, S
let maybe_author = slot_author::<P>(slot_num, &authorities); let maybe_author = slot_author::<P>(slot_num, &authorities);
let proposal_work = match maybe_author { let proposal_work = match maybe_author {
None => return Box::new(future::ok(())), None => return Box::new(future::ok(())),
Some(author) => if author == public_key { Some(author) => if author == &public_key {
debug!( debug!(
target: "aura", "Starting authorship at slot {}; timestamp = {}", target: "aura", "Starting authorship at slot {}; timestamp = {}",
slot_num, slot_num,
@@ -449,7 +444,7 @@ fn check_header<B: Block, P: Pair>(
allow_old_seals: bool, allow_old_seals: bool,
) -> Result<CheckedHeader<B::Header, P::Signature>, String> ) -> Result<CheckedHeader<B::Header, P::Signature>, String>
where DigestItemFor<B>: CompatibleDigestItem<P>, where DigestItemFor<B>: CompatibleDigestItem<P>,
P::Public: Clone + AsRef<P::Public>, P::Public: AsRef<P::Public>,
P::Signature: Decode, P::Signature: Decode,
{ {
let digest_item = match header.digest_mut().pop() { let digest_item = match header.digest_mut().pop() {