Skip to content

Commit a49e299

Browse files
committed
Account for coinbase tx in ChannelContext::minimum_depth
Now that FundedScope::minimum_depth_override is used to override the minimum depth with COINBASE_MATURITY when the funding transaction is the coinbase transaction, use this in ChannelContext::minimum_depth method. Also, add a minimum_depth to Channel. The one on ChannelContext can become private once FudningScope doesn't need to be accessed directly from a ChannelManager macro. This fixes ChannelDetails showing an incorrect minimum depth when the coinbase transaction is used to fund the channel.
1 parent 4325faf commit a49e299

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lightning/src/ln/channel.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,10 @@ where
18521852
},
18531853
}
18541854
}
1855+
1856+
pub fn minimum_depth(&self) -> Option<u32> {
1857+
self.context().minimum_depth(self.funding())
1858+
}
18551859
}
18561860

18571861
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -3690,8 +3694,8 @@ where
36903694
self.temporary_channel_id
36913695
}
36923696

3693-
pub fn minimum_depth(&self) -> Option<u32> {
3694-
self.minimum_depth
3697+
pub(super) fn minimum_depth(&self, funding: &FundingScope) -> Option<u32> {
3698+
funding.minimum_depth_override.or(self.minimum_depth)
36953699
}
36963700

36973701
/// Gets the "user_id" value passed into the construction of this channel. It has no special
@@ -9021,9 +9025,9 @@ where
90219025
}
90229026

90239027
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
9024-
let minimum_depth = funding
9025-
.minimum_depth_override
9026-
.or(self.context.minimum_depth)
9028+
let minimum_depth = self
9029+
.context
9030+
.minimum_depth(funding)
90279031
.expect("ChannelContext::minimum_depth should be set for FundedChannel");
90289032

90299033
// Zero-conf channels always meet the minimum depth.

lightning/src/ln/channel_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl ChannelDetails {
531531
next_outbound_htlc_limit_msat: balance.next_outbound_htlc_limit_msat,
532532
next_outbound_htlc_minimum_msat: balance.next_outbound_htlc_minimum_msat,
533533
user_channel_id: context.get_user_id(),
534-
confirmations_required: context.minimum_depth(),
534+
confirmations_required: channel.minimum_depth(),
535535
confirmations: Some(funding.get_funding_tx_confirmations(best_block_height)),
536536
force_close_spend_delay: funding.get_counterparty_selected_contest_delay(),
537537
is_outbound: funding.is_outbound(),

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,7 +3174,7 @@ macro_rules! locked_close_channel {
31743174
// into the map (which prevents the `PeerState` from being cleaned up) for channels that
31753175
// never even got confirmations (which would open us up to DoS attacks).
31763176
let update_id = $channel_context.get_latest_monitor_update_id();
3177-
if $channel_funding.get_funding_tx_confirmation_height().is_some() || $channel_context.minimum_depth() == Some(0) || update_id > 1 {
3177+
if $channel_funding.get_funding_tx_confirmation_height().is_some() || $channel_context.minimum_depth($channel_funding) == Some(0) || update_id > 1 {
31783178
let chan_id = $channel_context.channel_id();
31793179
$peer_state.closed_channel_monitor_update_ids.insert(chan_id, update_id);
31803180
}
@@ -8375,7 +8375,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83758375

83768376
if accept_0conf {
83778377
// This should have been correctly configured by the call to Inbound(V1/V2)Channel::new.
8378-
debug_assert!(channel.context().minimum_depth().unwrap() == 0);
8378+
debug_assert!(channel.minimum_depth().unwrap() == 0);
83798379
} else if channel.funding().get_channel_type().requires_zero_conf() {
83808380
let send_msg_err_event = MessageSendEvent::HandleError {
83818381
node_id: channel.context().get_counterparty_node_id(),
@@ -8456,7 +8456,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
84568456
Some(funded_chan) => {
84578457
// This covers non-zero-conf inbound `Channel`s that we are currently monitoring, but those
84588458
// which have not yet had any confirmations on-chain.
8459-
if !funded_chan.funding.is_outbound() && funded_chan.context.minimum_depth().unwrap_or(1) != 0 &&
8459+
if !funded_chan.funding.is_outbound() && chan.minimum_depth().unwrap_or(1) != 0 &&
84608460
funded_chan.funding.get_funding_tx_confirmations(best_block_height) == 0
84618461
{
84628462
num_unfunded_channels += 1;
@@ -8469,7 +8469,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
84698469
}
84708470

84718471
// 0conf channels are not considered unfunded.
8472-
if chan.context().minimum_depth().unwrap_or(1) == 0 {
8472+
if chan.minimum_depth().unwrap_or(1) == 0 {
84738473
continue;
84748474
}
84758475

0 commit comments

Comments
 (0)