Skip to content

Commit e744298

Browse files
ChannelMonitor: track user-processed payment claims
When an Event::PaymentClaimed is processed by the user, we need to track that so we don't keep regenerating the event redundantly on startup. Here we add a map to claims in this state, similar to the existing htlcs_resolved_to_user map. Note that this map will only be updated for closed channels -- if the channel is open, the inbound payment is pruned automatically when the HTLC is no longer present in any unrevoked commitment transaction, which stops the redundant event regeneration. Upcoming commits will add the actual tracking that uses this map, as well as generating the relevant monitor update to trigger this tracking
1 parent a4b5c7e commit e744298

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lightning/src/chain/channelmonitor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,10 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
13571357
/// this and we'll store the set of fully resolved payments here.
13581358
htlcs_resolved_to_user: HashSet<SentHTLCId>,
13591359

1360+
/// The set of inbound payments for which the user has processed an [`Event::PaymentClaimed`].
1361+
/// This is used to avoid regenerating the event redundantly on restart for closed channels.
1362+
inbound_payments_claimed: HashSet<PaymentHash>,
1363+
13601364
/// The set of `SpendableOutput` events which we have already passed upstream to be claimed.
13611365
/// These are tracked explicitly to ensure that we don't generate the same events redundantly
13621366
/// if users duplicatively confirm old transactions. Specifically for transactions claiming a
@@ -1770,6 +1774,7 @@ pub(crate) fn write_chanmon_internal<Signer: EcdsaChannelSigner, W: Writer>(
17701774
(34, channel_monitor.alternative_funding_confirmed, option),
17711775
(35, channel_monitor.is_manual_broadcast, required),
17721776
(37, channel_monitor.funding_seen_onchain, required),
1777+
(39, channel_monitor.inbound_payments_claimed, required),
17731778
});
17741779

17751780
Ok(())
@@ -1969,6 +1974,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
19691974
confirmed_commitment_tx_counterparty_output: None,
19701975
htlcs_resolved_on_chain: Vec::new(),
19711976
htlcs_resolved_to_user: new_hash_set(),
1977+
inbound_payments_claimed: new_hash_set(),
19721978
spendable_txids_confirmed: Vec::new(),
19731979

19741980
best_block,
@@ -6523,6 +6529,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65236529
let mut funding_spend_confirmed = None;
65246530
let mut htlcs_resolved_on_chain = Some(Vec::new());
65256531
let mut htlcs_resolved_to_user = Some(new_hash_set());
6532+
let mut inbound_payments_claimed = Some(new_hash_set());
65266533
let mut funding_spend_seen = Some(false);
65276534
let mut counterparty_node_id = None;
65286535
let mut confirmed_commitment_tx_counterparty_output = None;
@@ -6562,6 +6569,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65626569
(34, alternative_funding_confirmed, option),
65636570
(35, is_manual_broadcast, (default_value, false)),
65646571
(37, funding_seen_onchain, (default_value, true)),
6572+
(39, inbound_payments_claimed, option),
65656573
});
65666574
// Note that `payment_preimages_with_info` was added (and is always written) in LDK 0.1, so
65676575
// we can use it to determine if this monitor was last written by LDK 0.1 or later.
@@ -6727,6 +6735,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
67276735
confirmed_commitment_tx_counterparty_output,
67286736
htlcs_resolved_on_chain: htlcs_resolved_on_chain.unwrap(),
67296737
htlcs_resolved_to_user: htlcs_resolved_to_user.unwrap(),
6738+
inbound_payments_claimed: inbound_payments_claimed.unwrap(),
67306739
spendable_txids_confirmed: spendable_txids_confirmed.unwrap(),
67316740

67326741
best_block,

0 commit comments

Comments
 (0)