Skip to content

Commit 038d216

Browse files
Gate holder broadcast queueing on funding confirmation
Don't queue holder commitment broadcasts until funding is confirmed, unless explicitly overridden via broadcast_latest_holder_commitment_txn. Attempting to broadcast commitments before funding confirms would fail mempool validation since the funding output doesn't exist yet.
1 parent 787e0a9 commit 038d216

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,6 +2342,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23422342
/// close channel with their commitment transaction after a substantial amount of time. Best
23432343
/// may be to contact the other node operator out-of-band to coordinate other options available
23442344
/// to you.
2345+
///
2346+
/// Note: For channels using manual funding broadcast (see
2347+
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
2348+
/// automatic broadcasts are suppressed until the funding transaction has been observed on-chain.
2349+
/// Calling this method overrides that suppression and queues the latest holder commitment
2350+
/// transaction for broadcast even if the funding has not yet been seen on-chain. This may result
2351+
/// in unconfirmable transactions being broadcast or [`Event::BumpTransaction`] notifications for
2352+
/// transactions that cannot be confirmed until the funding transaction is visible.
2353+
///
2354+
/// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
23452355
pub fn broadcast_latest_holder_commitment_txn<B: Deref, F: Deref, L: Deref>(
23462356
&self, broadcaster: &B, fee_estimator: &F, logger: &L,
23472357
) where
@@ -2352,10 +2362,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23522362
let mut inner = self.inner.lock().unwrap();
23532363
let fee_estimator = LowerBoundedFeeEstimator::new(&**fee_estimator);
23542364
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
2365+
23552366
inner.queue_latest_holder_commitment_txn_for_broadcast(
23562367
broadcaster,
23572368
&fee_estimator,
23582369
&logger,
2370+
false,
23592371
);
23602372
}
23612373

@@ -3973,8 +3985,15 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39733985
}
39743986

39753987
#[rustfmt::skip]
3988+
/// Note: For channels where the funding transaction is being manually managed (see
3989+
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
3990+
/// this method returns without queuing any transactions until the funding transaction has been
3991+
/// observed on-chain, unless `require_funding_seen` is `false`. This prevents attempting to
3992+
/// broadcast unconfirmable holder commitment transactions before the funding is visible.
3993+
/// See also
3994+
/// [`crate::chain::channelmonitor::ChannelMonitor::broadcast_latest_holder_commitment_txn`].
39763995
pub(crate) fn queue_latest_holder_commitment_txn_for_broadcast<B: Deref, F: Deref, L: Deref>(
3977-
&mut self, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &WithChannelMonitor<L>
3996+
&mut self, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &WithChannelMonitor<L>, require_funding_seen: bool,
39783997
)
39793998
where
39803999
B::Target: BroadcasterInterface,
@@ -3986,6 +4005,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39864005
message: "ChannelMonitor-initiated commitment transaction broadcast".to_owned(),
39874006
};
39884007
let (claimable_outpoints, _) = self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
4008+
// In manual-broadcast mode, if `require_funding_seen` is true and we have not yet observed
4009+
// the funding transaction on-chain, do not queue any transactions.
4010+
if require_funding_seen && self.is_manual_broadcast && !self.funding_seen_onchain {
4011+
log_info!(logger, "Not broadcasting holder commitment for manual-broadcast channel before funding appears on-chain");
4012+
return;
4013+
}
39894014
let conf_target = self.closure_conf_target();
39904015
self.onchain_tx_handler.update_claims_view_from_requests(
39914016
claimable_outpoints, self.best_block.height, self.best_block.height, broadcaster,
@@ -4300,7 +4325,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
43004325
log_trace!(logger, "Avoiding commitment broadcast, already detected confirmed spend onchain");
43014326
continue;
43024327
}
4303-
self.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &bounded_fee_estimator, logger);
4328+
self.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &bounded_fee_estimator, logger, true);
43044329
} else if !self.holder_tx_signed {
43054330
log_error!(logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast");
43064331
log_error!(logger, " in channel monitor for channel {}!", &self.channel_id());
@@ -5835,7 +5860,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
58355860
// Only attempt to broadcast the new commitment after the `block_disconnected` call above so that
58365861
// it doesn't get removed from the set of pending claims.
58375862
if should_broadcast_commitment {
5838-
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, &bounded_fee_estimator, logger);
5863+
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, &bounded_fee_estimator, logger, true);
58395864
}
58405865

58415866
self.best_block = fork_point;
@@ -5896,7 +5921,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
58965921
// Only attempt to broadcast the new commitment after the `transaction_unconfirmed` call above so
58975922
// that it doesn't get removed from the set of pending claims.
58985923
if should_broadcast_commitment {
5899-
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, fee_estimator, logger);
5924+
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, fee_estimator, logger, true);
59005925
}
59015926
}
59025927

@@ -7053,7 +7078,7 @@ mod tests {
70537078
let monitor = ChannelMonitor::new(
70547079
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
70557080
&channel_parameters, true, 0, HolderCommitmentTransaction::dummy(0, funding_outpoint, Vec::new()),
7056-
best_block, dummy_key, channel_id,
7081+
best_block, dummy_key, channel_id, false,
70577082
);
70587083

70597084
let nondust_htlcs = preimages_slice_to_htlcs!(preimages[0..10]);
@@ -7314,7 +7339,7 @@ mod tests {
73147339
let monitor = ChannelMonitor::new(
73157340
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
73167341
&channel_parameters, true, 0, HolderCommitmentTransaction::dummy(0, funding_outpoint, Vec::new()),
7317-
best_block, dummy_key, channel_id,
7342+
best_block, dummy_key, channel_id, false
73187343
);
73197344

73207345
let chan_id = monitor.inner.lock().unwrap().channel_id();

0 commit comments

Comments
 (0)