Skip to content

Commit c6c9756

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 8adfa9b commit c6c9756

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
@@ -1829,6 +1829,10 @@ where
18291829
ChannelPhase::UnfundedV2(chan) => chan.context.get_available_balances_for_scope(&chan.funding, fee_estimator),
18301830
}
18311831
}
1832+
1833+
pub fn minimum_depth(&self) -> Option<u32> {
1834+
self.context().minimum_depth(self.funding())
1835+
}
18321836
}
18331837

18341838
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -3675,8 +3679,8 @@ where
36753679
self.temporary_channel_id
36763680
}
36773681

3678-
pub fn minimum_depth(&self) -> Option<u32> {
3679-
self.minimum_depth
3682+
pub(super) fn minimum_depth(&self, funding: &FundingScope) -> Option<u32> {
3683+
funding.minimum_depth_override.or(self.minimum_depth)
36803684
}
36813685

36823686
/// Gets the "user_id" value passed into the construction of this channel. It has no special
@@ -8977,9 +8981,9 @@ where
89778981
}
89788982

89798983
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
8980-
let minimum_depth = funding
8981-
.minimum_depth_override
8982-
.or(self.context.minimum_depth)
8984+
let minimum_depth = self
8985+
.context
8986+
.minimum_depth(funding)
89838987
.expect("ChannelContext::minimum_depth should be set for FundedChannel");
89848988

89858989
// 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
@@ -3163,7 +3163,7 @@ macro_rules! locked_close_channel {
31633163
// into the map (which prevents the `PeerState` from being cleaned up) for channels that
31643164
// never even got confirmations (which would open us up to DoS attacks).
31653165
let update_id = $channel_context.get_latest_monitor_update_id();
3166-
if $channel_funding.get_funding_tx_confirmation_height().is_some() || $channel_context.minimum_depth() == Some(0) || update_id > 1 {
3166+
if $channel_funding.get_funding_tx_confirmation_height().is_some() || $channel_context.minimum_depth($channel_funding) == Some(0) || update_id > 1 {
31673167
let chan_id = $channel_context.channel_id();
31683168
$peer_state.closed_channel_monitor_update_ids.insert(chan_id, update_id);
31693169
}
@@ -8291,7 +8291,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82918291

82928292
if accept_0conf {
82938293
// This should have been correctly configured by the call to Inbound(V1/V2)Channel::new.
8294-
debug_assert!(channel.context().minimum_depth().unwrap() == 0);
8294+
debug_assert!(channel.minimum_depth().unwrap() == 0);
82958295
} else if channel.funding().get_channel_type().requires_zero_conf() {
82968296
let send_msg_err_event = MessageSendEvent::HandleError {
82978297
node_id: channel.context().get_counterparty_node_id(),
@@ -8369,7 +8369,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83698369
Some(funded_chan) => {
83708370
// This covers non-zero-conf inbound `Channel`s that we are currently monitoring, but those
83718371
// which have not yet had any confirmations on-chain.
8372-
if !funded_chan.funding.is_outbound() && funded_chan.context.minimum_depth().unwrap_or(1) != 0 &&
8372+
if !funded_chan.funding.is_outbound() && chan.minimum_depth().unwrap_or(1) != 0 &&
83738373
funded_chan.funding.get_funding_tx_confirmations(best_block_height) == 0
83748374
{
83758375
num_unfunded_channels += 1;
@@ -8382,7 +8382,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83828382
}
83838383

83848384
// 0conf channels are not considered unfunded.
8385-
if chan.context().minimum_depth().unwrap_or(1) == 0 {
8385+
if chan.minimum_depth().unwrap_or(1) == 0 {
83868386
continue;
83878387
}
83888388

0 commit comments

Comments
 (0)