@@ -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};
@@ -1661,29 +1661,66 @@ pub(super) struct FundingScope {
1661
1661
funding_transaction: Option<Transaction>,
1662
1662
}
1663
1663
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)?;
1674
1670
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
+ }
1687
1724
1688
1725
impl FundingScope {
1689
1726
pub fn get_value_satoshis(&self) -> u64 {
@@ -3547,7 +3584,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3547
3584
if let Some(info) = projected_commit_tx_info {
3548
3585
let total_pending_htlcs = self.pending_inbound_htlcs.len() + self.pending_outbound_htlcs.len()
3549
3586
+ 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
3551
3588
&& info.next_holder_htlc_id == self.next_holder_htlc_id
3552
3589
&& info.next_counterparty_htlc_id == self.next_counterparty_htlc_id
3553
3590
&& info.feerate == self.feerate_per_kw {
@@ -4367,7 +4404,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4367
4404
+ context.holding_cell_htlc_updates.len();
4368
4405
let commitment_tx_info = CommitmentTxInfoCached {
4369
4406
fee,
4370
- total_pending_htlcs,
4407
+ total_pending_htlcs: total_pending_htlcs as u64 ,
4371
4408
next_holder_htlc_id: match htlc.origin {
4372
4409
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
4373
4410
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4463,7 +4500,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4463
4500
let total_pending_htlcs = context.pending_inbound_htlcs.len() + context.pending_outbound_htlcs.len();
4464
4501
let commitment_tx_info = CommitmentTxInfoCached {
4465
4502
fee,
4466
- total_pending_htlcs,
4503
+ total_pending_htlcs: total_pending_htlcs as u64 ,
4467
4504
next_holder_htlc_id: match htlc.origin {
4468
4505
HTLCInitiator::LocalOffered => context.next_holder_htlc_id + 1,
4469
4506
HTLCInitiator::RemoteOffered => context.next_holder_htlc_id,
@@ -4930,12 +4967,21 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
4930
4967
#[cfg(any(test, fuzzing))]
4931
4968
struct CommitmentTxInfoCached {
4932
4969
fee: u64,
4933
- total_pending_htlcs: usize ,
4970
+ total_pending_htlcs: u64 ,
4934
4971
next_holder_htlc_id: u64,
4935
4972
next_counterparty_htlc_id: u64,
4936
4973
feerate: u32,
4937
4974
}
4938
4975
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
+
4939
4985
/// Partial data from ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo used to simplify the
4940
4986
/// return type of `ChannelContext::validate_commitment_signed`.
4941
4987
struct LatestHolderCommitmentTXInfo {
@@ -8796,7 +8842,7 @@ impl<SP: Deref> FundedChannel<SP> where
8796
8842
*self.funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
8797
8843
if let Some(info) = projected_commit_tx_info {
8798
8844
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
8800
8846
&& info.next_holder_htlc_id == self.context.next_holder_htlc_id
8801
8847
&& info.next_counterparty_htlc_id == self.context.next_counterparty_htlc_id
8802
8848
&& info.feerate == self.context.feerate_per_kw {
0 commit comments