@@ -1962,6 +1962,7 @@ pub(super) struct FundingScope {
1962
1962
funding_transaction: Option<Transaction>,
1963
1963
/// The hash of the block in which the funding transaction was included.
1964
1964
funding_tx_confirmed_in: Option<BlockHash>,
1965
+ funding_tx_confirmation_height: u32,
1965
1966
}
1966
1967
1967
1968
impl Writeable for FundingScope {
@@ -1973,6 +1974,7 @@ impl Writeable for FundingScope {
1973
1974
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
1974
1975
(9, self.funding_transaction, option),
1975
1976
(11, self.funding_tx_confirmed_in, option),
1977
+ (13, self.funding_tx_confirmation_height, required),
1976
1978
});
1977
1979
Ok(())
1978
1980
}
@@ -1987,6 +1989,7 @@ impl Readable for FundingScope {
1987
1989
let mut channel_transaction_parameters = RequiredWrapper(None);
1988
1990
let mut funding_transaction = None;
1989
1991
let mut funding_tx_confirmed_in = None;
1992
+ let mut funding_tx_confirmation_height = RequiredWrapper(None);
1990
1993
1991
1994
read_tlv_fields!(reader, {
1992
1995
(1, value_to_self_msat, required),
@@ -1995,6 +1998,7 @@ impl Readable for FundingScope {
1995
1998
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
1996
1999
(9, funding_transaction, option),
1997
2000
(11, funding_tx_confirmed_in, option),
2001
+ (13, funding_tx_confirmation_height, required),
1998
2002
});
1999
2003
2000
2004
Ok(Self {
@@ -2008,6 +2012,7 @@ impl Readable for FundingScope {
2008
2012
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
2009
2013
funding_transaction,
2010
2014
funding_tx_confirmed_in,
2015
+ funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
2011
2016
#[cfg(any(test, fuzzing))]
2012
2017
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2013
2018
#[cfg(any(test, fuzzing))]
@@ -2084,6 +2089,26 @@ impl FundingScope {
2084
2089
pub fn get_channel_type(&self) -> &ChannelTypeFeatures {
2085
2090
&self.channel_transaction_parameters.channel_type_features
2086
2091
}
2092
+
2093
+ /// Returns the height in which our funding transaction was confirmed.
2094
+ pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
2095
+ let conf_height = self.funding_tx_confirmation_height;
2096
+ if conf_height > 0 {
2097
+ Some(conf_height)
2098
+ } else {
2099
+ None
2100
+ }
2101
+ }
2102
+
2103
+ /// Returns the current number of confirmations on the funding transaction.
2104
+ pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
2105
+ if self.funding_tx_confirmation_height == 0 {
2106
+ // We either haven't seen any confirmation yet, or observed a reorg.
2107
+ return 0;
2108
+ }
2109
+
2110
+ height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
2111
+ }
2087
2112
}
2088
2113
2089
2114
/// Info about a pending splice, used in the pre-splice channel
@@ -2245,7 +2270,6 @@ where
2245
2270
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
2246
2271
expecting_peer_commitment_signed: bool,
2247
2272
2248
- funding_tx_confirmation_height: u32,
2249
2273
short_channel_id: Option<u64>,
2250
2274
/// Either the height at which this channel was created or the height at which it was last
2251
2275
/// serialized if it was serialized by versions prior to 0.0.103.
@@ -3093,6 +3117,7 @@ where
3093
3117
},
3094
3118
funding_transaction: None,
3095
3119
funding_tx_confirmed_in: None,
3120
+ funding_tx_confirmation_height: 0,
3096
3121
};
3097
3122
let channel_context = ChannelContext {
3098
3123
user_id,
@@ -3156,7 +3181,6 @@ where
3156
3181
closing_fee_limits: None,
3157
3182
target_closing_feerate_sats_per_kw: None,
3158
3183
3159
- funding_tx_confirmation_height: 0,
3160
3184
short_channel_id: None,
3161
3185
channel_creation_height: current_chain_height,
3162
3186
@@ -3334,6 +3358,7 @@ where
3334
3358
},
3335
3359
funding_transaction: None,
3336
3360
funding_tx_confirmed_in: None,
3361
+ funding_tx_confirmation_height: 0,
3337
3362
};
3338
3363
let channel_context = Self {
3339
3364
user_id,
@@ -3395,7 +3420,6 @@ where
3395
3420
closing_fee_limits: None,
3396
3421
target_closing_feerate_sats_per_kw: None,
3397
3422
3398
- funding_tx_confirmation_height: 0,
3399
3423
short_channel_id: None,
3400
3424
channel_creation_height: current_chain_height,
3401
3425
@@ -3651,16 +3675,6 @@ where
3651
3675
self.outbound_scid_alias = outbound_scid_alias;
3652
3676
}
3653
3677
3654
- /// Returns the height in which our funding transaction was confirmed.
3655
- pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
3656
- let conf_height = self.funding_tx_confirmation_height;
3657
- if conf_height > 0 {
3658
- Some(conf_height)
3659
- } else {
3660
- None
3661
- }
3662
- }
3663
-
3664
3678
/// Performs checks against necessary constraints after receiving either an `accept_channel` or
3665
3679
/// `accept_channel2` message.
3666
3680
#[rustfmt::skip]
@@ -3802,16 +3816,6 @@ where
3802
3816
Ok(())
3803
3817
}
3804
3818
3805
- /// Returns the current number of confirmations on the funding transaction.
3806
- pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
3807
- if self.funding_tx_confirmation_height == 0 {
3808
- // We either haven't seen any confirmation yet, or observed a reorg.
3809
- return 0;
3810
- }
3811
-
3812
- height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
3813
- }
3814
-
3815
3819
/// Allowed in any state (including after shutdown)
3816
3820
pub fn get_counterparty_node_id(&self) -> PublicKey {
3817
3821
self.counterparty_node_id
@@ -7362,7 +7366,7 @@ where
7362
7366
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
7363
7367
{
7364
7368
// Broadcast only if not yet confirmed
7365
- if self.context .get_funding_tx_confirmation_height().is_none() {
7369
+ if self.funding .get_funding_tx_confirmation_height().is_none() {
7366
7370
funding_broadcastable = Some(funding_transaction.clone())
7367
7371
}
7368
7372
}
@@ -8771,13 +8775,13 @@ where
8771
8775
// Called:
8772
8776
// * always when a new block/transactions are confirmed with the new height
8773
8777
// * when funding is signed with a height of 0
8774
- if self.context .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8778
+ if self.funding .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8775
8779
return None;
8776
8780
}
8777
8781
8778
- let funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
8782
+ let funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
8779
8783
if funding_tx_confirmations <= 0 {
8780
- self.context .funding_tx_confirmation_height = 0;
8784
+ self.funding .funding_tx_confirmation_height = 0;
8781
8785
}
8782
8786
8783
8787
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
@@ -8797,7 +8801,7 @@ where
8797
8801
// We got a reorg but not enough to trigger a force close, just ignore.
8798
8802
false
8799
8803
} else {
8800
- if self.context .funding_tx_confirmation_height != 0 &&
8804
+ if self.funding .funding_tx_confirmation_height != 0 &&
8801
8805
self.context.channel_state < ChannelState::ChannelReady(ChannelReadyFlags::new())
8802
8806
{
8803
8807
// We should never see a funding transaction on-chain until we've received
@@ -8867,7 +8871,7 @@ where
8867
8871
for &(index_in_block, tx) in txdata.iter() {
8868
8872
// Check if the transaction is the expected funding transaction, and if it is,
8869
8873
// check that it pays the right amount to the right script.
8870
- if self.context .funding_tx_confirmation_height == 0 {
8874
+ if self.funding .funding_tx_confirmation_height == 0 {
8871
8875
if tx.compute_txid() == funding_txo.txid {
8872
8876
let txo_idx = funding_txo.index as usize;
8873
8877
if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.funding.get_funding_redeemscript().to_p2wsh() ||
@@ -8897,7 +8901,8 @@ where
8897
8901
}
8898
8902
}
8899
8903
}
8900
- self.context.funding_tx_confirmation_height = height;
8904
+
8905
+ self.funding.funding_tx_confirmation_height = height;
8901
8906
self.funding.funding_tx_confirmed_in = Some(*block_hash);
8902
8907
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
8903
8908
Ok(scid) => Some(scid),
@@ -8997,8 +9002,8 @@ where
8997
9002
8998
9003
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
8999
9004
self.context.channel_state.is_our_channel_ready() {
9000
- let mut funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
9001
- if self.context .funding_tx_confirmation_height == 0 {
9005
+ let mut funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
9006
+ if self.funding .funding_tx_confirmation_height == 0 {
9002
9007
// Note that check_get_channel_ready may reset funding_tx_confirmation_height to
9003
9008
// zero if it has been reorged out, however in either case, our state flags
9004
9009
// indicate we've already sent a channel_ready
@@ -9039,10 +9044,10 @@ where
9039
9044
/// before the channel has reached channel_ready and we can just wait for more blocks.
9040
9045
#[rustfmt::skip]
9041
9046
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
9042
- if self.context .funding_tx_confirmation_height != 0 {
9047
+ if self.funding .funding_tx_confirmation_height != 0 {
9043
9048
// We handle the funding disconnection by calling best_block_updated with a height one
9044
9049
// below where our funding was connected, implying a reorg back to conf_height - 1.
9045
- let reorg_height = self.context .funding_tx_confirmation_height - 1;
9050
+ let reorg_height = self.funding .funding_tx_confirmation_height - 1;
9046
9051
// We use the time field to bump the current time we set on channel updates if its
9047
9052
// larger. If we don't know that time has moved forward, we can just set it to the last
9048
9053
// time we saw and it will be ignored.
@@ -9117,7 +9122,7 @@ where
9117
9122
NS::Target: NodeSigner,
9118
9123
L::Target: Logger
9119
9124
{
9120
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
9125
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
9121
9126
return None;
9122
9127
}
9123
9128
@@ -9240,7 +9245,7 @@ where
9240
9245
}
9241
9246
9242
9247
self.context.announcement_sigs = Some((msg.node_signature, msg.bitcoin_signature));
9243
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
9248
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
9244
9249
return Err(ChannelError::Ignore(
9245
9250
"Got announcement_signatures prior to the required six confirmations - we may not have received a block yet that our peer has".to_owned()));
9246
9251
}
@@ -9254,7 +9259,7 @@ where
9254
9259
pub fn get_signed_channel_announcement<NS: Deref>(
9255
9260
&self, node_signer: &NS, chain_hash: ChainHash, best_block_height: u32, user_config: &UserConfig
9256
9261
) -> Option<msgs::ChannelAnnouncement> where NS::Target: NodeSigner {
9257
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
9262
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
9258
9263
return None;
9259
9264
}
9260
9265
let announcement = match self.get_channel_announcement(node_signer, chain_hash, user_config) {
@@ -11506,7 +11511,7 @@ where
11506
11511
0u8.write(writer)?;
11507
11512
11508
11513
self.funding.funding_tx_confirmed_in.write(writer)?;
11509
- self.context .funding_tx_confirmation_height.write(writer)?;
11514
+ self.funding .funding_tx_confirmation_height.write(writer)?;
11510
11515
self.context.short_channel_id.write(writer)?;
11511
11516
11512
11517
self.context.counterparty_dust_limit_satoshis.write(writer)?;
@@ -12165,6 +12170,7 @@ where
12165
12170
channel_transaction_parameters: channel_parameters,
12166
12171
funding_transaction,
12167
12172
funding_tx_confirmed_in,
12173
+ funding_tx_confirmation_height,
12168
12174
},
12169
12175
pending_funding: pending_funding.unwrap(),
12170
12176
context: ChannelContext {
@@ -12228,7 +12234,6 @@ where
12228
12234
closing_fee_limits: None,
12229
12235
target_closing_feerate_sats_per_kw,
12230
12236
12231
- funding_tx_confirmation_height,
12232
12237
short_channel_id,
12233
12238
channel_creation_height,
12234
12239
0 commit comments