Skip to content

Commit 2e85dde

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 ce9ebcc commit 2e85dde

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
@@ -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 {
@@ -8197,7 +8201,7 @@ impl<SP: Deref> FundedChannel<SP> where
81978201
}
81988202
}
81998203
self.context.funding_tx_confirmation_height = height;
8200-
self.context.funding_tx_confirmed_in = Some(*block_hash);
8204+
self.funding.funding_tx_confirmed_in = Some(*block_hash);
82018205
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
82028206
Ok(scid) => Some(scid),
82038207
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
@@ -8307,12 +8311,12 @@ impl<SP: Deref> FundedChannel<SP> where
83078311
// 0-conf channel, but not doing so may lead to the
83088312
// `ChannelManager::short_to_chan_info` map being inconsistent, so we currently have
83098313
// to.
8310-
if funding_tx_confirmations == 0 && self.context.funding_tx_confirmed_in.is_some() {
8314+
if funding_tx_confirmations == 0 && self.funding.funding_tx_confirmed_in.is_some() {
83118315
let err_reason = format!("Funding transaction was un-confirmed. Locked at {} confs, now have {} confs.",
83128316
self.context.minimum_depth.unwrap(), funding_tx_confirmations);
83138317
return Err(ClosureReason::ProcessingError { err: err_reason });
83148318
}
8315-
} else if !self.funding.is_outbound() && self.context.funding_tx_confirmed_in.is_none() &&
8319+
} else if !self.funding.is_outbound() && self.funding.funding_tx_confirmed_in.is_none() &&
83168320
height >= self.context.channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
83178321
log_info!(logger, "Closing channel {} due to funding timeout", &self.context.channel_id);
83188322
// If funding_tx_confirmed_in is unset, the channel must not be active
@@ -10690,7 +10694,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1069010694
// consider the stale state on reload.
1069110695
0u8.write(writer)?;
1069210696

10693-
self.context.funding_tx_confirmed_in.write(writer)?;
10697+
self.funding.funding_tx_confirmed_in.write(writer)?;
1069410698
self.context.funding_tx_confirmation_height.write(writer)?;
1069510699
self.context.short_channel_id.write(writer)?;
1069610700

@@ -11326,6 +11330,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1132611330

1132711331
channel_transaction_parameters: channel_parameters,
1132811332
funding_transaction,
11333+
funding_tx_confirmed_in,
1132911334
},
1133011335
pending_funding: pending_funding.unwrap(),
1133111336
context: ChannelContext {
@@ -11389,7 +11394,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1138911394
closing_fee_limits: None,
1139011395
target_closing_feerate_sats_per_kw,
1139111396

11392-
funding_tx_confirmed_in,
1139311397
funding_tx_confirmation_height,
1139411398
short_channel_id,
1139511399
channel_creation_height,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
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)