Skip to content

Commit 90966a9

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 bb405d6 commit 90966a9

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,10 @@ impl<SP: Deref> Channel<SP> where
17071707
ChannelPhase::UnfundedV2(chan) => chan.context.get_available_balances_for_scope(&chan.funding, fee_estimator),
17081708
}
17091709
}
1710+
1711+
pub fn minimum_depth(&self) -> Option<u32> {
1712+
self.context().minimum_depth(self.funding())
1713+
}
17101714
}
17111715

17121716
impl<SP: Deref> From<OutboundV1Channel<SP>> for Channel<SP>
@@ -3506,8 +3510,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35063510
self.temporary_channel_id
35073511
}
35083512

3509-
pub fn minimum_depth(&self) -> Option<u32> {
3510-
self.minimum_depth
3513+
pub(super) fn minimum_depth(&self, funding: &FundingScope) -> Option<u32> {
3514+
funding.minimum_depth_override.or(self.minimum_depth)
35113515
}
35123516

35133517
/// Gets the "user_id" value passed into the construction of this channel. It has no special
@@ -8700,8 +8704,7 @@ impl<SP: Deref> FundedChannel<SP> where
87008704
}
87018705

87028706
fn check_funding_meets_minimum_depth(&self, funding: &FundingScope, height: u32) -> bool {
8703-
let minimum_depth = funding.minimum_depth_override
8704-
.or(self.context.minimum_depth)
8707+
let minimum_depth = self.context.minimum_depth(funding)
87058708
.expect("ChannelContext::minimum_depth should be set for FundedChannel");
87068709

87078710
// 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
@@ -3154,7 +3154,7 @@ macro_rules! locked_close_channel {
31543154
// into the map (which prevents the `PeerState` from being cleaned up) for channels that
31553155
// never even got confirmations (which would open us up to DoS attacks).
31563156
let update_id = $channel_context.get_latest_monitor_update_id();
3157-
if $channel_funding.get_funding_tx_confirmation_height().is_some() || $channel_context.minimum_depth() == Some(0) || update_id > 1 {
3157+
if $channel_funding.get_funding_tx_confirmation_height().is_some() || $channel_context.minimum_depth($channel_funding) == Some(0) || update_id > 1 {
31583158
let chan_id = $channel_context.channel_id();
31593159
$peer_state.closed_channel_monitor_update_ids.insert(chan_id, update_id);
31603160
}
@@ -8282,7 +8282,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
82828282

82838283
if accept_0conf {
82848284
// This should have been correctly configured by the call to Inbound(V1/V2)Channel::new.
8285-
debug_assert!(channel.context().minimum_depth().unwrap() == 0);
8285+
debug_assert!(channel.minimum_depth().unwrap() == 0);
82868286
} else if channel.funding().get_channel_type().requires_zero_conf() {
82878287
let send_msg_err_event = MessageSendEvent::HandleError {
82888288
node_id: channel.context().get_counterparty_node_id(),
@@ -8360,7 +8360,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83608360
Some(funded_chan) => {
83618361
// This covers non-zero-conf inbound `Channel`s that we are currently monitoring, but those
83628362
// which have not yet had any confirmations on-chain.
8363-
if !funded_chan.funding.is_outbound() && funded_chan.context.minimum_depth().unwrap_or(1) != 0 &&
8363+
if !funded_chan.funding.is_outbound() && chan.minimum_depth().unwrap_or(1) != 0 &&
83648364
funded_chan.funding.get_funding_tx_confirmations(best_block_height) == 0
83658365
{
83668366
num_unfunded_channels += 1;
@@ -8373,7 +8373,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83738373
}
83748374

83758375
// 0conf channels are not considered unfunded.
8376-
if chan.context().minimum_depth().unwrap_or(1) == 0 {
8376+
if chan.minimum_depth().unwrap_or(1) == 0 {
83778377
continue;
83788378
}
83798379

0 commit comments

Comments
 (0)