Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve payment sync #1099

Merged
merged 10 commits into from
Oct 11, 2024
71 changes: 34 additions & 37 deletions libs/sdk-core/src/breez_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ impl BreezServices {
// update both closed channels and lightning transaction payments
let mut payments = closed_channel_payments;
payments.extend(new_data.payments.clone());
self.persister.insert_or_update_payments(&payments, true)?;
self.persister.insert_or_update_payments(&payments)?;
let duration = start.elapsed();
info!("Sync duration: {:?}", duration);

Expand Down Expand Up @@ -1290,40 +1290,37 @@ impl BreezServices {
amount_msat: u64,
label: Option<String>,
) -> Result<(), SendPaymentError> {
self.persister.insert_or_update_payments(
&[Payment {
id: invoice.payment_hash.clone(),
payment_type: PaymentType::Sent,
payment_time: SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as i64,
amount_msat,
fee_msat: 0,
status: PaymentStatus::Pending,
error: None,
description: invoice.description.clone(),
details: PaymentDetails::Ln {
data: LnPaymentDetails {
payment_hash: invoice.payment_hash.clone(),
label: label.unwrap_or_default(),
destination_pubkey: invoice.payee_pubkey.clone(),
payment_preimage: String::new(),
keysend: false,
bolt11: invoice.bolt11.clone(),
lnurl_success_action: None,
lnurl_pay_domain: None,
lnurl_pay_comment: None,
ln_address: None,
lnurl_metadata: None,
lnurl_withdraw_endpoint: None,
swap_info: None,
reverse_swap_info: None,
pending_expiration_block: None,
open_channel_bolt11: None,
},
self.persister.insert_or_update_payments(&[Payment {
id: invoice.payment_hash.clone(),
payment_type: PaymentType::Sent,
payment_time: SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() as i64,
amount_msat,
fee_msat: 0,
status: PaymentStatus::Pending,
error: None,
description: invoice.description.clone(),
details: PaymentDetails::Ln {
data: LnPaymentDetails {
payment_hash: invoice.payment_hash.clone(),
label: label.unwrap_or_default(),
destination_pubkey: invoice.payee_pubkey.clone(),
payment_preimage: String::new(),
keysend: false,
bolt11: invoice.bolt11.clone(),
lnurl_success_action: None,
lnurl_pay_domain: None,
lnurl_pay_comment: None,
ln_address: None,
lnurl_metadata: None,
lnurl_withdraw_endpoint: None,
swap_info: None,
reverse_swap_info: None,
pending_expiration_block: None,
open_channel_bolt11: None,
},
metadata: None,
}],
false,
)?;
},
metadata: None,
}])?;

self.persister.insert_payment_external_info(
&invoice.payment_hash,
Expand Down Expand Up @@ -1643,7 +1640,7 @@ impl BreezServices {
if let Some(ref p) = payment {
let res = cloned
.persister
.insert_or_update_payments(&vec![p.clone()], false);
.insert_or_update_payments(&vec![p.clone()]);
debug!("paid invoice was added to payments list {res:?}");
if let Ok(Some(mut node_info)) = cloned.persister.get_node_state() {
node_info.channels_balance_msat += p.amount_msat;
Expand Down Expand Up @@ -3111,7 +3108,7 @@ pub(crate) mod tests {
let test_config = create_test_config();
let persister = Arc::new(create_test_persister(test_config.clone()));
persister.init()?;
persister.insert_or_update_payments(&dummy_transactions, false)?;
persister.insert_or_update_payments(&dummy_transactions)?;
persister.insert_payment_external_info(
payment_hash_with_lnurl_success_action,
PaymentExternalInfo {
Expand Down Expand Up @@ -3332,7 +3329,7 @@ pub(crate) mod tests {
let test_config = create_test_config();
let persister = Arc::new(create_test_persister(test_config.clone()));
persister.init()?;
persister.insert_or_update_payments(&known_payments, false)?;
persister.insert_or_update_payments(&known_payments)?;
persister.set_lsp(MockBreezServer {}.lsp_id(), None)?;

let mut builder = BreezServicesBuilder::new(test_config.clone());
Expand Down
Loading
Loading