Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ macro_rules! new_full_start {
builder.client().clone(),
None,
);
Ok(sc_transaction_pool::BasicPool::new(
Ok(sc_transaction_pool::BasicPool::new_full(
builder.config().transaction_pool.clone(),
std::sync::Arc::new(pool_api),
builder.prometheus_registry(),
builder.spawn_handle(),
builder.client().clone(),
))
})?
.with_import_queue(|
Expand Down Expand Up @@ -221,12 +223,12 @@ pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
builder.client().clone(),
fetcher.clone(),
);
let pool = sc_transaction_pool::BasicPool::with_revalidation_type(
let pool = Arc::new(sc_transaction_pool::BasicPool::new_light(
builder.config().transaction_pool.clone(),
Arc::new(pool_api),
builder.prometheus_registry(),
sc_transaction_pool::RevalidationType::Light,
);
builder.spawn_handle(),
));
Ok(pool)
})?
.with_import_queue_and_fprb(|
Expand Down
14 changes: 7 additions & 7 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ macro_rules! new_full_start {
builder.client().clone(),
builder.prometheus_registry(),
);
let config = builder.config();

Ok(sc_transaction_pool::BasicPool::new(
config.transaction_pool.clone(),
Ok(sc_transaction_pool::BasicPool::new_full(
builder.config().transaction_pool.clone(),
std::sync::Arc::new(pool_api),
builder.prometheus_registry(),
builder.spawn_handle(),
builder.client().clone(),
))
})?
.with_import_queue(|
Expand Down Expand Up @@ -356,12 +356,12 @@ pub fn new_light_base(config: Configuration) -> Result<(
builder.client().clone(),
fetcher,
);
let pool = sc_transaction_pool::BasicPool::with_revalidation_type(
let pool = Arc::new(sc_transaction_pool::BasicPool::new_light(
builder.config().transaction_pool.clone(),
Arc::new(pool_api),
builder.prometheus_registry(),
sc_transaction_pool::RevalidationType::Light,
);
builder.spawn_handle(),
));
Ok(pool)
})?
.with_import_queue_and_fprb(|
Expand Down
15 changes: 8 additions & 7 deletions client/api/src/execution_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ pub struct ExecutionExtensions<Block: traits::Block> {
keystore: Option<BareCryptoStorePtr>,
// FIXME: these two are only RwLock because of https://github.com/paritytech/substrate/issues/4587
// remove when fixed.
// To break retain cycle between `Client` and `TransactionPool` we require this
// extension to be a `Weak` reference.
// That's also the reason why it's being registered lazily instead of
// during initialization.
transaction_pool: RwLock<Option<Weak<dyn sp_transaction_pool::OffchainSubmitTransaction<Block>>>>,
extensions_factory: RwLock<Box<dyn ExtensionsFactory>>,
}
Expand Down Expand Up @@ -121,13 +125,10 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
}

