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: delayed finalization #214

Merged
merged 3 commits into from
Nov 29, 2023
Merged
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ for a production deployment, but a great fit for development and testing:_
[#42](https://github.com/paritytech/substrate-contracts-node/pull/42).
Hereby blocks are authored immediately at every transaction, so there
is none of the typical six seconds block time associated with `grandpa` or `aura`.
* By default, either manual or instant seal does not result in block finalization unless the `engine_finalizeBlock`
RPC is executed. However, it is possible to configure the finalization of sealed blocks to occur after a certain
amount of time by setting the `--finalize-delay-sec` option to a specific value, which specifies the number of seconds
to delay before finalizing the blocks. The default value is 1 second.
```shell
./target/release/substrate-contracts-node --finalize-delay-sec 5
```
* _If no CLI arguments are passed the node is started in development mode
by default._
* A custom logging filter is applied by default that hides block production noise
Expand Down
4 changes: 4 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ pub struct Cli {
/// Relay chain arguments
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,

/// The number of seconds to delay before finalizing blocks.
#[arg(long, default_value_t = 1)]
pub finalize_delay_sec: u8,
}

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub fn run() -> Result<()> {

runner.run_node_until_exit(|config| async move {
if config.chain_spec.name() == "Development" { // TODO
return service::dev::new_full(config).map_err(sc_cli::Error::Service);
return service::dev::new_full(config, cli.finalize_delay_sec.into()).map_err(sc_cli::Error::Service);
}

let hwbench = (!cli.no_hardware_benchmarks)
Expand Down
20 changes: 17 additions & 3 deletions node/src/service/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ pub fn new_partial(
})
}

pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
pub fn new_full(
config: Configuration,
finalize_delay_sec: u64,
) -> Result<TaskManager, ServiceError> {
let sc_service::PartialComponents {
client,
backend,
Expand Down Expand Up @@ -195,7 +198,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
let params = sc_consensus_manual_seal::InstantSealParams {
block_import: client.clone(),
env: proposer,
client,
client: client.clone(),
pool: transaction_pool,
select_chain,
consensus_data_provider: None,
Expand All @@ -205,10 +208,21 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
};

let authorship_future = sc_consensus_manual_seal::run_instant_seal(params);

task_manager
.spawn_essential_handle()
.spawn_blocking("instant-seal", None, authorship_future);

let delayed_finalize_params = sc_consensus_manual_seal::DelayedFinalizeParams {
client,
spawn_handle: task_manager.spawn_handle(),
delay_sec: finalize_delay_sec,
};
task_manager.spawn_essential_handle().spawn_blocking(
"delayed_finalize",
None,
sc_consensus_manual_seal::run_delayed_finalize(delayed_finalize_params),
);

network_starter.start_network();
Ok(task_manager)
}