From a35415d1471e4a3be4c05d7a951eff5d1147309d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Silva?= Date: Sat, 27 Mar 2021 13:03:12 +0000 Subject: [PATCH] slots: remove mutex around BlockImport in SlotWorker --- Cargo.lock | 1 - client/consensus/aura/src/lib.rs | 13 ++++++------- client/consensus/babe/src/lib.rs | 8 ++++---- client/consensus/slots/Cargo.toml | 1 - client/consensus/slots/src/lib.rs | 6 ++---- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d41c255e3a8d7..3602f0cac5ce9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7318,7 +7318,6 @@ dependencies = [ "futures-timer 3.0.2", "log", "parity-scale-codec 2.0.1", - "parking_lot 0.11.1", "sc-client-api", "sc-telemetry", "sp-api", diff --git a/client/consensus/aura/src/lib.rs b/client/consensus/aura/src/lib.rs index 81c6015ac7efa..cc60406d1664b 100644 --- a/client/consensus/aura/src/lib.rs +++ b/client/consensus/aura/src/lib.rs @@ -35,7 +35,6 @@ use std::{ }; use futures::prelude::*; -use parking_lot::Mutex; use log::{debug, trace}; use codec::{Encode, Decode, Codec}; @@ -272,7 +271,7 @@ pub fn build_aura_worker( { AuraWorker { client, - block_import: Arc::new(Mutex::new(block_import)), + block_import, env: proposer_factory, keystore, sync_oracle, @@ -286,7 +285,7 @@ pub fn build_aura_worker( struct AuraWorker { client: Arc, - block_import: Arc>, + block_import: I, env: E, keystore: SyncCryptoStorePtr, sync_oracle: SO, @@ -326,8 +325,8 @@ where "aura" } - fn block_import(&self) -> Arc> { - self.block_import.clone() + fn block_import(&mut self) -> &mut Self::BlockImport { + &mut self.block_import } fn epoch_data( @@ -805,7 +804,7 @@ mod tests { let worker = AuraWorker { client: client.clone(), - block_import: Arc::new(Mutex::new(client)), + block_import: client, env: environ, keystore: keystore.into(), sync_oracle: DummyOracle.clone(), @@ -854,7 +853,7 @@ mod tests { let mut worker = AuraWorker { client: client.clone(), - block_import: Arc::new(Mutex::new(client.clone())), + block_import: client.clone(), env: environ, keystore: keystore.into(), sync_oracle: DummyOracle.clone(), diff --git a/client/consensus/babe/src/lib.rs b/client/consensus/babe/src/lib.rs index 14ac2ebbcf2a4..28cfec1238e42 100644 --- a/client/consensus/babe/src/lib.rs +++ b/client/consensus/babe/src/lib.rs @@ -448,7 +448,7 @@ pub fn start_babe(BabeParams { let worker = BabeSlotWorker { client: client.clone(), - block_import: Arc::new(Mutex::new(block_import)), + block_import, env, sync_oracle: sync_oracle.clone(), force_authoring, @@ -605,7 +605,7 @@ type SlotNotificationSinks = Arc< struct BabeSlotWorker { client: Arc, - block_import: Arc>, + block_import: I, env: E, sync_oracle: SO, force_authoring: bool, @@ -647,8 +647,8 @@ where "babe" } - fn block_import(&self) -> Arc> { - self.block_import.clone() + fn block_import(&mut self) -> &mut Self::BlockImport { + &mut self.block_import } fn epoch_data( diff --git a/client/consensus/slots/Cargo.toml b/client/consensus/slots/Cargo.toml index 623c4c4abd84c..64beea50fcf63 100644 --- a/client/consensus/slots/Cargo.toml +++ b/client/consensus/slots/Cargo.toml @@ -31,7 +31,6 @@ sp-inherents = { version = "3.0.0", path = "../../../primitives/inherents" } sp-timestamp = { version = "3.0.0", path = "../../../primitives/timestamp" } futures = "0.3.9" futures-timer = "3.0.1" -parking_lot = "0.11.1" log = "0.4.11" thiserror = "1.0.21" async-trait = "0.1.42" diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs index dbf62ccad23c8..351ef932ada19 100644 --- a/client/consensus/slots/src/lib.rs +++ b/client/consensus/slots/src/lib.rs @@ -32,12 +32,11 @@ pub use slots::SlotInfo; use slots::Slots; pub use aux_schema::{check_equivocation, MAX_SLOT_CAPACITY, PRUNING_BOUND}; -use std::{fmt::Debug, ops::Deref, sync::Arc, time::Duration}; +use std::{fmt::Debug, ops::Deref, time::Duration}; use codec::{Decode, Encode}; use futures::{future::Either, Future, TryFutureExt}; use futures_timer::Delay; use log::{debug, error, info, warn}; -use parking_lot::Mutex; use sp_api::{ProvideRuntimeApi, ApiRef}; use sp_arithmetic::traits::BaseArithmetic; use sp_consensus::{BlockImport, Proposer, SyncOracle, SelectChain, CanAuthorWith, SlotData}; @@ -110,7 +109,7 @@ pub trait SimpleSlotWorker { fn logging_target(&self) -> &'static str; /// A handle to a `BlockImport`. - fn block_import(&self) -> Arc>; + fn block_import(&mut self) -> &mut Self::BlockImport; /// Returns the epoch data necessary for authoring. For time-dependent epochs, /// use the provided slot number as a canonical source of time. @@ -398,7 +397,6 @@ pub trait SimpleSlotWorker { let header = block_import_params.post_header(); if let Err(err) = block_import - .lock() .import_block(block_import_params, Default::default()) { warn!(