Skip to content

Commit 6791d2c

Browse files
Clean up HTLC intercept errors
ChannelUnavailable is a better fit for errors regarding unavailable channels than APIMisuseError. Also log bytes in errors as hex instead of decimal.
1 parent fb6e018 commit 6791d2c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,20 +3080,20 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
30803080
let next_hop_scid = match self.channel_state.lock().unwrap().by_id.get(next_hop_channel_id) {
30813081
Some(chan) => {
30823082
if !chan.is_usable() {
3083-
return Err(APIError::APIMisuseError {
3084-
err: format!("Channel with id {:?} not fully established", next_hop_channel_id)
3083+
return Err(APIError::ChannelUnavailable {
3084+
err: format!("Channel with id {} not fully established", log_bytes!(*next_hop_channel_id))
30853085
})
30863086
}
30873087
chan.get_short_channel_id().unwrap_or(chan.outbound_scid_alias())
30883088
},
3089-
None => return Err(APIError::APIMisuseError {
3090-
err: format!("Channel with id {:?} not found", next_hop_channel_id)
3089+
None => return Err(APIError::ChannelUnavailable {
3090+
err: format!("Channel with id {} not found", log_bytes!(*next_hop_channel_id))
30913091
})
30923092
};
30933093

30943094
let payment = self.pending_intercepted_htlcs.lock().unwrap().remove(&intercept_id)
30953095
.ok_or_else(|| APIError::APIMisuseError {
3096-
err: format!("Payment with intercept id {:?} not found", intercept_id.0)
3096+
err: format!("Payment with intercept id {} not found", log_bytes!(intercept_id.0))
30973097
})?;
30983098

30993099
let routing = match payment.forward_info.routing {
@@ -3128,7 +3128,7 @@ impl<M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<M, T, K, F
31283128

31293129
let payment = self.pending_intercepted_htlcs.lock().unwrap().remove(&intercept_id)
31303130
.ok_or_else(|| APIError::APIMisuseError {
3131-
err: format!("Payment with InterceptId {:?} not found", intercept_id)
3131+
err: format!("Payment with intercept id {} not found", log_bytes!(intercept_id.0))
31323132
})?;
31333133

31343134
if let PendingHTLCRouting::Forward { short_channel_id, .. } = payment.forward_info.routing {

lightning/src/ln/payment_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,7 +1466,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
14661466

14671467
// Check for unknown channel id error.
14681468
let unknown_chan_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &[42; 32], nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
1469-
assert_eq!(unknown_chan_id_err , APIError::APIMisuseError { err: format!("Channel with id {:?} not found", [42; 32]) });
1469+
assert_eq!(unknown_chan_id_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not found", log_bytes!([42; 32])) });
14701470

14711471
if test == InterceptTest::Fail {
14721472
// Ensure we can fail the intercepted payment back.
@@ -1490,7 +1490,7 @@ fn do_test_intercepted_payment(test: InterceptTest) {
14901490
// Check that we'll fail as expected when sending to a channel that isn't in `ChannelReady` yet.
14911491
let temp_chan_id = nodes[1].node.create_channel(nodes[2].node.get_our_node_id(), 100_000, 0, 42, None).unwrap();
14921492
let unusable_chan_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &temp_chan_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
1493-
assert_eq!(unusable_chan_err , APIError::APIMisuseError { err: format!("Channel with id {:?} not fully established", temp_chan_id) });
1493+
assert_eq!(unusable_chan_err , APIError::ChannelUnavailable { err: format!("Channel with id {} not fully established", log_bytes!(temp_chan_id)) });
14941494
assert_eq!(nodes[1].node.get_and_clear_pending_msg_events().len(), 1);
14951495

14961496
// Open the just-in-time channel so the payment can then be forwarded.
@@ -1561,6 +1561,6 @@ fn do_test_intercepted_payment(test: InterceptTest) {
15611561
// Check for unknown intercept id error.
15621562
let (_, channel_id) = open_zero_conf_channel(&nodes[1], &nodes[2], None);
15631563
let unknown_intercept_id_err = nodes[1].node.forward_intercepted_htlc(intercept_id, &channel_id, nodes[2].node.get_our_node_id(), expected_outbound_amount_msat).unwrap_err();
1564-
assert_eq!(unknown_intercept_id_err , APIError::APIMisuseError { err: format!("Payment with intercept id {:?} not found", intercept_id.0) });
1564+
assert_eq!(unknown_intercept_id_err , APIError::APIMisuseError { err: format!("Payment with intercept id {} not found", log_bytes!(intercept_id.0)) });
15651565
}
15661566
}

0 commit comments

Comments
 (0)