Skip to content

Commit

Permalink
trampoline: Add handling for custom server errs
Browse files Browse the repository at this point in the history
Currently we can not handle custom errors returned by the server
directly as CLN does not understand the error codes (NODE|25, PERM|27)
that signal termporary and permanent failures on the trampoline server.

This is an internediate step where we at least pass down an error
message that reflects a server failure in the meantime.

Signed-off-by: Peter Neuroth <[email protected]>
  • Loading branch information
nepet authored and cdecker committed Aug 12, 2024
1 parent adc0547 commit 43f0220
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions libs/gl-plugin/src/tramp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const TLV_BOLT11: u64 = 33001;
// Type used to address the amount in msat in the onion payload, in case
// that the bolt11 does not have an amount set.
const TLV_AMT_MSAT: u64 = 33003;
// Error Message that CLN returns on an unknown onion error. This is the
// case when the trampoline server rejected with a custom error type.
const PAY_UNPARSEABLE_ONION_MSG: &str = "Malformed error reply";
const PAY_UNPARSEABLE_ONION_CODE: i32 = 202;

fn feature_guard(features: impl Into<Vec<u8>>, feature_bit: usize) -> Result<()> {
let mut features = features.into();
Expand Down Expand Up @@ -324,8 +328,17 @@ async fn do_pay(
})
.await
{
Ok(r) => Ok(r),
Err(e) => Err(anyhow!(e.to_string())),
Ok(v) => Ok(v),
Err(e) => {
if let Some(code) = e.code {
if code == PAY_UNPARSEABLE_ONION_CODE {
return Err(anyhow!("trampoline payment failed by the server"));
}
} else if e.message == PAY_UNPARSEABLE_ONION_MSG {
return Err(anyhow!("trampoline payment failed by the server"));
}
Err(e.into())
}
}
}

Expand Down

0 comments on commit 43f0220

Please sign in to comment.