Skip to content

Commit dc72eab

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 c7159c3 commit dc72eab

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

lightning/src/ln/channel.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,8 @@ pub(super) struct FundingScope {
16851685
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
16861686
/// [`ChannelContext::is_manual_broadcast`] is true) this will be a dummy empty transaction.
16871687
funding_transaction: Option<Transaction>,
1688+
/// The hash of the block in which the funding transaction was included.
1689+
funding_tx_confirmed_in: Option<BlockHash>,
16881690
}
16891691

16901692
impl Writeable for FundingScope {
@@ -1695,6 +1697,7 @@ impl Writeable for FundingScope {
16951697
(5, self.holder_selected_channel_reserve_satoshis, required),
16961698
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
16971699
(9, self.funding_transaction, option),
1700+
(11, self.funding_tx_confirmed_in, option),
16981701
});
16991702
Ok(())
17001703
}
@@ -1707,13 +1710,15 @@ impl Readable for FundingScope {
17071710
let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
17081711
let mut channel_transaction_parameters = RequiredWrapper(None);
17091712
let mut funding_transaction = None;
1713+
let mut funding_tx_confirmed_in = None;
17101714

17111715
read_tlv_fields!(reader, {
17121716
(1, value_to_self_msat, required),
17131717
(3, counterparty_selected_channel_reserve_satoshis, option),
17141718
(5, holder_selected_channel_reserve_satoshis, required),
17151719
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
17161720
(9, funding_transaction, option),
1721+
(11, funding_tx_confirmed_in, option),
17171722
});
17181723

17191724
Ok(Self {
@@ -1726,6 +1731,7 @@ impl Readable for FundingScope {
17261731
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
17271732
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
17281733
funding_transaction,
1734+
funding_tx_confirmed_in,
17291735
#[cfg(any(test, fuzzing))]
17301736
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
17311737
#[cfg(any(test, fuzzing))]
@@ -1799,6 +1805,11 @@ impl FundingScope {
17991805
pub fn get_channel_type(&self) -> &ChannelTypeFeatures {
18001806
&self.channel_transaction_parameters.channel_type_features
18011807
}
1808+
1809+
/// Returns the block hash in which our funding transaction was confirmed.
1810+
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
1811+
self.funding_tx_confirmed_in
1812+
}
18021813
}
18031814

18041815
/// Info about a pending splice, used in the pre-splice channel
@@ -1958,8 +1969,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
19581969
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
19591970
expecting_peer_commitment_signed: bool,
19601971

1961-
/// The hash of the block in which the funding transaction was included.
1962-
funding_tx_confirmed_in: Option<BlockHash>,
19631972
funding_tx_confirmation_height: u32,
19641973
short_channel_id: Option<u64>,
19651974
/// Either the height at which this channel was created or the height at which it was last
@@ -2770,6 +2779,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
27702779
channel_value_satoshis,
27712780
},
27722781
funding_transaction: None,
2782+
funding_tx_confirmed_in: None,
27732783
};
27742784
let channel_context = ChannelContext {
27752785
user_id,
@@ -2833,7 +2843,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
28332843
closing_fee_limits: None,
28342844
target_closing_feerate_sats_per_kw: None,
28352845

2836-
funding_tx_confirmed_in: None,
28372846
funding_tx_confirmation_height: 0,
28382847
short_channel_id: None,
28392848
channel_creation_height: current_chain_height,
@@ -3006,6 +3015,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30063015
channel_value_satoshis,
30073016
},
30083017
funding_transaction: None,
3018+
funding_tx_confirmed_in: None,
30093019
};
30103020
let channel_context = Self {
30113021
user_id,
@@ -3067,7 +3077,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
30673077
closing_fee_limits: None,
30683078
target_closing_feerate_sats_per_kw: None,
30693079

3070-
funding_tx_confirmed_in: None,
30713080
funding_tx_confirmation_height: 0,
30723081
short_channel_id: None,
30733082
channel_creation_height: current_chain_height,
@@ -3460,11 +3469,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
34603469
Ok(())
34613470
}
34623471

