@@ -1751,31 +1751,59 @@ impl<Signer: Sign> Channel<Signer> {
1751
1751
}
1752
1752
1753
1753
/// Returns (inbound_htlc_count, htlc_inbound_value_msat)
1754
- fn get_inbound_pending_htlc_stats ( & self ) -> ( u32 , u64 ) {
1754
+ fn get_inbound_pending_htlc_stats ( & self ) -> ( u32 , u64 , u64 , u64 ) {
1755
1755
let mut htlc_inbound_value_msat = 0 ;
1756
+ let mut counterparty_dusted_htlc_msat = 0 ;
1757
+ let mut holder_dusted_htlc_msat = 0 ;
1758
+
1759
+ let counterparty_dust_limit_timeout_sat = ( self . feerate_per_kw as u64 * HTLC_TIMEOUT_TX_WEIGHT / 1000 ) + self . counterparty_dust_limit_satoshis ;
1760
+ let holder_dust_limit_success_sat = ( self . feerate_per_kw as u64 * HTLC_SUCCESS_TX_WEIGHT / 1000 ) + self . holder_dust_limit_satoshis ;
1756
1761
for ref htlc in self . pending_inbound_htlcs . iter ( ) {
1757
1762
htlc_inbound_value_msat += htlc. amount_msat ;
1763
+ if htlc. amount_msat / 1000 < counterparty_dust_limit_timeout_sat {
1764
+ counterparty_dusted_htlc_msat += htlc. amount_msat ;
1765
+ }
1766
+ if htlc. amount_msat / 1000 < holder_dust_limit_success_sat {
1767
+ holder_dusted_htlc_msat += htlc. amount_msat ;
1768
+ }
1758
1769
}
1759
- ( self . pending_inbound_htlcs . len ( ) as u32 , htlc_inbound_value_msat)
1770
+ ( self . pending_inbound_htlcs . len ( ) as u32 , htlc_inbound_value_msat, counterparty_dusted_htlc_msat , holder_dusted_htlc_msat )
1760
1771
}
1761
1772
1762
- /// Returns (outbound_htlc_count, htlc_outbound_value_msat) *including* pending adds in our
1763
- /// holding cell.
1764
- fn get_outbound_pending_htlc_stats ( & self ) -> ( u32 , u64 ) {
1773
+ /// Returns (outbound_htlc_count, htlc_outbound_value_msat, outbound_dusted_htlc_value_msat ) *including*
1774
+ /// pending adds in our holding cell.
1775
+ fn get_outbound_pending_htlc_stats ( & self ) -> ( u32 , u64 , u64 , u64 ) {
1765
1776
let mut htlc_outbound_value_msat = 0 ;
1777
+ let mut counterparty_dusted_htlc_msat = 0 ;
1778
+ let mut holder_dusted_htlc_msat = 0 ;
1779
+
1780
+ let counterparty_dust_limit_success_sat = ( self . feerate_per_kw as u64 * HTLC_SUCCESS_TX_WEIGHT / 1000 ) + self . counterparty_dust_limit_satoshis ;
1781
+ let holder_dust_limit_timeout_sat = ( self . feerate_per_kw as u64 * HTLC_TIMEOUT_TX_WEIGHT / 1000 ) + self . holder_dust_limit_satoshis ;
1766
1782
for ref htlc in self . pending_outbound_htlcs . iter ( ) {
1767
1783
htlc_outbound_value_msat += htlc. amount_msat ;
1784
+ if htlc. amount_msat / 1000 < counterparty_dust_limit_success_sat {
1785
+ counterparty_dusted_htlc_msat += htlc. amount_msat ;
1786
+ }
1787
+ if htlc. amount_msat / 1000 < holder_dust_limit_timeout_sat {
1788
+ holder_dusted_htlc_msat += htlc. amount_msat ;
1789
+ }
1768
1790
}
1769
1791
1770
1792
let mut htlc_outbound_count = self . pending_outbound_htlcs . len ( ) ;
1771
1793
for update in self . holding_cell_htlc_updates . iter ( ) {
1772
1794
if let & HTLCUpdateAwaitingACK :: AddHTLC { ref amount_msat, .. } = update {
1773
1795
htlc_outbound_count += 1 ;
1774
1796
htlc_outbound_value_msat += amount_msat;
1797
+ if * amount_msat / 1000 < counterparty_dust_limit_success_sat {
1798
+ counterparty_dusted_htlc_msat += amount_msat;
1799
+ }
1800
+ if * amount_msat / 1000 < holder_dust_limit_timeout_sat {
1801
+ holder_dusted_htlc_msat += amount_msat;
1802
+ }
1775
1803
}
1776
1804
}
1777
1805
1778
- ( htlc_outbound_count as u32 , htlc_outbound_value_msat)
1806
+ ( htlc_outbound_count as u32 , htlc_outbound_value_msat, counterparty_dusted_htlc_msat , holder_dusted_htlc_msat )
1779
1807
}
1780
1808
1781
1809
/// Get the available (ie not including pending HTLCs) inbound and outbound balance in msat.
@@ -2003,7 +2031,8 @@ impl<Signer: Sign> Channel<Signer> {
2003
2031
return Err ( ChannelError :: Close ( format ! ( "Remote side tried to send less than our minimum HTLC value. Lower limit: ({}). Actual: ({})" , self . holder_htlc_minimum_msat, msg. amount_msat) ) ) ;
2004
2032
}
2005
2033
2006
- let ( inbound_htlc_count, htlc_inbound_value_msat) = self . get_inbound_pending_htlc_stats ( ) ;
2034
+ let ( inbound_htlc_count, htlc_inbound_value_msat, on_counterparty_tx_dust_inbound, on_holder_tx_dust_inbound) = self . get_inbound_pending_htlc_stats ( ) ;
2035
+ let ( _, _, on_counterparty_tx_dust_outbound, on_holder_tx_dust_outbound) = self . get_outbound_pending_htlc_stats ( ) ;
2007
2036
if inbound_htlc_count + 1 > OUR_MAX_HTLCS as u32 {
2008
2037
return Err ( ChannelError :: Close ( format ! ( "Remote tried to push more than our max accepted HTLCs ({})" , OUR_MAX_HTLCS ) ) ) ;
2009
2038
}
@@ -4075,7 +4104,8 @@ impl<Signer: Sign> Channel<Signer> {
4075
4104
return Err ( ChannelError :: Ignore ( "Cannot send an HTLC while disconnected from channel counterparty" . to_owned ( ) ) ) ;
4076
4105
}
4077
4106
4078
- let ( outbound_htlc_count, htlc_outbound_value_msat) = self . get_outbound_pending_htlc_stats ( ) ;
4107
+ let ( _, _, on_counterparty_tx_dust_inbound, on_holder_tx_dust_inbound) = self . get_inbound_pending_htlc_stats ( ) ;
4108
+ let ( outbound_htlc_count, htlc_outbound_value_msat, on_counterparty_tx_dust_outbound, on_holder_tx_dust_outbound) = self . get_outbound_pending_htlc_stats ( ) ;
4079
4109
if outbound_htlc_count + 1 > self . counterparty_max_accepted_htlcs as u32 {
4080
4110
return Err ( ChannelError :: Ignore ( format ! ( "Cannot push more than their max accepted HTLCs ({})" , self . counterparty_max_accepted_htlcs) ) ) ;
4081
4111
}
0 commit comments