difftreelog
Autoseal after idle n seconds
in: master
4 files changed
node/cli/Cargo.tomldiffbeforeafterboth1################################################################################2# Build Dependencies34[build-dependencies.substrate-build-script-utils]5git = 'https://github.com/paritytech/substrate.git'6branch = 'polkadot-v0.9.18'78################################################################################9# Substrate Dependecies1011[dependencies.codec]12default-features = false13features = ['derive']14package = 'parity-scale-codec'15version = '3.1.2'1617[dependencies.frame-benchmarking]18git = 'https://github.com/paritytech/substrate.git'19branch = 'polkadot-v0.9.18'2021[dependencies.frame-benchmarking-cli]22git = 'https://github.com/paritytech/substrate.git'23branch = 'polkadot-v0.9.18'2425[dependencies.pallet-transaction-payment-rpc]26git = 'https://github.com/paritytech/substrate.git'27branch = 'polkadot-v0.9.18'2829[dependencies.substrate-prometheus-endpoint]30git = 'https://github.com/paritytech/substrate.git'31branch = 'polkadot-v0.9.18'3233[dependencies.sc-basic-authorship]34git = 'https://github.com/paritytech/substrate.git'35branch = 'polkadot-v0.9.18'3637[dependencies.sc-chain-spec]38git = 'https://github.com/paritytech/substrate.git'39branch = 'polkadot-v0.9.18'4041[dependencies.sc-cli]42features = ['wasmtime']43git = 'https://github.com/paritytech/substrate.git'44branch = 'polkadot-v0.9.18'4546[dependencies.sc-client-api]47git = 'https://github.com/paritytech/substrate.git'48branch = 'polkadot-v0.9.18'4950[dependencies.sc-consensus]51git = 'https://github.com/paritytech/substrate.git'52branch = 'polkadot-v0.9.18'5354[dependencies.sc-consensus-aura]55git = 'https://github.com/paritytech/substrate.git'56branch = 'polkadot-v0.9.18'5758[dependencies.sc-executor]59features = ['wasmtime']60git = 'https://github.com/paritytech/substrate.git'61branch = 'polkadot-v0.9.18'6263[dependencies.sc-finality-grandpa]64git = 'https://github.com/paritytech/substrate.git'65branch = 'polkadot-v0.9.18'6667[dependencies.sc-keystore]68git = 'https://github.com/paritytech/substrate.git'69branch = 'polkadot-v0.9.18'7071[dependencies.sc-rpc]72git = 'https://github.com/paritytech/substrate.git'73branch = 'polkadot-v0.9.18'7475[dependencies.sc-rpc-api]76git = 'https://github.com/paritytech/substrate.git'77branch = 'polkadot-v0.9.18'7879[dependencies.sc-service]80features = ['wasmtime']81git = 'https://github.com/paritytech/substrate.git'82branch = 'polkadot-v0.9.18'8384[dependencies.sc-telemetry]85git = 'https://github.com/paritytech/substrate.git'86branch = 'polkadot-v0.9.18'8788[dependencies.sc-transaction-pool]89git = 'https://github.com/paritytech/substrate.git'90branch = 'polkadot-v0.9.18'9192[dependencies.sc-tracing]93git = 'https://github.com/paritytech/substrate.git'94branch = 'polkadot-v0.9.18'9596[dependencies.sp-block-builder]97git = 'https://github.com/paritytech/substrate.git'98branch = 'polkadot-v0.9.18'99100[dependencies.sp-api]101git = 'https://github.com/paritytech/substrate.git'102branch = 'polkadot-v0.9.18'103104[dependencies.sp-blockchain]105git = 'https://github.com/paritytech/substrate.git'106branch = 'polkadot-v0.9.18'107108[dependencies.sp-consensus]109git = 'https://github.com/paritytech/substrate.git'110branch = 'polkadot-v0.9.18'111112[dependencies.sp-consensus-aura]113git = 'https://github.com/paritytech/substrate.git'114branch = 'polkadot-v0.9.18'115116[dependencies.sp-core]117git = 'https://github.com/paritytech/substrate.git'118branch = 'polkadot-v0.9.18'119120[dependencies.sp-finality-grandpa]121git = 'https://github.com/paritytech/substrate.git'122branch = 'polkadot-v0.9.18'123124[dependencies.sp-inherents]125git = 'https://github.com/paritytech/substrate.git'126branch = 'polkadot-v0.9.18'127128[dependencies.sp-keystore]129git = 'https://github.com/paritytech/substrate.git'130branch = 'polkadot-v0.9.18'131132[dependencies.sp-offchain]133git = 'https://github.com/paritytech/substrate.git'134branch = 'polkadot-v0.9.18'135136[dependencies.sp-runtime]137git = 'https://github.com/paritytech/substrate.git'138branch = 'polkadot-v0.9.18'139140[dependencies.sp-session]141git = 'https://github.com/paritytech/substrate.git'142branch = 'polkadot-v0.9.18'143144[dependencies.sp-timestamp]145git = 'https://github.com/paritytech/substrate.git'146branch = 'polkadot-v0.9.18'147148[dependencies.sp-transaction-pool]149git = 'https://github.com/paritytech/substrate.git'150branch = 'polkadot-v0.9.18'151152[dependencies.sp-trie]153git = 'https://github.com/paritytech/substrate.git'154branch = 'polkadot-v0.9.18'155156[dependencies.substrate-frame-rpc-system]157git = 'https://github.com/paritytech/substrate.git'158branch = 'polkadot-v0.9.18'159160[dependencies.sc-network]161git = 'https://github.com/paritytech/substrate.git'162branch = 'polkadot-v0.9.18'163164[dependencies.serde]165features = ['derive']166version = '1.0.130'167168[dependencies.serde_json]169version = '1.0.68'170171[dependencies.sc-consensus-manual-seal]172git = 'https://github.com/paritytech/substrate.git'173branch = 'polkadot-v0.9.18'174175################################################################################176# Cumulus dependencies177178[dependencies.cumulus-client-consensus-aura]179git = 'https://github.com/paritytech/cumulus.git'180branch = 'polkadot-v0.9.18'181182[dependencies.cumulus-client-consensus-common]183git = 'https://github.com/paritytech/cumulus.git'184branch = 'polkadot-v0.9.18'185186[dependencies.cumulus-client-collator]187git = 'https://github.com/paritytech/cumulus.git'188branch = 'polkadot-v0.9.18'189190[dependencies.cumulus-client-cli]191git = 'https://github.com/paritytech/cumulus.git'192branch = 'polkadot-v0.9.18'193194[dependencies.cumulus-client-network]195git = 'https://github.com/paritytech/cumulus.git'196branch = 'polkadot-v0.9.18'197198[dependencies.cumulus-primitives-core]199git = 'https://github.com/paritytech/cumulus.git'200branch = 'polkadot-v0.9.18'201202[dependencies.cumulus-primitives-parachain-inherent]203git = 'https://github.com/paritytech/cumulus.git'204branch = 'polkadot-v0.9.18'205206[dependencies.cumulus-client-service]207git = 'https://github.com/paritytech/cumulus.git'208branch = 'polkadot-v0.9.18'209210[dependencies.cumulus-relay-chain-interface]211git = 'https://github.com/paritytech/cumulus.git'212branch = 'polkadot-v0.9.18'213214[dependencies.cumulus-relay-chain-inprocess-interface]215git = 'https://github.com/paritytech/cumulus.git'216branch = 'polkadot-v0.9.18'217218[dependencies.cumulus-relay-chain-rpc-interface]219git = 'https://github.com/paritytech/cumulus.git'220branch = 'polkadot-v0.9.18'221222################################################################################223# Polkadot dependencies224[dependencies.polkadot-primitives]225git = "https://github.com/paritytech/polkadot"226branch = 'release-v0.9.18'227228[dependencies.polkadot-service]229git = "https://github.com/paritytech/polkadot"230branch = 'release-v0.9.18'231232[dependencies.polkadot-cli]233git = "https://github.com/paritytech/polkadot"234branch = 'release-v0.9.18'235236[dependencies.polkadot-test-service]237git = "https://github.com/paritytech/polkadot"238branch = 'release-v0.9.18'239240[dependencies.polkadot-parachain]241git = "https://github.com/paritytech/polkadot"242branch = 'release-v0.9.18'243244245################################################################################246# Local dependencies247248[dependencies.unique-runtime-common]249default-features = false250path = "../../runtime/common"251252[dependencies.unique-runtime]253path = '../../runtime/unique'254optional = true255256[dependencies.quartz-runtime]257path = '../../runtime/quartz'258optional = true259260[dependencies.opal-runtime]261path = '../../runtime/opal'262263[dependencies.up-data-structs]264path = "../../primitives/data-structs"265default-features = false266267[dependencies.up-rpc]268path = "../../primitives/rpc"269270[dependencies.pallet-transaction-payment-rpc-runtime-api]271git = 'https://github.com/paritytech/substrate.git'272branch = 'polkadot-v0.9.18'273274################################################################################275# Package276277[package]278authors = ['Unique Network <support@uniquenetwork.io>']279build = 'build.rs'280description = 'Unique Node'281edition = '2021'282homepage = 'https://unique.network'283license = 'GPLv3'284name = 'unique-node'285repository = 'https://github.com/UniqueNetwork/unique-chain'286version = '0.9.18'287288[[bin]]289name = 'unique-collator'290path = "src/main.rs"291292[package.metadata.docs.rs]293targets = ['x86_64-unknown-linux-gnu']294295[dependencies]296futures = '0.3.17'297log = '0.4.14'298flexi_logger = "0.15.7"299parking_lot = '0.11.2'300clap = "3.1.2"301jsonrpc-core = '18.0.0'302jsonrpc-pubsub = "18.0.0"303304fc-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-mapping-sync = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }307fc-rpc = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }308fc-db = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }309fp-rpc = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }310pallet-ethereum = { git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }311312unique-rpc = { default-features = false, path = "../rpc" }313314[features]315default = []316runtime-benchmarks = [317 'unique-runtime/runtime-benchmarks',318 'polkadot-service/runtime-benchmarks',319]node/cli/src/cli.rsdiffbeforeafterboth--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -104,6 +104,15 @@
#[structopt(flatten)]
pub run: cumulus_client_cli::RunCmd,
+ /// When running the node in the `--dev` mode and
+ /// there is no transaction in the transaction pool,
+ /// an empty block will be sealed automatically
+ /// after the `--idle-autoseal-interval` milliseconds.
+ ///
+ /// Default interval is 500 milliseconds
+ #[structopt(default_value = "500", long)]
+ pub idle_autoseal_interval: u64,
+
/// Relaychain arguments
#[structopt(raw = true)]
pub relaychain_args: Vec<String>,
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -35,7 +35,7 @@
use crate::{
chain_spec::{self, RuntimeId, RuntimeIdentification, ServiceId, ServiceIdentification},
cli::{Cli, RelayChainCli, Subcommand},
- service::{new_partial, start_node, start_dev_node},
+ service::{new_partial, start_node, start_dev_node, AutosealInterval},
};
#[cfg(feature = "unique-runtime")]
@@ -60,7 +60,7 @@
};
use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::Block as BlockT;
-use std::{io::Write, net::SocketAddr};
+use std::{io::Write, net::SocketAddr, time::Duration};
use unique_runtime_common::types::Block;
@@ -405,8 +405,12 @@
if is_dev_service {
info!("Running Dev service");
+ let autoseal_interval = AutosealInterval::new(
+ Duration::from_millis(cli.idle_autoseal_interval)
+ )?;
+
return start_node_using_chain_runtime! {
- start_dev_node(config).map_err(Into::into)
+ start_dev_node(config, autoseal_interval).map_err(Into::into)
};
};
node/cli/src/service.rsdiffbeforeafterboth--- a/node/cli/src/service.rs
+++ b/node/cli/src/service.rs
@@ -21,8 +21,11 @@
use std::sync::Mutex;
use std::collections::BTreeMap;
use std::time::Duration;
+use std::pin::Pin;
use fc_rpc_core::types::FeeHistoryCache;
-use futures::StreamExt;
+use futures::Future;
+use futures::{Stream, StreamExt, stream::select, task::{Context, Poll}};
+use futures_timer::Delay;
use unique_rpc::overrides_handle;
@@ -111,6 +114,40 @@
}
}
+pub struct AutosealInterval {
+ duration: Duration,
+ delay_handle: Pin<Box<Delay>>
+}
+
+impl AutosealInterval {
+ pub fn new(duration: Duration) -> Result<Self, String> {
+ if duration.is_zero() {
+ return Err("Invalid autoseal interval: 0 seconds".into());
+ }
+
+ Ok(Self {
+ duration,
+ delay_handle: Box::pin(Delay::new(duration))
+ })
+ }
+}
+
+impl Stream for AutosealInterval {
+ type Item = ();
+
+ fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
+ match self.delay_handle.as_mut().poll(cx) {
+ Poll::Ready(_) => {
+ let duration = self.duration;
+ self.delay_handle.reset(duration);
+
+ Poll::Ready(Some(()))
+ }
+ Poll::Pending => Poll::Pending
+ }
+ }
+}
+
pub fn open_frontier_backend(config: &Configuration) -> Result<Arc<fc_db::Backend<Block>>, String> {
let config_dir = config
.base_path
@@ -712,6 +749,7 @@
/// the parachain inherent
pub fn start_dev_node<Runtime, RuntimeApi, ExecutorDispatch>(
config: Configuration,
+ autoseal_interval: AutosealInterval,
) -> sc_service::error::Result<TaskManager>
where
Runtime: RuntimeInstance + Send + Sync + 'static,
@@ -735,7 +773,6 @@
+ sp_consensus_aura::AuraApi<Block, AuraId>,
ExecutorDispatch: NativeExecutionDispatch + 'static,
{
- use futures::Stream;
use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams};
use fc_consensus::FrontierBlockImport;
use sc_client_api::HeaderBackend;
@@ -799,21 +836,36 @@
telemetry.as_ref().map(|x| x.handle()),
);
- let commands_stream: Box<dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin> =
+ let transactions_commands_stream: Box<dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin> =
Box::new(
- // This bit cribbed from the implementation of instant seal.
transaction_pool
.pool()
.validated_pool()
.import_notification_stream()
.map(|_| EngineCommand::SealNewBlock {
- create_empty: true, // was false in Moonbeam
+ create_empty: true,
finalize: false,
parent_hash: None,
sender: None,
}),
);
+ let autoseal_interval = Box::pin(autoseal_interval);
+ let idle_commands_stream: Box<dyn Stream<Item = EngineCommand<Hash>> + Send + Sync + Unpin> =
+ Box::new(
+ autoseal_interval.map(|_| EngineCommand::SealNewBlock {
+ create_empty: true,
+ finalize: false,
+ parent_hash: None,
+ sender: None,
+ })
+ );
+
+ let commands_stream = select(
+ transactions_commands_stream,
+ idle_commands_stream
+ );
+
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
let client_set_aside_for_cidp = client.clone();