3463-
/// Returns the block hash in which our funding transaction was confirmed.
3464-
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
3465-
self.funding_tx_confirmed_in
3466-
}
3467-
34683472
/// Returns the current number of confirmations on the funding transaction.
34693473
pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
34703474
if self.funding_tx_confirmation_height == 0 {
@@ -8305,7 +8309,7 @@ impl<SP: Deref> FundedChannel<SP> where
83058309
}
83068310

83078311
self.context.funding_tx_confirmation_height = height;
8308-
self.context.funding_tx_confirmed_in = Some(*block_hash);
8312+
self.funding.funding_tx_confirmed_in = Some(*block_hash);
83098313
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
83108314
Ok(scid) => Some(scid),
83118315
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
@@ -8422,12 +8426,12 @@ impl<SP: Deref> FundedChannel<SP> where
84228426
// 0-conf channel, but not doing so may lead to the
84238427
// `ChannelManager::short_to_chan_info` map being inconsistent, so we currently have
84248428
// to.
8425-
if funding_tx_confirmations == 0 && self.context.funding_tx_confirmed_in.is_some() {
8429+
if funding_tx_confirmations == 0 && self.funding.funding_tx_confirmed_in.is_some() {
84268430
let err_reason = format!("Funding transaction was un-confirmed. Locked at {} confs, now have {} confs.",
84278431
self.context.minimum_depth.unwrap(), funding_tx_confirmations);
84288432
return Err(ClosureReason::ProcessingError { err: err_reason });
84298433
}
8430-
} else if !self.funding.is_outbound() && self.context.funding_tx_confirmed_in.is_none() &&
8434+
} else if !self.funding.is_outbound() && self.funding.funding_tx_confirmed_in.is_none() &&
84318435
height >= self.context.channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
84328436
log_info!(logger, "Closing channel {} due to funding timeout", &self.context.channel_id);
84338437
// If funding_tx_confirmed_in is unset, the channel must not be active
@@ -10720,7 +10724,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1072010724
// consider the stale state on reload.
1072110725
0u8.write(writer)?;
1072210726

10723-
self.context.funding_tx_confirmed_in.write(writer)?;
10727+
self.funding.funding_tx_confirmed_in.write(writer)?;
1072410728
self.context.funding_tx_confirmation_height.write(writer)?;
1072510729
self.context.short_channel_id.write(writer)?;
1072610730

@@ -11356,6 +11360,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1135611360

1135711361
channel_transaction_parameters: channel_parameters,
1135811362
funding_transaction,
11363+
funding_tx_confirmed_in,
1135911364
},
1136011365
pending_funding: pending_funding.unwrap(),
1136111366
context: ChannelContext {
@@ -11419,7 +11424,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1141911424
closing_fee_limits: None,
1142011425
target_closing_feerate_sats_per_kw,
1142111426

11422-
funding_tx_confirmed_in,
1142311427
funding_tx_confirmation_height,
1142411428
short_channel_id,
1142511429
channel_creation_height,

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11639,7 +11639,7 @@ where
1163911639
for chan in peer_state.channel_by_id.values().filter_map(Channel::as_funded) {
1164011640
let txid_opt = chan.funding.get_funding_txo();
1164111641
let height_opt = chan.context.get_funding_tx_confirmation_height();
11642-
let hash_opt = chan.context.get_funding_tx_confirmed_in();
11642+
let hash_opt = chan.funding.get_funding_tx_confirmed_in();
1164311643
if let (Some(funding_txo), Some(conf_height), Some(block_hash)) = (txid_opt, height_opt, hash_opt) {
1164411644
res.push((funding_txo.txid, conf_height, Some(block_hash)));
1164511645
}

0 commit comments

Comments
 (0)