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

Commit

Permalink
refactor use of ProposerFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Feb 25, 2020
1 parent 7ab5213 commit d38b267
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 39 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ pub fn new_full(config: Configuration<GenesisConfig>)
.build()?;

if participates_in_consensus {
let proposer = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
let proposer = sc_basic_authorship::ProposerFactory::new(
service.client(),
service.transaction_pool()
);

let client = service.client();
let select_chain = service.select_chain()
Expand Down
16 changes: 8 additions & 8 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ macro_rules! new_full {
($with_startup_data)(&block_import, &babe_link);

if participates_in_consensus {
let proposer = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
let proposer = sc_basic_authorship::ProposerFactory::new(
service.client(),
service.transaction_pool()
);

let client = service.client();
let select_chain = service.select_chain()
Expand Down Expand Up @@ -501,10 +501,10 @@ mod tests {
let parent_header = service.client().header(&parent_id).unwrap().unwrap();
let parent_hash = parent_header.hash();
let parent_number = *parent_header.number();
let mut proposer_factory = sc_basic_authorship::ProposerFactory {
client: service.client(),
transaction_pool: service.transaction_pool(),
};
let mut proposer_factory = sc_basic_authorship::ProposerFactory::new(
service.client(),
service.transaction_pool()
);

let epoch = babe_link.epoch_changes().lock().epoch_for_child_of(
descendent_query(&*service.client()),
Expand Down
10 changes: 2 additions & 8 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,7 @@ mod tests {
txpool.submit_at(&BlockId::number(0), vec![extrinsic(0), extrinsic(1)])
).unwrap();

let mut proposer_factory = ProposerFactory {
client: client.clone(),
transaction_pool: txpool.clone(),
};
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());

let cell = Mutex::new(time::Instant::now());
let mut proposer = proposer_factory.init_with_now(
Expand Down Expand Up @@ -367,10 +364,7 @@ mod tests {
txpool.submit_at(&BlockId::number(0), vec![extrinsic(0)]),
).unwrap();

let mut proposer_factory = ProposerFactory {
client: client.clone(),
transaction_pool: txpool.clone(),
};
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());

let mut proposer = proposer_factory.init_with_now(
&client.header(&block_id).unwrap().unwrap(),
Expand Down
5 changes: 1 addition & 4 deletions client/basic-authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
//! # let client = Arc::new(substrate_test_runtime_client::new());
//! # let txpool = Arc::new(BasicPool::new(Default::default(), Arc::new(FullChainApi::new(client.clone()))).0);
//! // The first step is to create a `ProposerFactory`.
//! let mut proposer_factory = ProposerFactory {
//! client: client.clone(),
//! transaction_pool: txpool.clone(),
//! };
//! let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone());
//!
//! // From this factory, we create a `Proposer`.
//! let proposer = proposer_factory.init(
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use super::*;
use authorship::claim_slot;

use sp_consensus_babe::{AuthorityPair, SlotNumber};
use sc_block_builder::BlockBuilder;
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sp_consensus::{
NoNetwork as DummyOracle, Proposal, RecordProof,
import_queue::{BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport},
Expand Down
24 changes: 12 additions & 12 deletions client/consensus/manual-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ mod tests {
let select_chain = LongestChain::new(backend.clone());
let inherent_data_providers = InherentDataProviders::new();
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
let env = ProposerFactory {
transaction_pool: pool.clone(),
client: client.clone(),
};
let env = ProposerFactory::new(
client.clone(),
pool.clone()
);
// this test checks that blocks are created as soon as transactions are imported into the pool.
let (sender, receiver) = futures::channel::oneshot::channel();
let mut sender = Arc::new(Some(sender));
Expand Down Expand Up @@ -309,10 +309,10 @@ mod tests {
let select_chain = LongestChain::new(backend.clone());
let inherent_data_providers = InherentDataProviders::new();
let pool = Arc::new(BasicPool::new(Options::default(), api()).0);
let env = ProposerFactory {
transaction_pool: pool.clone(),
client: client.clone(),
};
let env = ProposerFactory::new(
client.clone(),
pool.clone()
);
// this test checks that blocks are created as soon as an engine command is sent over the stream.
let (mut sink, stream) = futures::channel::mpsc::channel(1024);
let future = run_manual_seal(
Expand Down Expand Up @@ -378,10 +378,10 @@ mod tests {
let inherent_data_providers = InherentDataProviders::new();
let pool_api = api();
let pool = Arc::new(BasicPool::new(Options::default(), pool_api.clone()).0);
let env = ProposerFactory {
transaction_pool: pool.clone(),
client: client.clone(),
};
let env = ProposerFactory::new(
client.clone(),
pool.clone(),
);
// this test checks that blocks are created as soon as an engine command is sent over the stream.
let (mut sink, stream) = futures::channel::mpsc::channel(1024);
let future = run_manual_seal(
Expand Down
1 change: 1 addition & 0 deletions client/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sc-client = { version = "0.8.0-dev", path = "../" }
sp-inherents = { version = "2.0.0-dev", path = "../../primitives/inherents" }
sp-blockchain = { version = "2.0.0-dev", path = "../../primitives/blockchain" }
sc-network = { version = "0.8.0-dev", path = "../network" }
sc-block-builder = { version = "0.8.0-dev", path = "../block-builder" }
sc-network-gossip = { version = "0.8.0-dev", path = "../network-gossip" }
sp-finality-tracker = { version = "2.0.0-dev", path = "../../primitives/finality-tracker" }
sp-finality-grandpa = { version = "2.0.0-dev", path = "../../primitives/finality-grandpa" }
Expand Down
1 change: 1 addition & 0 deletions client/finality-grandpa/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use finality_proof::{
FinalityProofProvider, AuthoritySetForFinalityProver, AuthoritySetForFinalityChecker,
};
use consensus_changes::ConsensusChanges;
use sc_block_builder::BlockBuilderProvider;

type PeerData =
Mutex<
Expand Down
2 changes: 1 addition & 1 deletion client/network/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sc_client_api::{
FinalityNotification,
backend::{TransactionFor, AuxStore, Backend, Finalizer},
};
use sc_block_builder::BlockBuilder;
use sc_block_builder::{BlockBuilder, BlockBuilderProvider};
use sc_client::LongestChain;
use sc_network::config::Roles;
use sp_consensus::block_validation::DefaultBlockAnnounceValidator;
Expand Down
2 changes: 1 addition & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ impl<B, E, Block, RA> BlockBuilderProvider<B, Block, Self> for Client<B, E, Bloc
E: CallExecutor<Block> + Send + Sync + 'static,
Block: BlockT,
Self: ChainHeaderBackend<Block> + ProvideRuntimeApi<Block>,
Self::Api: ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
<Self as ProvideRuntimeApi<Block>>::Api: ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>>
+ BlockBuilderApi<Block, Error = Error>,
{
fn new_block_at<R: Into<RecordProof>>(
Expand Down
1 change: 1 addition & 0 deletions primitives/api/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sp-version = { version = "2.0.0-dev", path = "../../version" }
sp-runtime = { version = "2.0.0-dev", path = "../../runtime" }
sp-blockchain = { version = "2.0.0-dev", path = "../../blockchain" }
sp-consensus = { version = "0.8.0-dev", path = "../../../primitives/consensus/common" }
sc-block-builder = { version = "0.8.0-dev", path = "../../../client/block-builder" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
sp-state-machine = { version = "0.8.0-dev", path = "../../../primitives/state-machine" }
trybuild = "1.0.17"
Expand Down
1 change: 1 addition & 0 deletions primitives/api/test/tests/runtime_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use sp_state_machine::{

use sp_consensus::SelectChain;
use codec::Encode;
use sc_block_builder::BlockBuilderProvider;

fn calling_function_with_strat(strat: ExecutionStrategy) {
let client = TestClientBuilder::new().set_execution_strategy(strat).build();
Expand Down
1 change: 1 addition & 0 deletions test-utils/runtime/client/src/trait_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use substrate_test_client::sp_consensus::BlockOrigin;
use substrate_test_runtime::{self, Transfer};
use sp_runtime::generic::BlockId;
use sp_runtime::traits::{Block as BlockT, HasherFor};
use sc_block_builder::BlockBuilderProvider;

/// helper to test the `leaves` implementation for various backends
pub fn test_leaves_for_backend<B: 'static>(backend: Arc<B>) where
Expand Down

0 comments on commit d38b267

Please sign in to comment.