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

Commit

Permalink
slots: remove mutex around BlockImport in SlotWorker
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilva committed Mar 27, 2021
1 parent 56d92e2 commit a35415d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions client/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use std::{
};

use futures::prelude::*;
use parking_lot::Mutex;
use log::{debug, trace};

use codec::{Encode, Decode, Codec};
Expand Down Expand Up @@ -272,7 +271,7 @@ pub fn build_aura_worker<P, B, C, PF, I, SO, BS, Error>(
{
AuraWorker {
client,
block_import: Arc::new(Mutex::new(block_import)),
block_import,
env: proposer_factory,
keystore,
sync_oracle,
Expand All @@ -286,7 +285,7 @@ pub fn build_aura_worker<P, B, C, PF, I, SO, BS, Error>(

struct AuraWorker<C, E, I, P, SO, BS> {
client: Arc<C>,
block_import: Arc<Mutex<I>>,
block_import: I,
env: E,
keystore: SyncCryptoStorePtr,
sync_oracle: SO,
Expand Down Expand Up @@ -326,8 +325,8 @@ where
"aura"
}

fn block_import(&self) -> Arc<Mutex<Self::BlockImport>> {
self.block_import.clone()
fn block_import(&mut self) -> &mut Self::BlockImport {
&mut self.block_import
}

fn epoch_data(
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
8 changes: 4 additions & 4 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ pub fn start_babe<B, C, SC, E, I, SO, CAW, BS, Error>(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,
Expand Down Expand Up @@ -605,7 +605,7 @@ type SlotNotificationSinks<B> = Arc<

struct BabeSlotWorker<B: BlockT, C, E, I, SO, BS> {
client: Arc<C>,
block_import: Arc<Mutex<I>>,
block_import: I,
env: E,
sync_oracle: SO,
force_authoring: bool,
Expand Down Expand Up @@ -647,8 +647,8 @@ where
"babe"
}

fn block_import(&self) -> Arc<Mutex<Self::BlockImport>> {
self.block_import.clone()
fn block_import(&mut self) -> &mut Self::BlockImport {
&mut self.block_import
}

fn epoch_data(
Expand Down
1 change: 0 additions & 1 deletion client/consensus/slots/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -110,7 +109,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
fn logging_target(&self) -> &'static str;

/// A handle to a `BlockImport`.
fn block_import(&self) -> Arc<Mutex<Self::BlockImport>>;
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.
Expand Down Expand Up @@ -398,7 +397,6 @@ pub trait SimpleSlotWorker<B: BlockT> {

let header = block_import_params.post_header();
if let Err(err) = block_import
.lock()
.import_block(block_import_params, Default::default())
{
warn!(
Expand Down

0 comments on commit a35415d

Please sign in to comment.