Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: separate manual-seal #1151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions parachain/src/chain_spec/interlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ pub type InterlayDevChainSpec = sc_service::GenericChainSpec<InterlayDevGenesisE
pub struct InterlayDevGenesisExt {
/// Genesis config.
pub(crate) genesis_config: interlay_runtime::GenesisConfig,
/// The flag to enable instant-seal mode.
pub(crate) enable_instant_seal: bool,
/// The flag to enable manual-seal mode.
pub(crate) enable_manual_seal: bool,
/// The flag to enable EVM contract creation.
pub(crate) enable_create: bool,
}

impl sp_runtime::BuildStorage for InterlayDevGenesisExt {
fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> {
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
interlay_runtime::EnableManualSeal::set(&self.enable_instant_seal);
interlay_runtime::EnableManualSeal::set(&self.enable_manual_seal);
interlay_runtime::evm::EnableCreate::set(&self.enable_create);
});
self.genesis_config.assimilate_storage(storage)
Expand Down Expand Up @@ -51,7 +51,7 @@ fn default_pair_interlay(currency_id: CurrencyId) -> VaultCurrencyPair<CurrencyI
}
}

pub fn interlay_dev_config(enable_instant_seal: bool) -> InterlayDevChainSpec {
pub fn interlay_dev_config(enable_manual_seal: bool) -> InterlayDevChainSpec {
let id: ParaId = PARA_ID.into();
InterlayDevChainSpec::from_genesis(
"Interlay",
Expand All @@ -71,7 +71,7 @@ pub fn interlay_dev_config(enable_instant_seal: bool) -> InterlayDevChainSpec {
1,
false, // disable difficulty check
),
enable_instant_seal,
enable_manual_seal,
enable_create: true,
},
Vec::new(),
Expand Down
10 changes: 5 additions & 5 deletions parachain/src/chain_spec/kintsugi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ pub type KintsugiDevChainSpec = sc_service::GenericChainSpec<KintsugiDevGenesisE
pub struct KintsugiDevGenesisExt {
/// Genesis config.
pub(crate) genesis_config: kintsugi_runtime::GenesisConfig,
/// The flag to enable instant-seal mode.
pub(crate) enable_instant_seal: bool,
/// The flag to enable manual-seal mode.
pub(crate) enable_manual_seal: bool,
/// The flag to enable EVM contract creation.
pub(crate) enable_create: bool,
}

impl sp_runtime::BuildStorage for KintsugiDevGenesisExt {
fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> {
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
kintsugi_runtime::EnableManualSeal::set(&self.enable_instant_seal);
kintsugi_runtime::EnableManualSeal::set(&self.enable_manual_seal);
kintsugi_runtime::evm::EnableCreate::set(&self.enable_create);
});
self.genesis_config.assimilate_storage(storage)
Expand Down Expand Up @@ -51,7 +51,7 @@ fn default_pair_kintsugi(currency_id: CurrencyId) -> VaultCurrencyPair<CurrencyI
}
}

