Skip to content

Commit 1d6c09a

Browse files
author
Antoine Riard
committed
Clarify policy applied in send htlc error msgs
max_htlc_value_in_flight_msat is applied per-direction
1 parent fd26091 commit 1d6c09a

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

src/ln/channel.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,10 +1590,9 @@ impl Channel {
15901590
if inbound_htlc_count + 1 > OUR_MAX_HTLCS as u32 {
15911591
return Err(ChannelError::Close("Remote tried to push more than our max accepted HTLCs"));
15921592
}
1593-
//TODO: Spec is unclear if this is per-direction or in total (I assume per direction):
15941593
// Check our_max_htlc_value_in_flight_msat
15951594
if htlc_inbound_value_msat + msg.amount_msat > Channel::get_our_max_htlc_value_in_flight_msat(self.channel_value_satoshis) {
1596-
return Err(ChannelError::Close("Remote HTLC add would put them over their max HTLC value in flight"));
1595+
return Err(ChannelError::Close("Remote HTLC add would put them over our max HTLC value"));
15971596
}
15981597
// Check our_channel_reserve_satoshis (we're getting paid, so they have to at least meet
15991598
// the reserve_satoshis we told them to always have as direct payment so that they lose
@@ -3214,16 +3213,15 @@ impl Channel {
32143213
if outbound_htlc_count + 1 > self.their_max_accepted_htlcs as u32 {
32153214
return Err(ChannelError::Ignore("Cannot push more than their max accepted HTLCs"));
32163215
}
3217-
//TODO: Spec is unclear if this is per-direction or in total (I assume per direction):
32183216
// Check their_max_htlc_value_in_flight_msat
32193217
if htlc_outbound_value_msat + amount_msat > self.their_max_htlc_value_in_flight_msat {
3220-
return Err(ChannelError::Ignore("Cannot send value that would put us over the max HTLC value in flight"));
3218+
return Err(ChannelError::Ignore("Cannot send value that would put us over the max HTLC value in flight our peer will accept"));
32213219
}
32223220

32233221
// Check self.their_channel_reserve_satoshis (the amount we must keep as
32243222
// reserve for them to have something to claim if we misbehave)
32253223
if self.value_to_self_msat < self.their_channel_reserve_satoshis * 1000 + amount_msat + htlc_outbound_value_msat {
3226-
return Err(ChannelError::Ignore("Cannot send value that would put us over the reserve value"));
3224+
return Err(ChannelError::Ignore("Cannot send value that would put us over their reserve value"));
32273225
}
32283226

32293227
//TODO: Check cltv_expiry? Do this in channel manager?

src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ pub fn route_over_limit(origin_node: &Node, expected_route: &[&Node], recv_value
702702

703703
let err = origin_node.node.send_payment(route, our_payment_hash).err().unwrap();
704704
match err {
705-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight"),
705+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept"),
706706
_ => panic!("Unknown error variants"),
707707
};
708708
}

src/ln/functional_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,7 @@ fn do_channel_reserve_test(test_recv: bool) {
12351235
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
12361236
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
12371237
match err {
1238-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight"),
1238+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept"),
12391239
_ => panic!("Unknown error variants"),
12401240
}
12411241
}
@@ -1271,7 +1271,7 @@ fn do_channel_reserve_test(test_recv: bool) {
12711271
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
12721272
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
12731273
match err {
1274-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the reserve value"),
1274+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over their reserve value"),
12751275
_ => panic!("Unknown error variants"),
12761276
}
12771277
}
@@ -1296,7 +1296,7 @@ fn do_channel_reserve_test(test_recv: bool) {
12961296
{
12971297
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
12981298
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
1299-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the reserve value"),
1299+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over their reserve value"),
13001300
_ => panic!("Unknown error variants"),
13011301
}
13021302
}
@@ -1359,7 +1359,7 @@ fn do_channel_reserve_test(test_recv: bool) {
13591359
{
13601360
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_22+1);
13611361
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
1362-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the reserve value"),
1362+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over their reserve value"),
13631363
_ => panic!("Unknown error variants"),
13641364
}
13651365
}
@@ -4852,7 +4852,7 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_value_in_flight() {
48524852
let err = nodes[0].node.send_payment(route, our_payment_hash);
48534853

48544854
if let Err(APIError::ChannelUnavailable{err}) = err {
4855-
assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight");
4855+
assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept");
48564856
} else {
48574857
assert!(false);
48584858
}
@@ -4975,7 +4975,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_in_flight_msat() {
49754975
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
49764976

49774977
if let Err(msgs::HandleError{err, action: Some(msgs::ErrorAction::SendErrorMessage {..})}) = err {
4978-
assert_eq!(err,"Remote HTLC add would put them over their max HTLC value in flight");
4978+
assert_eq!(err,"Remote HTLC add would put them over our max HTLC value");
49794979
} else {
49804980
assert!(false);
49814981
}

0 commit comments

Comments
 (0)