git.delta.rocks / unique-network / refs/commits / 219f5f01d1e5

difftreelog

Merge pull request #332 from UniqueNetwork/feature/autoseal-every-n-secs

kozyrevdev2022-04-01parents: #62bde24 #7e36fe0.patch.diff
in: master
Feature/autoseal every n secs

4 files changed

modifiednode/cli/Cargo.tomldiffbeforeafterboth
300clap = "3.1.2"300clap = "3.1.2"
301jsonrpc-core = '18.0.0'301jsonrpc-core = '18.0.0'
302jsonrpc-pubsub = "18.0.0"302jsonrpc-pubsub = "18.0.0"
303tokio = { version = "1.17.0", features = ["time"] }
303304
304fc-rpc-core = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }305fc-rpc-core = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
305fc-consensus = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }306fc-consensus = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
modifiednode/cli/src/cli.rsdiffbeforeafterboth
104 #[structopt(flatten)]104 #[structopt(flatten)]
105 pub run: cumulus_client_cli::RunCmd,105 pub run: cumulus_client_cli::RunCmd,
106
107 /// When running the node in the `--dev` mode and
108 /// there is no transaction in the transaction pool,
109 /// an empty block will be sealed automatically
110 /// after the `--idle-autoseal-interval` milliseconds.
111 ///
112 /// The default interval is 500 milliseconds
113 #[structopt(default_value = "500", long)]
114 pub idle_autoseal_interval: u64,
106115
107 /// Relaychain arguments116 /// Relaychain arguments
108 #[structopt(raw = true)]117 #[structopt(raw = true)]
modifiednode/cli/src/command.rsdiffbeforeafterboth
60};60};
61use sp_core::hexdisplay::HexDisplay;61use sp_core::hexdisplay::HexDisplay;
62use sp_runtime::traits::Block as BlockT;62use sp_runtime::traits::Block as BlockT;
63use std::{io::Write, net::SocketAddr};63use std::{io::Write, net::SocketAddr, time::Duration};
6464
65use unique_runtime_common::types::Block;65use unique_runtime_common::types::Block;
6666
405 if is_dev_service {405 if is_dev_service {
406 info!("Running Dev service");406 info!("Running Dev service");
407
408 let autoseal_interval = Duration::from_millis(cli.idle_autoseal_interval);
407409
408 return start_node_using_chain_runtime! {410 return start_node_using_chain_runtime! {
409 start_dev_node(config).map_err(Into::into)411 start_dev_node(config, autoseal_interval).map_err(Into::into)
410 };412 };
411 };413 };
412414
modifiednode/cli/src/service.rsdiffbeforeafterboth
21use std::sync::Mutex;21use std::sync::Mutex;
22use std::collections::BTreeMap;22use std::collections::BTreeMap;
23use std::time::Duration;23use std::time::Duration;
24use std::pin::Pin;
24use fc_rpc_core::types::FeeHistoryCache;25use fc_rpc_core::types::FeeHistoryCache;
25use futures::StreamExt;26use futures::{
27 Stream, StreamExt,
28 stream::select,
29 task::{Context, Poll},
30};
31use tokio::time::Interval;
2632
27use unique_rpc::overrides_handle;33use unique_rpc::overrides_handle;
2834
111 }117 }
112}118}
119
120pub struct AutosealInterval {
121 interval: Interval,
122}
123
124impl AutosealInterval {
125 pub fn new(config: &Configuration, interval: Duration) -> Self {
126 let _tokio_runtime = config.tokio_handle.enter();
127 let interval = tokio::time::interval(interval);
128
129 Self { interval }
130 }
131}
132
133impl Stream for AutosealInterval {
134 type Item = tokio::time::Instant;
135
136 fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
137 self.interval.poll_tick(cx).map(Some)
138 }
139}
113140
114pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {141pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {
115 let config_dir = config142 let config_dir = config
712/// the parachain inherent739/// the parachain inherent
713pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(740pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(
714 config: Configuration,741 config: Configuration,
742 autoseal_interval: Duration,
715) -> sc_service::error::Result<TaskManager>743) -> sc_service::error::Result<TaskManager>
716where744where
717 Runtime: RuntimeInstance + Send + Sync + 'static,745 Runtime: RuntimeInstance + Send + Sync + 'static,
735 + sp_consensus_aura::AuraApi<Block, AuraId>,763 + sp_consensus_aura::AuraApi<Block, AuraId>,
736 ExecutorDispatch: NativeExecutionDispatch + 'static,764 ExecutorDispatch: NativeExecutionDispatch + 'static,
737{765{
738 use futures::Stream;
739 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};766 use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};
740 use fc_consensus::FrontierBlockImport;767 use fc_consensus::FrontierBlockImport;
741 use sc_client_api::HeaderBackend;768 use sc_client_api::HeaderBackend;
799 telemetry.as_ref().map(|x| x.handle()),826 telemetry.as_ref().map(|x| x.handle()),
800 );827 );
801828
802 let commands_stream: Box<dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin> =829 let transactions_commands_stream: Box<
830 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,
803 Box::new(831 > = Box::new(
804 // This bit cribbed from the implementation of instant seal.
805 transaction_pool832 transaction_pool
806 .pool()833 .pool()
807 .validated_pool()834 .validated_pool()
808 .import_notification_stream()835 .import_notification_stream()
809 .map(|_| EngineCommand::SealNewBlock {836 .map(|_| EngineCommand::SealNewBlock {
810 create_empty: true, // was false in Moonbeam837 create_empty: true,
811 finalize: false,838 finalize: false,
812 parent_hash: None,839 parent_hash: None,
813 sender: None,840 sender: None,
814 }),841 }),
815 );842 );
843
844 let autoseal_interval = Box::pin(AutosealInterval::new(&config, autoseal_interval));
845 let idle_commands_stream: Box<
846 dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin,
847 > = Box::new(autoseal_interval.map(|_| EngineCommand::SealNewBlock {
848 create_empty: true,
849 finalize: false,
850 parent_hash: None,
851 sender: None,
852 }));
853
854 let commands_stream = select(transactions_commands_stream, idle_commands_stream);
816855
817 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;856 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
818 let client_set_aside_for_cidp = client.clone();857 let client_set_aside_for_cidp = client.clone();