diff --git a/crates/sc-consensus-nakamoto/src/block_import.rs b/crates/sc-consensus-nakamoto/src/block_import.rs index d2c40396..9a82d809 100644 --- a/crates/sc-consensus-nakamoto/src/block_import.rs +++ b/crates/sc-consensus-nakamoto/src/block_import.rs @@ -267,10 +267,11 @@ where /// Result of the operation of importing a Bitcoin block. /// -/// Same semantic with [`sc_consensus::ImportResult`] for including more information -/// in the Imported variant. +/// Same semantic with [`sc_consensus::ImportResult`] with additional information +/// in the [`ImportStatus::Imported`] variant. #[derive(Debug, Clone)] pub enum ImportStatus { + /// Block was imported successfully. Imported { block_number: u32, block_hash: BlockHash, @@ -287,6 +288,7 @@ pub enum ImportStatus { } impl ImportStatus { + /// Returns `true` if the import status is [`Self::UnknownParent`]. pub fn is_unknown_parent(&self) -> bool { matches!(self, Self::UnknownParent) } diff --git a/crates/subcoin-node/src/cli.rs b/crates/subcoin-node/src/cli.rs index f75d1d6e..7174ec28 100644 --- a/crates/subcoin-node/src/cli.rs +++ b/crates/subcoin-node/src/cli.rs @@ -60,6 +60,19 @@ pub fn run() -> sc_cli::Result<()> { network: bitcoin::Network::Bitcoin, config: &config, })?; + task_manager.spawn_handle().spawn("finalizer", None, { + let client = client.clone(); + let spawn_handle = task_manager.spawn_handle(); + let confirmation_depth = 6u32; + // TODO: proper value + let is_major_syncing = std::sync::Arc::new(true.into()); + subcoin_service::finalize_confirmed_blocks( + client, + spawn_handle, + confirmation_depth, + is_major_syncing, + ) + }); Ok((import_blocks_cmd.run(client, data_dir), task_manager)) }) } diff --git a/crates/subcoin-node/src/commands/import_blocks.rs b/crates/subcoin-node/src/commands/import_blocks.rs index f3779dc4..3159df54 100644 --- a/crates/subcoin-node/src/commands/import_blocks.rs +++ b/crates/subcoin-node/src/commands/import_blocks.rs @@ -17,21 +17,26 @@ use subcoin_service::FullClient; /// Import Bitcoin blocks from bitcoind database. #[derive(clap::Parser, Debug, Clone)] pub struct ImportBlocks { - /// Path of the bitcoind database. + /// Path to the bitcoind database. /// - /// Value of the `-data-dir` argument in the bitcoind program. + /// This corresponds to the value of the `-data-dir` argument in the bitcoind program. #[clap(index = 1, value_parser)] pub data_dir: PathBuf, - /// Specify the block number of last block to import. + /// Number of blocks to import. /// - /// The default value is the highest block in the database. + /// The process will stop after importing the specified number of blocks. + pub block_count: Option, + + /// Block number of last block to import. + /// + /// The default value is to the highest block in the database. #[clap(long)] - pub to: Option, + pub end_block: Option, - /// Whether to execute the transactions in the block. + /// Whether to execute the transactions within the blocks. #[clap(long, default_value_t = true)] - pub execute_block: bool, + pub execute_transactions: bool, #[allow(missing_docs)] #[clap(flatten)] @@ -46,6 +51,7 @@ pub struct ImportBlocks { pub struct ImportBlocksCmd { shared_params: SharedParams, import_params: ImportParams, + block_count: Option, to: Option, execute_block: bool, } @@ -58,8 +64,9 @@ impl ImportBlocksCmd { Self { shared_params, import_params, - to: cmd.to, - execute_block: cmd.execute_block, + block_count: cmd.block_count, + to: cmd.end_block, + execute_block: cmd.execute_transactions, } } @@ -142,6 +149,12 @@ impl ImportBlocksCmd { } total_imported += 1; + + if let Some(block_count) = self.block_count { + if total_imported == block_count { + break; + } + } } tracing::info!("Imported {total_imported} blocks successfully");