@@ -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};
@@ -1661,29 +1661,66 @@ pub(super) struct FundingScope {
16611661 funding_transaction: Option<Transaction>,
16621662}
16631663
1664- #[cfg(not(any(test, fuzzing)))]
1665- impl_writeable_tlv_based!(FundingScope, {
1666- (0, value_to_self_msat, required),
1667- (1, counterparty_selected_channel_reserve_satoshis, option),
1668- (2, holder_selected_channel_reserve_satoshis, required),
1669- (3, holder_max_commitment_tx_output, required),
1670- (4, counterparty_max_commitment_tx_output, required),
1671- (5, channel_transaction_parameters, (required: ReadableArgs, None)),
1672- (6, funding_transaction, option),
1673- });
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)?;
16741670
1675- #[cfg(any(test, fuzzing))]
1676- impl_writeable_tlv_based!(FundingScope, {
1677- (0, value_to_self_msat, required),
1678- (1, counterparty_selected_channel_reserve_satoshis, option),
1679- (2, holder_selected_channel_reserve_satoshis, required),
1680- (3, holder_max_commitment_tx_output, required),
1681- (4, counterparty_max_commitment_tx_output, required),
1682- (5, channel_transaction_parameters, (required: ReadableArgs, None)),
1683- (6, funding_transaction, option),
1684- (126, next_local_commitment_tx_fee_info_cached, required), // FIXME: This won't work
1685- (127, next_remote_commitment_tx_fee_info_cached, required), // FIXME: This won't work
1686- });
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.holder_max_commitment_tx_output, required),
1676+ (4, self.counterparty_max_commitment_tx_output, required),
1677+ (5, self.channel_transaction_parameters, (required: ReadableArgs, None)),
1678+ (6, self.funding_transaction, option),
1679+ });
1680+ Ok(())
1681+ }
1682+ }
1683+
1684+ impl Readable for FundingScope {
1685+ fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
1686+ let mut value_to_self_msat = RequiredWrapper(None);
1687+ let mut counterparty_selected_channel_reserve_satoshis = None;
1688+ let mut holder_selected_channel_reserve_satoshis = RequiredWrapper(None);
1689+ let mut holder_max_commitment_tx_output = RequiredWrapper(None);
1690+ let mut counterparty_max_commitment_tx_output = RequiredWrapper(None);
1691+ let mut channel_transaction_parameters = RequiredWrapper(None);
1692+ let mut funding_transaction = None;
1693+
1694+ #[cfg(any(test, fuzzing))]
1695+ let next_local_commitment_tx_fee_info_cached = Readable::read(reader)?;
1696+ #[cfg(any(test, fuzzing))]
1697+ let next_remote_commitment_tx_fee_info_cached = Readable::read(reader)?;
1698+
1699+ read_tlv_fields!(reader, {
1700+ (0, value_to_self_msat, required),
1701+ (1, counterparty_selected_channel_reserve_satoshis, option),
1702+ (2, holder_selected_channel_reserve_satoshis, required),
1703+ (3, holder_max_commitment_tx_output, required),
1704+ (4, counterparty_max_commitment_tx_output, required),
1705+ (5, channel_transaction_parameters, (required: ReadableArgs, None)),
1706+ (6, funding_transaction, option),
1707+ });
1708+
1709+ Ok(Self {
1710+ value_to_self_msat: value_to_self_msat.0.unwrap(),
1711+ counterparty_selected_channel_reserve_satoshis,
1712+ holder_selected_channel_reserve_satoshis: holder_selected_channel_reserve_satoshis.0.unwrap(),
1713+ holder_max_commitment_tx_output: holder_max_commitment_tx_output.0.unwrap(),
1714+ counterparty_max_commitment_tx_output: counterparty_max_commitment_tx_output.0.unwrap(),
1715+ channel_transaction_parameters: channel_transaction_parameters.0.unwrap(),
1716+ funding_transaction,
1717+ #[cfg(any(test, fuzzing))]
1718+ next_local_commitment_tx_fee_info_cached,
1719+ #[cfg(any(test, fuzzing))]
1720+ next_remote_commitment_tx_fee_info_cached,
1721+ })
1722+ }
1723+ }
16871724
16881725impl FundingScope {
16891726 pub fn get_value_satoshis(&self) -> u64 {
@@ -3547,7 +3584,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35473584 if let Some(info) = projected_commit_tx_info {
35483585 let total_pending_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len()
35493586 + self.holding_cell_htlc_updates.len();
3550- if info.total_pending_htlcs == total_pending_htlcs
3587+ if info.total_pending_htlcs == total_pending_htlcs as u64
35513588 && info.next_holder_htlc_id == self.next_holder_htlc_id
35523589 && info.next_counterparty_htlc_id == self.next_counterparty_htlc_id
35533590 && info.feerate == self.feerate_per_kw {
@@ -4367,7 +4404,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
43674404 + context.holding_cell_htlc_updates.len();
43684405 let commitment_tx_info = CommitmentTxInfoCached {
43694406 fee,
4370- total_pending_htlcs,
4407+ total_pending_htlcs: total_pending_htlcs as u64 ,
43714408 next_holder_htlc_id: match htlc.origin {
43724409 HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
43734410 HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4463,7 +4500,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
44634500 let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
44644501 let commitment_tx_info = CommitmentTxInfoCached {
44654502 fee,
4466- total_pending_htlcs,
4503+ total_pending_htlcs: total_pending_htlcs as u64 ,
44674504 next_holder_htlc_id: match htlc.origin {
44684505 HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
44694506 HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4930,12 +4967,21 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
49304967#[cfg(any(test, fuzzing))]
49314968struct CommitmentTxInfoCached {
49324969 fee: u64,
4933- total_pending_htlcs: usize ,
4970+ total_pending_htlcs: u64 ,
49344971 next_holder_htlc_id: u64,
49354972 next_counterparty_htlc_id: u64,
49364973 feerate: u32,
49374974}
49384975
4976+ #[cfg(any(test, fuzzing))]
4977+ impl_writeable_tlv_based!(CommitmentTxInfoCached, {
4978+ (0, fee, required),
4979+ (1, total_pending_htlcs, required),
4980+ (2, next_holder_htlc_id, required),
4981+ (3, next_counterparty_htlc_id, required),
4982+ (4, feerate, required),
4983+ });
4984+
49394985/// Partial data from ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo used to simplify the
49404986/// return type of `ChannelContext::validate_commitment_signed`.
49414987struct LatestHolderCommitmentTXInfo {
@@ -8796,7 +8842,7 @@ impl<SP: Deref> FundedChannel<SP> where
87968842 *self.funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
87978843 if let Some(info) = projected_commit_tx_info {
87988844 let total_pending_htlcs = self.context.pending_inbound_htlcs.len() + self.context.pending_outbound_htlcs.len();
8799- if info.total_pending_htlcs == total_pending_htlcs
8845+ if info.total_pending_htlcs == total_pending_htlcs as u64
88008846 && info.next_holder_htlc_id == self.context.next_holder_htlc_id
88018847 && info.next_counterparty_htlc_id == self.context.next_counterparty_htlc_id
88028848 && info.feerate == self.context.feerate_per_kw {
0 commit comments