Skip to content

Commit a091350

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 620f5ba commit a091350

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
@@ -1169,7 +1169,11 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
11691169
funding: FundingScope,
11701170
pending_funding: Vec<FundingScope>,
11711171

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

11751179
latest_update_id: u64,
@@ -1701,8 +1705,8 @@ pub(crate) fn write_chanmon_internal<Signer: EcdsaChannelSigner, W: Writer>(
17011705
(31, channel_monitor.funding.channel_parameters, required),
17021706
(32, channel_monitor.pending_funding, optional_vec),
17031707
(34, channel_monitor.alternative_funding_confirmed, option),
1704-
(36, channel_monitor.is_manual_broadcast, required),
1705-
(38, channel_monitor.funding_seen_onchain, required),
1708+
(35, channel_monitor.is_manual_broadcast, required),
1709+
(37, channel_monitor.funding_seen_onchain, required),
17061710
});
17071711

17081712
Ok(())
@@ -2298,8 +2302,11 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
22982302
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
22992303
/// automatic broadcasts are suppressed until the funding transaction has been observed on-chain.
23002304
/// Calling this method overrides that suppression and queues the latest holder commitment
2301-
/// transaction for broadcast even if the funding has not yet been seen on-chain. This is unsafe
2302-
/// and may result in unconfirmable transactions.
2305+
/// transaction for broadcast even if the funding has not yet been seen on-chain. This may result
2306+
/// in unconfirmable transactions being broadcast or [`Event::BumpTransaction`] notifications for
2307+
/// transactions that cannot be confirmed until the funding transaction is visible.
2308+
///
2309+
/// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
23032310
#[rustfmt::skip]
23042311
pub fn broadcast_latest_holder_commitment_txn<B: Deref, F: Deref, L: Deref>(
23052312
&self, broadcaster: &B, fee_estimator: &F, logger: &L
@@ -5246,14 +5253,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
52465253
F::Target: FeeEstimator,
52475254
L::Target: Logger,
52485255
{
5249-
for &(_, tx) in txdata.iter() {
5250-
let txid = tx.compute_txid();
5251-
if txid == self.funding.funding_txid() ||
5252-
self.pending_funding.iter().any(|f| f.funding_txid() == txid)
5253-
{
5254-
self.funding_seen_onchain = true;
5255-
}
5256-
}
52575256
let txn_matched = self.filter_block(txdata);
52585257
for tx in &txn_matched {
52595258
let mut output_val = Amount::ZERO;
@@ -5833,10 +5832,17 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
58335832

58345833
/// Filters a block's `txdata` for transactions spending watched outputs or for any child
58355834
/// transactions thereof.
5835+
/// While iterating, this also tracks whether we observed the funding transaction.
58365836
#[rustfmt::skip]
5837-
fn filter_block<'a>(&self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {
5837+
fn filter_block<'a>(&mut self, txdata: &TransactionData<'a>) -> Vec<&'a Transaction> {
58385838
let mut matched_txn = new_hash_set();
58395839
txdata.iter().filter(|&&(_, tx)| {
5840+
let txid = tx.compute_txid();
5841+
if !self.funding_seen_onchain && (txid == self.funding.funding_txid() ||
5842+
self.pending_funding.iter().any(|f| f.funding_txid() == txid))
5843+
{
5844+
self.funding_seen_onchain = true;
5845+
}
58405846
let mut matches = self.spends_watched_output(tx);
58415847
for input in tx.input.iter() {
58425848
if matches { break; }
@@ -5845,7 +5851,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
58455851
}
58465852
}
58475853
if matches {
5848-
matched_txn.insert(tx.compute_txid());
5854+
matched_txn.insert(txid);
58495855
}
58505856
matches
58515857
}).map(|(_, tx)| *tx).collect()
@@ -6506,8 +6512,8 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65066512
(31, channel_parameters, (option: ReadableArgs, None)),
65076513
(32, pending_funding, optional_vec),
65086514
(34, alternative_funding_confirmed, option),
6509-
(36, is_manual_broadcast, option),
6510-
(38, funding_seen_onchain, option),
6515+
(35, is_manual_broadcast, option),
6516+
(37, funding_seen_onchain, option),
65116517
});
65126518
// Note that `payment_preimages_with_info` was added (and is always written) in LDK 0.1, so
65136519
// we can use it to determine if this monitor was last written by LDK 0.1 or later.

0 commit comments

Comments
 (0)