Skip to content

Commit

Permalink
Allow not waiting for block download before sync (#888)
Browse files Browse the repository at this point in the history
Fix #410
  • Loading branch information
romanz authored Jun 6, 2023
1 parent 3e3bc3a commit f3ef48f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/config_specification.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ doc = "Disable Electrum RPC server - only sync and index blocks."
name = "sync_once"
doc = "Exit after the initial sync is over (don't start Electrum server)."

[[switch]]
name = "skip_block_download_wait"
doc = "Don't wait for block download to finish before starting sync."

[[switch]]
name = "version"
doc = "Print out the program version."
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub struct Config {
pub auto_reindex: bool,
pub ignore_mempool: bool,
pub sync_once: bool,
pub skip_block_download_wait: bool,
pub disable_electrum_rpc: bool,
pub server_banner: String,
pub signet_magic: Magic,
Expand Down Expand Up @@ -346,6 +347,7 @@ impl Config {
auto_reindex: config.auto_reindex,
ignore_mempool: config.ignore_mempool,
sync_once: config.sync_once,
skip_block_download_wait: config.skip_block_download_wait,
disable_electrum_rpc: config.disable_electrum_rpc,
server_banner: config.server_banner,
signet_magic: magic,
Expand Down
8 changes: 6 additions & 2 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ enum PollResult {
Retry,
}

fn rpc_poll(client: &mut Client) -> PollResult {
fn rpc_poll(client: &mut Client, skip_block_download_wait: bool) -> PollResult {
match client.get_blockchain_info() {
Ok(info) => {
if skip_block_download_wait {
// bitcoind RPC is available, don't wait for block download to finish
return PollResult::Done(Ok(()));
}
let left_blocks = info.headers - info.blocks;
if info.initial_block_download || left_blocks > 0 {
info!(
Expand Down Expand Up @@ -108,7 +112,7 @@ impl Daemon {
exit_flag
.poll()
.context("bitcoin RPC polling interrupted")?;
match rpc_poll(&mut rpc) {
match rpc_poll(&mut rpc, config.skip_block_download_wait) {
PollResult::Done(result) => {
result.context("bitcoind RPC polling failed")?;
break; // on success, finish polling
Expand Down

0 comments on commit f3ef48f

Please sign in to comment.