@@ -60,7 +60,7 @@ use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Reci
60
60
use crate::events::{ClosureReason, Event};
61
61
use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
62
62
use crate::routing::gossip::NodeId;
63
- use crate::util::ser::{Readable, ReadableArgs, TransactionU16LenLimited, Writeable, Writer};
63
+ use crate::util::ser::{Readable, ReadableArgs, RequiredWrapper, TransactionU16LenLimited, Writeable, Writer};
64
64
use crate::util::logger::{Logger, Record, WithContext};
65
65
use crate::util::errors::APIError;
66
66
use crate::util::config::{UserConfig, ChannelConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits, MaxDustHTLCExposure};
@@ -1514,6 +1514,7 @@ impl<SP: Deref> Channel<SP> where
1514
1514
};
1515
1515
let mut funded_channel = FundedChannel {
1516
1516
funding: chan.funding,
1517
+ pending_funding: vec![],
1517
1518
context: chan.context,
1518
1519
interactive_tx_signing_session: chan.interactive_tx_signing_session,
1519
1520
holder_commitment_point,
@@ -1660,6 +1661,63 @@ pub(super) struct FundingScope {
1660
1661
funding_transaction: Option<Transaction>,
1661
1662
}
1662
1663
1664
+ impl Writeable for FundingScope {
1665
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
1666
+ #[cfg(any(test, fuzzing))]
1667
+ self.next_local_commitment_tx_fee_info_cached.write(writer)?;
1668
+ #[cfg(any(test, fuzzing))]
1669
+ self.next_remote_commitment_tx_fee_info_cached.write(writer)?;
1670
+
1671
+ write_tlv_fields!(writer, {
1672
+ (0, self.value_to_self_msat, required),
1673
+ (1, self.counterparty_selected_channel_reserve_satoshis, option),
1674
+ (2, self.holder_selected_channel_reserve_satoshis, required),
1675
+ (3, self.channel_transaction_parameters, (required: ReadableArgs, None)),
1676
+ (4, self.funding_transaction, option),
1677
+ });
1678
+ Ok(())
1679
+ }
1680
+ }
1681
+
1682
+ impl Readable for FundingScope {
1683
+ fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
1684
+ let mut value_to_self_msat = RequiredWrapper(None);
1685
+ let mut counterparty_selected_channel_reserve_satoshis = None;
1686
+ let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
1687
+ let mut channel_transaction_parameters = RequiredWrapper(None);
1688
+ let mut funding_transaction = None;
1689
+
1690
+ #[cfg(any(test, fuzzing))]
1691
+ let next_local_commitment_tx_fee_info_cached = Readable::read(reader)?;
1692
+ #[cfg(any(test, fuzzing))]
1693
+ let next_remote_commitment_tx_fee_info_cached = Readable::read(reader)?;
1694
+
1695
+ read_tlv_fields!(reader, {
1696
+ (0, value_to_self_msat, required),
1697
+ (1, counterparty_selected_channel_reserve_satoshis, option),
1698
+ (2, holder_selected_channel_reserve_satoshis, required),
1699
+ (3, channel_transaction_parameters, (required: ReadableArgs, None)),
1700
+ (4, funding_transaction, option),
1701
+ });
1702
+
1703
+ Ok(Self {
1704
+ value_to_self_msat: value_to_self_msat.0.unwrap(),
1705
+ counterparty_selected_channel_reserve_satoshis,
1706
+ holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.0.unwrap(),
1707
+ #[cfg(debug_assertions)]
1708
+ holder_max_commitment_tx_output: Mutex::new((0, 0)),
1709
+ #[cfg(debug_assertions)]
1710
+ counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1711
+ channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
1712
+ funding_transaction,
1713
+ #[cfg(any(test, fuzzing))]
1714
+ next_local_commitment_tx_fee_info_cached,
1715
+ #[cfg(any(test, fuzzing))]
1716
+ next_remote_commitment_tx_fee_info_cached,
1717
+ })
1718
+ }
1719
+ }
1720
+
1663
1721
impl FundingScope {
1664
1722
pub fn get_value_satoshis(&self) -> u64 {
1665
1723
self.channel_transaction_parameters.channel_value_satoshis
@@ -3522,7 +3580,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3522
3580
if let Some(info) = projected_commit_tx_info {
3523
3581
let total_pending_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len()
3524
3582
+ self.holding_cell_htlc_updates.len();
3525
- if info.total_pending_htlcs == total_pending_htlcs
3583
+ if info.total_pending_htlcs == total_pending_htlcs as u64
3526
3584
&& info.next_holder_htlc_id == self.next_holder_htlc_id
3527
3585
&& info.next_counterparty_htlc_id == self.next_counterparty_htlc_id
3528
3586
&& info.feerate == self.feerate_per_kw {
@@ -4342,7 +4400,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4342
4400
+ context.holding_cell_htlc_updates.len();
4343
4401
let commitment_tx_info = CommitmentTxInfoCached {
4344
4402
fee,
4345
- total_pending_htlcs,
4403
+ total_pending_htlcs: total_pending_htlcs as u64 ,
4346
4404
next_holder_htlc_id: match htlc.origin {
4347
4405
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
4348
4406
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4438,7 +4496,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4438
4496
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
4439
4497
let commitment_tx_info = CommitmentTxInfoCached {
4440
4498
fee,
4441
- total_pending_htlcs,
4499
+ total_pending_htlcs: total_pending_htlcs as u64 ,
4442
4500
next_holder_htlc_id: match htlc.origin {
4443
4501
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
4444
4502
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4890,6 +4948,7 @@ pub(super) struct DualFundingChannelContext {
4890
4948
// Counterparty designates channel data owned by the another channel participant entity.
4891
4949
pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
4892
4950
pub funding: FundingScope,
4951
+ pending_funding: Vec<FundingScope>,
4893
4952
pub context: ChannelContext<SP>,
4894
4953
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
4895
4954
holder_commitment_point: HolderCommitmentPoint,
@@ -4904,12 +4963,21 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
4904
4963
#[cfg(any(test, fuzzing))]
4905
4964
struct CommitmentTxInfoCached {
4906
4965
fee: u64,
4907
- total_pending_htlcs: usize ,
4966
+ total_pending_htlcs: u64 ,
4908
4967
next_holder_htlc_id: u64,
4909
4968
next_counterparty_htlc_id: u64,
4910
4969
feerate: u32,
4911
4970
}
4912
4971
4972
+ #[cfg(any(test, fuzzing))]
4973
+ impl_writeable_tlv_based!(CommitmentTxInfoCached, {
4974
+ (0, fee, required),
4975
+ (1, total_pending_htlcs, required),
4976
+ (2, next_holder_htlc_id, required),
4977
+ (3, next_counterparty_htlc_id, required),
4978
+ (4, feerate, required),
4979
+ });
4980
+
4913
4981
/// Partial data from ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo used to simplify the
4914
4982
/// return type of `ChannelContext::validate_commitment_signed`.
4915
4983
struct LatestHolderCommitmentTXInfo {
@@ -8770,7 +8838,7 @@ impl<SP: Deref> FundedChannel<SP> where
8770
8838
*self.funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
8771
8839
if let Some(info) = projected_commit_tx_info {
8772
8840
let total_pending_htlcs = self.context.pending_inbound_htlcs.len() + self.context.pending_outbound_htlcs.len();
8773
- if info.total_pending_htlcs == total_pending_htlcs
8841
+ if info.total_pending_htlcs == total_pending_htlcs as u64
8774
8842
&& info.next_holder_htlc_id == self.context.next_holder_htlc_id
8775
8843
&& info.next_counterparty_htlc_id == self.context.next_counterparty_htlc_id
8776
8844
&& info.feerate == self.context.feerate_per_kw {
@@ -9472,6 +9540,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9472
9540
9473
9541
let mut channel = FundedChannel {
9474
9542
funding: self.funding,
9543
+ pending_funding: vec![],
9475
9544
context: self.context,
9476
9545
interactive_tx_signing_session: None,
9477
9546
is_v2_established: false,
@@ -9748,6 +9817,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9748
9817
// `ChannelMonitor`.
9749
9818
let mut channel = FundedChannel {
9750
9819
funding: self.funding,
9820
+ pending_funding: vec![],
9751
9821
context: self.context,
9752
9822
interactive_tx_signing_session: None,
9753
9823
is_v2_established: false,
@@ -10542,6 +10612,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
10542
10612
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
10543
10613
(51, is_manual_broadcast, option), // Added in 0.0.124
10544
10614
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
10615
+ (55, self.pending_funding, optional_vec), // Added in 0.2
10545
10616
});
10546
10617
10547
10618
Ok(())
@@ -10766,7 +10837,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
10766
10837
_ => return Err(DecodeError::InvalidValue),
10767
10838
};
10768
10839
10769
- let mut channel_parameters: ChannelTransactionParameters = ReadableArgs::<u64>::read(reader, channel_value_satoshis)?;
10840
+ let mut channel_parameters: ChannelTransactionParameters = ReadableArgs::<Option< u64>> ::read(reader, Some( channel_value_satoshis) )?;
10770
10841
let funding_transaction: Option<Transaction> = Readable::read(reader)?;
10771
10842
10772
10843
let counterparty_cur_commitment_point = Readable::read(reader)?;
@@ -10833,6 +10904,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
10833
10904
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
10834
10905
let mut is_manual_broadcast = None;
10835
10906
10907
+ let mut pending_funding = Some(Vec::new());
10908
+
10836
10909
read_tlv_fields!(reader, {
10837
10910
(0, announcement_sigs, option),
10838
10911
(1, minimum_depth, option),
@@ -10868,6 +10941,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
10868
10941
(49, local_initiated_shutdown, option),
10869
10942
(51, is_manual_broadcast, option),
10870
10943
(53, funding_tx_broadcast_safe_event_emitted, option),
10944
+ (55, pending_funding, optional_vec), // Added in 0.2
10871
10945
});
10872
10946
10873
10947
let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -11009,6 +11083,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
11009
11083
channel_transaction_parameters: channel_parameters,
11010
11084
funding_transaction,
11011
11085
},
11086
+ pending_funding: pending_funding.unwrap(),
11012
11087
context: ChannelContext {
11013
11088
user_id,
11014
11089
0 commit comments