Skip to content

Commit 6d4f901

Browse files
fixup: drop manual_broadcast_pending and use holder_tx_signed and funding_seen_onchain instead
1 parent e8b3566 commit 6d4f901

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,11 +1190,11 @@ pub(crate) struct ChannelMonitorImpl<Signer: EcdsaChannelSigner> {
11901190
/// True if this channel was configured for manual funding broadcasts. Monitors written by
11911191
/// versions prior to introducing the flag will load with `false` until a new update persists it.
11921192
is_manual_broadcast: bool,
1193-
/// True once we've observed either funding transaction on-chain. Older monitors assume this is
1194-
/// `true` when absent during upgrade so holder broadcasts aren't gated unexpectedly.
1193+
/// True once we've observed either funding transaction on-chain. Older monitors assume
1194+
/// this is `true` when absent during upgrade so holder broadcasts aren't gated unexpectedly.
1195+
/// In manual-broadcast channels we also use this to trigger deferred holder
1196+
/// broadcasts once the funding transaction finally appears on-chain.
11951197
funding_seen_onchain: bool,
1196-
/// Tracks whether manual-broadcasting was requested before the funding transaction appeared on-chain.
1197-
manual_broadcast_pending: bool,
11981198

11991199
latest_update_id: u64,
12001200
commitment_transaction_number_obscure_factor: u64,
@@ -1736,7 +1736,6 @@ pub(crate) fn write_chanmon_internal<Signer: EcdsaChannelSigner, W: Writer>(
17361736
(34, channel_monitor.alternative_funding_confirmed, option),
17371737
(35, channel_monitor.is_manual_broadcast, required),
17381738
(37, channel_monitor.funding_seen_onchain, required),
1739-
(39, channel_monitor.manual_broadcast_pending, required),
17401739
});
17411740

17421741
Ok(())
@@ -1914,7 +1913,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
19141913

19151914
is_manual_broadcast,
19161915
funding_seen_onchain: false,
1917-
manual_broadcast_pending: false,
19181916

19191917
latest_update_id: 0,
19201918
commitment_transaction_number_obscure_factor,
@@ -3986,7 +3984,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39863984
// the funding transaction on-chain, do not queue any transactions.
39873985
if require_funding_seen && self.is_manual_broadcast && !self.funding_seen_onchain {
39883986
log_info!(logger, "Not broadcasting holder commitment for manual-broadcast channel before funding appears on-chain");
3989-
self.manual_broadcast_pending = true;
39903987
return;
39913988
}
39923989
let reason = ClosureReason::HolderForceClosed {
@@ -3999,7 +3996,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39993996
claimable_outpoints, self.best_block.height, self.best_block.height, broadcaster,
40003997
conf_target, &self.destination_script, fee_estimator, logger,
40013998
);
4002-
self.manual_broadcast_pending = false;
40033999
}
40044000

40054001
fn renegotiated_funding<L: Deref>(
@@ -5259,6 +5255,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
52595255
F::Target: FeeEstimator,
52605256
L::Target: Logger,
52615257
{
5258+
let funding_seen_before = self.funding_seen_onchain;
52625259
let txn_matched = self.filter_block(txdata);
52635260
for tx in &txn_matched {
52645261
let mut output_val = Amount::ZERO;
@@ -5281,7 +5278,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
52815278
let mut watch_outputs = Vec::new();
52825279
let mut claimable_outpoints = Vec::new();
52835280

5284-
if self.is_manual_broadcast && self.funding_seen_onchain && self.manual_broadcast_pending {
5281+
if self.is_manual_broadcast && !funding_seen_before && self.funding_seen_onchain && self.holder_tx_signed
5282+
{
52855283
self.queue_latest_holder_commitment_txn_for_broadcast(
52865284
&broadcaster,
52875285
fee_estimator,
@@ -5507,12 +5505,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
55075505
// manual-broadcast mode.
55085506
let (mut claimables, mut outputs) =
55095507
self.generate_claimable_outpoints_and_watch_outputs(None);
5510-
if self.is_manual_broadcast && !self.funding_seen_onchain {
5511-
self.manual_broadcast_pending = true;
5512-
} else {
5508+
if !(self.is_manual_broadcast && !self.funding_seen_onchain) {
55135509
claimable_outpoints.append(&mut claimables);
55145510
watch_outputs.append(&mut outputs);
5515-
self.manual_broadcast_pending = false;
55165511
}
55175512
}
55185513

@@ -5552,12 +5547,9 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
55525547
let reason = ClosureReason::HTLCsTimedOut { payment_hash: Some(payment_hash) };
55535548
let (mut new_outpoints, mut new_outputs) =
55545549
self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
5555-
if self.is_manual_broadcast && !self.funding_seen_onchain {
5556-
self.manual_broadcast_pending = true;
5557-
} else {
5550+
if !(self.is_manual_broadcast && !self.funding_seen_onchain) {
55585551
claimable_outpoints.append(&mut new_outpoints);
55595552
watch_outputs.append(&mut new_outputs);
5560-
self.manual_broadcast_pending = false;
55615553
}
55625554
}
55635555

@@ -6525,7 +6517,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65256517
let mut alternative_funding_confirmed = None;
65266518
let mut is_manual_broadcast = None;
65276519
let mut funding_seen_onchain = None;
6528-
let mut manual_broadcast_pending = None;
65296520
read_tlv_fields!(reader, {
65306521
(1, funding_spend_confirmed, option),
65316522
(3, htlcs_resolved_on_chain, optional_vec),
@@ -6548,7 +6539,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65486539
(34, alternative_funding_confirmed, option),
65496540
(35, is_manual_broadcast, option),
65506541
(37, funding_seen_onchain, option),
6551-
(39, manual_broadcast_pending, option),
65526542
});
65536543
// Note that `payment_preimages_with_info` was added (and is always written) in LDK 0.1, so
65546544
// we can use it to determine if this monitor was last written by LDK 0.1 or later.
@@ -6583,7 +6573,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
65836573
let channel_parameters = channel_parameters.unwrap_or_else(|| {
65846574
onchain_tx_handler.channel_parameters().clone()
65856575
});
6586-
let manual_broadcast_pending = manual_broadcast_pending.unwrap_or(false);
65876576

65886577
// Monitors for anchor outputs channels opened in v0.0.116 suffered from a bug in which the
65896578
// wrong `counterparty_payment_script` was being tracked. Fix it now on deserialization to
@@ -6670,7 +6659,6 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
66706659
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
66716660
// Assume "seen" when absent to prevent gating holder broadcasts after upgrade.
66726661
funding_seen_onchain: funding_seen_onchain.unwrap_or(true),
6673-
manual_broadcast_pending,
66746662

66756663
latest_update_id,
66766664
commitment_transaction_number_obscure_factor,
@@ -7163,7 +7151,6 @@ mod tests {
71637151
{
71647152
let inner = monitor.inner.lock().unwrap();
71657153
assert!(!inner.funding_seen_onchain);
7166-
assert!(inner.manual_broadcast_pending);
71677154
}
71687155

71697156
// Now confirm the funding transaction via transactions_confirmed.
@@ -7180,7 +7167,7 @@ mod tests {
71807167
);
71817168
{
71827169
let inner = monitor.inner.lock().unwrap();
7183-
assert!(!inner.manual_broadcast_pending);
7170+
assert!(inner.funding_seen_onchain);
71847171
}
71857172

71867173
// Next height update should allow broadcast.

0 commit comments

Comments
 (0)