Skip to content

Commit

Permalink
Check local db in the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-21 committed Nov 22, 2024
1 parent 99eca02 commit 41ebb8c
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/notification_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,32 +203,36 @@ fn handle_payment_received_notification(
payment_hash: String,
timeout_instant: Instant,
) -> NotificationHandlingResult<Notification> {
// Check if the payment was already received
debug!("Checking exitent payments...");
if let Some(payment) = get_confirmed_payment(&rt, &sdk, &payment_hash)? {
debug!("Checking exitent payments... Found");
return Ok(Notification::Bolt11PaymentReceived {
amount_sat: payment.amount_msat / 1000,
payment_hash,
});
}
debug!("Checking exitent payments... None");
while Instant::now() < timeout_instant {
// Check if the payment was already received
debug!("Checking exitent payments...");
if let Some(payment) = get_confirmed_payment(&rt, &sdk, &payment_hash)? {
debug!("Checking exitent payments... Found");
return Ok(Notification::Bolt11PaymentReceived {
amount_sat: payment.amount_msat / 1000,
payment_hash,
});
}
debug!("Checking exitent payments... None");

// Wait for payment to be received
debug!("Waiting for payment to be received...");
if let Some(details) =
wait_for_payment_with_timeout(&event_receiver, &payment_hash, timeout_instant)?
{
debug!("Received payment event");
debug!("Waiting for synced event...");
// We want to wait as long as possible to decrease the likelihood of the signer being shut down
// while HTLCs are still in-flight.
wait_for_synced_event(&event_receiver)?;
debug!("Received synced event");
return Ok(Notification::Bolt11PaymentReceived {
amount_sat: details.payment.map(|p| p.amount_msat).unwrap_or(0) / 1000, // payment will only be None for corrupted GL payments. This is unlikely, so giving an optional amount seems overkill.
payment_hash,
});
// Wait for payment to be received
debug!("Waiting for payment to be received...");
match event_receiver.recv_timeout(Duration::from_secs(1)) {
Ok(BreezEvent::InvoicePaid { details }) if details.payment_hash == payment_hash => {
debug!("Waiting for payment to be received... Received");
return Ok(Notification::Bolt11PaymentReceived {
// Payment will only be None for corrupted GL payments.
// This is unlikely, so giving an optional amount seems overkill.
amount_sat: details.payment.map(|p| p.amount_msat).unwrap_or(0) / 1000,
payment_hash,
});
}
Ok(_) => continue,
Err(RecvTimeoutError::Timeout) => continue,
Err(RecvTimeoutError::Disconnected) => {
permanent_failure!("The SDK stopped running unexpectedly");
}
}
}

runtime_error!(
Expand Down

0 comments on commit 41ebb8c

Please sign in to comment.