Skip to content

Commit 60057a2

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 0eb94f4 commit 60057a2

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ use crate::chain::channelmonitor::{
4949
use crate::chain::transaction::{OutPoint, TransactionData};
5050
use crate::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Watch};
5151
use crate::events::{
52-
self, ClosureReason, Event, EventHandler, EventsProvider, HTLCHandlingFailureType,
53-
InboundChannelFunds, PaymentFailureReason, ReplayEvent,
52+
self, ClosureReason, Event, EventHandler, EventsProvider, HTLCHandlingFailureType, InboundChannelFunds, PaymentFailureReason, PaymentPurpose, ReplayEvent
5453
};
5554
use crate::events::{FundingInfo, PaidBolt12Invoice};
5655
use crate::ln::chan_utils::selected_commitment_sat_per_1000_weight;
@@ -93,7 +92,7 @@ use crate::offers::async_receive_offer_cache::AsyncReceiveOfferCache;
9392
use crate::offers::flow::{HeldHtlcReplyPath, InvreqResponseInstructions, OffersMessageFlow};
9493
use crate::offers::invoice::{Bolt12Invoice, UnsignedBolt12Invoice};
9594
use crate::offers::invoice_error::InvoiceError;
96-
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestVerifiedFromOffer};
95+
use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields, InvoiceRequestVerifiedFromOffer};
9796
use crate::offers::nonce::Nonce;
9897
use crate::offers::offer::{Offer, OfferFromHrn, RecurrenceData, RecurrenceFields};
9998
use crate::offers::parse::Bolt12SemanticError;
@@ -9514,6 +9513,32 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
95149513
payment_id,
95159514
durable_preimage_channel,
95169515
}) = payment {
9516+
// At this point, the payment has been successfully claimed. If it belongs
9517+
// to a recurring offer, we can safely advance the recurrence state.
9518+
9519+
match &purpose {
9520+
PaymentPurpose::Bolt12OfferPayment {
9521+
payment_context: Bolt12OfferContext {
9522+
invoice_request: InvoiceRequestFields {
9523+
payer_signing_pubkey,
9524+
recurrence_counter: Some(paid_counter),
9525+
..
9526+
},
9527+
..
9528+
},
9529+
..
9530+
} => {
9531+
let mut sessions = self.active_recurrence_sessions.lock().unwrap();
9532+
9533+
if let Some(data) = sessions.get_mut(payer_signing_pubkey) {
9534+
if data.next_payable_counter == *paid_counter {
9535+
data.next_payable_counter += 1;
9536+
}
9537+
}
9538+
},
9539+
_ => {}
9540+
}
9541+
95179542
let event = events::Event::PaymentClaimed {
95189543
payment_hash,
95199544
purpose,

0 commit comments

Comments
 (0)