@@ -60,7 +60,7 @@ use crate::sign::{EntropySource, ChannelSigner, SignerProvider, NodeSigner, Reci
6060use crate::events::{ClosureReason, Event};
6161use crate::events::bump_transaction::BASE_INPUT_WEIGHT;
6262use 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};
6464use crate::util::logger::{Logger, Record, WithContext};
6565use crate::util::errors::APIError;
6666use crate::util::config::{UserConfig, ChannelConfig, LegacyChannelConfig, ChannelHandshakeConfig, ChannelHandshakeLimits, MaxDustHTLCExposure};
@@ -1517,6 +1517,7 @@ impl<SP: Deref> Channel<SP> where
15171517 };
15181518 let mut funded_channel = FundedChannel {
15191519 funding: chan.funding,
1520+ pending_funding: vec![],
15201521 context: chan.context,
15211522 interactive_tx_signing_session: chan.interactive_tx_signing_session,
15221523 holder_commitment_point,
@@ -1663,6 +1664,53 @@ pub(super) struct FundingScope {
16631664 funding_transaction: Option<Transaction>,
16641665}
16651666
1667+ impl Writeable for FundingScope {
1668+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
1669+ write_tlv_fields!(writer, {
1670+ (1, self.value_to_self_msat, required),
1671+ (3, self.counterparty_selected_channel_reserve_satoshis, option),
1672+ (5, self.holder_selected_channel_reserve_satoshis, required),
1673+ (7, self.channel_transaction_parameters, (required: ReadableArgs, None)),
1674+ (9, self.funding_transaction, option),
1675+ });
1676+ Ok(())
1677+ }
1678+ }
1679+
1680+ impl Readable for FundingScope {
1681+ fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
1682+ let mut value_to_self_msat = RequiredWrapper(None);
1683+ let mut counterparty_selected_channel_reserve_satoshis = None;
1684+ let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
1685+ let mut channel_transaction_parameters = RequiredWrapper(None);
1686+ let mut funding_transaction = None;
1687+
1688+ read_tlv_fields!(reader, {
1689+ (1, value_to_self_msat, required),
1690+ (3, counterparty_selected_channel_reserve_satoshis, option),
1691+ (5, holder_selected_channel_reserve_satoshis, required),
1692+ (7, channel_transaction_parameters, (required: ReadableArgs, None)),
1693+ (9, funding_transaction, option),
1694+ });
1695+
1696+ Ok(Self {
1697+ value_to_self_msat: value_to_self_msat.0.unwrap(),
1698+ counterparty_selected_channel_reserve_satoshis,
1699+ holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.0.unwrap(),
1700+ #[cfg(debug_assertions)]
1701+ holder_max_commitment_tx_output: Mutex::new((0, 0)),
1702+ #[cfg(debug_assertions)]
1703+ counterparty_max_commitment_tx_output: Mutex::new((0, 0)),
1704+ channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
1705+ funding_transaction,
1706+ #[cfg(any(test, fuzzing))]
1707+ next_local_commitment_tx_fee_info_cached: Mutex::new(None),
1708+ #[cfg(any(test, fuzzing))]
1709+ next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
1710+ })
1711+ }
1712+ }
1713+
16661714impl FundingScope {
16671715 pub fn get_value_satoshis(&self) -> u64 {
16681716 self.channel_transaction_parameters.channel_value_satoshis
@@ -4319,7 +4367,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43194367 + context.holding_cell_htlc_updates.len();
43204368 let commitment_tx_info = CommitmentTxInfoCached {
43214369 fee,
4322- total_pending_htlcs,
4370+ total_pending_htlcs: total_pending_htlcs ,
43234371 next_holder_htlc_id: match htlc.origin {
43244372 HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
43254373 HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4415,7 +4463,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44154463 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
44164464 let commitment_tx_info = CommitmentTxInfoCached {
44174465 fee,
4418- total_pending_htlcs,
4466+ total_pending_htlcs: total_pending_htlcs ,
44194467 next_holder_htlc_id: match htlc.origin {
44204468 HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
44214469 HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4868,6 +4916,7 @@ pub(super) struct DualFundingChannelContext {
48684916// Counterparty designates channel data owned by the another channel participant entity.
48694917pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
48704918 pub funding: FundingScope,
4919+ pending_funding: Vec<FundingScope>,
48714920 pub context: ChannelContext<SP>,
48724921 pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
48734922 holder_commitment_point: HolderCommitmentPoint,
@@ -9455,6 +9504,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
94559504
94569505 let mut channel = FundedChannel {
94579506 funding: self.funding,
9507+ pending_funding: vec![],
94589508 context: self.context,
94599509 interactive_tx_signing_session: None,
94609510 is_v2_established: false,
@@ -9731,6 +9781,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
97319781 // `ChannelMonitor`.
97329782 let mut channel = FundedChannel {
97339783 funding: self.funding,
9784+ pending_funding: vec![],
97349785 context: self.context,
97359786 interactive_tx_signing_session: None,
97369787 is_v2_established: false,
@@ -10525,6 +10576,7 @@ impl<SP: Deref> Writeable for FundedChannel<SP> where SP::Target: SignerProvider
1052510576 (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
1052610577 (51, is_manual_broadcast, option), // Added in 0.0.124
1052710578 (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
10579+ (54, self.pending_funding, optional_vec), // Added in 0.2
1052810580 });
1052910581
1053010582 Ok(())
@@ -10749,7 +10801,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1074910801 _ => return Err(DecodeError::InvalidValue),
1075010802 };
1075110803
10752- let mut channel_parameters: ChannelTransactionParameters = ReadableArgs::<u64>::read(reader, channel_value_satoshis)?;
10804+ let mut channel_parameters: ChannelTransactionParameters = ReadableArgs::<Option< u64>> ::read(reader, Some( channel_value_satoshis) )?;
1075310805 let funding_transaction: Option<Transaction> = Readable::read(reader)?;
1075410806
1075510807 let counterparty_cur_commitment_point = Readable::read(reader)?;
@@ -10816,6 +10868,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1081610868 let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
1081710869 let mut is_manual_broadcast = None;
1081810870
10871+ let mut pending_funding = Some(Vec::new());
10872+
1081910873 read_tlv_fields!(reader, {
1082010874 (0, announcement_sigs, option),
1082110875 (1, minimum_depth, option),
@@ -10851,6 +10905,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1085110905 (49, local_initiated_shutdown, option),
1085210906 (51, is_manual_broadcast, option),
1085310907 (53, funding_tx_broadcast_safe_event_emitted, option),
10908+ (54, pending_funding, optional_vec), // Added in 0.2
1085410909 });
1085510910
1085610911 let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
@@ -10992,6 +11047,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c Channel
1099211047 channel_transaction_parameters: channel_parameters,
1099311048 funding_transaction,
1099411049 },
11050+ pending_funding: pending_funding.unwrap(),
1099511051 context: ChannelContext {
1099611052 user_id,
1099711053
0 commit comments