Skip to content

Commit 6f0a30b

Browse files
author
Frank Bell
committed
feat: delayed finalization
Based on inkdevhub/swanky-node#61
1 parent a7733f8 commit 6f0a30b

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ for a production deployment, but a great fit for development and testing:_
1515
[#42](https://github.com/paritytech/substrate-contracts-node/pull/42).
1616
Hereby blocks are authored immediately at every transaction, so there
1717
is none of the typical six seconds block time associated with `grandpa` or `aura`.
18+
* By default, either manual or instant seal does not result in block finalization unless the `engine_finalizeBlock`
19+
RPC is executed. However, it is possible to configure the finalization of sealed blocks to occur after a certain
20+
amount of time by setting the `--finalize-delay-sec` option to a specific value, which specifies the number of seconds
21+
to delay before finalizing the blocks. Using a value of `0` would lead to instant finalization, with the blocks being
22+
finalized immediately upon being sealed.
23+
```shell
24+
./target/release/substrate-contracts-node --finalize-delay-sec 5
25+
```
1826
* _If no CLI arguments are passed the node is started in development mode
1927
by default._
2028
* A custom logging filter is applied by default that hides block production noise

node/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ pub struct Cli {
8383
/// Relay chain arguments
8484
#[arg(raw = true)]
8585
pub relay_chain_args: Vec<String>,
86+
87+
/// The number of seconds to delay before finalizing blocks. A value of `0` would lead to instant finalization.
88+
#[clap(long)]
89+
pub finalize_delay_sec: Option<u64>,
8690
}
8791

8892
#[derive(Debug)]

node/src/command.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub fn run() -> Result<()> {
225225

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

231231
let hwbench = (!cli.no_hardware_benchmarks)

node/src/service/dev.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn new_partial(
101101
})
102102
}
103103

104-
pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
104+
pub fn new_full(config: Configuration, finalize_delay_sec: Option<u64>) -> Result<TaskManager, ServiceError> {
105105
let sc_service::PartialComponents {
106106
client,
107107
backend,
@@ -195,7 +195,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
195195
let params = sc_consensus_manual_seal::InstantSealParams {
196196
block_import: client.clone(),
197197
env: proposer,
198-
client,
198+
client: client.clone(),
199199
pool: transaction_pool,
200200
select_chain,
201201
consensus_data_provider: None,
@@ -206,6 +206,20 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
206206

207207
let authorship_future = sc_consensus_manual_seal::run_instant_seal(params);
208208

209+
if let Some(sec) = finalize_delay_sec {
210+
let delayed_finalize_params = sc_consensus_manual_seal::DelayedFinalizeParams {
211+
client,
212+
spawn_handle: task_manager.spawn_handle(),
213+
delay_sec: sec,
214+
};
215+
216+
task_manager.spawn_essential_handle().spawn_blocking(
217+
"delayed_finalize",
218+
None,
219+
sc_consensus_manual_seal::run_delayed_finalize(delayed_finalize_params),
220+
);
221+
}
222+
209223
task_manager
210224
.spawn_essential_handle()
211225
.spawn_blocking("instant-seal", None, authorship_future);

0 commit comments

Comments
 (0)