pub fn kintsugi_dev_config(enable_instant_seal: bool) -> KintsugiDevChainSpec {
pub fn kintsugi_dev_config(enable_manual_seal: bool) -> KintsugiDevChainSpec {
let id: ParaId = PARA_ID.into();
KintsugiDevChainSpec::from_genesis(
"Kintsugi",
Expand All @@ -71,7 +71,7 @@ pub fn kintsugi_dev_config(enable_instant_seal: bool) -> KintsugiDevChainSpec {
1,
false, // disable difficulty check
),
enable_instant_seal,
enable_manual_seal,
enable_create: true,
},
Vec::new(),
Expand Down
4 changes: 2 additions & 2 deletions parachain/src/chain_spec/testnet_kintsugi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn local_config(id: ParaId) -> KintsugiChainSpec {
)
}

pub fn development_config(id: ParaId, enable_instant_seal: bool) -> KintsugiDevChainSpec {
pub fn development_config(id: ParaId, enable_manual_seal: bool) -> KintsugiDevChainSpec {
KintsugiDevChainSpec::from_genesis(
"Kintsugi",
"kintsugi",
Expand Down Expand Up @@ -103,7 +103,7 @@ pub fn development_config(id: ParaId, enable_instant_seal: bool) -> KintsugiDevC
DEFAULT_BITCOIN_CONFIRMATIONS,
true, // disable difficulty check
),
enable_instant_seal,
enable_manual_seal,
enable_create: true,
},
Vec::new(),
Expand Down
24 changes: 17 additions & 7 deletions parachain/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ pub enum Subcommand {
TryRuntime,
}

#[derive(clap::ValueEnum, Debug, Clone)]
pub enum RuntimeName {
Interlay,
Kintsugi,
}

/// Command for exporting the metadata.
#[derive(Debug, Parser)]
pub struct ExportMetadataCommand {
Expand All @@ -68,10 +74,14 @@ pub struct ExportMetadataCommand {
pub runtime: RuntimeName,
}

#[derive(clap::ValueEnum, Debug, Clone)]
pub enum RuntimeName {
Interlay,
Kintsugi,
/// Available Sealing methods.
#[derive(Copy, Clone, Debug, Default, clap::ValueEnum)]
pub enum Sealing {
/// Seal using rpc method.
#[default]
Manual,
/// Seal when transaction is executed.
Instant,
}

#[derive(Debug, Parser)]
Expand All @@ -94,12 +104,12 @@ pub struct Cli {
#[clap(raw = true)]
pub relaychain_args: Vec<String>,

/// Instant block sealing
/// Choose sealing method.
///
/// This flag requires `--dev` **or** `--chain=...`,
/// `--force-authoring` and `--alice` flags.
#[clap(long = "instant-seal")]
pub instant_seal: bool,
#[arg(long, value_enum, ignore_case = true)]
pub sealing: Option<Sealing>,
}

#[derive(Debug)]
Expand Down
23 changes: 12 additions & 11 deletions parachain/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

use crate::{
chain_spec,
cli::{Cli, RelayChainCli, RuntimeName, Subcommand},
cli::{Cli, RelayChainCli, RuntimeName, Sealing, Subcommand},
service::{new_partial, InterlayRuntimeExecutor, KintsugiRuntimeExecutor},
};
use cumulus_primitives_core::ParaId;
Expand Down Expand Up @@ -66,19 +66,19 @@ impl<T: sc_service::ChainSpec + 'static> IdentifyChain for T {
}
}

fn load_spec(id: &str, enable_instant_seal: bool) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
fn load_spec(id: &str, enable_manual_seal: bool) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"" => Box::new(chain_spec::testnet_kintsugi::local_config(DEFAULT_PARA_ID.into())),
"dev" => Box::new(chain_spec::testnet_kintsugi::development_config(
DEFAULT_PARA_ID.into(),
enable_instant_seal,
enable_manual_seal,
)),
"kintsugi-dev" | "kintsugi-bench" => Box::new(chain_spec::kintsugi::kintsugi_dev_config(enable_instant_seal)),
"kintsugi-dev" | "kintsugi-bench" => Box::new(chain_spec::kintsugi::kintsugi_dev_config(enable_manual_seal)),
"kintsugi-latest" => Box::new(chain_spec::kintsugi::kintsugi_mainnet_config()),
"kintsugi" => Box::new(chain_spec::KintsugiChainSpec::from_json_bytes(
&include_bytes!("../res/kintsugi.json")[..],
)?),
"interlay-dev" | "interlay-bench" => Box::new(chain_spec::interlay::interlay_dev_config(enable_instant_seal)),
"interlay-dev" | "interlay-bench" => Box::new(chain_spec::interlay::interlay_dev_config(enable_manual_seal)),
"interlay-latest" => Box::new(chain_spec::interlay::interlay_mainnet_config()),
"interlay" => Box::new(chain_spec::InterlayChainSpec::from_json_bytes(
&include_bytes!("../res/interlay.json")[..],
Expand Down Expand Up @@ -154,7 +154,8 @@ impl SubstrateCli for Cli {
}

fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
load_spec(id, self.instant_seal)
let enable_manual_seal = self.sealing.is_some();
load_spec(id, enable_manual_seal)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
Expand Down Expand Up @@ -313,7 +314,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::Benchmark(cmd)) => {
// some benchmarks set the timestamp so we ignore
// the aura check which would otherwise panic
cli.instant_seal = true;
cli.sealing = Some(Sealing::Manual);
let runner = cli.create_runner(cmd)?;
match cmd {
BenchmarkCmd::Pallet(cmd) => {
Expand Down Expand Up @@ -470,8 +471,8 @@ pub fn run() -> Result<()> {

runner
.run_node_until_exit(|config| async move {
if cli.instant_seal {
start_instant(cli, config).await
if let Some(sealing) = cli.sealing {
start_instant(cli, config, sealing).await
} else {
start_node(cli, config).await
}
Expand All @@ -481,10 +482,10 @@ pub fn run() -> Result<()> {
}
}

async fn start_instant(cli: Cli, config: Configuration) -> sc_service::error::Result<TaskManager> {
async fn start_instant(cli: Cli, config: Configuration, sealing: Sealing) -> sc_service::error::Result<TaskManager> {
with_runtime_or_err!(config.chain_spec, {
{
crate::service::start_instant::<RuntimeApi, Executor, TransactionConverter>(config, cli.eth)
crate::service::start_instant::<RuntimeApi, Executor, TransactionConverter>(config, cli.eth, sealing)
.await
.map(|r| r.0)
.map_err(Into::into)
Expand Down
1 change: 1 addition & 0 deletions parachain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod chain_spec;
pub mod service;

mod cli;
mod eth;
40 changes: 26 additions & 14 deletions parachain/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::cli::Sealing;
use cumulus_client_cli::CollatorOptions;
use cumulus_client_consensus_aura::{AuraConsensus, BuildAuraConsensusParams, SlotProportion};
use cumulus_client_consensus_common::{ParachainBlockImport as TParachainBlockImport, ParachainConsensus};
Expand All @@ -15,6 +16,7 @@ use polkadot_service::CollatorPair;
use primitives::*;
use sc_client_api::{HeaderBackend, StateBackendFor};
use sc_consensus::{ImportQueue, LongestChain};
use sc_consensus_manual_seal::EngineCommand;
use sc_executor::NativeElseWasmExecutor;
use sc_network::NetworkBlock;
use sc_network_sync::SyncingService;
Expand Down Expand Up @@ -219,7 +221,7 @@ where
pub fn new_partial<RuntimeApi, Executor>(
config: &Configuration,
eth_config: &EthConfiguration,
instant_seal: bool,
manual_seal: bool,
) -> Result<
PartialComponents<
FullClient<RuntimeApi, Executor>,
Expand Down Expand Up @@ -285,7 +287,7 @@ where
client.clone(),
);

let select_chain = if instant_seal {
let select_chain = if manual_seal {
Some(LongestChain::new(backend.clone()))
} else {
None
Expand All @@ -294,8 +296,8 @@ where
let overrides = interbtc_rpc::overrides_handle(client.clone());
let frontier_backend = open_frontier_backend(client.clone(), config, eth_config, overrides.clone())?;

let import_queue = if instant_seal {
// instant sealing
let import_queue = if manual_seal {
// manual / instant seal
sc_consensus_manual_seal::import_queue(
Box::new(EthBlockImport::new(client.clone(), client.clone())),
&task_manager.spawn_essential_handle(),
Expand Down Expand Up @@ -679,6 +681,7 @@ where
pub async fn start_instant<RuntimeApi, Executor, CT>(
mut config: Configuration,
eth_config: EthConfiguration,
sealing: Sealing,
) -> sc_service::error::Result<(TaskManager, RpcHandlers)>
where
RuntimeApi: ConstructRuntimeApi<Block, FullClient<RuntimeApi, Executor>> + Send + Sync + 'static,
Expand Down Expand Up @@ -731,15 +734,24 @@ where
// Channel for the rpc handler to communicate with the authorship task.
let (command_sink, commands_stream) = futures::channel::mpsc::channel(1024);

let pool = transaction_pool.pool().clone();
let import_stream = pool.validated_pool().import_notification_stream().map(|_| {
sc_consensus_manual_seal::rpc::EngineCommand::SealNewBlock {
create_empty: true,
finalize: true,
parent_hash: None,
sender: None,
let commands_stream: Box<dyn futures::Stream<Item = EngineCommand<H256>> + Send + Sync + Unpin> = match sealing
{
Sealing::Instant => {
let import_stream = transaction_pool
.pool()
.validated_pool()
.import_notification_stream()
.map(|_| EngineCommand::SealNewBlock {
create_empty: true,
finalize: true,
parent_hash: None,
sender: None,
});
// combine so we can still seal blocks manually
Box::new(futures::stream_select!(commands_stream, import_stream))
Comment on lines +750 to +751
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noting that other projects (such as moonbeam) don't allow manual-seal as well as instant-seal.

}
});
Sealing::Manual => Box::new(commands_stream),
};

let client_for_cidp = client.clone();

Expand All @@ -748,7 +760,7 @@ where
env: proposer_factory,
client: client.clone(),
pool: transaction_pool.clone(),
commands_stream: futures::stream_select!(commands_stream, import_stream),
commands_stream,
select_chain,
consensus_data_provider: None,
create_inherent_data_providers: move |block: Hash, _| {
Expand All @@ -774,7 +786,7 @@ where
});
// we spawn the future on a background thread managed by service.
task_manager.spawn_essential_handle().spawn_blocking(
"instant-seal",
"authorship_task",
Some("block-authoring"),
authorship_future,
);
Expand Down