Skip to content

Commit 39667e3

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 dd17aa4 commit 39667e3

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
@@ -1948,6 +1948,8 @@ pub(super) struct FundingScope {
19481948
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
19491949
/// [`ChannelContext::is_manual_broadcast`] is true) this will be a dummy empty transaction.
19501950
funding_transaction: Option<Transaction>,
1951+
/// The hash of the block in which the funding transaction was included.
1952+
funding_tx_confirmed_in: Option<BlockHash>,
19511953
}
19521954

19531955
impl Writeable for FundingScope {
@@ -1958,6 +1960,7 @@ impl Writeable for FundingScope {
19581960
(5, self.holder_selected_channel_reserve_satoshis, required),
19591961
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
19601962
(9, self.funding_transaction, option),
1963+
(11, self.funding_tx_confirmed_in, option),
19611964
});
19621965
Ok(())
19631966
}
@@ -1971,13 +1974,15 @@ impl Readable for FundingScope {
19711974
let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
19721975
let mut channel_transaction_parameters = RequiredWrapper(None);
19731976
let mut funding_transaction = None;
1977+
let mut funding_tx_confirmed_in = None;
19741978

19751979
read_tlv_fields!(reader, {
19761980
(1, value_to_self_msat, required),
19771981
(3, counterparty_selected_channel_reserve_satoshis, option),
19781982
(5, holder_selected_channel_reserve_satoshis, required),
19791983
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
19801984
(9, funding_transaction, option),
1985+
(11, funding_tx_confirmed_in, option),
19811986
});
19821987

19831988
Ok(Self {
@@ -1990,6 +1995,7 @@ impl Readable for FundingScope {
19901995
counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
19911996
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
19921997
funding_transaction,
1998+
funding_tx_confirmed_in,
19931999
#[cfg(any(test, fuzzing))]
19942000
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
19952001
#[cfg(any(test, fuzzing))]
@@ -2227,8 +2233,6 @@ where
22272233
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
22282234
expecting_peer_commitment_signed: bool,
22292235

2230-
/// The hash of the block in which the funding transaction was included.
2231-
funding_tx_confirmed_in: Option<BlockHash>,
22322236
funding_tx_confirmation_height: u32,
22332237
short_channel_id: Option<u64>,
22342238
/// Either the height at which this channel was created or the height at which it was last
@@ -3072,6 +3076,7 @@ where
30723076
channel_value_satoshis,
30733077
},
30743078
funding_transaction: None,
3079+
funding_tx_confirmed_in: None,
30753080
};
30763081
let channel_context = ChannelContext {
30773082
user_id,
@@ -3135,7 +3140,6 @@ where
31353140
closing_fee_limits: None,
31363141
target_closing_feerate_sats_per_kw: None,
31373142

3138-
funding_tx_confirmed_in: None,
31393143
funding_tx_confirmation_height: 0,
31403144
short_channel_id: None,
31413145
channel_creation_height: current_chain_height,
@@ -3313,6 +3317,7 @@ where
33133317
channel_value_satoshis,
33143318
},
33153319
funding_transaction: None,
3320+
funding_tx_confirmed_in: None,
33163321
};
33173322
let channel_context = Self {
33183323
user_id,
@@ -3374,7 +3379,6 @@ where
33743379
closing_fee_limits: None,
33753380
target_closing_feerate_sats_per_kw: None,
33763381

3377-
funding_tx_confirmed_in: None,
33783382
funding_tx_confirmation_height: 0,
33793383
short_channel_id: None,
33803384
channel_creation_height: current_chain_height,
@@ -3784,11 +3788,6 @@ where
37843788
Ok(())
37853789
}
37863790

3787-
/// Returns the block hash in which our funding transaction was confirmed.
3788-
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
3789-
self.funding_tx_confirmed_in
3790-
}
3791-
37923791
/// Returns the current number of confirmations on the funding transaction.
37933792
pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
37943793
if self.funding_tx_confirmation_height == 0 {
@@ -8855,7 +8854,7 @@ where
88558854
}
88568855
}
88578856
self.context.funding_tx_confirmation_height = height;
8858-
self.context.funding_tx_confirmed_in = Some(*block_hash);
8857+
self.funding.funding_tx_confirmed_in = Some(*block_hash);
88598858
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
88608859
Ok(scid) => Some(scid),
88618860
Err(_) => panic!("Block was bogus - either height was > 16 million, had > 16 million transactions, or had > 65k outputs"),
@@ -8967,12 +8966,12 @@ where
89678966
// 0-conf channel, but not doing so may lead to the
89688967
// `ChannelManager::short_to_chan_info` map being inconsistent, so we currently have
89698968
// to.
8970-
if funding_tx_confirmations == 0 && self.context.funding_tx_confirmed_in.is_some() {
8969+
if funding_tx_confirmations == 0 && self.funding.funding_tx_confirmed_in.is_some() {
89718970
let err_reason = format!("Funding transaction was un-confirmed. Locked at {} confs, now have {} confs.",
89728971
self.context.minimum_depth.unwrap(), funding_tx_confirmations);
89738972
return Err(ClosureReason::ProcessingError { err: err_reason });
89748973
}
8975-
} else if !self.funding.is_outbound() && self.context.funding_tx_confirmed_in.is_none() &&
8974+
} else if !self.funding.is_outbound() && self.funding.funding_tx_confirmed_in.is_none() &&
89768975
height >= self.context.channel_creation_height + FUNDING_CONF_DEADLINE_BLOCKS {
89778976
log_info!(logger, "Closing channel {} due to funding timeout", &self.context.channel_id);
89788977
// If funding_tx_confirmed_in is unset, the channel must not be active
@@ -10154,6 +10153,11 @@ where
1015410153
false
1015510154
}
1015610155
}
10156+
10157+
/// Returns the block hash in which our funding transaction was confirmed.
10158+
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
10159+
self.funding.funding_tx_confirmed_in
10160+
}
1015710161
}
1015810162

