Skip to content

Commit 0b7fa8b

Browse files
Gate holder broadcast queueing until funding is seen unless explicitly overridden
1 parent 762c6c3 commit 0b7fa8b

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
@@ -2327,6 +2327,16 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23272327
/// close channel with their commitment transaction after a substantial amount of time. Best
23282328
/// may be to contact the other node operator out-of-band to coordinate other options available
23292329
/// to you.
2330+
///
2331+
/// Note: For channels using manual funding broadcast (see
2332+
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
2333+
/// automatic broadcasts are suppressed until the funding transaction has been observed on-chain.
2334+
/// Calling this method overrides that suppression and queues the latest holder commitment
2335+
/// transaction for broadcast even if the funding has not yet been seen on-chain. This may result
2336+
/// in unconfirmable transactions being broadcast or [`Event::BumpTransaction`] notifications for
2337+
/// transactions that cannot be confirmed until the funding transaction is visible.
2338+
///
2339+
/// [`Event::BumpTransaction`]: crate::events::Event::BumpTransaction
23302340
pub fn broadcast_latest_holder_commitment_txn<B: Deref, F: Deref, L: Deref>(
23312341
&self, broadcaster: &B, fee_estimator: &F, logger: &L,
23322342
) where
@@ -2337,10 +2347,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
23372347
let mut inner = self.inner.lock().unwrap();
23382348
let fee_estimator = LowerBoundedFeeEstimator::new(&**fee_estimator);
23392349
let logger = WithChannelMonitor::from_impl(logger, &*inner, None);
2350+
23402351
inner.queue_latest_holder_commitment_txn_for_broadcast(
23412352
broadcaster,
23422353
&fee_estimator,
23432354
&logger,
2355+
false,
23442356
);
23452357
}
23462358

@@ -3958,8 +3970,15 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39583970
}
39593971

39603972
#[rustfmt::skip]
3973+
/// Note: For channels where the funding transaction is being manually managed (see
3974+
/// [`crate::ln::channelmanager::ChannelManager::funding_transaction_generated_manual_broadcast`]),
3975+
/// this method returns without queuing any transactions until the funding transaction has been
3976+
/// observed on-chain, unless `require_funding_seen` is `false`. This prevents attempting to
3977+
/// broadcast unconfirmable holder commitment transactions before the funding is visible.
3978+
/// See also
3979+
/// [`crate::chain::channelmonitor::ChannelMonitor::broadcast_latest_holder_commitment_txn`].
39613980
pub(crate) fn queue_latest_holder_commitment_txn_for_broadcast<B: Deref, F: Deref, L: Deref>(
3962-
&mut self, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &WithChannelMonitor<L>
3981+
&mut self, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &WithChannelMonitor<L>, require_funding_seen: bool,
39633982
)
39643983
where
39653984
B::Target: BroadcasterInterface,
@@ -3971,6 +3990,12 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
39713990
message: "ChannelMonitor-initiated commitment transaction broadcast".to_owned(),
39723991
};
39733992
let (claimable_outpoints, _) = self.generate_claimable_outpoints_and_watch_outputs(Some(reason));
3993+
// In manual-broadcast mode, if `require_funding_seen` is true and we have not yet observed
3994+
// the funding transaction on-chain, do not queue any transactions.
3995+
if require_funding_seen && self.is_manual_broadcast && !self.funding_seen_onchain {
3996+
log_info!(logger, "Not broadcasting holder commitment for manual-broadcast channel before funding appears on-chain");
3997+
return;
3998+
}
39743999
let conf_target = self.closure_conf_target();
39754000
self.onchain_tx_handler.update_claims_view_from_requests(
39764001
claimable_outpoints, self.best_block.height, self.best_block.height, broadcaster,
@@ -4285,7 +4310,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
42854310
log_trace!(logger, "Avoiding commitment broadcast, already detected confirmed spend onchain");
42864311
continue;
42874312
}
4288-
self.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &bounded_fee_estimator, logger);
4313+
self.queue_latest_holder_commitment_txn_for_broadcast(broadcaster, &bounded_fee_estimator, logger, true);
42894314
} else if !self.holder_tx_signed {
42904315
log_error!(logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast");
42914316
log_error!(logger, " in channel monitor for channel {}!", &self.channel_id());
@@ -5751,7 +5776,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
57515776
// Only attempt to broadcast the new commitment after the `block_disconnected` call above so that
57525777
// it doesn't get removed from the set of pending claims.
57535778
if should_broadcast_commitment {
5754-
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, &bounded_fee_estimator, logger);
5779+
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, &bounded_fee_estimator, logger, true);
57555780
}
57565781

57575782
self.best_block = fork_point;
@@ -5812,7 +5837,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
58125837
// Only attempt to broadcast the new commitment after the `transaction_unconfirmed` call above so
58135838
// that it doesn't get removed from the set of pending claims.
58145839
if should_broadcast_commitment {
5815-
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, fee_estimator, logger);
5840+
self.queue_latest_holder_commitment_txn_for_broadcast(&broadcaster, fee_estimator, logger, true);
58165841
}
58175842
}
58185843

@@ -6945,7 +6970,7 @@ mod tests {
69456970
let monitor = ChannelMonitor::new(
69466971
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
69476972
&channel_parameters, true, 0, HolderCommitmentTransaction::dummy(0, funding_outpoint, Vec::new()),
6948-
best_block, dummy_key, channel_id,
6973+
best_block, dummy_key, channel_id, false,
69496974
);
69506975

69516976
let nondust_htlcs = preimages_slice_to_htlcs!(preimages[0..10]);
@@ -7205,7 +7230,7 @@ mod tests {
72057230
let monitor = ChannelMonitor::new(
72067231
Secp256k1::new(), keys, Some(shutdown_script.into_inner()), 0, &ScriptBuf::new(),
72077232
&channel_parameters, true, 0, HolderCommitmentTransaction::dummy(0, funding_outpoint, Vec::new()),
7208-
best_block, dummy_key, channel_id,
7233+
best_block, dummy_key, channel_id, false
72097234
);
72107235

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

0 commit comments

Comments
 (0)