Skip to content

Commit 97ec653

Browse files
committed
Fix bug with on-chain events
Previously we were saving the incorrect timestamp so we were always reprocessing txs that came in as new on-chain events. This fixes so we correctly use the new onchain sync timestamp and edits a test to make sure we'd catch this in the future
1 parent 1d54b47 commit 97ec653

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

orange-sdk/src/rebalancer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bitcoin_payment_instructions::amount::Amount;
1010
use graduated_rebalancer::{RebalanceTrigger, RebalancerEvent, TriggerParams};
1111
use ldk_node::lightning::util::logger::Logger as _;
1212
use ldk_node::lightning::util::persist::KVStore;
13-
use ldk_node::lightning::{log_error, log_info, log_warn};
13+
use ldk_node::lightning::{log_error, log_info, log_trace, log_warn};
1414
use ldk_node::payment::{ConfirmationStatus, PaymentDirection, PaymentKind, PaymentStatus};
1515
use std::cmp;
1616
use std::sync::Arc;
@@ -149,8 +149,8 @@ impl RebalanceTrigger for OrangeTrigger {
149149
let new_onchain_sync_time =
150150
self.ln_wallet.inner.ldk_node.status().latest_onchain_wallet_sync_timestamp;
151151
let onchain_sync_time = self.onchain_sync_time.load(Ordering::Relaxed);
152-
if new_onchain_sync_time.is_some()
153-
&& onchain_sync_time != new_onchain_sync_time.unwrap_or(0)
152+
if let Some(new_onchain_sync_time) = new_onchain_sync_time
153+
&& onchain_sync_time != new_onchain_sync_time
154154
{
155155
// find all new confirmed inbound onchain payments since last sync
156156
let new_recvs = self.ln_wallet.inner.ldk_node.list_payments_with_filter(|p| {
@@ -166,7 +166,7 @@ impl RebalanceTrigger for OrangeTrigger {
166166
)
167167
});
168168

169-
self.onchain_sync_time.swap(onchain_sync_time, Ordering::Relaxed);
169+
self.onchain_sync_time.swap(new_onchain_sync_time, Ordering::Relaxed);
170170

171171
// now create events for these payments
172172
for payment in new_recvs {
@@ -175,12 +175,15 @@ impl RebalanceTrigger for OrangeTrigger {
175175
PaymentKind::Onchain { txid, status } => (txid, status),
176176
_ => continue,
177177
};
178-
if let Err(e) = self.event_queue.add_event(Event::OnchainPaymentReceived {
178+
let event = Event::OnchainPaymentReceived {
179179
payment_id,
180180
txid,
181181
amount_sat: payment.amount_msat.expect("must have amount") / 1_000,
182182
status,
183-
}) {
183+
};
184+
185+
log_trace!(self.logger, "Generated OnchainPaymentReceived event: {event:?}");
186+
if let Err(e) = self.event_queue.add_event(event) {
184187
log_error!(
185188
self.logger,
186189
"Failed to add OnchainPaymentReceived event: {e:?}"

orange-sdk/tests/integration_tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ fn test_receive_to_onchain() {
461461
"Rebalance fee should be less than 5% of received amount, got {:.2}%",
462462
fee_ratio * 100.0
463463
);
464+
465+
assert!(wallet.next_event().is_none());
464466
})
465467
}
466468

0 commit comments

Comments
 (0)