@@ -1687,6 +1687,7 @@ pub(super) struct FundingScope {
1687
1687
funding_transaction: Option<Transaction>,
1688
1688
/// The hash of the block in which the funding transaction was included.
1689
1689
funding_tx_confirmed_in: Option<BlockHash>,
1690
+ funding_tx_confirmation_height: u32,
1690
1691
}
1691
1692
1692
1693
impl Writeable for FundingScope {
@@ -1698,6 +1699,7 @@ impl Writeable for FundingScope {
1698
1699
(7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
1699
1700
(9, self.funding_transaction, option),
1700
1701
(11, self.funding_tx_confirmed_in, option),
1702
+ (13, self.funding_tx_confirmation_height, required),
1701
1703
});
1702
1704
Ok(())
1703
1705
}
@@ -1711,6 +1713,7 @@ impl Readable for FundingScope {
1711
1713
let mut channel_transaction_parameters = RequiredWrapper(None);
1712
1714
let mut funding_transaction = None;
1713
1715
let mut funding_tx_confirmed_in = None;
1716
+ let mut funding_tx_confirmation_height = RequiredWrapper(None);
1714
1717
1715
1718
read_tlv_fields!(reader, {
1716
1719
(1, value_to_self_msat, required),
@@ -1719,6 +1722,7 @@ impl Readable for FundingScope {
1719
1722
(7, channel_transaction_parameters, (required: ReadableArgs, None)),
1720
1723
(9, funding_transaction, option),
1721
1724
(11, funding_tx_confirmed_in, option),
1725
+ (13, funding_tx_confirmation_height, required),
1722
1726
});
1723
1727
1724
1728
Ok(Self {
@@ -1732,6 +1736,7 @@ impl Readable for FundingScope {
1732
1736
channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
1733
1737
funding_transaction,
1734
1738
funding_tx_confirmed_in,
1739
+ funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
1735
1740
#[cfg(any(test, fuzzing))]
1736
1741
next_local_commitment_tx_fee_info_cached: Mutex::new(None),
1737
1742
#[cfg(any(test, fuzzing))]
@@ -1810,6 +1815,26 @@ impl FundingScope {
1810
1815
pub fn get_funding_tx_confirmed_in(&self) -> Option<BlockHash> {
1811
1816
self.funding_tx_confirmed_in
1812
1817
}
1818
+
1819
+ /// Returns the height in which our funding transaction was confirmed.
1820
+ pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
1821
+ let conf_height = self.funding_tx_confirmation_height;
1822
+ if conf_height > 0 {
1823
+ Some(conf_height)
1824
+ } else {
1825
+ None
1826
+ }
1827
+ }
1828
+
1829
+ /// Returns the current number of confirmations on the funding transaction.
1830
+ pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
1831
+ if self.funding_tx_confirmation_height == 0 {
1832
+ // We either haven't seen any confirmation yet, or observed a reorg.
1833
+ return 0;
1834
+ }
1835
+
1836
+ height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
1837
+ }
1813
1838
}
1814
1839
1815
1840
/// Info about a pending splice, used in the pre-splice channel
@@ -1969,7 +1994,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1969
1994
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
1970
1995
expecting_peer_commitment_signed: bool,
1971
1996
1972
- funding_tx_confirmation_height: u32,
1973
1997
short_channel_id: Option<u64>,
1974
1998
/// Either the height at which this channel was created or the height at which it was last
1975
1999
/// serialized if it was serialized by versions prior to 0.0.103.
@@ -2780,6 +2804,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2780
2804
},
2781
2805
funding_transaction: None,
2782
2806
funding_tx_confirmed_in: None,
2807
+ funding_tx_confirmation_height: 0,
2783
2808
};
2784
2809
let channel_context = ChannelContext {
2785
2810
user_id,
@@ -2843,7 +2868,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2843
2868
closing_fee_limits: None,
2844
2869
target_closing_feerate_sats_per_kw: None,
2845
2870
2846
- funding_tx_confirmation_height: 0,
2847
2871
short_channel_id: None,
2848
2872
channel_creation_height: current_chain_height,
2849
2873
@@ -3016,6 +3040,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3016
3040
},
3017
3041
funding_transaction: None,
3018
3042
funding_tx_confirmed_in: None,
3043
+ funding_tx_confirmation_height: 0,
3019
3044
};
3020
3045
let channel_context = Self {
3021
3046
user_id,
@@ -3077,7 +3102,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3077
3102
closing_fee_limits: None,
3078
3103
target_closing_feerate_sats_per_kw: None,
3079
3104
3080
- funding_tx_confirmation_height: 0,
3081
3105
short_channel_id: None,
3082
3106
channel_creation_height: current_chain_height,
3083
3107
@@ -3319,16 +3343,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3319
3343
self.outbound_scid_alias = outbound_scid_alias;
3320
3344
}
3321
3345
3322
- /// Returns the height in which our funding transaction was confirmed.
3323
- pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
3324
- let conf_height = self.funding_tx_confirmation_height;
3325
- if conf_height > 0 {
3326
- Some(conf_height)
3327
- } else {
3328
- None
3329
- }
3330
- }
3331
-
3332
3346
/// Performs checks against necessary constraints after receiving either an `accept_channel` or
3333
3347
/// `accept_channel2` message.
3334
3348
pub fn do_accept_channel_checks(
@@ -3469,16 +3483,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3469
3483
Ok(())
3470
3484
}
3471
3485
3472
- /// Returns the current number of confirmations on the funding transaction.
3473
- pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
3474
- if self.funding_tx_confirmation_height == 0 {
3475
- // We either haven't seen any confirmation yet, or observed a reorg.
3476
- return 0;
3477
- }
3478
-
3479
- height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
3480
- }
3481
-
3482
3486
/// Allowed in any state (including after shutdown)
3483
3487
pub fn get_counterparty_node_id(&self) -> PublicKey {
3484
3488
self.counterparty_node_id
@@ -6740,7 +6744,7 @@ impl<SP: Deref> FundedChannel<SP> where
6740
6744
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
6741
6745
{
6742
6746
// Broadcast only if not yet confirmed
6743
- if self.context .get_funding_tx_confirmation_height().is_none() {
6747
+ if self.funding .get_funding_tx_confirmation_height().is_none() {
6744
6748
funding_broadcastable = Some(funding_transaction.clone())
6745
6749
}
6746
6750
}
@@ -8076,13 +8080,13 @@ impl<SP: Deref> FundedChannel<SP> where
8076
8080
// Called:
8077
8081
// * always when a new block/transactions are confirmed with the new height
8078
8082
// * when funding is signed with a height of 0
8079
- if self.context .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8083
+ if self.funding .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8080
8084
return None;
8081
8085
}
8082
8086
8083
- let funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
8087
+ let funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
8084
8088
if funding_tx_confirmations <= 0 {
8085
- self.context .funding_tx_confirmation_height = 0;
8089
+ self.funding .funding_tx_confirmation_height = 0;
8086
8090
}
8087
8091
8088
8092
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
@@ -8102,7 +8106,7 @@ impl<SP: Deref> FundedChannel<SP> where
8102
8106
// We got a reorg but not enough to trigger a force close, just ignore.
8103
8107
false
8104
8108
} else {
8105
- if self.context .funding_tx_confirmation_height != 0 &&
8109
+ if self.funding .funding_tx_confirmation_height != 0 &&
8106
8110
self.context.channel_state < ChannelState::ChannelReady(ChannelReadyFlags::new())
8107
8111
{
8108
8112
// We should never see a funding transaction on-chain until we've received
@@ -8170,7 +8174,7 @@ impl<SP: Deref> FundedChannel<SP> where
8170
8174
for &(index_in_block, tx) in txdata.iter() {
8171
8175
// Check if the transaction is the expected funding transaction, and if it is,
8172
8176
// check that it pays the right amount to the right script.
8173
- if self.context .funding_tx_confirmation_height == 0 {
8177
+ if self.funding .funding_tx_confirmation_height == 0 {
8174
8178
if tx.compute_txid() == funding_txo.txid {
8175
8179
let txo_idx = funding_txo.index as usize;
8176
8180
if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.funding.get_funding_redeemscript().to_p2wsh() ||
@@ -8200,7 +8204,8 @@ impl<SP: Deref> FundedChannel<SP> where
8200
8204
}
8201
8205
}
8202
8206
}
8203
- self.context.funding_tx_confirmation_height = height;
8207
+
8208
+ self.funding.funding_tx_confirmation_height = height;
8204
8209
self.funding.funding_tx_confirmed_in = Some(*block_hash);
8205
8210
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
8206
8211
Ok(scid) => Some(scid),
@@ -8294,8 +8299,8 @@ impl<SP: Deref> FundedChannel<SP> where
8294
8299
8295
8300
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
8296
8301
self.context.channel_state.is_our_channel_ready() {
8297
- let mut funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
8298
- if self.context .funding_tx_confirmation_height == 0 {
8302
+ let mut funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
8303
+ if self.funding .funding_tx_confirmation_height == 0 {
8299
8304
// Note that check_get_channel_ready may reset funding_tx_confirmation_height to
8300
8305
// zero if it has been reorged out, however in either case, our state flags
8301
8306
// indicate we've already sent a channel_ready
@@ -8335,10 +8340,10 @@ impl<SP: Deref> FundedChannel<SP> where
8335
8340
/// force-close the channel, but may also indicate a harmless reorganization of a block or two
8336
8341
/// before the channel has reached channel_ready and we can just wait for more blocks.
8337
8342
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
8338
- if self.context .funding_tx_confirmation_height != 0 {
8343
+ if self.funding .funding_tx_confirmation_height != 0 {
8339
8344
// We handle the funding disconnection by calling best_block_updated with a height one
8340
8345
// below where our funding was connected, implying a reorg back to conf_height - 1.
8341
- let reorg_height = self.context .funding_tx_confirmation_height - 1;
8346
+ let reorg_height = self.funding .funding_tx_confirmation_height - 1;
8342
8347
// We use the time field to bump the current time we set on channel updates if its
8343
8348
// larger. If we don't know that time has moved forward, we can just set it to the last
8344
8349
// time we saw and it will be ignored.
@@ -8411,7 +8416,7 @@ impl<SP: Deref> FundedChannel<SP> where
8411
8416
NS::Target: NodeSigner,
8412
8417
L::Target: Logger
8413
8418
{
8414
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
8419
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
8415
8420
return None;
8416
8421
}
8417
8422
@@ -8532,7 +8537,7 @@ impl<SP: Deref> FundedChannel<SP> where
8532
8537
}
8533
8538
8534
8539
self.context.announcement_sigs = Some((msg.node_signature, msg.bitcoin_signature));
8535
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
8540
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
8536
8541
return Err(ChannelError::Ignore(
8537
8542
"Got announcement_signatures prior to the required six confirmations - we may not have received a block yet that our peer has".to_owned()));
8538
8543
}
@@ -8545,7 +8550,7 @@ impl<SP: Deref> FundedChannel<SP> where
8545
8550
pub fn get_signed_channel_announcement<NS: Deref>(
8546
8551
&self, node_signer: &NS, chain_hash: ChainHash, best_block_height: u32, user_config: &UserConfig
8547
8552
) -> Option<msgs::ChannelAnnouncement> where NS::Target: NodeSigner {
8548
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
8553
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
8549
8554
return None;
8550
8555
}
8551
8556
let announcement = match self.get_channel_announcement(node_signer, chain_hash, user_config) {
@@ -10695,7 +10700,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10695
10700
0u8.write(writer)?;
10696
10701
10697
10702
self.funding.funding_tx_confirmed_in.write(writer)?;
10698
- self.context .funding_tx_confirmation_height.write(writer)?;
10703
+ self.funding .funding_tx_confirmation_height.write(writer)?;
10699
10704
self.context.short_channel_id.write(writer)?;
10700
10705
10701
10706
self.context.counterparty_dust_limit_satoshis.write(writer)?;
@@ -11331,6 +11336,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11331
11336
channel_transaction_parameters: channel_parameters,
11332
11337
funding_transaction,
11333
11338
funding_tx_confirmed_in,
11339
+ funding_tx_confirmation_height,
11334
11340
},
11335
11341
pending_funding: pending_funding.unwrap(),
11336
11342
context: ChannelContext {
@@ -11394,7 +11400,6 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11394
11400
closing_fee_limits: None,
11395
11401
target_closing_feerate_sats_per_kw,
11396
11402
11397
- funding_tx_confirmation_height,
11398
11403
short_channel_id,
11399
11404
channel_creation_height,
11400
11405
0 commit comments