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

Commit a35415d

Browse files
committed
slots: remove mutex around BlockImport in SlotWorker
1 parent 56d92e2 commit a35415d

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/consensus/aura/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ use std::{
3535
};
3636

3737
use futures::prelude::*;
38-
use parking_lot::Mutex;
3938
use log::{debug, trace};
4039

4140
use codec::{Encode, Decode, Codec};
@@ -272,7 +271,7 @@ pub fn build_aura_worker<P, B, C, PF, I, SO, BS, Error>(
272271
{
273272
AuraWorker {
274273
client,
275-
block_import: Arc::new(Mutex::new(block_import)),
274+
block_import,
276275
env: proposer_factory,
277276
keystore,
278277
sync_oracle,
@@ -286,7 +285,7 @@ pub fn build_aura_worker<P, B, C, PF, I, SO, BS, Error>(
286285

287286
struct AuraWorker<C, E, I, P, SO, BS> {
288287
client: Arc<C>,
289-
block_import: Arc<Mutex<I>>,
288+
block_import: I,
290289
env: E,
291290
keystore: SyncCryptoStorePtr,
292291
sync_oracle: SO,
@@ -326,8 +325,8 @@ where
326325
"aura"
327326
}
328327

329-
fn block_import(&self) -> Arc<Mutex<Self::BlockImport>> {
330-
self.block_import.clone()
328+
fn block_import(&mut self) -> &mut Self::BlockImport {
329+
&mut self.block_import
331330
}
332331

333332
fn epoch_data(
@@ -805,7 +804,7 @@ mod tests {
805804

806805
let worker = AuraWorker {
807806
client: client.clone(),
808-
block_import: Arc::new(Mutex::new(client)),
807+
block_import: client,
809808
env: environ,
810809
keystore: keystore.into(),
811810
sync_oracle: DummyOracle.clone(),
@@ -854,7 +853,7 @@ mod tests {
854853

855854
let mut worker = AuraWorker {
856855
client: client.clone(),
857-
block_import: Arc::new(Mutex::new(client.clone())),
856+
block_import: client.clone(),
858857
env: environ,
859858
keystore: keystore.into(),
860859
sync_oracle: DummyOracle.clone(),

client/consensus/babe/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ pub fn start_babe<B, C, SC, E, I, SO, CAW, BS, Error>(BabeParams {
448448

449449
let worker = BabeSlotWorker {
450450
client: client.clone(),
451-
block_import: Arc::new(Mutex::new(block_import)),
451+
block_import,
452452
env,
453453
sync_oracle: sync_oracle.clone(),
454454
force_authoring,
@@ -605,7 +605,7 @@ type SlotNotificationSinks<B> = Arc<
605605

606606
struct BabeSlotWorker<B: BlockT, C, E, I, SO, BS> {
607607
client: Arc<C>,
608-
block_import: Arc<Mutex<I>>,
608+
block_import: I,
609609
env: E,
610610
sync_oracle: SO,
611611
force_authoring: bool,
@@ -647,8 +647,8 @@ where
647647
"babe"
648648
}
649649

650-
fn block_import(&self) -> Arc<Mutex<Self::BlockImport>> {
651-
self.block_import.clone()
650+
fn block_import(&mut self) -> &mut Self::BlockImport {
651+
&mut self.block_import
652652
}
653653

654654
fn epoch_data(

client/consensus/slots/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ sp-inherents = { version = "3.0.0", path = "../../../primitives/inherents" }
3131
sp-timestamp = { version = "3.0.0", path = "../../../primitives/timestamp" }
3232
futures = "0.3.9"
3333
futures-timer = "3.0.1"
34-
parking_lot = "0.11.1"
3534
log = "0.4.11"
3635
thiserror = "1.0.21"
3736
async-trait = "0.1.42"

client/consensus/slots/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ pub use slots::SlotInfo;
3232
use slots::Slots;
3333
pub use aux_schema::{check_equivocation, MAX_SLOT_CAPACITY, PRUNING_BOUND};
3434

35-
use std::{fmt::Debug, ops::Deref, sync::Arc, time::Duration};
35+
use std::{fmt::Debug, ops::Deref, time::Duration};
3636
use codec::{Decode, Encode};
3737
use futures::{future::Either, Future, TryFutureExt};
3838
use futures_timer::Delay;
3939
use log::{debug, error, info, warn};
40-
use parking_lot::Mutex;
4140
use sp_api::{ProvideRuntimeApi, ApiRef};
4241
use sp_arithmetic::traits::BaseArithmetic;
4342
use sp_consensus::{BlockImport, Proposer, SyncOracle, SelectChain, CanAuthorWith, SlotData};
@@ -110,7 +109,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
110109
fn logging_target(&self) -> &'static str;
111110

112111
/// A handle to a `BlockImport`.
113-
fn block_import(&self) -> Arc<Mutex<Self::BlockImport>>;
112+
fn block_import(&mut self) -> &mut Self::BlockImport;
114113

115114
/// Returns the epoch data necessary for authoring. For time-dependent epochs,
116115
/// use the provided slot number as a canonical source of time.
@@ -398,7 +397,6 @@ pub trait SimpleSlotWorker<B: BlockT> {
398397

399398
let header = block_import_params.post_header();
400399
if let Err(err) = block_import
401-
.lock()
402400
.import_block(block_import_params, Default::default())
403401
{
404402
warn!(

0 commit comments

Comments
 (0)