@@ -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))]
@@ -1805,6 +1810,26 @@ impl FundingScope {
1805
1810
pub fn get_channel_type(&self) -> &ChannelTypeFeatures {
1806
1811
&self.channel_transaction_parameters.channel_type_features
1807
1812
}
1813
+
1814
+ /// Returns the height in which our funding transaction was confirmed.
1815
+ pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
1816
+ let conf_height = self.funding_tx_confirmation_height;
1817
+ if conf_height > 0 {
1818
+ Some(conf_height)
1819
+ } else {
1820
+ None
1821
+ }
1822
+ }
1823
+
1824
+ /// Returns the current number of confirmations on the funding transaction.
1825
+ pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
1826
+ if self.funding_tx_confirmation_height == 0 {
1827
+ // We either haven't seen any confirmation yet, or observed a reorg.
1828
+ return 0;
1829
+ }
1830
+
1831
+ height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
1832
+ }
1808
1833
}
1809
1834
1810
1835
/// Info about a pending splice, used in the pre-splice channel
@@ -1964,7 +1989,6 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1964
1989
/// milliseconds, so any accidental force-closes here should be exceedingly rare.
1965
1990
expecting_peer_commitment_signed: bool,
1966
1991
1967
- funding_tx_confirmation_height: u32,
1968
1992
short_channel_id: Option<u64>,
1969
1993
/// Either the height at which this channel was created or the height at which it was last
1970
1994
/// serialized if it was serialized by versions prior to 0.0.103.
@@ -2775,6 +2799,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2775
2799
},
2776
2800
funding_transaction: None,
2777
2801
funding_tx_confirmed_in: None,
2802
+ funding_tx_confirmation_height: 0,
2778
2803
};
2779
2804
let channel_context = ChannelContext {
2780
2805
user_id,
@@ -2838,7 +2863,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2838
2863
closing_fee_limits: None,
2839
2864
target_closing_feerate_sats_per_kw: None,
2840
2865
2841
- funding_tx_confirmation_height: 0,
2842
2866
short_channel_id: None,
2843
2867
channel_creation_height: current_chain_height,
2844
2868
@@ -3011,6 +3035,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3011
3035
},
3012
3036
funding_transaction: None,
3013
3037
funding_tx_confirmed_in: None,
3038
+ funding_tx_confirmation_height: 0,
3014
3039
};
3015
3040
let channel_context = Self {
3016
3041
user_id,
@@ -3072,7 +3097,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3072
3097
closing_fee_limits: None,
3073
3098
target_closing_feerate_sats_per_kw: None,
3074
3099
3075
- funding_tx_confirmation_height: 0,
3076
3100
short_channel_id: None,
3077
3101
channel_creation_height: current_chain_height,
3078
3102
@@ -3314,16 +3338,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3314
3338
self.outbound_scid_alias = outbound_scid_alias;
3315
3339
}
3316
3340
3317
- /// Returns the height in which our funding transaction was confirmed.
3318
- pub fn get_funding_tx_confirmation_height(&self) -> Option<u32> {
3319
- let conf_height = self.funding_tx_confirmation_height;
3320
- if conf_height > 0 {
3321
- Some(conf_height)
3322
- } else {
3323
- None
3324
- }
3325
- }
3326
-
3327
3341
/// Performs checks against necessary constraints after receiving either an `accept_channel` or
3328
3342
/// `accept_channel2` message.
3329
3343
pub fn do_accept_channel_checks(
@@ -3464,16 +3478,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3464
3478
Ok(())
3465
3479
}
3466
3480
3467
- /// Returns the current number of confirmations on the funding transaction.
3468
- pub fn get_funding_tx_confirmations(&self, height: u32) -> u32 {
3469
- if self.funding_tx_confirmation_height == 0 {
3470
- // We either haven't seen any confirmation yet, or observed a reorg.
3471
- return 0;
3472
- }
3473
-
3474
- height.checked_sub(self.funding_tx_confirmation_height).map_or(0, |c| c + 1)
3475
- }
3476
-
3477
3481
/// Allowed in any state (including after shutdown)
3478
3482
pub fn get_counterparty_node_id(&self) -> PublicKey {
3479
3483
self.counterparty_node_id
@@ -6735,7 +6739,7 @@ impl<SP: Deref> FundedChannel<SP> where
6735
6739
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
6736
6740
{
6737
6741
// Broadcast only if not yet confirmed
6738
- if self.context .get_funding_tx_confirmation_height().is_none() {
6742
+ if self.funding .get_funding_tx_confirmation_height().is_none() {
6739
6743
funding_broadcastable = Some(funding_transaction.clone())
6740
6744
}
6741
6745
}
@@ -8071,13 +8075,13 @@ impl<SP: Deref> FundedChannel<SP> where
8071
8075
// Called:
8072
8076
// * always when a new block/transactions are confirmed with the new height
8073
8077
// * when funding is signed with a height of 0
8074
- if self.context .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8078
+ if self.funding .funding_tx_confirmation_height == 0 && self.context.minimum_depth != Some(0) {
8075
8079
return None;
8076
8080
}
8077
8081
8078
- let funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
8082
+ let funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
8079
8083
if funding_tx_confirmations <= 0 {
8080
- self.context .funding_tx_confirmation_height = 0;
8084
+ self.funding .funding_tx_confirmation_height = 0;
8081
8085
}
8082
8086
8083
8087
if funding_tx_confirmations < self.context.minimum_depth.unwrap_or(0) as i64 {
@@ -8097,7 +8101,7 @@ impl<SP: Deref> FundedChannel<SP> where
8097
8101
// We got a reorg but not enough to trigger a force close, just ignore.
8098
8102
false
8099
8103
} else {
8100
- if self.context .funding_tx_confirmation_height != 0 &&
8104
+ if self.funding .funding_tx_confirmation_height != 0 &&
8101
8105
self.context.channel_state < ChannelState::ChannelReady(ChannelReadyFlags::new())
8102
8106
{
8103
8107
// We should never see a funding transaction on-chain until we've received
@@ -8165,7 +8169,7 @@ impl<SP: Deref> FundedChannel<SP> where
8165
8169
for &(index_in_block, tx) in txdata.iter() {
8166
8170
// Check if the transaction is the expected funding transaction, and if it is,
8167
8171
// check that it pays the right amount to the right script.
8168
- if self.context .funding_tx_confirmation_height == 0 {
8172
+ if self.funding .funding_tx_confirmation_height == 0 {
8169
8173
if tx.compute_txid() == funding_txo.txid {
8170
8174
let txo_idx = funding_txo.index as usize;
8171
8175
if txo_idx >= tx.output.len() || tx.output[txo_idx].script_pubkey != self.funding.get_funding_redeemscript().to_p2wsh() ||
@@ -8195,7 +8199,8 @@ impl<SP: Deref> FundedChannel<SP> where
8195
8199
}
8196
8200
}
8197
8201
}
8198
- self.context.funding_tx_confirmation_height = height;
8202
+
8203
+ self.funding.funding_tx_confirmation_height = height;
8199
8204
self.funding.funding_tx_confirmed_in = Some(*block_hash);
8200
8205
self.context.short_channel_id = match scid_from_parts(height as u64, index_in_block as u64, txo_idx as u64) {
8201
8206
Ok(scid) => Some(scid),
@@ -8289,8 +8294,8 @@ impl<SP: Deref> FundedChannel<SP> where
8289
8294
8290
8295
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) ||
8291
8296
self.context.channel_state.is_our_channel_ready() {
8292
- let mut funding_tx_confirmations = height as i64 - self.context .funding_tx_confirmation_height as i64 + 1;
8293
- if self.context .funding_tx_confirmation_height == 0 {
8297
+ let mut funding_tx_confirmations = height as i64 - self.funding .funding_tx_confirmation_height as i64 + 1;
8298
+ if self.funding .funding_tx_confirmation_height == 0 {
8294
8299
// Note that check_get_channel_ready may reset funding_tx_confirmation_height to
8295
8300
// zero if it has been reorged out, however in either case, our state flags
8296
8301
// indicate we've already sent a channel_ready
@@ -8330,10 +8335,10 @@ impl<SP: Deref> FundedChannel<SP> where
8330
8335
/// force-close the channel, but may also indicate a harmless reorganization of a block or two
8331
8336
/// before the channel has reached channel_ready and we can just wait for more blocks.
8332
8337
pub fn funding_transaction_unconfirmed<L: Deref>(&mut self, logger: &L) -> Result<(), ClosureReason> where L::Target: Logger {
8333
- if self.context .funding_tx_confirmation_height != 0 {
8338
+ if self.funding .funding_tx_confirmation_height != 0 {
8334
8339
// We handle the funding disconnection by calling best_block_updated with a height one
8335
8340
// below where our funding was connected, implying a reorg back to conf_height - 1.
8336
- let reorg_height = self.context .funding_tx_confirmation_height - 1;
8341
+ let reorg_height = self.funding .funding_tx_confirmation_height - 1;
8337
8342
// We use the time field to bump the current time we set on channel updates if its
8338
8343
// larger. If we don't know that time has moved forward, we can just set it to the last
8339
8344
// time we saw and it will be ignored.
@@ -8406,7 +8411,7 @@ impl<SP: Deref> FundedChannel<SP> where
8406
8411
NS::Target: NodeSigner,
8407
8412
L::Target: Logger
8408
8413
{
8409
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
8414
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
8410
8415
return None;
8411
8416
}
8412
8417
@@ -8527,7 +8532,7 @@ impl<SP: Deref> FundedChannel<SP> where
8527
8532
}
8528
8533
8529
8534
self.context.announcement_sigs = Some((msg.node_signature, msg.bitcoin_signature));
8530
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
8535
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
8531
8536
return Err(ChannelError::Ignore(
8532
8537
"Got announcement_signatures prior to the required six confirmations - we may not have received a block yet that our peer has".to_owned()));
8533
8538
}
@@ -8540,7 +8545,7 @@ impl<SP: Deref> FundedChannel<SP> where
8540
8545
pub fn get_signed_channel_announcement<NS: Deref>(
8541
8546
&self, node_signer: &NS, chain_hash: ChainHash, best_block_height: u32, user_config: &UserConfig
8542
8547
) -> Option<msgs::ChannelAnnouncement> where NS::Target: NodeSigner {
8543
- if self.context .funding_tx_confirmation_height == 0 || self.context .funding_tx_confirmation_height + 5 > best_block_height {
8548
+ if self.funding .funding_tx_confirmation_height == 0 || self.funding .funding_tx_confirmation_height + 5 > best_block_height {
8544
8549
return None;
8545
8550
}
8546
8551
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