1015910163
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -11448,7 +11452,7 @@ where
1144811452
// consider the stale state on reload.
1144911453
0u8.write(writer)?;
1145011454

11451-
self.context.funding_tx_confirmed_in.write(writer)?;
11455+
self.funding.funding_tx_confirmed_in.write(writer)?;
1145211456
self.context.funding_tx_confirmation_height.write(writer)?;
1145311457
self.context.short_channel_id.write(writer)?;
1145411458

@@ -12107,6 +12111,7 @@ where
1210712111

1210812112
channel_transaction_parameters: channel_parameters,
1210912113
funding_transaction,
12114+
funding_tx_confirmed_in,
1211012115
},
1211112116
pending_funding: pending_funding.unwrap(),
1211212117
context: ChannelContext {
@@ -12170,7 +12175,6 @@ where
1217012175
closing_fee_limits: None,
1217112176
target_closing_feerate_sats_per_kw,
1217212177

12173-
funding_tx_confirmed_in,
1217412178
funding_tx_confirmation_height,
1217512179
short_channel_id,
1217612180
channel_creation_height,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11938,7 +11938,7 @@ where
1193811938
for chan in peer_state.channel_by_id.values().filter_map(Channel::as_funded) {
1193911939
let txid_opt = chan.funding.get_funding_txo();
1194011940
let height_opt = chan.context.get_funding_tx_confirmation_height();
11941-
let hash_opt = chan.context.get_funding_tx_confirmed_in();
11941+
let hash_opt = chan.get_funding_tx_confirmed_in();
1194211942
if let (Some(funding_txo), Some(conf_height), Some(block_hash)) = (txid_opt, height_opt, hash_opt) {
1194311943
res.push((funding_txo.txid, conf_height, Some(block_hash)));
1194411944
}

0 commit comments

Comments
 (0)