1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 01:43:29 +01:00

Allow not waiting for block download before sync (#888)

Fix #410
This commit is contained in:
Roman Zeyde 2023-06-06 20:23:51 +03:00 committed by GitHub
parent 3e3bc3a642
commit f3ef48fea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View File

@ -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."

View File

@ -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,
@ -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,

View File

@ -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!(
@ -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