Skip to content

Commit 127ce29

Browse files
authored
Merge pull request #310 from ariard/2019-02-clarify-send-htlc-policy
Clarify policy applied in send htlc error msgs
2 parents e65e03f + 1d6c09a commit 127ce29

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
@@ -1661,10 +1661,9 @@ impl Channel {
16611661
if inbound_htlc_count + 1 > OUR_MAX_HTLCS as u32 {
16621662
return Err(ChannelError::Close("Remote tried to push more than our max accepted HTLCs"));
16631663
}
1664-
//TODO: Spec is unclear if this is per-direction or in total (I assume per direction):
16651664
// Check our_max_htlc_value_in_flight_msat
16661665
if htlc_inbound_value_msat + msg.amount_msat > Channel::get_our_max_htlc_value_in_flight_msat(self.channel_value_satoshis) {
1667-
return Err(ChannelError::Close("Remote HTLC add would put them over their max HTLC value in flight"));
1666+
return Err(ChannelError::Close("Remote HTLC add would put them over our max HTLC value"));
16681667
}
16691668
// Check our_channel_reserve_satoshis (we're getting paid, so they have to at least meet
16701669
// the reserve_satoshis we told them to always have as direct payment so that they lose
@@ -3316,16 +3315,15 @@ impl Channel {
33163315
if outbound_htlc_count + 1 > self.their_max_accepted_htlcs as u32 {
33173316
return Err(ChannelError::Ignore("Cannot push more than their max accepted HTLCs"));
33183317
}
3319-
//TODO: Spec is unclear if this is per-direction or in total (I assume per direction):
33203318
// Check their_max_htlc_value_in_flight_msat
33213319
if htlc_outbound_value_msat + amount_msat > self.their_max_htlc_value_in_flight_msat {
3322-
return Err(ChannelError::Ignore("Cannot send value that would put us over the max HTLC value in flight"));
3320+
return Err(ChannelError::Ignore("Cannot send value that would put us over the max HTLC value in flight our peer will accept"));
33233321
}
33243322

33253323
// Check self.their_channel_reserve_satoshis (the amount we must keep as
33263324
// reserve for them to have something to claim if we misbehave)
33273325
if self.value_to_self_msat < self.their_channel_reserve_satoshis * 1000 + amount_msat + htlc_outbound_value_msat {
3328-
return Err(ChannelError::Ignore("Cannot send value that would put us over the reserve value"));
3326+
return Err(ChannelError::Ignore("Cannot send value that would put us over their reserve value"));
33293327
}
33303328

33313329
//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
@@ -740,7 +740,7 @@ pub fn route_over_limit(origin_node: &Node, expected_route: &[&Node], recv_value
740740

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

src/ln/functional_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ fn do_channel_reserve_test(test_recv: bool) {
12341234
assert!(route.hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
12351235
let err = nodes[0].node.send_payment(route, our_payment_hash).err().unwrap();
12361236
match err {
1237-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight"),
1237+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept"),
12381238
_ => panic!("Unknown error variants"),
12391239
}
12401240
}
@@ -1270,7 +1270,7 @@ fn do_channel_reserve_test(test_recv: bool) {
12701270
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value + 1);
12711271
let err = nodes[0].node.send_payment(route.clone(), our_payment_hash).err().unwrap();
12721272
match err {
1273-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the reserve value"),
1273+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over their reserve value"),
12741274
_ => panic!("Unknown error variants"),
12751275
}
12761276
}
@@ -1295,7 +1295,7 @@ fn do_channel_reserve_test(test_recv: bool) {
12951295
{
12961296
let (route, our_payment_hash, _) = get_route_and_payment_hash!(recv_value_2 + 1);
12971297
match nodes[0].node.send_payment(route, our_payment_hash).err().unwrap() {
1298-
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over the reserve value"),
1298+
APIError::ChannelUnavailable{err} => assert_eq!(err, "Cannot send value that would put us over their reserve value"),
12991299
_ => panic!("Unknown error variants"),
13001300
}
13011301
}
@@ -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
}
@@ -5017,7 +5017,7 @@ fn test_update_add_htlc_bolt2_sender_exceed_max_htlc_value_in_flight() {
50175017
let err = nodes[0].node.send_payment(route, our_payment_hash);
50185018

50195019
if let Err(APIError::ChannelUnavailable{err}) = err {
5020-
assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight");
5020+
assert_eq!(err, "Cannot send value that would put us over the max HTLC value in flight our peer will accept");
50215021
} else {
50225022
assert!(false);
50235023
}
@@ -5141,7 +5141,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_in_flight_msat() {
51415141
let err = nodes[1].node.handle_update_add_htlc(&nodes[0].node.get_our_node_id(), &updates.update_add_htlcs[0]);
51425142

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

0 commit comments

Comments
 (0)