/// Register transaction pool extension.
///
/// To break retain cycle between `Client` and `TransactionPool` we require this
/// extension to be a `Weak` reference.
/// That's also the reason why it's being registered lazily instead of
/// during initialization.
pub fn register_transaction_pool(&self, pool: Weak<dyn sp_transaction_pool::OffchainSubmitTransaction<Block>>) {
*self.transaction_pool.write() = Some(pool);
pub fn register_transaction_pool<T>(&self, pool: &Arc<T>)
where T: sp_transaction_pool::OffchainSubmitTransaction<Block> + 'static
{
*self.transaction_pool.write() = Some(Arc::downgrade(&pool) as _);
}

/// Create `ExecutionManager` and `Extensions` for given offchain call.
Expand Down
6 changes: 6 additions & 0 deletions client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ pub struct Blockchain<Block: BlockT> {
storage: Arc<RwLock<BlockchainStorage<Block>>>,
}

impl<Block: BlockT> Default for Blockchain<Block> {
fn default() -> Self {
Self::new()
}
}

impl<Block: BlockT + Clone> Clone for Blockchain<Block> {
fn clone(&self) -> Self {
let storage = Arc::new(RwLock::new(self.storage.read().clone()));
Expand Down
52 changes: 28 additions & 24 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,13 @@ mod tests {
fn should_cease_building_block_when_deadline_is_reached() {
// given
let client = Arc::new(substrate_test_runtime_client::new());
let txpool = Arc::new(
BasicPool::new(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
).0
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let txpool = BasicPool::new_full(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
spawner,
client.clone(),
);

futures::executor::block_on(
Expand Down Expand Up @@ -411,12 +412,13 @@ mod tests {
#[test]
fn should_not_panic_when_deadline_is_reached() {
let client = Arc::new(substrate_test_runtime_client::new());
let txpool = Arc::new(
BasicPool::new(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
).0
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let txpool = BasicPool::new_full(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
spawner,
client.clone(),
);

let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
Expand Down Expand Up @@ -446,12 +448,13 @@ mod tests {
fn proposed_storage_changes_should_match_execute_block_storage_changes() {
let (client, backend) = TestClientBuilder::new().build_with_backend();
let client = Arc::new(client);
let txpool = Arc::new(
BasicPool::new(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
).0
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let txpool = BasicPool::new_full(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
spawner,
client.clone(),
);

let genesis_hash = client.info().best_hash;
Expand Down Expand Up @@ -508,12 +511,13 @@ mod tests {
fn should_not_remove_invalid_transactions_when_skipping() {
// given
let mut client = Arc::new(substrate_test_runtime_client::new());
let txpool = Arc::new(
BasicPool::new(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
).0
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let txpool = BasicPool::new_full(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
spawner,
client.clone(),
);

futures::executor::block_on(
Expand Down
7 changes: 5 additions & 2 deletions client/basic-authorship/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@
//! # };
//! # use sc_transaction_pool::{BasicPool, FullChainApi};
//! # let client = Arc::new(substrate_test_runtime_client::new());
//! # let txpool = Arc::new(BasicPool::new(
//! # let spawner = sp_core::testing::SpawnBlockingExecutor::new();
//! # let txpool = BasicPool::new_full(
//! # Default::default(),
//! # Arc::new(FullChainApi::new(client.clone(), None)),
//! # None).0,
//! # None,
//! # spawner,
//! # client.clone(),
//! # );
//! // The first step is to create a `ProposerFactory`.
//! let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
Expand Down
20 changes: 13 additions & 7 deletions client/consensus/manual-seal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ mod tests {
AccountKeyring::*,
TestClientBuilder,
};
use sc_transaction_pool::{
BasicPool,
txpool::Options,
};
use sc_transaction_pool::{BasicPool, RevalidationType, txpool::Options};
use substrate_test_runtime_transaction_pool::{TestApi, uxt};
use sp_transaction_pool::{TransactionPool, MaintainedTransactionPool, TransactionSource};
use sp_runtime::generic::BlockId;
Expand All @@ -223,7 +220,10 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
let inherent_data_providers = InherentDataProviders::new();
let pool = Arc::new(BasicPool::new(Options::default(), api(), None).0);
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(), api(), None, RevalidationType::Full, spawner,
));
let env = ProposerFactory::new(
client.clone(),
pool.clone(),
Expand Down Expand Up @@ -288,7 +288,10 @@ mod tests {
let (client, select_chain) = builder.build_with_longest_chain();
let client = Arc::new(client);
let inherent_data_providers = InherentDataProviders::new();
let pool = Arc::new(BasicPool::new(Options::default(), api(), None).0);
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(), api(), None, RevalidationType::Full, spawner,
));
let env = ProposerFactory::new(
client.clone(),
pool.clone(),
Expand Down Expand Up @@ -357,7 +360,10 @@ mod tests {
let client = Arc::new(client);
let inherent_data_providers = InherentDataProviders::new();
let pool_api = api();
let pool = Arc::new(BasicPool::new(Options::default(), pool_api.clone(), None).0);
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let pool = Arc::new(BasicPool::with_revalidation_type(
Options::default(), pool_api.clone(), None, RevalidationType::Full, spawner,
));
let env = ProposerFactory::new(
client.clone(),
pool.clone(),
Expand Down
5 changes: 3 additions & 2 deletions client/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ use sc_telemetry::{telemetry, CONSENSUS_INFO, CONSENSUS_DEBUG};
use parking_lot::RwLock;

use finality_grandpa::Error as GrandpaError;
use finality_grandpa::{voter, BlockNumberOps, voter_set::VoterSet};
use finality_grandpa::{voter, voter_set::VoterSet};
pub use finality_grandpa::BlockNumberOps;

use std::{fmt, io};
use std::sync::Arc;
Expand Down Expand Up @@ -126,7 +127,7 @@ pub use authorities::SharedAuthoritySet;
pub use finality_proof::{FinalityProofProvider, StorageAndProofProvider};
pub use import::GrandpaBlockImport;
pub use justification::GrandpaJustification;
pub use light_import::light_block_import;
pub use light_import::{light_block_import, GrandpaLightBlockImport};
pub use voting_rule::{
BeforeBestBlockBy, ThreeQuartersOfTheUnfinalizedChain, VotingRule, VotingRulesBuilder
};
Expand Down
12 changes: 6 additions & 6 deletions client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ mod tests {
use substrate_test_runtime_client::{TestClient, runtime::Block};
use sc_transaction_pool::{BasicPool, FullChainApi};
use sp_transaction_pool::{TransactionPool, InPoolTransaction};
use sc_client_api::ExecutorProvider;

struct MockNetworkStateInfo();

Expand All @@ -227,7 +226,7 @@ mod tests {
}

struct TestPool(
BasicPool<FullChainApi<TestClient, Block>, Block>
Arc<BasicPool<FullChainApi<TestClient, Block>, Block>>
);

impl sp_transaction_pool::OffchainSubmitTransaction<Block> for TestPool {
Expand All @@ -248,13 +247,14 @@ mod tests {
let _ = env_logger::try_init();

let client = Arc::new(substrate_test_runtime_client::new());
let pool = Arc::new(TestPool(BasicPool::new(
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let pool = TestPool(BasicPool::new_full(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
).0));
client.execution_extensions()
.register_transaction_pool(Arc::downgrade(&pool.clone()) as _);
spawner,
client.clone(),
));
let db = sc_client_db::offchain::LocalStorage::new_test();
let network_state = Arc::new(MockNetworkStateInfo());
let header = client.header(&BlockId::number(0)).unwrap().unwrap();
Expand Down
7 changes: 5 additions & 2 deletions client/rpc/src/author/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ impl Default for TestSetup {
let client_builder = substrate_test_runtime_client::TestClientBuilder::new();
let client = Arc::new(client_builder.set_keystore(keystore.clone()).build());

let pool = Arc::new(BasicPool::new(
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
let pool = BasicPool::new_full(
Default::default(),
Arc::new(FullChainApi::new(client.clone(), None)),
None,
).0);
spawner,
client.clone(),
);
TestSetup {
client,
keystore,
Expand Down
Loading