Skip to content

Commit

Permalink
sync: sync all payment updates
Browse files Browse the repository at this point in the history
Rather than syncing payments based on the payment time, sync based on
the created and updated indices in core lightning. This ensures that all
updates are retrieved, also when a payment is updated after the fact. To
do this, listsendpays is called, rather than listpays. listsendpays
contains a filter based on index. Starting off with the last synced
index, fetch all missing newly created payments and updates. It's
possible that this particular sync doesn't fetch all payment parts
associated to a payment. Therefore, the sendpays are cached into a local
database. When a new sync round is done, all known existing parts are
fetched from the local database as well, to ensure the resulting sdk
payments are 'complete', i.e. they're not missing any parts. This should
fix the issue where for closed channels, payments would be marked
forever pending.
  • Loading branch information
JssDWt committed Oct 4, 2024
1 parent 5912fc0 commit 3c5588a
Show file tree
Hide file tree
Showing 10 changed files with 509 additions and 88 deletions.
17 changes: 7 additions & 10 deletions libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,16 +1188,16 @@ impl BreezServices {
let node_pubkey = self.node_api.start().await?;
self.connect_lsp_peer(node_pubkey).await?;

// First query the changes since last sync time.
let since_timestamp = self.persister.get_last_sync_time()?.unwrap_or(0);
// First query the changes since last sync state.
let sync_state = self.persister.get_sync_state()?;
let new_data = &self
.node_api
.pull_changed(since_timestamp, match_local_balance)
.pull_changed(sync_state.clone(), match_local_balance)
.await?;

debug!(
"pull changed time={:?} {:?}",
since_timestamp, new_data.payments
"pull changed old state={:?} new state={:?}",
sync_state, new_data.sync_state
);

// update node state and channels state
Expand Down Expand Up @@ -1232,11 +1232,8 @@ impl BreezServices {
let duration = start.elapsed();
info!("Sync duration: {:?}", duration);

// update the cached last sync time
if let Ok(last_payment_timestamp) = self.persister.last_payment_timestamp() {
self.persister.set_last_sync_time(last_payment_timestamp)?;
}

// update the cached sync state
self.persister.set_sync_state(&new_data.sync_state)?;
self.notify_event_listeners(BreezEvent::Synced).await?;
Ok(())
}
Expand Down
Loading

0 comments on commit 3c5588a

Please sign in to comment.