Skip to content

Commit 398b9bc

Browse files
fixup: address comments:
keep doc/comments to 100 chars max per line adjust channel monitor comments move funding search to filter_block make is_manual_broadcast and funding_seen_onchain odd. its ok to be odd
1 parent d3f7fca commit 398b9bc

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

lightning-liquidity/src/lsps2/service.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,9 @@ where
10231023
/// were being held for that JIT channel are forwarded. In a `client_trusts_lsp` flow, once
10241024
/// the fee has been fully paid, the channel's funding transaction will be broadcasted.
10251025
///
1026-
/// Note that `next_channel_id` and `skimmed_fee_msat` are required to be provided. Therefore, the corresponding
1027-
/// [`Event::PaymentForwarded`] events need to be generated and serialized by LDK versions
1028-
/// greater or equal to 0.0.122.
1026+
/// Note that `next_channel_id` and `skimmed_fee_msat` are required to be provided.
1027+
/// Therefore, the corresponding [`Event::PaymentForwarded`] events need to be generated and
1028+
/// serialized by LDK versions greater or equal to 0.0.122.
10291029
///
10301030
/// [`Event::PaymentForwarded`]: lightning::events::Event::PaymentForwarded
10311031
pub fn payment_forwarded(

lightning/src/chain/channelmonitor.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,11 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
11311131
funding: FundingScope,
11321132
pending_funding: Vec<FundingScope>,
11331133

1134+
/// True if this channel was configured for manual funding broadcasts. Monitors written by
1135+
/// versions prior to introducing the flag will load with `false` until a new update persists it.
11341136
is_manual_broadcast: bool,
1137+
/// True once we've observed either funding transaction on-chain. Older monitors assume this is
1138+
/// `true` when absent during upgrade so holder broadcasts aren't gated unexpectedly.
11351139
funding_seen_onchain: bool,
11361140

11371141
latest_update_id: u64,
@@ -1663,8 +1667,8 @@ pub(crate) fn write_chanmon_internal<Signer: EcdsaChannelSigner, W: Writer>(
16631667
(31, channel_monitor.funding.channel_parameters, required),
16641668
(32, channel_monitor.pending_funding, optional_vec),
16651669
(34, channel_monitor.alternative_funding_confirmed, option),
1666-
(36, channel_monitor.is_manual_broadcast, required),
1667-
(38, channel_monitor.funding_seen_onchain, required),
1670+
(35, channel_monitor.is_manual_broadcast, required),
1671+
(37, channel_monitor.funding_seen_onchain, required),
16681672
});
16691673

16701674
Ok(())
@@ -2260,8 +2264,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
22602264
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
22612265
/// automatic broadcasts are suppressed until the funding transaction has been observed on-chain.
22622266
/// Calling this method overrides that suppression and queues the latest holder commitment
2263-
/// transaction for broadcast even if the funding has not yet been seen on-chain. This is unsafe
2264-
/// and may result in unconfirmable transactions.
2267+
/// transaction for broadcast even if the funding has not yet been seen on-chain. This may result
2268+
/// in unconfirmable transactions being broadcast or [`Event::BumpTransaction`] notifications for
2269+
/// transactions that cannot be confirmed until the funding transaction is visible.
2270+
///
2271+
/// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
22652272
#[rustfmt::skip]
22662273
pub fn broadcast_latest_holder_commitment_txn<B: Deref, F: Deref, L: Deref>(
22672274
&self, broadcaster: &B, fee_estimator: &F, logger: &L
@@ -5180,14 +5187,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
51805187
F::Target: FeeEstimator,
51815188
L::Target: Logger,
51825189
{
5183-
for &(_, tx) in txdata.iter() {
5184-
let txid = tx.compute_txid();
5185-
if txid == self.funding.funding_txid() ||
5186-
self.pending_funding.iter().any(|f| f.funding_txid() == txid)
5187-
{
5188-
self.funding_seen_onchain = true;
5189-
}
5190-
}
51915190
let txn_matched = self.filter_block(txdata);
51925191
for tx in &txn_matched {
51935192
let mut output_val = Amount::ZERO;
@@ -5767,10 +5766,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
57675766

57685767
/// Filters a block's `txdata` for transactions spending watched outputs or for any child
57695768
/// transactions thereof.
5769+
/// While iterating, this also tracks whether we observed the funding transaction.
57705770
#[rustfmt::skip]
5771-
fn filter_block<'a>(&self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {
5771+
fn filter_block<'a>(&mut self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {
57725772
let mut matched_txn = new_hash_set();
57735773
txdata.iter().filter(|&&(_, tx)| {
5774+
let txid = tx.compute_txid();
5775+
if !self.funding_seen_onchain && (txid == self.funding.funding_txid() ||
5776+
self.pending_funding.iter().any(|f| f.funding_txid() == txid))
5777+
{
5778+
self.funding_seen_onchain = true;
5779+
}
57745780
let mut matches = self.spends_watched_output(tx);
57755781
for input in tx.input.iter() {
57765782
if matches { break; }
@@ -5779,7 +5785,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
57795785
}
57805786
}
57815787
if matches {
5782-
matched_txn.insert(tx.compute_txid());
5788+
matched_txn.insert(txid);
57835789
}
57845790
matches
57855791
}).map(|(_, tx)| *tx).collect()
@@ -6440,8 +6446,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
64406446
(31, channel_parameters, (option: ReadableArgs, None)),
64416447
(32, pending_funding, optional_vec),
64426448
(34, alternative_funding_confirmed, option),
6443-
(36, is_manual_broadcast, option),
6444-
(38, funding_seen_onchain, option),
6449+
(35, is_manual_broadcast, option),
6450+
(37, funding_seen_onchain, option),
64456451
});
64466452
// Note that `payment_preimages_with_info` was added (and is always written) in LDK 0.1, so
64476453
// we can use it to determine if this monitor was last written by LDK 0.1 or later.

0 commit comments

Comments
 (0)