Skip to content

Commit cee02cc

Browse files
committed
Move ChannelContext::funding_tx_confirmed_in to FundingScope
When processing confirmed transactions, if the funding transaction is found then information about it in the ChannelContext is updated. In preparation for splicing, move this data to FundingScope.
1 parent 2f6c2fb commit cee02cc

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,8 @@ pub(super) struct FundingScope {
18161816
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
18171817
/// [`ChannelContext::is_manual_broadcast`] is true) this will be a dummy empty transaction.
18181818
funding_transaction: Option<Transaction>,
1819+
/// The hash of the block in which the funding transaction was included.
1820+
funding_tx_confirmed_in: Option<BlockHash>,
18191821
}
18201822

18211823
impl Writeable for FundingScope {
@@ -1826,6 +1828,7 @@ impl Writeable for FundingScope {
18261828
(5, self.holder_selected_channel_reserve_satoshis, required),
18271829
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
18281830
(9, self.funding_transaction, option),
1831+
(11, self.funding_tx_confirmed_in, option),
18291832
});
18301833
Ok(())
18311834
}
@@ -1838,13 +1841,15 @@ impl Readable for FundingScope {
18381841
let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
18391842
let mut channel_transaction_parameters = RequiredWrapper(None);
18401843
let mut funding_transaction = None;
1844+
let mut funding_tx_confirmed_in = None;
18411845

18421846
read_tlv_fields!(reader, {
18431847
(1, value_to_self_msat, required),
18441848
(3, counterparty_selected_channel_reserve_satoshis, option),
18451849
(5, holder_selected_channel_reserve_satoshis, required),
18461850
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
18471851
(9, funding_transaction, option),
1852+
(11, funding_tx_confirmed_in, option),
18481853
});
18491854

18501855
Ok(Self {
@@ -1857,6 +1862,7 @@ impl Readable for FundingScope {
18571862
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
18581863
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
18591864
funding_transaction,
1865+
funding_tx_confirmed_in,
18601866
#[cfg(any(test, fuzzing))]
18611867
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
18621868
#[cfg(any(test, fuzzing))]
@@ -2089,8 +2095,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
20892095
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
20902096
expecting_peer_commitment_signed: bool,
20912097

2092-
/// The hash of the block in which the funding transaction was included.
2093-
funding_tx_confirmed_in: Option<BlockHash>,
20942098
funding_tx_confirmation_height: u32,
20952099
short_channel_id: Option<u64>,
20962100
/// Either the height at which this channel was created or the height at which it was last
@@ -2905,6 +2909,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29052909
channel_value_satoshis,
29062910
},
29072911
funding_transaction: None,
2912+
funding_tx_confirmed_in: None,
29082913
};
29092914
let channel_context = ChannelContext {
29102915
user_id,
@@ -2968,7 +2973,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29682973
closing_fee_limits: None,
29692974
target_closing_feerate_sats_per_kw: None,
29702975

2971-
funding_tx_confirmed_in: None,
29722976
funding_tx_confirmation_height: 0,
29732977
short_channel_id: None,
29742978
channel_creation_height: current_chain_height,
@@ -3139,6 +3143,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31393143
channel_value_satoshis,
31403144
},
31413145
funding_transaction: None,
3146+
funding_tx_confirmed_in: None,
31423147
};
31433148
let channel_context = Self {
31443149
user_id,
@@ -3200,7 +3205,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32003205
closing_fee_limits: None,
32013206
target_closing_feerate_sats_per_kw: None,
32023207

3203-
funding_tx_confirmed_in: None,
32043208
funding_tx_confirmation_height: 0,
32053209
short_channel_id: None,
32063210
channel_creation_height: current_chain_height,
@@ -3602,11 +3606,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
36023606
Ok(())
36033607
}
36043608

3605-
/// Returns the block hash in which our funding transaction was confirmed.
3606-
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
3607-
self.funding_tx_confirmed_in
3608-
}
3609-
36103609
/// Returns the current number of confirmations on the funding transaction.
36113610
pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
36123611
if self.funding_tx_confirmation_height == 0 {
@@ -8458,7 +8457,7 @@ impl<SP: Deref> FundedChannel<SP> where
84588457
}
84598458
}
84608459
self.context.funding_tx_confirmation_height = height;
8461-
self.context.funding_tx_confirmed_in = Some(*block_hash);
8460+
self.funding.funding_tx_confirmed_in = Some(*block_hash);
84628461
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
84638462
Ok(scid) => Some(scid),
84648463
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
@@ -8568,12 +8567,12 @@ impl<SP: Deref> FundedChannel<SP> where
85688567
// 0-conf channel, but not doing so may lead to the
85698568
// `ChannelManager::short_to_chan_info` map being inconsistent, so we currently have
85708569
// to.
8571-
if funding_tx_confirmations == 0 && self.context.funding_tx_confirmed_in.is_some() {
8570+
if funding_tx_confirmations == 0 && self.funding.funding_tx_confirmed_in.is_some() {
85728571
let err_reason = format!("Funding transaction was un-confirmed. Locked at {} confs, now have {} confs.",
85738572
self.context.minimum_depth.unwrap(), funding_tx_confirmations);
85748573
return Err(ClosureReason::ProcessingError { err: err_reason });
85758574
}
8576-
} else if !self.funding.is_outbound() && self.context.funding_tx_confirmed_in.is_none() &&
8575+
} else if !self.funding.is_outbound() && self.funding.funding_tx_confirmed_in.is_none() &&
85778576
height >= self.context.channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
85788577
log_info!(logger, "Closing channel {} due to funding timeout", &self.context.channel_id);
85798578
// If funding_tx_confirmed_in is unset, the channel must not be active
@@ -9740,6 +9739,11 @@ impl<SP: Deref> FundedChannel<SP> where
97409739
false
97419740
}
97429741
}
9742+
9743+
/// Returns the block hash in which our funding transaction was confirmed.
9744+
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
9745+
self.funding.funding_tx_confirmed_in
9746+
}
97439747
}
97449748

