poller: don't poll now if blockchain syncing
If a user broadcasts a spend while the blockchain is syncing (e.g. via liana-cli), we tell the poller to run now. However, if the blockchain is still syncing, the blockchain height is likely to increase before the poll completes and so the poller is likely to restart multiple times. Even if the poller doesn't restart multiple times, this change makes the poller behaviour consistent with regard to a syncing blockchain.
This commit is contained in:
parent
0f9f1f352c
commit
4694eaaef9
@ -89,9 +89,28 @@ impl Poller {
|
||||
}
|
||||
Ok(PollerMessage::PollNow(sender)) => {
|
||||
// We've been asked to poll, don't wait any further and signal completion to
|
||||
// the caller.
|
||||
// the caller, unless the block chain is still syncing.
|
||||
// Polling while the block chain is syncing could lead to poller restarts
|
||||
// if the height increases before completion, and in any case this is consistent
|
||||
// with regular poller behaviour.
|
||||
if !synced {
|
||||
let progress = self.bit.sync_progress();
|
||||
log::info!(
|
||||
"Block chain synchronization progress: {:.2}% ({} blocks / {} headers)",
|
||||
progress.rounded_up_progress() * 100.0,
|
||||
progress.blocks,
|
||||
progress.headers
|
||||
);
|
||||
synced = progress.is_complete();
|
||||
}
|
||||
// Update `last_poll` even if we don't poll now so that we don't attempt another
|
||||
// poll too soon.
|
||||
last_poll = Some(time::Instant::now());
|
||||
looper::poll(&mut self.bit, &self.db, &self.secp, &self.descs);
|
||||
if synced {
|
||||
looper::poll(&mut self.bit, &self.db, &self.secp, &self.descs);
|
||||
} else {
|
||||
log::warn!("Skipped poll as block chain is still synchronizing.");
|
||||
}
|
||||
if let Err(e) = sender.send(()) {
|
||||
log::error!("Error sending immediate poll completion signal: {}.", e);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user