diff --git a/libs/sdk-core/src/breez_services.rs b/libs/sdk-core/src/breez_services.rs
index 7da47c959..dfdb1f09c 100644
--- a/libs/sdk-core/src/breez_services.rs
+++ b/libs/sdk-core/src/breez_services.rs
@@ -641,13 +641,20 @@ impl BreezServices {
/// * channels - The list of channels and their status
/// * payments - The incoming/outgoing payments
pub async fn sync(&self) -> Result<()> {
+ self.do_sync(false).await
+ }
+
+ async fn do_sync(&self, balance_changed: bool) -> Result<()> {
let start = Instant::now();
self.start_node().await?;
self.connect_lsp_peer().await?;
// First query the changes since last sync time.
let since_timestamp = self.persister.last_payment_timestamp().unwrap_or(0);
- let new_data = &self.node_api.pull_changed(since_timestamp).await?;
+ let new_data = &self
+ .node_api
+ .pull_changed(since_timestamp, balance_changed)
+ .await?;
debug!(
"pull changed time={:?} {:?}",
@@ -714,12 +721,9 @@ impl BreezServices {
return Err(payment_res.err().unwrap());
}
let payment = payment_res.unwrap();
- self.sync().await?;
+ self.do_sync(true).await?;
- match self
- .persister
- .get_completed_payment_by_hash(&payment.payment_hash)?
- {
+ match self.persister.get_payment_by_hash(&payment.payment_hash)? {
Some(p) => {
self.notify_event_listeners(BreezEvent::PaymentSucceed { details: p.clone() })
.await?;
@@ -929,7 +933,7 @@ impl BreezServices {
.insert_or_update_payments(&vec![payment.unwrap()]);
debug!("paid invoice was added to payments list {:?}", res);
}
- if let Err(e) = cloned.sync().await {
+ if let Err(e) = cloned.do_sync(true).await {
error!("failed to sync after paid invoice: {:?}", e);
}
_ = cloned.on_event(BreezEvent::InvoicePaid {
diff --git a/libs/sdk-core/src/greenlight/node_api.rs b/libs/sdk-core/src/greenlight/node_api.rs
index 1c1b3d49f..328a76e82 100644
--- a/libs/sdk-core/src/greenlight/node_api.rs
+++ b/libs/sdk-core/src/greenlight/node_api.rs
@@ -1,7 +1,7 @@
use std::cmp::{max, min};
use std::str::FromStr;
use std::sync::Arc;
-use std::time::{SystemTime, UNIX_EPOCH};
+use std::time::{Duration, SystemTime, UNIX_EPOCH};
use anyhow::{anyhow, Result};
use bitcoin::bech32::{u5, ToBase32};
@@ -28,6 +28,7 @@ use lightning_invoice::{RawInvoice, SignedRawInvoice};
use serde::{Deserialize, Serialize};
use strum_macros::{Display, EnumString};
use tokio::sync::{mpsc, Mutex};
+use tokio::time::sleep;
use tonic::Streaming;
use crate::invoice::parse_invoice;
@@ -44,6 +45,7 @@ pub(crate) struct Greenlight {
tls_config: TlsConfig,
gl_client: Mutex