Skip to content

Commit 3ba20a6

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 db06e2d commit 3ba20a6

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
@@ -1821,6 +1821,8 @@ pub(super) struct FundingScope {
18211821
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
18221822
/// [`ChannelContext::is_manual_broadcast`] is true) this will be a dummy empty transaction.
18231823
funding_transaction: Option<Transaction>,
1824+
/// The hash of the block in which the funding transaction was included.
1825+
funding_tx_confirmed_in: Option<BlockHash>,
18241826
}
18251827

18261828
impl Writeable for FundingScope {
@@ -1831,6 +1833,7 @@ impl Writeable for FundingScope {
18311833
(5, self.holder_selected_channel_reserve_satoshis, required),
18321834
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
18331835
(9, self.funding_transaction, option),
1836+
(11, self.funding_tx_confirmed_in, option),
18341837
});
18351838
Ok(())
18361839
}
@@ -1843,13 +1846,15 @@ impl Readable for FundingScope {
18431846
let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
18441847
let mut channel_transaction_parameters = RequiredWrapper(None);
18451848
let mut funding_transaction = None;
1849+
let mut funding_tx_confirmed_in = None;
18461850

18471851
read_tlv_fields!(reader, {
18481852
(1, value_to_self_msat, required),
18491853
(3, counterparty_selected_channel_reserve_satoshis, option),
18501854
(5, holder_selected_channel_reserve_satoshis, required),
18511855
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
18521856
(9, funding_transaction, option),
1857+
(11, funding_tx_confirmed_in, option),
18531858
});
18541859

18551860
Ok(Self {
@@ -1862,6 +1867,7 @@ impl Readable for FundingScope {
18621867
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
18631868
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
18641869
funding_transaction,
1870+
funding_tx_confirmed_in,
18651871
#[cfg(any(test, fuzzing))]
18661872
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
18671873
#[cfg(any(test, fuzzing))]
@@ -2094,8 +2100,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
20942100
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
20952101
expecting_peer_commitment_signed: bool,
20962102

2097-
/// The hash of the block in which the funding transaction was included.
2098-
funding_tx_confirmed_in: Option<BlockHash>,
20992103
funding_tx_confirmation_height: u32,
21002104
short_channel_id: Option<u64>,
21012105
/// Either the height at which this channel was created or the height at which it was last
@@ -2910,6 +2914,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29102914
channel_value_satoshis,
29112915
},
29122916
funding_transaction: None,
2917+
funding_tx_confirmed_in: None,
29132918
};
29142919
let channel_context = ChannelContext {
29152920
user_id,
@@ -2973,7 +2978,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
29732978
closing_fee_limits: None,
29742979
target_closing_feerate_sats_per_kw: None,
29752980

2976-
funding_tx_confirmed_in: None,
29772981
funding_tx_confirmation_height: 0,
29782982
short_channel_id: None,
29792983
channel_creation_height: current_chain_height,
@@ -3150,6 +3154,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31503154
channel_value_satoshis,
31513155
},
31523156
funding_transaction: None,
3157+
funding_tx_confirmed_in: None,
31533158
};
31543159
let channel_context = Self {
31553160
user_id,
@@ -3211,7 +3216,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
32113216
closing_fee_limits: None,
32123217
target_closing_feerate_sats_per_kw: None,
32133218

3214-
funding_tx_confirmed_in: None,
32153219
funding_tx_confirmation_height: 0,
32163220
short_channel_id: None,
32173221
channel_creation_height: current_chain_height,
@@ -3613,11 +3617,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
36133617
Ok(())
36143618
}
36153619

3616-
/// Returns the block hash in which our funding transaction was confirmed.
3617-
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
3618-
self.funding_tx_confirmed_in
3619-
}
3620-
36213620
/// Returns the current number of confirmations on the funding transaction.
36223621
pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
36233622
if self.funding_tx_confirmation_height == 0 {
@@ -8577,7 +8576,7 @@ impl<SP: Deref> FundedChannel<SP> where
85778576
}
85788577
}
85798578
self.context.funding_tx_confirmation_height = height;
8580-
self.context.funding_tx_confirmed_in = Some(*block_hash);
8579+
self.funding.funding_tx_confirmed_in = Some(*block_hash);
85818580
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
85828581
Ok(scid) => Some(scid),
85838582
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
@@ -8687,12 +8686,12 @@ impl<SP: Deref> FundedChannel<SP> where
86878686
// 0-conf channel, but not doing so may lead to the
86888687
// `ChannelManager::short_to_chan_info` map being inconsistent, so we currently have
86898688
// to.
8690-
if funding_tx_confirmations == 0 && self.context.funding_tx_confirmed_in.is_some() {
8689+
if funding_tx_confirmations == 0 && self.funding.funding_tx_confirmed_in.is_some() {
86918690
let err_reason = format!("Funding transaction was un-confirmed. Locked at {} confs, now have {} confs.",
86928691
self.context.minimum_depth.unwrap(), funding_tx_confirmations);
86938692
return Err(ClosureReason::ProcessingError { err: err_reason });
86948693
}
8695-
} else if !self.funding.is_outbound() && self.context.funding_tx_confirmed_in.is_none() &&
8694+
} else if !self.funding.is_outbound() && self.funding.funding_tx_confirmed_in.is_none() &&
86968695
height >= self.context.channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
86978696
log_info!(logger, "Closing channel {} due to funding timeout", &self.context.channel_id);
86988697
// If funding_tx_confirmed_in is unset, the channel must not be active
@@ -9849,6 +9848,11 @@ impl<SP: Deref> FundedChannel<SP> where
98499848
false
98509849
}
98519850
}
9851+
9852+
/// Returns the block hash in which our funding transaction was confirmed.
9853+
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
9854+
self.funding.funding_tx_confirmed_in
9855+
}
98529856
}
98539857

98549858
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -11098,7 +11102,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1109811102
// consider the stale state on reload.
1109911103
0u8.write(writer)?;
1110011104

11101-
self.context.funding_tx_confirmed_in.write(writer)?;
11105+
self.funding.funding_tx_confirmed_in.write(writer)?;
1110211106
self.context.funding_tx_confirmation_height.write(writer)?;
1110311107
self.context.short_channel_id.write(writer)?;
1110411108

@@ -11755,6 +11759,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1175511759

1175611760
channel_transaction_parameters: channel_parameters,
1175711761
funding_transaction,
11762+
funding_tx_confirmed_in,
1175811763
},
1175911764
pending_funding: pending_funding.unwrap(),
1176011765
context: ChannelContext {
@@ -11818,7 +11823,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1181811823
closing_fee_limits: None,
1181911824
target_closing_feerate_sats_per_kw,
1182011825

11821-
funding_tx_confirmed_in,
1182211826
funding_tx_confirmation_height,
1182311827
short_channel_id,
1182411828
channel_creation_height,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11929,7 +11929,7 @@ where
1192911929
for chan in peer_state.channel_by_id.values().filter_map(Channel::as_funded) {
1193011930
let txid_opt = chan.funding.get_funding_txo();
1193111931
let height_opt = chan.context.get_funding_tx_confirmation_height();
11932-
let hash_opt = chan.context.get_funding_tx_confirmed_in();
11932+
let hash_opt = chan.get_funding_tx_confirmed_in();
1193311933
if let (Some(funding_txo), Some(conf_height), Some(block_hash)) = (txid_opt, height_opt, hash_opt) {
1193411934
res.push((funding_txo.txid, conf_height, Some(block_hash)));
1193511935
}

0 commit comments

Comments
 (0)