97459749
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -10971,7 +10975,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1097110975
// consider the stale state on reload.
1097210976
0u8.write(writer)?;
1097310977

10974-
self.context.funding_tx_confirmed_in.write(writer)?;
10978+
self.funding.funding_tx_confirmed_in.write(writer)?;
1097510979
self.context.funding_tx_confirmation_height.write(writer)?;
1097610980
self.context.short_channel_id.write(writer)?;
1097710981

@@ -11628,6 +11632,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1162811632

1162911633
channel_transaction_parameters: channel_parameters,
1163011634
funding_transaction,
11635+
funding_tx_confirmed_in,
1163111636
},
1163211637
pending_funding: pending_funding.unwrap(),
1163311638
context: ChannelContext {
@@ -11691,7 +11696,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1169111696
closing_fee_limits: None,
1169211697
target_closing_feerate_sats_per_kw,
1169311698

11694-
funding_tx_confirmed_in,
1169511699
funding_tx_confirmation_height,
1169611700
short_channel_id,
1169711701
channel_creation_height,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11678,7 +11678,7 @@ where
1167811678
for chan in peer_state.channel_by_id.values().filter_map(Channel::as_funded) {
1167911679
let txid_opt = chan.funding.get_funding_txo();
1168011680
let height_opt = chan.context.get_funding_tx_confirmation_height();
11681-
let hash_opt = chan.context.get_funding_tx_confirmed_in();
11681+
let hash_opt = chan.get_funding_tx_confirmed_in();
1168211682
if let (Some(funding_txo), Some(conf_height), Some(block_hash)) = (txid_opt, height_opt, hash_opt) {
1168311683
res.push((funding_txo.txid, conf_height, Some(block_hash)));
1168411684
}

0 commit comments

Comments
 (0)