Skip to content

Commit 6c5ef04

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 04a2776 commit 6c5ef04

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23462346
/// close channel with their commitment transaction after a substantial amount of time. Best
23472347
/// may be to contact the other node operator out-of-band to coordinate other options available
23482348
/// to you.
2349+
///
2350+
/// Note: For channels using manual funding broadcast (see
2351+
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
2352+
/// automatic broadcasts are suppressed until the funding transaction has been observed on-chain.
2353+
/// Calling this method overrides that suppression and queues the latest holder commitment
2354+
/// transaction for broadcast even if the funding has not yet been seen on-chain. This may result
2355+
/// in unconfirmable transactions being broadcast or [`Event::BumpTransaction`] notifications for
2356+
/// transactions that cannot be confirmed until the funding transaction is visible.
2357+
///
2358+
/// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
23492359
pub fn broadcast_latest_holder_commitment_txn<B: Deref, F: Deref, L: Deref>(
23502360
&self, broadcaster: &B, fee_estimator: &F, logger: &L,
23512361
) where
@@ -2356,10 +2366,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23562366
let mut inner = self.inner.lock().unwrap();
23572367
let fee_estimator = LowerBoundedFeeEstimator::new(&**fee_estimator);
23582368
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
2369+
23592370
inner.queue_latest_holder_commitment_txn_for_broadcast(
23602371
broadcaster,
23612372
&fee_estimator,
23622373
&logger,
2374+
false,
23632375
);
23642376
}
23652377

@@ -3977,8 +3989,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39773989
}
39783990

39793991
#[rustfmt::skip]
3992+
/// Note: For channels where the funding transaction is being manually managed (see
3993+
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
3994+
/// this method returns without queuing any transactions until the funding transaction has been
3995+
/// observed on-chain, unless `require_funding_seen` is `false`. This prevents attempting to
3996+
/// broadcast unconfirmable holder commitment transactions before the funding is visible.
3997+
/// See also [`ChannelMonitor::broadcast_latest_holder_commitment_txn`].
3998+
///
3999+
/// [`ChannelMonitor::broadcast_latest_holder_commitment_txn`]: crate::chain::channelmonitor::ChannelMonitor::broadcast_latest_holder_commitment_txn
39804000
pub(crate) fn queue_latest_holder_commitment_txn_for_broadcast<B: Deref, F: Deref, L: Deref>(
3981-
&mut self, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &WithChannelMonitor<L>
4001+
&mut self, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &WithChannelMonitor<L>, require_funding_seen: bool,
39824002
)
39834003
where
39844004
B::Target: BroadcasterInterface,
@@ -3990,6 +4010,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39904010
message: "ChannelMonitor-initiated commitment transaction broadcast".to_owned(),
39914011
};
39924012
let (claimable_outpoints, _) = self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
4013+
// In manual-broadcast mode, if `require_funding_seen` is true and we have not yet observed
4014+
// the funding transaction on-chain, do not queue any transactions.
4015+
if require_funding_seen && self.is_manual_broadcast && !self.funding_seen_onchain {
4016+
log_info!(logger, "Not broadcasting holder commitment for manual-broadcast channel before funding appears on-chain");
4017+
return;
4018+
}
39934019
let conf_target = self.closure_conf_target();
39944020
self.onchain_tx_handler.update_claims_view_from_requests(
39954021
claimable_outpoints, self.best_block.height, self.best_block.height, broadcaster,
@@ -4312,7 +4338,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
43124338
log_trace!(logger, "Avoiding commitment broadcast, already detected confirmed spend onchain");
43134339
continue;
43144340
}
4315-
self.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &bounded_fee_estimator, logger);
4341+
self.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &bounded_fee_estimator, logger, true);
43164342
} else if !self.holder_tx_signed {
43174343
log_error!(logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast");
43184344
log_error!(logger, " in channel monitor for channel {}!", &self.channel_id());
@@ -5860,7 +5886,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
58605886
// Only attempt to broadcast the new commitment after the `block_disconnected` call above so that
58615887
// it doesn't get removed from the set of pending claims.
58625888
if should_broadcast_commitment {
5863-
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, &bounded_fee_estimator, logger);
5889+
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, &bounded_fee_estimator, logger, true);
58645890
}
58655891

58665892
self.best_block = fork_point;
@@ -5921,7 +5947,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
59215947
// Only attempt to broadcast the new commitment after the `transaction_unconfirmed` call above so
59225948
// that it doesn't get removed from the set of pending claims.
59235949
if should_broadcast_commitment {
5924-
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, fee_estimator, logger);
5950+
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, fee_estimator, logger, true);
59255951
}
59265952
}
59275953

@@ -7071,7 +7097,7 @@ mod tests {
70717097
let monitor = ChannelMonitor::new(
70727098
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
70737099
&channel_parameters, true, 0, HolderCommitmentTransaction::dummy(0, funding_outpoint, Vec::new()),
7074-
best_block, dummy_key, channel_id,
7100+
best_block, dummy_key, channel_id, false,
70757101
);
70767102

70777103
let nondust_htlcs = preimages_slice_to_htlcs!(preimages[0..10]);
@@ -7332,7 +7358,7 @@ mod tests {
73327358
let monitor = ChannelMonitor::new(
73337359
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
73347360
&channel_parameters, true, 0, HolderCommitmentTransaction::dummy(0, funding_outpoint, Vec::new()),
7335-
best_block, dummy_key, channel_id,
7361+
best_block, dummy_key, channel_id, false
73367362
);
73377363

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

0 commit comments

Comments
 (0)