Skip to content

Commit e3addaa

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 f4d7525 commit e3addaa

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
@@ -1960,6 +1960,8 @@ pub(super) struct FundingScope {
19601960
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
19611961
/// [`ChannelContext::is_manual_broadcast`] is true) this will be a dummy empty transaction.
19621962
funding_transaction: Option<Transaction>,
1963+
/// The hash of the block in which the funding transaction was included.
1964+
funding_tx_confirmed_in: Option<BlockHash>,
19631965
}
19641966

19651967
impl Writeable for FundingScope {
@@ -1970,6 +1972,7 @@ impl Writeable for FundingScope {
19701972
(5, self.holder_selected_channel_reserve_satoshis, required),
19711973
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
19721974
(9, self.funding_transaction, option),
1975+
(11, self.funding_tx_confirmed_in, option),
19731976
});
19741977
Ok(())
19751978
}
@@ -1983,13 +1986,15 @@ impl Readable for FundingScope {
19831986
let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
19841987
let mut channel_transaction_parameters = RequiredWrapper(None);
19851988
let mut funding_transaction = None;
1989+
let mut funding_tx_confirmed_in = None;
19861990

19871991
read_tlv_fields!(reader, {
19881992
(1, value_to_self_msat, required),
19891993
(3, counterparty_selected_channel_reserve_satoshis, option),
19901994
(5, holder_selected_channel_reserve_satoshis, required),
19911995
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
19921996
(9, funding_transaction, option),
1997+
(11, funding_tx_confirmed_in, option),
19931998
});
19941999

19952000
Ok(Self {
@@ -2002,6 +2007,7 @@ impl Readable for FundingScope {
20022007
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
20032008
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
20042009
funding_transaction,
2010+
funding_tx_confirmed_in,
20052011
#[cfg(any(test, fuzzing))]
20062012
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
20072013
#[cfg(any(test, fuzzing))]
@@ -2239,8 +2245,6 @@ where
22392245
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
22402246
expecting_peer_commitment_signed: bool,
22412247

2242-
/// The hash of the block in which the funding transaction was included.
2243-
funding_tx_confirmed_in: Option<BlockHash>,
22442248
funding_tx_confirmation_height: u32,
22452249
short_channel_id: Option<u64>,
22462250
/// Either the height at which this channel was created or the height at which it was last
@@ -3088,6 +3092,7 @@ where
30883092
channel_value_satoshis,
30893093
},
30903094
funding_transaction: None,
3095+
funding_tx_confirmed_in: None,
30913096
};
30923097
let channel_context = ChannelContext {
30933098
user_id,
@@ -3151,7 +3156,6 @@ where
31513156
closing_fee_limits: None,
31523157
target_closing_feerate_sats_per_kw: None,
31533158

3154-
funding_tx_confirmed_in: None,
31553159
funding_tx_confirmation_height: 0,
31563160
short_channel_id: None,
31573161
channel_creation_height: current_chain_height,
@@ -3329,6 +3333,7 @@ where
33293333
channel_value_satoshis,
33303334
},
33313335
funding_transaction: None,
3336+
funding_tx_confirmed_in: None,
33323337
};
33333338
let channel_context = Self {
33343339
user_id,
@@ -3390,7 +3395,6 @@ where
33903395
closing_fee_limits: None,
33913396
target_closing_feerate_sats_per_kw: None,
33923397

3393-
funding_tx_confirmed_in: None,
33943398
funding_tx_confirmation_height: 0,
33953399
short_channel_id: None,
33963400
channel_creation_height: current_chain_height,
@@ -3798,11 +3802,6 @@ where
37983802
Ok(())
37993803
}
38003804

3801-
/// Returns the block hash in which our funding transaction was confirmed.
3802-
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
3803-
self.funding_tx_confirmed_in
3804-
}
3805-
38063805
/// Returns the current number of confirmations on the funding transaction.
38073806
pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
38083807
if self.funding_tx_confirmation_height == 0 {
@@ -8899,7 +8898,7 @@ where
88998898
}
89008899
}
89018900
self.context.funding_tx_confirmation_height = height;
8902-
self.context.funding_tx_confirmed_in = Some(*block_hash);
8901+
self.funding.funding_tx_confirmed_in = Some(*block_hash);
89038902
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
89048903
Ok(scid) => Some(scid),
89058904
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
@@ -9015,12 +9014,12 @@ where
90159014
// 0-conf channel, but not doing so may lead to the
90169015
// `ChannelManager::short_to_chan_info` map being inconsistent, so we currently have
90179016
// to.
9018-
if funding_tx_confirmations == 0 && self.context.funding_tx_confirmed_in.is_some() {
9017+
if funding_tx_confirmations == 0 && self.funding.funding_tx_confirmed_in.is_some() {
90199018
let err_reason = format!("Funding transaction was un-confirmed. Locked at {} confs, now have {} confs.",
90209019
self.context.minimum_depth.unwrap(), funding_tx_confirmations);
90219020
return Err(ClosureReason::ProcessingError { err: err_reason });
90229021
}
9023-
} else if !self.funding.is_outbound() && self.context.funding_tx_confirmed_in.is_none() &&
9022+
} else if !self.funding.is_outbound() && self.funding.funding_tx_confirmed_in.is_none() &&
90249023
height >= self.context.channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
90259024
log_info!(logger, "Closing channel {} due to funding timeout", &self.context.channel_id);
90269025
// If funding_tx_confirmed_in is unset, the channel must not be active
@@ -10200,6 +10199,11 @@ where
1020010199
false
1020110200
}
1020210201
}
10202+
10203+
/// Returns the block hash in which our funding transaction was confirmed.
10204+
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
10205+
self.funding.funding_tx_confirmed_in
10206+
}
1020310207
}
1020410208

1020510209
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -11501,7 +11505,7 @@ where
1150111505
// consider the stale state on reload.
1150211506
0u8.write(writer)?;
1150311507

11504-
self.context.funding_tx_confirmed_in.write(writer)?;
11508+
self.funding.funding_tx_confirmed_in.write(writer)?;
1150511509
self.context.funding_tx_confirmation_height.write(writer)?;
1150611510
self.context.short_channel_id.write(writer)?;
1150711511

@@ -12160,6 +12164,7 @@ where
1216012164

1216112165
channel_transaction_parameters: channel_parameters,
1216212166
funding_transaction,
12167+
funding_tx_confirmed_in,
1216312168
},
1216412169
pending_funding: pending_funding.unwrap(),
1216512170
context: ChannelContext {
@@ -12223,7 +12228,6 @@ where
1222312228
closing_fee_limits: None,
1222412229
target_closing_feerate_sats_per_kw,
1222512230

12226-
funding_tx_confirmed_in,
1222712231
funding_tx_confirmation_height,
1222812232
short_channel_id,
1222912233
channel_creation_height,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12084,7 +12084,7 @@ where
1208412084
for chan in peer_state.channel_by_id.values().filter_map(Channel::as_funded) {
1208512085
let txid_opt = chan.funding.get_funding_txo();
1208612086
let height_opt = chan.context.get_funding_tx_confirmation_height();
12087-
let hash_opt = chan.context.get_funding_tx_confirmed_in();
12087+
let hash_opt = chan.get_funding_tx_confirmed_in();
1208812088
if let (Some(funding_txo), Some(conf_height), Some(block_hash)) =
1208912089
(txid_opt, height_opt, hash_opt)
1209012090
{

0 commit comments

Comments
 (0)