Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1429: Immediately sync bitcoin tx status upon subscribing r=binarybaron a=binarybaron



Co-authored-by: binarybaron <86064887+binarybaron@users.noreply.github.com>
  • Loading branch information
bors[bot] and binarybaron authored Aug 13, 2023
2 parents 20afb35 + 2e181da commit 4c69013
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions swap/src/bitcoin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,10 @@ impl Client {
self.blockchain.get_tx(txid)
}

fn update_state(&mut self) -> Result<()> {
fn update_state(&mut self, force_sync: bool) -> Result<()> {
let now = Instant::now();
if now < self.last_sync + self.sync_interval {

if !force_sync && now < self.last_sync + self.sync_interval {
return Ok(());
}

Expand All @@ -783,9 +784,14 @@ impl Client {

if !self.script_history.contains_key(&script) {
self.script_history.insert(script.clone(), vec![]);
}

self.update_state()?;
// When we first subscribe to a script we want to immediately fetch its status
// Otherwise we would have to wait for the next sync interval, which can take a minute
// This would result in potentially inaccurate status updates until that next sync interval is hit
self.update_state(true)?;
} else {
self.update_state(false)?;
}

let history = self.script_history.entry(script).or_default();

Expand Down

0 comments on commit 4c69013

Please sign in to comment.