@@ -1950,6 +1950,7 @@ pub(super) struct FundingScope {
1950
1950
funding_transaction: Option<Transaction>,
1951
1951
/// The hash of the block in which the funding transaction was included.
1952
1952
funding_tx_confirmed_in: Option<BlockHash>,
1953
+ funding_tx_confirmation_height: u32,
1953
1954
}
1954
1955
1955
1956
impl Writeable for FundingScope {
@@ -1961,6 +1962,7 @@ impl Writeable for FundingScope {
1961
1962
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
1962
1963
(9, self.funding_transaction, option),
1963
1964
(11, self.funding_tx_confirmed_in, option),
1965
+ (13, self.funding_tx_confirmation_height, required),
1964
1966
});
1965
1967
Ok(())
1966
1968
}
@@ -1975,6 +1977,7 @@ impl Readable for FundingScope {
1975
1977
let mut channel_transaction_parameters = RequiredWrapper(None);
1976
1978
let mut funding_transaction = None;
1977
1979
let mut funding_tx_confirmed_in = None;
1980
+ let mut funding_tx_confirmation_height = RequiredWrapper(None);
1978
1981
1979
1982
read_tlv_fields!(reader, {
1980
1983
(1, value_to_self_msat, required),
@@ -1983,6 +1986,7 @@ impl Readable for FundingScope {
1983
1986
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
1984
1987
(9, funding_transaction, option),
1985
1988
(11, funding_tx_confirmed_in, option),
1989
+ (13, funding_tx_confirmation_height, required),
1986
1990
});
1987
1991
1988
1992
Ok(Self {
@@ -1996,6 +2000,7 @@ impl Readable for FundingScope {
1996
2000
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
1997
2001
funding_transaction,
1998
2002
funding_tx_confirmed_in,
2003
+ funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
1999
2004
#[cfg(any(test, fuzzing))]
2000
2005
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2001
2006
#[cfg(any(test, fuzzing))]
@@ -2072,6 +2077,26 @@ impl FundingScope {
2072
2077
pub fn get_channel_type(&self) -> &ChannelTypeFeatures {
2073
2078
&self.channel_transaction_parameters.channel_type_features
2074
2079
}
2080
+
2081
+ /// Returns the height in which our funding transaction was confirmed.
2082
+ pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
2083
+ let conf_height = self.funding_tx_confirmation_height;
2084
+ if conf_height > 0 {
2085
+ Some(conf_height)
2086
+ } else {
2087
+ None
2088
+ }
2089
+ }
2090
+
2091
+ /// Returns the current number of confirmations on the funding transaction.
2092
+ pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
2093
+ if self.funding_tx_confirmation_height == 0 {
2094
+ // We either haven't seen any confirmation yet, or observed a reorg.
2095
+ return 0;
2096
+ }
2097
+
2098
+ height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
2099
+ }
2075
2100
}
2076
2101
2077
2102
/// Info about a pending splice, used in the pre-splice channel
@@ -2233,7 +2258,6 @@ where
2233
2258
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
2234
2259
expecting_peer_commitment_signed: bool,
2235
2260
2236
- funding_tx_confirmation_height: u32,
2237
2261
short_channel_id: Option<u64>,
2238
2262
/// Either the height at which this channel was created or the height at which it was last
2239
2263
/// serialized if it was serialized by versions prior to 0.0.103.
@@ -3077,6 +3101,7 @@ where
3077
3101
},
3078
3102
funding_transaction: None,
3079
3103
funding_tx_confirmed_in: None,
3104
+ funding_tx_confirmation_height: 0,
3080
3105
};
3081
3106
let channel_context = ChannelContext {
3082
3107
user_id,
@@ -3140,7 +3165,6 @@ where
3140
3165
closing_fee_limits: None,
3141
3166
target_closing_feerate_sats_per_kw: None,
3142
3167
3143
- funding_tx_confirmation_height: 0,
3144
3168
short_channel_id: None,
3145
3169
channel_creation_height: current_chain_height,
3146
3170
@@ -3318,6 +3342,7 @@ where
3318
3342
},
3319
3343
funding_transaction: None,
3320
3344
funding_tx_confirmed_in: None,
3345
+ funding_tx_confirmation_height: 0,
3321
3346
};
3322
3347
let channel_context = Self {
3323
3348
user_id,
@@ -3379,7 +3404,6 @@ where
3379
3404
closing_fee_limits: None,
3380
3405
target_closing_feerate_sats_per_kw: None,
3381
3406
3382
- funding_tx_confirmation_height: 0,
3383
3407
short_channel_id: None,
3384
3408
channel_creation_height: current_chain_height,
3385
3409
@@ -3637,16 +3661,6 @@ where
3637
3661
self.outbound_scid_alias = outbound_scid_alias;
3638
3662
}
3639
3663
3640
- /// Returns the height in which our funding transaction was confirmed.
3641
- pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
3642
- let conf_height = self.funding_tx_confirmation_height;
3643
- if conf_height > 0 {
3644
- Some(conf_height)
3645
- } else {
3646
- None
3647
- }
3648
- }
3649
-
3650
3664
/// Performs checks against necessary constraints after receiving either an `accept_channel` or
3651
3665
/// `accept_channel2` message.
3652
3666
#[rustfmt::skip]
@@ -3788,16 +3802,6 @@ where
3788
3802
Ok(())
3789
3803
}
3790
3804
3791
- /// Returns the current number of confirmations on the funding transaction.
3792
- pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
3793
- if self.funding_tx_confirmation_height == 0 {
3794
- // We either haven't seen any confirmation yet, or observed a reorg.
3795
- return 0;
3796
- }
3797
-
3798
- height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
3799
- }
3800
-
3801
3805
/// Allowed in any state (including after shutdown)
3802
3806
pub fn get_counterparty_node_id(&self) -> PublicKey {
3803
3807
self.counterparty_node_id
@@ -7331,7 +7335,7 @@ where
7331
7335
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
7332
7336
{
7333
7337
// Broadcast only if not yet confirmed
7334
- if self.context .get_funding_tx_confirmation_height().is_none() {
7338
+ if self.funding .get_funding_tx_confirmation_height().is_none() {
7335
7339
funding_broadcastable = Some(funding_transaction.clone())
7336
7340
}
7337
7341
}
@@ -8727,13 +8731,13 @@ where
8727
8731
// Called:
8728
8732
// * always when a new block/transactions are confirmed with the new height
8729
8733
// * when funding is signed with a height of 0
8730
- if self.context .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8734
+ if self.funding .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8731
8735
return None;
8732
8736
}
8733
8737
8734
- let funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
8738
+ let funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
8735
8739
if funding_tx_confirmations <= 0 {
8736
- self.context .funding_tx_confirmation_height = 0;
8740
+ self.funding .funding_tx_confirmation_height = 0;
8737
8741
}
8738
8742
8739
8743
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
@@ -8753,7 +8757,7 @@ where
8753
8757
// We got a reorg but not enough to trigger a force close, just ignore.
8754
8758
false
8755
8759
} else {
8756
- if self.context .funding_tx_confirmation_height != 0 &&
8760
+ if self.funding .funding_tx_confirmation_height != 0 &&
8757
8761
self.context.channel_state < ChannelState::ChannelReady(ChannelReadyFlags::new())
8758
8762
{
8759
8763
// We should never see a funding transaction on-chain until we've received
@@ -8823,7 +8827,7 @@ where
8823
8827
for &(index_in_block, tx) in txdata.iter() {
8824
8828
// Check if the transaction is the expected funding transaction, and if it is,
8825
8829
// check that it pays the right amount to the right script.
8826
- if self.context .funding_tx_confirmation_height == 0 {
8830
+ if self.funding .funding_tx_confirmation_height == 0 {
8827
8831
if tx.compute_txid() == funding_txo.txid {
8828
8832
let txo_idx = funding_txo.index as usize;
8829
8833
if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.funding.get_funding_redeemscript().to_p2wsh() ||
@@ -8853,7 +8857,8 @@ where
8853
8857
}
8854
8858
}
8855
8859
}
8856
- self.context.funding_tx_confirmation_height = height;
8860
+
8861
+ self.funding.funding_tx_confirmation_height = height;
8857
8862
self.funding.funding_tx_confirmed_in = Some(*block_hash);
8858
8863
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
8859
8864
Ok(scid) => Some(scid),
@@ -8949,8 +8954,8 @@ where
8949
8954
8950
8955
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
8951
8956
self.context.channel_state.is_our_channel_ready() {
8952
- let mut funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
8953
- if self.context .funding_tx_confirmation_height == 0 {
8957
+ let mut funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
8958
+ if self.funding .funding_tx_confirmation_height == 0 {
8954
8959
// Note that check_get_channel_ready may reset funding_tx_confirmation_height to
8955
8960
// zero if it has been reorged out, however in either case, our state flags
8956
8961
// indicate we've already sent a channel_ready
@@ -8991,10 +8996,10 @@ where
8991
8996
/// before the channel has reached channel_ready and we can just wait for more blocks.
8992
8997
#[rustfmt::skip]
8993
8998
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
8994
- if self.context .funding_tx_confirmation_height != 0 {
8999
+ if self.funding .funding_tx_confirmation_height != 0 {
8995
9000
// We handle the funding disconnection by calling best_block_updated with a height one
8996
9001
// below where our funding was connected, implying a reorg back to conf_height - 1.
8997
- let reorg_height = self.context .funding_tx_confirmation_height - 1;
9002
+ let reorg_height = self.funding .funding_tx_confirmation_height - 1;
8998
9003
// We use the time field to bump the current time we set on channel updates if its
8999
9004
// larger. If we don't know that time has moved forward, we can just set it to the last
9000
9005
// time we saw and it will be ignored.
@@ -9069,7 +9074,7 @@ where
9069
9074
NS::Target: NodeSigner,
9070
9075
L::Target: Logger
9071
9076
{
9072
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
9077
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
9073
9078
return None;
9074
9079
}
9075
9080
@@ -9192,7 +9197,7 @@ where
9192
9197
}
9193
9198
9194
9199
self.context.announcement_sigs = Some((msg.node_signature, msg.bitcoin_signature));
9195
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
9200
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
9196
9201
return Err(ChannelError::Ignore(
9197
9202
"Got announcement_signatures prior to the required six confirmations - we may not have received a block yet that our peer has".to_owned()));
9198
9203
}
@@ -9206,7 +9211,7 @@ where
9206
9211
pub fn get_signed_channel_announcement<NS: Deref>(
9207
9212
&self, node_signer: &NS, chain_hash: ChainHash, best_block_height: u32, user_config: &UserConfig
9208
9213
) -> Option<msgs::ChannelAnnouncement> where NS::Target: NodeSigner {
9209
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
9214
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
9210
9215
return None;
9211
9216
}
9212
9217
let announcement = match self.get_channel_announcement(node_signer, chain_hash, user_config) {
@@ -11453,7 +11458,7 @@ where
11453
11458
0u8.write(writer)?;
11454
11459
11455
11460
self.funding.funding_tx_confirmed_in.write(writer)?;
11456
- self.context .funding_tx_confirmation_height.write(writer)?;
11461
+ self.funding .funding_tx_confirmation_height.write(writer)?;
11457
11462
self.context.short_channel_id.write(writer)?;
11458
11463
11459
11464
self.context.counterparty_dust_limit_satoshis.write(writer)?;
@@ -12112,6 +12117,7 @@ where
12112
12117
channel_transaction_parameters: channel_parameters,
12113
12118
funding_transaction,
12114
12119
funding_tx_confirmed_in,
12120
+ funding_tx_confirmation_height,
12115
12121
},
12116
12122
pending_funding: pending_funding.unwrap(),
12117
12123
context: ChannelContext {
@@ -12175,7 +12181,6 @@ where
12175
12181
closing_fee_limits: None,
12176
12182
target_closing_feerate_sats_per_kw,
12177
12183
12178
- funding_tx_confirmation_height,
12179
12184
short_channel_id,
12180
12185
channel_creation_height,
12181
12186
0 commit comments