Skip to content

Commit a46e1e3

Browse files
committed
Introduce recurrence state-update logic
This commit adds the final piece of the payee-side recurrence flow: updating the internal `next_payable_counter` once a recurring payment has been successfully claimed. The update is performed immediately before emitting the `PaymentClaimed` event, ensuring the counter is advanced only after the payment is fully completed and acknowledged by the node. This provides a clear correctness boundary and avoids premature state transitions. The approach is intentionally conservative for this PoC. Future refinements may place the update earlier in the pipeline or integrate it more tightly with the payment-claim flow, but the current design offers simple and reliable semantics.
1 parent 64ea83c commit a46e1e3

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use crate::chain::transaction::{OutPoint, TransactionData};
5050
use crate::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Watch};
5151
use crate::events::{
5252
self, ClosureReason, Event, EventHandler, EventsProvider, HTLCHandlingFailureType,
53-
InboundChannelFunds, PaymentFailureReason, ReplayEvent,
53+
InboundChannelFunds, PaymentFailureReason, PaymentPurpose, ReplayEvent,
5454
};
5555
use crate::events::{FundingInfo, PaidBolt12Invoice};
5656
use crate::ln::chan_utils::selected_commitment_sat_per_1000_weight;
@@ -93,7 +93,9 @@ use crate::offers::async_receive_offer_cache::AsyncReceiveOfferCache;
9393
use crate::offers::flow::{HeldHtlcReplyPath, InvreqResponseInstructions, OffersMessageFlow};
9494
use crate::offers::invoice::{Bolt12Invoice, UnsignedBolt12Invoice};
9595
use crate::offers::invoice_error::InvoiceError;
96-
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestVerifiedFromOffer};
96+
use crate::offers::invoice_request::{
97+
InvoiceRequest, InvoiceRequestFields, InvoiceRequestVerifiedFromOffer,
98+
};
9799
use crate::offers::nonce::Nonce;
98100
use crate::offers::offer::{Offer, OfferFromHrn, RecurrenceData, RecurrenceFields};
99101
use crate::offers::parse::Bolt12SemanticError;
@@ -9514,6 +9516,32 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95149516
payment_id,
95159517
durable_preimage_channel,
95169518
}) = payment {
9519+
// At this point, the payment has been successfully claimed. If it belongs
9520+
// to a recurring offer, we can safely advance the recurrence state.
9521+
9522+
match &purpose {
9523+
PaymentPurpose::Bolt12OfferPayment {
9524+
payment_context: Bolt12OfferContext {
9525+
invoice_request: InvoiceRequestFields {
9526+
payer_signing_pubkey,
9527+
recurrence_counter: Some(paid_counter),
9528+
..
9529+
},
9530+
..
9531+
},
9532+
..
9533+
} => {
9534+
let mut sessions = self.active_recurrence_sessions.lock().unwrap();
9535+
9536+
if let Some(data) = sessions.get_mut(payer_signing_pubkey) {
9537+
if data.next_payable_counter == *paid_counter {
9538+
data.next_payable_counter += 1;
9539+
}
9540+
}
9541+
},
9542+
_ => {}
9543+
}
9544+
95179545
let event = events::Event::PaymentClaimed {
95189546
payment_hash,
95199547
purpose,

0 commit comments

Comments
 (0)