Skip to content

Commit 9d8d24f

Browse files
authored
Merge pull request #1009 from ariard/2021-07-add-forward-dust-limit
Add new config setting `max_balance_dust_htlc_msat`
2 parents d4b6f58 + 730f6f3 commit 9d8d24f

File tree

6 files changed

+297
-41
lines changed

6 files changed

+297
-41
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ fn check_api_err(api_err: APIError) {
247247
_ if err.starts_with("Cannot send value that would put counterparty balance under holder-announced channel reserve value") => {},
248248
_ if err.starts_with("Cannot send value that would overdraw remaining funds.") => {},
249249
_ if err.starts_with("Cannot send value that would not leave enough to pay for fees.") => {},
250+
_ if err.starts_with("Cannot send value that would put our exposure to dust HTLCs at") => {},
250251
_ => panic!("{}", err),
251252
}
252253
},

lightning/src/ln/channel.rs

Lines changed: 117 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ enum HTLCInitiator {
275275
RemoteOffered,
276276
}
277277

278+
/// An enum gathering stats on pending HTLCs, either inbound or outbound side.
279+
struct HTLCStats {
280+
pending_htlcs: u32,
281+
pending_htlcs_value_msat: u64,
282+
on_counterparty_tx_dust_exposure_msat: u64,
283+
on_holder_tx_dust_exposure_msat: u64,
284+
}
285+
278286
/// Used when calculating whether we or the remote can afford an additional HTLC.
279287
struct HTLCCandidate {
280288
amount_msat: u64,
@@ -1842,32 +1850,63 @@ impl<Signer: Sign> Channel<Signer> {
18421850
Ok(())
18431851
}
18441852

1845-
/// Returns (inbound_htlc_count, htlc_inbound_value_msat)
1846-
fn get_inbound_pending_htlc_stats(&self) -> (u32, u64) {
1847-
let mut htlc_inbound_value_msat = 0;
1853+
/// Returns a HTLCStats about inbound pending htlcs
1854+
fn get_inbound_pending_htlc_stats(&self) -> HTLCStats {
1855+
let mut stats = HTLCStats {
1856+
pending_htlcs: self.pending_inbound_htlcs.len() as u32,
1857+
pending_htlcs_value_msat: 0,
1858+
on_counterparty_tx_dust_exposure_msat: 0,
1859+
on_holder_tx_dust_exposure_msat: 0,
1860+
};
1861+
1862+
let counterparty_dust_limit_timeout_sat = (self.get_dust_buffer_feerate() as u64 * HTLC_TIMEOUT_TX_WEIGHT / 1000) + self.counterparty_dust_limit_satoshis;
1863+
let holder_dust_limit_success_sat = (self.get_dust_buffer_feerate() as u64 * HTLC_SUCCESS_TX_WEIGHT / 1000) + self.holder_dust_limit_satoshis;
18481864
for ref htlc in self.pending_inbound_htlcs.iter() {
1849-
htlc_inbound_value_msat += htlc.amount_msat;
1865+
stats.pending_htlcs_value_msat += htlc.amount_msat;
1866+
if htlc.amount_msat / 1000 < counterparty_dust_limit_timeout_sat {
1867+
stats.on_counterparty_tx_dust_exposure_msat += htlc.amount_msat;
1868+
}
1869+
if htlc.amount_msat / 1000 < holder_dust_limit_success_sat {
1870+
stats.on_holder_tx_dust_exposure_msat += htlc.amount_msat;
1871+
}
18501872
}
1851-
(self.pending_inbound_htlcs.len() as u32, htlc_inbound_value_msat)
1873+
stats
18521874
}
18531875

1854-
/// Returns (outbound_htlc_count, htlc_outbound_value_msat) *including* pending adds in our
1855-
/// holding cell.
1856-
fn get_outbound_pending_htlc_stats(&self) -> (u32, u64) {
1857-
let mut htlc_outbound_value_msat = 0;
1876+
/// Returns a HTLCStats about pending outbound htlcs, *including* pending adds in our holding cell.
1877+
fn get_outbound_pending_htlc_stats(&self) -> HTLCStats {
1878+
let mut stats = HTLCStats {
1879+
pending_htlcs: self.pending_outbound_htlcs.len() as u32,
1880+
pending_htlcs_value_msat: 0,
1881+
on_counterparty_tx_dust_exposure_msat: 0,
1882+
on_holder_tx_dust_exposure_msat: 0,
1883+
};
1884+
1885+
let counterparty_dust_limit_success_sat = (self.get_dust_buffer_feerate() as u64 * HTLC_SUCCESS_TX_WEIGHT / 1000) + self.counterparty_dust_limit_satoshis;
1886+
let holder_dust_limit_timeout_sat = (self.get_dust_buffer_feerate() as u64 * HTLC_TIMEOUT_TX_WEIGHT / 1000) + self.holder_dust_limit_satoshis;
18581887
for ref htlc in self.pending_outbound_htlcs.iter() {
1859-
htlc_outbound_value_msat += htlc.amount_msat;
1888+
stats.pending_htlcs_value_msat += htlc.amount_msat;
1889+
if htlc.amount_msat / 1000 < counterparty_dust_limit_success_sat {
1890+
stats.on_counterparty_tx_dust_exposure_msat += htlc.amount_msat;
1891+
}
1892+
if htlc.amount_msat / 1000 < holder_dust_limit_timeout_sat {
1893+
stats.on_holder_tx_dust_exposure_msat += htlc.amount_msat;
1894+
}
18601895
}
18611896

1862-
let mut htlc_outbound_count = self.pending_outbound_htlcs.len();
18631897
for update in self.holding_cell_htlc_updates.iter() {
18641898
if let &HTLCUpdateAwaitingACK::AddHTLC { ref amount_msat, .. } = update {
1865-
htlc_outbound_count += 1;
1866-
htlc_outbound_value_msat += amount_msat;
1899+
stats.pending_htlcs += 1;
1900+
stats.pending_htlcs_value_msat += amount_msat;
1901+
if *amount_msat / 1000 < counterparty_dust_limit_success_sat {
1902+
stats.on_counterparty_tx_dust_exposure_msat += amount_msat;
1903+
}
1904+
if *amount_msat / 1000 < holder_dust_limit_timeout_sat {
1905+
stats.on_holder_tx_dust_exposure_msat += amount_msat;
1906+
}
18671907
}
18681908
}
1869-
1870-
(htlc_outbound_count as u32, htlc_outbound_value_msat)
1909+
stats
18711910
}
18721911

18731912
/// Get the available (ie not including pending HTLCs) inbound and outbound balance in msat.
@@ -1879,11 +1918,11 @@ impl<Signer: Sign> Channel<Signer> {
18791918
(
18801919
cmp::max(self.channel_value_satoshis as i64 * 1000
18811920
- self.value_to_self_msat as i64
1882-
- self.get_inbound_pending_htlc_stats().1 as i64
1921+
- self.get_inbound_pending_htlc_stats().pending_htlcs_value_msat as i64
18831922
- Self::get_holder_selected_channel_reserve_satoshis(self.channel_value_satoshis) as i64 * 1000,
18841923
0) as u64,
18851924
cmp::max(self.value_to_self_msat as i64
1886-
- self.get_outbound_pending_htlc_stats().1 as i64
1925+
- self.get_outbound_pending_htlc_stats().pending_htlcs_value_msat as i64
18871926
- self.counterparty_selected_channel_reserve_satoshis.unwrap_or(0) as i64 * 1000,
18881927
0) as u64
18891928
)
@@ -2095,12 +2134,13 @@ impl<Signer: Sign> Channel<Signer> {
20952134
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)));
20962135
}
20972136

2098-
let (inbound_htlc_count, htlc_inbound_value_msat) = self.get_inbound_pending_htlc_stats();
2099-
if inbound_htlc_count + 1 > OUR_MAX_HTLCS as u32 {
2137+
let inbound_stats = self.get_inbound_pending_htlc_stats();
2138+
let outbound_stats = self.get_outbound_pending_htlc_stats();
2139+
if inbound_stats.pending_htlcs + 1 > OUR_MAX_HTLCS as u32 {
21002140
return Err(ChannelError::Close(format!("Remote tried to push more than our max accepted HTLCs ({})", OUR_MAX_HTLCS)));
21012141
}
21022142
let holder_max_htlc_value_in_flight_msat = Channel::<Signer>::get_holder_max_htlc_value_in_flight_msat(self.channel_value_satoshis);
2103-
if htlc_inbound_value_msat + msg.amount_msat > holder_max_htlc_value_in_flight_msat {
2143+
if inbound_stats.pending_htlcs_value_msat + msg.amount_msat > holder_max_htlc_value_in_flight_msat {
21042144
return Err(ChannelError::Close(format!("Remote HTLC add would put them over our max HTLC value ({})", holder_max_htlc_value_in_flight_msat)));
21052145
}
21062146
// Check holder_selected_channel_reserve_satoshis (we're getting paid, so they have to at least meet
@@ -2124,8 +2164,28 @@ impl<Signer: Sign> Channel<Signer> {
21242164
}
21252165
}
21262166

2167+
let exposure_dust_limit_timeout_sats = (self.get_dust_buffer_feerate() as u64 * HTLC_TIMEOUT_TX_WEIGHT / 1000) + self.counterparty_dust_limit_satoshis;
2168+
if msg.amount_msat / 1000 < exposure_dust_limit_timeout_sats {
2169+
let on_counterparty_tx_dust_htlc_exposure_msat = inbound_stats.on_counterparty_tx_dust_exposure_msat + outbound_stats.on_counterparty_tx_dust_exposure_msat + msg.amount_msat;
2170+
if on_counterparty_tx_dust_htlc_exposure_msat > self.get_max_dust_htlc_exposure_msat() {
2171+
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx",
2172+
on_counterparty_tx_dust_htlc_exposure_msat, self.get_max_dust_htlc_exposure_msat());
2173+
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x1000|7);
2174+
}
2175+
}
2176+
2177+
let exposure_dust_limit_success_sats = (self.get_dust_buffer_feerate() as u64 * HTLC_SUCCESS_TX_WEIGHT / 1000) + self.holder_dust_limit_satoshis;
2178+
if msg.amount_msat / 1000 < exposure_dust_limit_success_sats {
2179+
let on_holder_tx_dust_htlc_exposure_msat = inbound_stats.on_holder_tx_dust_exposure_msat + outbound_stats.on_holder_tx_dust_exposure_msat + msg.amount_msat;
2180+
if on_holder_tx_dust_htlc_exposure_msat > self.get_max_dust_htlc_exposure_msat() {
2181+
log_info!(logger, "Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
2182+
on_holder_tx_dust_htlc_exposure_msat, self.get_max_dust_htlc_exposure_msat());
2183+
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x1000|7);
2184+
}
2185+
}
2186+
21272187
let pending_value_to_self_msat =
2128-
self.value_to_self_msat + htlc_inbound_value_msat - removed_outbound_total_msat;
2188+
self.value_to_self_msat + inbound_stats.pending_htlcs_value_msat - removed_outbound_total_msat;
21292189
let pending_remote_value_msat =
21302190
self.channel_value_satoshis * 1000 - pending_value_to_self_msat;
21312191
if pending_remote_value_msat < msg.amount_msat {
@@ -3558,11 +3618,24 @@ impl<Signer: Sign> Channel<Signer> {
35583618
cmp::max(self.config.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
35593619
}
35603620

3621+
pub fn get_max_dust_htlc_exposure_msat(&self) -> u64 {
3622+
self.config.max_dust_htlc_exposure_msat
3623+
}
3624+
35613625
#[cfg(test)]
35623626
pub fn get_feerate(&self) -> u32 {
35633627
self.feerate_per_kw
35643628
}
35653629

3630+
pub fn get_dust_buffer_feerate(&self) -> u32 {
3631+
// When calculating our exposure to dust HTLCs, we assume that the channel feerate
3632+
// may, at any point, increase by at least 10 sat/vB (i.e 2530 sat/kWU) or 25%,
3633+
// whichever is higher. This ensures that we aren't suddenly exposed to significantly
3634+
// more dust balance if the feerate increases when we have several HTLCs pending
3635+
// which are near the dust limit.
3636+
cmp::max(2530, self.feerate_per_kw * 1250 / 1000)
3637+
}
3638+
35663639
pub fn get_cur_holder_commitment_transaction_number(&self) -> u64 {
35673640
self.cur_holder_commitment_transaction_number + 1
35683641
}
@@ -4207,12 +4280,13 @@ impl<Signer: Sign> Channel<Signer> {
42074280
return Err(ChannelError::Ignore("Cannot send an HTLC while disconnected from channel counterparty".to_owned()));
42084281
}
42094282

4210-
let (outbound_htlc_count, htlc_outbound_value_msat) = self.get_outbound_pending_htlc_stats();
4211-
if outbound_htlc_count + 1 > self.counterparty_max_accepted_htlcs as u32 {
4283+
let inbound_stats = self.get_inbound_pending_htlc_stats();
4284+
let outbound_stats = self.get_outbound_pending_htlc_stats();
4285+
if outbound_stats.pending_htlcs + 1 > self.counterparty_max_accepted_htlcs as u32 {
42124286
return Err(ChannelError::Ignore(format!("Cannot push more than their max accepted HTLCs ({})", self.counterparty_max_accepted_htlcs)));
42134287
}
42144288
// Check their_max_htlc_value_in_flight_msat
4215-
if htlc_outbound_value_msat + amount_msat > self.counterparty_max_htlc_value_in_flight_msat {
4289+
if outbound_stats.pending_htlcs_value_msat + amount_msat > self.counterparty_max_htlc_value_in_flight_msat {
42164290
return Err(ChannelError::Ignore(format!("Cannot send value that would put us over the max HTLC value in flight our peer will accept ({})", self.counterparty_max_htlc_value_in_flight_msat)));
42174291
}
42184292

@@ -4227,7 +4301,25 @@ impl<Signer: Sign> Channel<Signer> {
42274301
}
42284302
}
42294303

4230-
let pending_value_to_self_msat = self.value_to_self_msat - htlc_outbound_value_msat;
4304+
let exposure_dust_limit_success_sats = (self.get_dust_buffer_feerate() as u64 * HTLC_SUCCESS_TX_WEIGHT / 1000) + self.counterparty_dust_limit_satoshis;
4305+
if amount_msat / 1000 < exposure_dust_limit_success_sats {
4306+
let on_counterparty_dust_htlc_exposure_msat = inbound_stats.on_counterparty_tx_dust_exposure_msat + outbound_stats.on_counterparty_tx_dust_exposure_msat + amount_msat;
4307+
if on_counterparty_dust_htlc_exposure_msat > self.get_max_dust_htlc_exposure_msat() {
4308+
return Err(ChannelError::Ignore(format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx",
4309+
on_counterparty_dust_htlc_exposure_msat, self.get_max_dust_htlc_exposure_msat())));
4310+
}
4311+
}
4312+
4313+
let exposure_dust_limit_timeout_sats = (self.get_dust_buffer_feerate() as u64 * HTLC_TIMEOUT_TX_WEIGHT / 1000) + self.holder_dust_limit_satoshis;
4314+
if amount_msat / 1000 < exposure_dust_limit_timeout_sats {
4315+
let on_holder_dust_htlc_exposure_msat = inbound_stats.on_holder_tx_dust_exposure_msat + outbound_stats.on_holder_tx_dust_exposure_msat + amount_msat;
4316+
if on_holder_dust_htlc_exposure_msat > self.get_max_dust_htlc_exposure_msat() {
4317+
return Err(ChannelError::Ignore(format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx",
4318+
on_holder_dust_htlc_exposure_msat, self.get_max_dust_htlc_exposure_msat())));
4319+
}
4320+
}
4321+
4322+
let pending_value_to_self_msat = self.value_to_self_msat - outbound_stats.pending_htlcs_value_msat;
42314323
if pending_value_to_self_msat < amount_msat {
42324324
return Err(ChannelError::Ignore(format!("Cannot send value that would overdraw remaining funds. Amount: {}, pending value to self {}", amount_msat, pending_value_to_self_msat)));
42334325
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,9 @@ pub fn test_default_channel_config() -> UserConfig {
13941394
// When most of our tests were written, the default HTLC minimum was fixed at 1000.
13951395
// It now defaults to 1, so we simply set it to the expected value here.
13961396
default_config.own_channel_config.our_htlc_minimum_msat = 1000;
1397+
// When most of our tests were written, we didn't have the notion of a `max_dust_htlc_exposure_msat`,
1398+
// It now defaults to 5_000_000 msat; to avoid interfering with tests we bump it to 50_000_000 msat.
1399+
default_config.channel_options.max_dust_htlc_exposure_msat = 50_000_000;
13971400
default_config
13981401
}
13991402

lightning/src/ln/functional_tests.rs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9764,3 +9764,116 @@ fn test_keysend_payments_to_private_node() {
97649764
pass_along_path(&nodes[0], &path, 10000, payment_hash, None, event, true, Some(test_preimage));
97659765
claim_payment(&nodes[0], &path, test_preimage);
97669766
}
9767+
9768+
fn do_test_max_dust_htlc_exposure(dust_outbound_balance: bool, at_forward: bool, on_holder_tx: bool) {
9769+
// Test that we properly reject dust HTLC violating our `max_dust_htlc_exposure_msat` policy.
9770+
//
9771+
// At HTLC forward (`send_payment()`), if the sum of the trimmed-to-dust HTLC inbound and
9772+
// trimmed-to-dust HTLC outbound balance and this new payment as included on next counterparty
9773+
// commitment are above our `max_dust_htlc_exposure_msat`, we'll reject the update.
9774+
// At HTLC reception (`update_add_htlc()`), if the sum of the trimmed-to-dust HTLC inbound
9775+
// and trimmed-to-dust HTLC outbound balance and this new received HTLC as included on next
9776+
// counterparty commitment are above our `max_dust_htlc_exposure_msat`, we'll fail the update.
9777+
// Note, we return a `temporary_channel_failure` (0x1000 | 7), as the channel might be
9778+
// available again for HTLC processing once the dust bandwidth has cleared up.
9779+
9780+
let chanmon_cfgs = create_chanmon_cfgs(2);
9781+
let mut config = test_default_channel_config();
9782+
config.channel_options.max_dust_htlc_exposure_msat = 5_000_000; // default setting value
9783+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
9784+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(config)]);
9785+
let mut nodes = create_network(2, &node_cfgs, &node_chanmgrs);
9786+
9787+
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), 1_000_000, 500_000_000, 42, None).unwrap();
9788+
let mut open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
9789+
open_channel.max_htlc_value_in_flight_msat = 50_000_000;
9790+
open_channel.max_accepted_htlcs = 60;
9791+
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &open_channel);
9792+
let mut accept_channel = get_event_msg!(nodes[1], MessageSendEvent::SendAcceptChannel, nodes[0].node.get_our_node_id());
9793+
if on_holder_tx {
9794+
accept_channel.dust_limit_satoshis = 660;
9795+
}
9796+
nodes[0].node.handle_accept_channel(&nodes[1].node.get_our_node_id(), InitFeatures::known(), &accept_channel);
9797+
9798+
let (temporary_channel_id, tx, _) = create_funding_transaction(&nodes[0], 1_000_000, 42);
9799+
9800+
if on_holder_tx {
9801+
if let Some(mut chan) = nodes[1].node.channel_state.lock().unwrap().by_id.get_mut(&temporary_channel_id) {
9802+
chan.holder_dust_limit_satoshis = 660;
9803+
}
9804+
}
9805+
9806+
nodes[0].node.funding_transaction_generated(&temporary_channel_id, tx.clone()).unwrap();
9807+
nodes[1].node.handle_funding_created(&nodes[0].node.get_our_node_id(), &get_event_msg!(nodes[0], MessageSendEvent::SendFundingCreated, nodes[1].node.get_our_node_id()));
9808+
check_added_monitors!(nodes[1], 1);
9809+
9810+
nodes[0].node.handle_funding_signed(&nodes[1].node.get_our_node_id(), &get_event_msg!(nodes[1], MessageSendEvent::SendFundingSigned, nodes[0].node.get_our_node_id()));
9811+
check_added_monitors!(nodes[0], 1);
9812+
9813+
let (funding_locked, _) = create_chan_between_nodes_with_value_confirm(&nodes[0], &nodes[1], &tx);
9814+
let (announcement, as_update, bs_update) = create_chan_between_nodes_with_value_b(&nodes[0], &nodes[1], &funding_locked);
9815+
update_nodes_with_chan_announce(&nodes, 0, 1, &announcement, &as_update, &bs_update);
9816+
9817+
if on_holder_tx {
9818+
if dust_outbound_balance {
9819+
for i in 0..2 {
9820+
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 2_300_000);
9821+
if let Err(_) = nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret)) { panic!("Unexpected event at dust HTLC {}", i); }
9822+
}
9823+
} else {
9824+
for _ in 0..2 {
9825+
route_payment(&nodes[0], &[&nodes[1]], 2_300_000);
9826+
}
9827+
}
9828+
} else {
9829+
if dust_outbound_balance {
9830+
for i in 0..25 {
9831+
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], 200_000); // + 177_000 msat of HTLC-success tx at 253 sats/kWU
9832+
if let Err(_) = nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret)) { panic!("Unexpected event at dust HTLC {}", i); }
9833+
}
9834+
} else {
9835+
for _ in 0..25 {
9836+
route_payment(&nodes[0], &[&nodes[1]], 200_000); // + 167_000 msat of HTLC-timeout tx at 253 sats/kWU
9837+
}
9838+
}
9839+
}
9840+
9841+
if at_forward {
9842+
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[1], nodes[0], if on_holder_tx { 2_300_000 } else { 200_000 });
9843+
let mut config = UserConfig::default();
9844+
if on_holder_tx {
9845+
unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", 6_900_000, config.channel_options.max_dust_htlc_exposure_msat)));
9846+
} else {
9847+
unwrap_send_err!(nodes[1].node.send_payment(&route, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable { ref err }, assert_eq!(err, &format!("Cannot send value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", 5_200_000, config.channel_options.max_dust_htlc_exposure_msat)));
9848+
}
9849+
} else {
9850+
let (route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1 ], if on_holder_tx { 2_300_000 } else { 200_000 });
9851+
nodes[0].node.send_payment(&route, payment_hash, &Some(payment_secret)).unwrap();
9852+
check_added_monitors!(nodes[0], 1);
9853+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
9854+
assert_eq!(events.len(), 1);
9855+
let payment_event = SendEvent::from_event(events.remove(0));
9856+
nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &payment_event.msgs[0]);
9857+
if on_holder_tx {
9858+
nodes[1].logger.assert_log("lightning::ln::channel".to_string(), format!("Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on holder commitment tx", 6_900_000, config.channel_options.max_dust_htlc_exposure_msat), 1);
9859+
} else {
9860+
nodes[1].logger.assert_log("lightning::ln::channel".to_string(), format!("Cannot accept value that would put our exposure to dust HTLCs at {} over the limit {} on counterparty commitment tx", 5_200_000, config.channel_options.max_dust_htlc_exposure_msat), 1);
9861+
}
9862+
}
9863+
9864+
let _ = nodes[1].node.get_and_clear_pending_msg_events();
9865+
let mut added_monitors = nodes[1].chain_monitor.added_monitors.lock().unwrap();
9866+
added_monitors.clear();
9867+
}
9868+
9869+
#[test]
9870+
fn test_max_dust_htlc_exposure() {
9871+
do_test_max_dust_htlc_exposure(true, true, true);
9872+
do_test_max_dust_htlc_exposure(false, true, true);
9873+
do_test_max_dust_htlc_exposure(false, false, true);
9874+
do_test_max_dust_htlc_exposure(false, false, false);
9875+
do_test_max_dust_htlc_exposure(true, true, false);
9876+
do_test_max_dust_htlc_exposure(true, false, false);
9877+
do_test_max_dust_htlc_exposure(true, false, true);
9878+
do_test_max_dust_htlc_exposure(false, true, false);
9879+
}

0 commit comments

Comments
 (0)