mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Split the service initialisation up into seperate functions (#6332)
* Seperate out the complexity in ServiceBuilder::build_common into seperate functions * Fix line widths * Move some functions to their respective crates
This commit is contained in:
@@ -41,8 +41,9 @@ use sp_api::{ApiExt, ProvideRuntimeApi};
|
||||
use futures::future::Future;
|
||||
use log::{debug, warn};
|
||||
use sc_network::NetworkStateInfo;
|
||||
use sp_core::{offchain::{self, OffchainStorage}, ExecutionContext};
|
||||
use sp_core::{offchain::{self, OffchainStorage}, ExecutionContext, traits::SpawnNamed};
|
||||
use sp_runtime::{generic::BlockId, traits::{self, Header}};
|
||||
use futures::{prelude::*, future::ready};
|
||||
|
||||
mod api;
|
||||
|
||||
@@ -161,6 +162,43 @@ impl<Client, Storage, Block> OffchainWorkers<
|
||||
}
|
||||
}
|
||||
|
||||
/// Inform the offchain worker about new imported blocks
|
||||
pub async fn notification_future<Client, Storage, Block, Spawner>(
|
||||
is_validator: bool,
|
||||
client: Arc<Client>,
|
||||
offchain: Arc<OffchainWorkers<Client, Storage, Block>>,
|
||||
spawner: Spawner,
|
||||
network_state_info: Arc<dyn NetworkStateInfo + Send + Sync>,
|
||||
)
|
||||
where
|
||||
Block: traits::Block,
|
||||
Client: ProvideRuntimeApi<Block> + sc_client_api::BlockchainEvents<Block> + Send + Sync + 'static,
|
||||
Client::Api: OffchainWorkerApi<Block>,
|
||||
Storage: OffchainStorage + 'static,
|
||||
Spawner: SpawnNamed
|
||||
{
|
||||
client.import_notification_stream().for_each(move |n| {
|
||||
if n.is_new_best {
|
||||
spawner.spawn(
|
||||
"offchain-on-block",
|
||||
offchain.on_block_imported(
|
||||
&n.header,
|
||||
network_state_info.clone(),
|
||||
is_validator,
|
||||
).boxed(),
|
||||
);
|
||||
} else {
|
||||
log::debug!(
|
||||
target: "sc_offchain",
|
||||
"Skipping offchain workers for non-canon block: {:?}",
|
||||
n.header,
|
||||
)
|
||||
}
|
||||
|
||||
ready(())
|
||||
}).await;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user