mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-21 16:45:41 +00:00
Simplify a few chain components creation APIs related to the service (#6611)
* Simplify a few chain components creation APIs related to the service * Fix basic-authorship doc tests * Remove DefaultQueue * Update client/service/src/builder.rs Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com> * Move ExecutionExtensions comment around * Remove unused BlakeTwo256 Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Generated
+1
@@ -7686,6 +7686,7 @@ dependencies = [
|
|||||||
"sp-state-machine",
|
"sp-state-machine",
|
||||||
"sp-std",
|
"sp-std",
|
||||||
"sp-test-primitives",
|
"sp-test-primitives",
|
||||||
|
"sp-trie",
|
||||||
"sp-utils",
|
"sp-utils",
|
||||||
"sp-version",
|
"sp-version",
|
||||||
"substrate-prometheus-endpoint",
|
"substrate-prometheus-endpoint",
|
||||||
|
|||||||
@@ -49,10 +49,12 @@ macro_rules! new_full_start {
|
|||||||
builder.client().clone(),
|
builder.client().clone(),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
Ok(sc_transaction_pool::BasicPool::new(
|
Ok(sc_transaction_pool::BasicPool::new_full(
|
||||||
builder.config().transaction_pool.clone(),
|
builder.config().transaction_pool.clone(),
|
||||||
std::sync::Arc::new(pool_api),
|
std::sync::Arc::new(pool_api),
|
||||||
builder.prometheus_registry(),
|
builder.prometheus_registry(),
|
||||||
|
builder.spawn_handle(),
|
||||||
|
builder.client().clone(),
|
||||||
))
|
))
|
||||||
})?
|
})?
|
||||||
.with_import_queue(|
|
.with_import_queue(|
|
||||||
@@ -221,12 +223,12 @@ pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
|
|||||||
builder.client().clone(),
|
builder.client().clone(),
|
||||||
fetcher.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(),
|
builder.config().transaction_pool.clone(),
|
||||||
Arc::new(pool_api),
|
Arc::new(pool_api),
|
||||||
builder.prometheus_registry(),
|
builder.prometheus_registry(),
|
||||||
sc_transaction_pool::RevalidationType::Light,
|
builder.spawn_handle(),
|
||||||
);
|
));
|
||||||
Ok(pool)
|
Ok(pool)
|
||||||
})?
|
})?
|
||||||
.with_import_queue_and_fprb(|
|
.with_import_queue_and_fprb(|
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ macro_rules! new_full_start {
|
|||||||
builder.client().clone(),
|
builder.client().clone(),
|
||||||
builder.prometheus_registry(),
|
builder.prometheus_registry(),
|
||||||
);
|
);
|
||||||
let config = builder.config();
|
Ok(sc_transaction_pool::BasicPool::new_full(
|
||||||
|
builder.config().transaction_pool.clone(),
|
||||||
Ok(sc_transaction_pool::BasicPool::new(
|
|
||||||
config.transaction_pool.clone(),
|
|
||||||
std::sync::Arc::new(pool_api),
|
std::sync::Arc::new(pool_api),
|
||||||
builder.prometheus_registry(),
|
builder.prometheus_registry(),
|
||||||
|
builder.spawn_handle(),
|
||||||
|
builder.client().clone(),
|
||||||
))
|
))
|
||||||
})?
|
})?
|
||||||
.with_import_queue(|
|
.with_import_queue(|
|
||||||
@@ -356,12 +356,12 @@ pub fn new_light_base(config: Configuration) -> Result<(
|
|||||||
builder.client().clone(),
|
builder.client().clone(),
|
||||||
fetcher,
|
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(),
|
builder.config().transaction_pool.clone(),
|
||||||
Arc::new(pool_api),
|
Arc::new(pool_api),
|
||||||
builder.prometheus_registry(),
|
builder.prometheus_registry(),
|
||||||
sc_transaction_pool::RevalidationType::Light,
|
builder.spawn_handle(),
|
||||||
);
|
));
|
||||||
Ok(pool)
|
Ok(pool)
|
||||||
})?
|
})?
|
||||||
.with_import_queue_and_fprb(|
|
.with_import_queue_and_fprb(|
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ pub struct ExecutionExtensions<Block: traits::Block> {
|
|||||||
keystore: Option<BareCryptoStorePtr>,
|
keystore: Option<BareCryptoStorePtr>,
|
||||||
// FIXME: these two are only RwLock because of https://github.com/paritytech/substrate/issues/4587
|
// FIXME: these two are only RwLock because of https://github.com/paritytech/substrate/issues/4587
|
||||||
// remove when fixed.
|
// 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>>>>,
|
transaction_pool: RwLock<Option<Weak<dyn sp_transaction_pool::OffchainSubmitTransaction<Block>>>>,
|
||||||
extensions_factory: RwLock<Box<dyn ExtensionsFactory>>,
|
extensions_factory: RwLock<Box<dyn ExtensionsFactory>>,
|
||||||
}
|
}
|
||||||
@@ -121,13 +125,10 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Register transaction pool extension.
|
/// Register transaction pool extension.
|
||||||
///
|
pub fn register_transaction_pool<T>(&self, pool: &Arc<T>)
|
||||||
/// To break retain cycle between `Client` and `TransactionPool` we require this
|
where T: sp_transaction_pool::OffchainSubmitTransaction<Block> + 'static
|
||||||
/// extension to be a `Weak` reference.
|
{
|
||||||
/// That's also the reason why it's being registered lazily instead of
|
*self.transaction_pool.write() = Some(Arc::downgrade(&pool) as _);
|
||||||
/// during initialization.
|
|
||||||
pub fn register_transaction_pool(&self, pool: Weak<dyn sp_transaction_pool::OffchainSubmitTransaction<Block>>) {
|
|
||||||
*self.transaction_pool.write() = Some(pool);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create `ExecutionManager` and `Extensions` for given offchain call.
|
/// Create `ExecutionManager` and `Extensions` for given offchain call.
|
||||||
|
|||||||
@@ -114,6 +114,12 @@ pub struct Blockchain<Block: BlockT> {
|
|||||||
storage: Arc<RwLock<BlockchainStorage<Block>>>,
|
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> {
|
impl<Block: BlockT + Clone> Clone for Blockchain<Block> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
let storage = Arc::new(RwLock::new(self.storage.read().clone()));
|
let storage = Arc::new(RwLock::new(self.storage.read().clone()));
|
||||||
|
|||||||
@@ -358,12 +358,13 @@ mod tests {
|
|||||||
fn should_cease_building_block_when_deadline_is_reached() {
|
fn should_cease_building_block_when_deadline_is_reached() {
|
||||||
// given
|
// given
|
||||||
let client = Arc::new(substrate_test_runtime_client::new());
|
let client = Arc::new(substrate_test_runtime_client::new());
|
||||||
let txpool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let txpool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
futures::executor::block_on(
|
futures::executor::block_on(
|
||||||
@@ -411,12 +412,13 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn should_not_panic_when_deadline_is_reached() {
|
fn should_not_panic_when_deadline_is_reached() {
|
||||||
let client = Arc::new(substrate_test_runtime_client::new());
|
let client = Arc::new(substrate_test_runtime_client::new());
|
||||||
let txpool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let txpool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
|
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
|
||||||
@@ -446,12 +448,13 @@ mod tests {
|
|||||||
fn proposed_storage_changes_should_match_execute_block_storage_changes() {
|
fn proposed_storage_changes_should_match_execute_block_storage_changes() {
|
||||||
let (client, backend) = TestClientBuilder::new().build_with_backend();
|
let (client, backend) = TestClientBuilder::new().build_with_backend();
|
||||||
let client = Arc::new(client);
|
let client = Arc::new(client);
|
||||||
let txpool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let txpool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let genesis_hash = client.info().best_hash;
|
let genesis_hash = client.info().best_hash;
|
||||||
@@ -508,12 +511,13 @@ mod tests {
|
|||||||
fn should_not_remove_invalid_transactions_when_skipping() {
|
fn should_not_remove_invalid_transactions_when_skipping() {
|
||||||
// given
|
// given
|
||||||
let mut client = Arc::new(substrate_test_runtime_client::new());
|
let mut client = Arc::new(substrate_test_runtime_client::new());
|
||||||
let txpool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let txpool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
futures::executor::block_on(
|
futures::executor::block_on(
|
||||||
|
|||||||
@@ -31,10 +31,13 @@
|
|||||||
//! # };
|
//! # };
|
||||||
//! # use sc_transaction_pool::{BasicPool, FullChainApi};
|
//! # use sc_transaction_pool::{BasicPool, FullChainApi};
|
||||||
//! # let client = Arc::new(substrate_test_runtime_client::new());
|
//! # 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(),
|
//! # Default::default(),
|
||||||
//! # Arc::new(FullChainApi::new(client.clone(), None)),
|
//! # Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
//! # None).0,
|
//! # None,
|
||||||
|
//! # spawner,
|
||||||
|
//! # client.clone(),
|
||||||
//! # );
|
//! # );
|
||||||
//! // The first step is to create a `ProposerFactory`.
|
//! // The first step is to create a `ProposerFactory`.
|
||||||
//! let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
|
//! let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
|
||||||
|
|||||||
@@ -200,10 +200,7 @@ mod tests {
|
|||||||
AccountKeyring::*,
|
AccountKeyring::*,
|
||||||
TestClientBuilder,
|
TestClientBuilder,
|
||||||
};
|
};
|
||||||
use sc_transaction_pool::{
|
use sc_transaction_pool::{BasicPool, RevalidationType, txpool::Options};
|
||||||
BasicPool,
|
|
||||||
txpool::Options,
|
|
||||||
};
|
|
||||||
use substrate_test_runtime_transaction_pool::{TestApi, uxt};
|
use substrate_test_runtime_transaction_pool::{TestApi, uxt};
|
||||||
use sp_transaction_pool::{TransactionPool, MaintainedTransactionPool, TransactionSource};
|
use sp_transaction_pool::{TransactionPool, MaintainedTransactionPool, TransactionSource};
|
||||||
use sp_runtime::generic::BlockId;
|
use sp_runtime::generic::BlockId;
|
||||||
@@ -223,7 +220,10 @@ mod tests {
|
|||||||
let (client, select_chain) = builder.build_with_longest_chain();
|
let (client, select_chain) = builder.build_with_longest_chain();
|
||||||
let client = Arc::new(client);
|
let client = Arc::new(client);
|
||||||
let inherent_data_providers = InherentDataProviders::new();
|
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(
|
let env = ProposerFactory::new(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
pool.clone(),
|
pool.clone(),
|
||||||
@@ -288,7 +288,10 @@ mod tests {
|
|||||||
let (client, select_chain) = builder.build_with_longest_chain();
|
let (client, select_chain) = builder.build_with_longest_chain();
|
||||||
let client = Arc::new(client);
|
let client = Arc::new(client);
|
||||||
let inherent_data_providers = InherentDataProviders::new();
|
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(
|
let env = ProposerFactory::new(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
pool.clone(),
|
pool.clone(),
|
||||||
@@ -357,7 +360,10 @@ mod tests {
|
|||||||
let client = Arc::new(client);
|
let client = Arc::new(client);
|
||||||
let inherent_data_providers = InherentDataProviders::new();
|
let inherent_data_providers = InherentDataProviders::new();
|
||||||
let pool_api = api();
|
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(
|
let env = ProposerFactory::new(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
pool.clone(),
|
pool.clone(),
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ use sc_telemetry::{telemetry, CONSENSUS_INFO, CONSENSUS_DEBUG};
|
|||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
|
||||||
use finality_grandpa::Error as GrandpaError;
|
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::{fmt, io};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -126,7 +127,7 @@ pub use authorities::SharedAuthoritySet;
|
|||||||
pub use finality_proof::{FinalityProofProvider, StorageAndProofProvider};
|
pub use finality_proof::{FinalityProofProvider, StorageAndProofProvider};
|
||||||
pub use import::GrandpaBlockImport;
|
pub use import::GrandpaBlockImport;
|
||||||
pub use justification::GrandpaJustification;
|
pub use justification::GrandpaJustification;
|
||||||
pub use light_import::light_block_import;
|
pub use light_import::{light_block_import, GrandpaLightBlockImport};
|
||||||
pub use voting_rule::{
|
pub use voting_rule::{
|
||||||
BeforeBestBlockBy, ThreeQuartersOfTheUnfinalizedChain, VotingRule, VotingRulesBuilder
|
BeforeBestBlockBy, ThreeQuartersOfTheUnfinalizedChain, VotingRule, VotingRulesBuilder
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -212,7 +212,6 @@ mod tests {
|
|||||||
use substrate_test_runtime_client::{TestClient, runtime::Block};
|
use substrate_test_runtime_client::{TestClient, runtime::Block};
|
||||||
use sc_transaction_pool::{BasicPool, FullChainApi};
|
use sc_transaction_pool::{BasicPool, FullChainApi};
|
||||||
use sp_transaction_pool::{TransactionPool, InPoolTransaction};
|
use sp_transaction_pool::{TransactionPool, InPoolTransaction};
|
||||||
use sc_client_api::ExecutorProvider;
|
|
||||||
|
|
||||||
struct MockNetworkStateInfo();
|
struct MockNetworkStateInfo();
|
||||||
|
|
||||||
@@ -227,7 +226,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct TestPool(
|
struct TestPool(
|
||||||
BasicPool<FullChainApi<TestClient, Block>, Block>
|
Arc<BasicPool<FullChainApi<TestClient, Block>, Block>>
|
||||||
);
|
);
|
||||||
|
|
||||||
impl sp_transaction_pool::OffchainSubmitTransaction<Block> for TestPool {
|
impl sp_transaction_pool::OffchainSubmitTransaction<Block> for TestPool {
|
||||||
@@ -248,13 +247,14 @@ mod tests {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
|
|
||||||
let client = Arc::new(substrate_test_runtime_client::new());
|
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(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0));
|
spawner,
|
||||||
client.execution_extensions()
|
client.clone(),
|
||||||
.register_transaction_pool(Arc::downgrade(&pool.clone()) as _);
|
));
|
||||||
let db = sc_client_db::offchain::LocalStorage::new_test();
|
let db = sc_client_db::offchain::LocalStorage::new_test();
|
||||||
let network_state = Arc::new(MockNetworkStateInfo());
|
let network_state = Arc::new(MockNetworkStateInfo());
|
||||||
let header = client.header(&BlockId::number(0)).unwrap().unwrap();
|
let header = client.header(&BlockId::number(0)).unwrap().unwrap();
|
||||||
|
|||||||
@@ -61,11 +61,14 @@ impl Default for TestSetup {
|
|||||||
let client_builder = substrate_test_runtime_client::TestClientBuilder::new();
|
let client_builder = substrate_test_runtime_client::TestClientBuilder::new();
|
||||||
let client = Arc::new(client_builder.set_keystore(keystore.clone()).build());
|
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(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0);
|
spawner,
|
||||||
|
client.clone(),
|
||||||
|
);
|
||||||
TestSetup {
|
TestSetup {
|
||||||
client,
|
client,
|
||||||
keystore,
|
keystore,
|
||||||
|
|||||||
@@ -66,8 +66,6 @@ use sc_client_api::{
|
|||||||
use sp_blockchain::{HeaderMetadata, HeaderBackend};
|
use sp_blockchain::{HeaderMetadata, HeaderBackend};
|
||||||
use crate::{ServiceComponents, TelemetryOnConnectSinks, RpcHandlers, NetworkStatusSinks};
|
use crate::{ServiceComponents, TelemetryOnConnectSinks, RpcHandlers, NetworkStatusSinks};
|
||||||
|
|
||||||
pub type BackgroundTask = Pin<Box<dyn Future<Output=()> + Send>>;
|
|
||||||
|
|
||||||
/// Aggregator for the components required to build a service.
|
/// Aggregator for the components required to build a service.
|
||||||
///
|
///
|
||||||
/// # Usage
|
/// # Usage
|
||||||
@@ -518,6 +516,11 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
|
|||||||
self.remote_backend.clone()
|
self.remote_backend.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a spawn handle created by the task manager.
|
||||||
|
pub fn spawn_handle(&self) -> SpawnTaskHandle {
|
||||||
|
self.task_manager.spawn_handle()
|
||||||
|
}
|
||||||
|
|
||||||
/// Consume the builder and return the parts needed for chain operations.
|
/// Consume the builder and return the parts needed for chain operations.
|
||||||
pub fn to_chain_ops_parts(self) -> (Arc<TCl>, Arc<Backend>, TImpQu, TaskManager) {
|
pub fn to_chain_ops_parts(self) -> (Arc<TCl>, Arc<Backend>, TImpQu, TaskManager) {
|
||||||
(self.client, self.backend, self.import_queue, self.task_manager)
|
(self.client, self.backend, self.import_queue, self.task_manager)
|
||||||
@@ -728,15 +731,11 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
|
|||||||
self,
|
self,
|
||||||
transaction_pool_builder: impl FnOnce(
|
transaction_pool_builder: impl FnOnce(
|
||||||
&Self,
|
&Self,
|
||||||
) -> Result<(UExPool, Option<BackgroundTask>), Error>,
|
) -> Result<Arc<UExPool>, Error>,
|
||||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
||||||
UExPool, TRpc, Backend>, Error>
|
UExPool, TRpc, Backend>, Error>
|
||||||
where TSc: Clone, TFchr: Clone {
|
where TSc: Clone, TFchr: Clone {
|
||||||
let (transaction_pool, background_task) = transaction_pool_builder(&self)?;
|
let transaction_pool = transaction_pool_builder(&self)?;
|
||||||
|
|
||||||
if let Some(background_task) = background_task{
|
|
||||||
self.task_manager.spawn_handle().spawn("txpool-background", background_task);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(ServiceBuilder {
|
Ok(ServiceBuilder {
|
||||||
config: self.config,
|
config: self.config,
|
||||||
@@ -749,7 +748,7 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
|
|||||||
import_queue: self.import_queue,
|
import_queue: self.import_queue,
|
||||||
finality_proof_request_builder: self.finality_proof_request_builder,
|
finality_proof_request_builder: self.finality_proof_request_builder,
|
||||||
finality_proof_provider: self.finality_proof_provider,
|
finality_proof_provider: self.finality_proof_provider,
|
||||||
transaction_pool: Arc::new(transaction_pool),
|
transaction_pool: transaction_pool,
|
||||||
rpc_extensions_builder: self.rpc_extensions_builder,
|
rpc_extensions_builder: self.rpc_extensions_builder,
|
||||||
remote_backend: self.remote_backend,
|
remote_backend: self.remote_backend,
|
||||||
block_announce_validator_builder: self.block_announce_validator_builder,
|
block_announce_validator_builder: self.block_announce_validator_builder,
|
||||||
@@ -978,12 +977,7 @@ ServiceBuilder<
|
|||||||
// Prometheus metrics.
|
// Prometheus metrics.
|
||||||
let metrics_service = if let Some(PrometheusConfig { port, registry }) = config.prometheus_config.clone() {
|
let metrics_service = if let Some(PrometheusConfig { port, registry }) = config.prometheus_config.clone() {
|
||||||
// Set static metrics.
|
// Set static metrics.
|
||||||
let metrics = MetricsService::with_prometheus(
|
let metrics = MetricsService::with_prometheus(®istry, &config)?;
|
||||||
®istry,
|
|
||||||
&config.network.node_name,
|
|
||||||
&config.impl_version,
|
|
||||||
&config.role,
|
|
||||||
)?;
|
|
||||||
spawn_handle.spawn(
|
spawn_handle.spawn(
|
||||||
"prometheus-endpoint",
|
"prometheus-endpoint",
|
||||||
prometheus_endpoint::init_prometheus(port, registry).map(drop)
|
prometheus_endpoint::init_prometheus(port, registry).map(drop)
|
||||||
@@ -1122,10 +1116,6 @@ ServiceBuilder<
|
|||||||
|
|
||||||
/// Builds the full service.
|
/// Builds the full service.
|
||||||
pub fn build_full(self) -> Result<ServiceComponents<TBl, TBackend, TSc, TExPool, TCl>, Error> {
|
pub fn build_full(self) -> Result<ServiceComponents<TBl, TBackend, TSc, TExPool, TCl>, Error> {
|
||||||
// make transaction pool available for off-chain runtime calls.
|
|
||||||
self.client.execution_extensions()
|
|
||||||
.register_transaction_pool(Arc::downgrade(&self.transaction_pool) as _);
|
|
||||||
|
|
||||||
self.build_common()
|
self.build_common()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,6 +181,11 @@ impl Configuration {
|
|||||||
pub fn display_role(&self) -> String {
|
pub fn display_role(&self) -> String {
|
||||||
self.role.to_string()
|
self.role.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the prometheus metrics registry, if available.
|
||||||
|
pub fn prometheus_registry<'a>(&'a self) -> Option<&'a Registry> {
|
||||||
|
self.prometheus_config.as_ref().map(|config| &config.registry)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Available RPC methods.
|
/// Available RPC methods.
|
||||||
|
|||||||
@@ -577,11 +577,14 @@ mod tests {
|
|||||||
// given
|
// given
|
||||||
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
|
let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain();
|
||||||
let client = Arc::new(client);
|
let client = Arc::new(client);
|
||||||
let pool = Arc::new(BasicPool::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
|
let pool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0);
|
spawner,
|
||||||
|
client.clone(),
|
||||||
|
);
|
||||||
let source = sp_runtime::transaction_validity::TransactionSource::External;
|
let source = sp_runtime::transaction_validity::TransactionSource::External;
|
||||||
let best = longest_chain.best_chain().unwrap();
|
let best = longest_chain.best_chain().unwrap();
|
||||||
let transaction = Transfer {
|
let transaction = Transfer {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use std::{convert::TryFrom, time::SystemTime};
|
use std::{convert::TryFrom, time::SystemTime};
|
||||||
|
|
||||||
use crate::NetworkStatus;
|
use crate::{NetworkStatus, config::Configuration};
|
||||||
use prometheus_endpoint::{register, Gauge, U64, F64, Registry, PrometheusError, Opts, GaugeVec};
|
use prometheus_endpoint::{register, Gauge, U64, F64, Registry, PrometheusError, Opts, GaugeVec};
|
||||||
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
|
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
|
||||||
use sp_runtime::traits::{NumberFor, Block, SaturatedConversion, UniqueSaturatedInto};
|
use sp_runtime::traits::{NumberFor, Block, SaturatedConversion, UniqueSaturatedInto};
|
||||||
@@ -261,17 +261,17 @@ impl MetricsService {
|
|||||||
|
|
||||||
|
|
||||||
impl MetricsService {
|
impl MetricsService {
|
||||||
pub fn with_prometheus(registry: &Registry, name: &str, version: &str, role: &Role)
|
pub fn with_prometheus(registry: &Registry, config: &Configuration)
|
||||||
-> Result<Self, PrometheusError>
|
-> Result<Self, PrometheusError>
|
||||||
{
|
{
|
||||||
let role_bits = match role {
|
let role_bits = match config.role {
|
||||||
Role::Full => 1u64,
|
Role::Full => 1u64,
|
||||||
Role::Light => 2u64,
|
Role::Light => 2u64,
|
||||||
Role::Sentry { .. } => 3u64,
|
Role::Sentry { .. } => 3u64,
|
||||||
Role::Authority { .. } => 4u64,
|
Role::Authority { .. } => 4u64,
|
||||||
};
|
};
|
||||||
|
|
||||||
PrometheusMetrics::setup(registry, name, version, role_bits).map(|p| {
|
PrometheusMetrics::setup(registry, &config.network.node_name, &config.impl_version, role_bits).map(|p| {
|
||||||
Self::inner_new(Some(p))
|
Self::inner_new(Some(p))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ use sp_runtime::{
|
|||||||
generic::BlockId,
|
generic::BlockId,
|
||||||
traits::{Block as BlockT, NumberFor, AtLeast32Bit, Extrinsic, Zero},
|
traits::{Block as BlockT, NumberFor, AtLeast32Bit, Extrinsic, Zero},
|
||||||
};
|
};
|
||||||
|
use sp_core::traits::SpawnNamed;
|
||||||
use sp_transaction_pool::{
|
use sp_transaction_pool::{
|
||||||
TransactionPool, PoolStatus, ImportNotificationStream, TxHash, TransactionFor,
|
TransactionPool, PoolStatus, ImportNotificationStream, TxHash, TransactionFor,
|
||||||
TransactionStatusStreamFor, MaintainedTransactionPool, PoolFuture, ChainEvent,
|
TransactionStatusStreamFor, MaintainedTransactionPool, PoolFuture, ChainEvent,
|
||||||
@@ -152,18 +153,6 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
|||||||
Block: BlockT,
|
Block: BlockT,
|
||||||
PoolApi: ChainApi<Block=Block> + 'static,
|
PoolApi: ChainApi<Block=Block> + 'static,
|
||||||
{
|
{
|
||||||
/// Create new basic transaction pool with provided api.
|
|
||||||
///
|
|
||||||
/// It will also optionally return background task that might be started by the
|
|
||||||
/// caller.
|
|
||||||
pub fn new(
|
|
||||||
options: sc_transaction_graph::Options,
|
|
||||||
pool_api: Arc<PoolApi>,
|
|
||||||
prometheus: Option<&PrometheusRegistry>,
|
|
||||||
) -> (Self, Option<Pin<Box<dyn Future<Output=()> + Send>>>) {
|
|
||||||
Self::with_revalidation_type(options, pool_api, prometheus, RevalidationType::Full)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create new basic transaction pool with provided api, for tests.
|
/// Create new basic transaction pool with provided api, for tests.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn new_test(
|
pub fn new_test(
|
||||||
@@ -186,6 +175,18 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create new basic transaction pool for a light node with the provided api.
|
||||||
|
pub fn new_light(
|
||||||
|
options: sc_transaction_graph::Options,
|
||||||
|
pool_api: Arc<PoolApi>,
|
||||||
|
prometheus: Option<&PrometheusRegistry>,
|
||||||
|
spawner: impl SpawnNamed,
|
||||||
|
) -> Self {
|
||||||
|
Self::with_revalidation_type(
|
||||||
|
options, pool_api, prometheus, RevalidationType::Light, spawner,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Create new basic transaction pool with provided api and custom
|
/// Create new basic transaction pool with provided api and custom
|
||||||
/// revalidation type.
|
/// revalidation type.
|
||||||
pub fn with_revalidation_type(
|
pub fn with_revalidation_type(
|
||||||
@@ -193,7 +194,8 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
|||||||
pool_api: Arc<PoolApi>,
|
pool_api: Arc<PoolApi>,
|
||||||
prometheus: Option<&PrometheusRegistry>,
|
prometheus: Option<&PrometheusRegistry>,
|
||||||
revalidation_type: RevalidationType,
|
revalidation_type: RevalidationType,
|
||||||
) -> (Self, Option<Pin<Box<dyn Future<Output=()> + Send>>>) {
|
spawner: impl SpawnNamed,
|
||||||
|
) -> Self {
|
||||||
let pool = Arc::new(sc_transaction_graph::Pool::new(options, pool_api.clone()));
|
let pool = Arc::new(sc_transaction_graph::Pool::new(options, pool_api.clone()));
|
||||||
let (revalidation_queue, background_task) = match revalidation_type {
|
let (revalidation_queue, background_task) = match revalidation_type {
|
||||||
RevalidationType::Light => (revalidation::RevalidationQueue::new(pool_api.clone(), pool.clone()), None),
|
RevalidationType::Light => (revalidation::RevalidationQueue::new(pool_api.clone(), pool.clone()), None),
|
||||||
@@ -203,22 +205,23 @@ impl<PoolApi, Block> BasicPool<PoolApi, Block>
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
if let Some(background_task) = background_task {
|
||||||
BasicPool {
|
spawner.spawn("txpool-background", background_task);
|
||||||
api: pool_api,
|
}
|
||||||
pool,
|
|
||||||
revalidation_queue: Arc::new(revalidation_queue),
|
BasicPool {
|
||||||
revalidation_strategy: Arc::new(Mutex::new(
|
api: pool_api,
|
||||||
match revalidation_type {
|
pool,
|
||||||
RevalidationType::Light => RevalidationStrategy::Light(RevalidationStatus::NotScheduled),
|
revalidation_queue: Arc::new(revalidation_queue),
|
||||||
RevalidationType::Full => RevalidationStrategy::Always,
|
revalidation_strategy: Arc::new(Mutex::new(
|
||||||
}
|
match revalidation_type {
|
||||||
)),
|
RevalidationType::Light => RevalidationStrategy::Light(RevalidationStatus::NotScheduled),
|
||||||
ready_poll: Default::default(),
|
RevalidationType::Full => RevalidationStrategy::Always,
|
||||||
metrics: PrometheusMetrics::new(prometheus),
|
}
|
||||||
},
|
)),
|
||||||
background_task,
|
ready_poll: Default::default(),
|
||||||
)
|
metrics: PrometheusMetrics::new(prometheus),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets shared reference to the underlying pool.
|
/// Gets shared reference to the underlying pool.
|
||||||
@@ -334,6 +337,35 @@ impl<PoolApi, Block> TransactionPool for BasicPool<PoolApi, Block>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Block, Client> BasicPool<FullChainApi<Client, Block>, Block>
|
||||||
|
where
|
||||||
|
Block: BlockT,
|
||||||
|
Client: sp_api::ProvideRuntimeApi<Block>
|
||||||
|
+ sc_client_api::BlockBackend<Block>
|
||||||
|
+ sp_runtime::traits::BlockIdTo<Block>,
|
||||||
|
Client: sc_client_api::ExecutorProvider<Block> + Send + Sync + 'static,
|
||||||
|
Client::Api: sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block>,
|
||||||
|
sp_api::ApiErrorFor<Client, Block>: Send + std::fmt::Display,
|
||||||
|
{
|
||||||
|
/// Create new basic transaction pool for a full node with the provided api.
|
||||||
|
pub fn new_full(
|
||||||
|
options: sc_transaction_graph::Options,
|
||||||
|
pool_api: Arc<FullChainApi<Client, Block>>,
|
||||||
|
prometheus: Option<&PrometheusRegistry>,
|
||||||
|
spawner: impl SpawnNamed,
|
||||||
|
client: Arc<Client>,
|
||||||
|
) -> Arc<Self> {
|
||||||
|
let pool = Arc::new(Self::with_revalidation_type(
|
||||||
|
options, pool_api, prometheus, RevalidationType::Full, spawner
|
||||||
|
));
|
||||||
|
|
||||||
|
// make transaction pool available for off-chain runtime calls.
|
||||||
|
client.execution_extensions().register_transaction_pool(&pool);
|
||||||
|
|
||||||
|
pool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<Block, Client> sp_transaction_pool::LocalTransactionPool
|
impl<Block, Client> sp_transaction_pool::LocalTransactionPool
|
||||||
for BasicPool<FullChainApi<Client, Block>, Block>
|
for BasicPool<FullChainApi<Client, Block>, Block>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ sp-std = { version = "2.0.0-rc4", path = "../../std" }
|
|||||||
sp-version = { version = "2.0.0-rc4", path = "../../version" }
|
sp-version = { version = "2.0.0-rc4", path = "../../version" }
|
||||||
sp-runtime = { version = "2.0.0-rc4", path = "../../runtime" }
|
sp-runtime = { version = "2.0.0-rc4", path = "../../runtime" }
|
||||||
sp-utils = { version = "2.0.0-rc4", path = "../../utils" }
|
sp-utils = { version = "2.0.0-rc4", path = "../../utils" }
|
||||||
|
sp-trie = { version = "2.0.0-rc4", path = "../../trie" }
|
||||||
codec = { package = "parity-scale-codec", version = "1.3.1", features = ["derive"] }
|
codec = { package = "parity-scale-codec", version = "1.3.1", features = ["derive"] }
|
||||||
parking_lot = "0.10.0"
|
parking_lot = "0.10.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|||||||
@@ -54,4 +54,4 @@ impl CloneableSpawn for Executor {
|
|||||||
/// Create tasks executor.
|
/// Create tasks executor.
|
||||||
pub fn executor() -> Box<dyn CloneableSpawn> {
|
pub fn executor() -> Box<dyn CloneableSpawn> {
|
||||||
Box::new(Executor::new())
|
Box::new(Executor::new())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,12 +298,13 @@ mod tests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
let client = Arc::new(substrate_test_runtime_client::new());
|
let client = Arc::new(substrate_test_runtime_client::new());
|
||||||
let pool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let pool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let source = sp_runtime::transaction_validity::TransactionSource::External;
|
let source = sp_runtime::transaction_validity::TransactionSource::External;
|
||||||
@@ -337,12 +338,13 @@ mod tests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
let client = Arc::new(substrate_test_runtime_client::new());
|
let client = Arc::new(substrate_test_runtime_client::new());
|
||||||
let pool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let pool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let accounts = FullSystem::new(client, pool, DenyUnsafe::Yes);
|
let accounts = FullSystem::new(client, pool, DenyUnsafe::Yes);
|
||||||
@@ -360,12 +362,13 @@ mod tests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
let client = Arc::new(substrate_test_runtime_client::new());
|
let client = Arc::new(substrate_test_runtime_client::new());
|
||||||
let pool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let pool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let accounts = FullSystem::new(client, pool, DenyUnsafe::No);
|
let accounts = FullSystem::new(client, pool, DenyUnsafe::No);
|
||||||
@@ -392,12 +395,13 @@ mod tests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
let client = Arc::new(substrate_test_runtime_client::new());
|
let client = Arc::new(substrate_test_runtime_client::new());
|
||||||
let pool = Arc::new(
|
let spawner = sp_core::testing::SpawnBlockingExecutor::new();
|
||||||
BasicPool::new(
|
let pool = BasicPool::new_full(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
Arc::new(FullChainApi::new(client.clone(), None)),
|
Arc::new(FullChainApi::new(client.clone(), None)),
|
||||||
None,
|
None,
|
||||||
).0
|
spawner,
|
||||||
|
client.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let accounts = FullSystem::new(client, pool, DenyUnsafe::No);
|
let accounts = FullSystem::new(client, pool, DenyUnsafe::No);
|
||||||
|
|||||||
Reference in New Issue
Block a user