Skip to content

Commit

Permalink
plugin: Make onion fields optional
Browse files Browse the repository at this point in the history
As reported by JssDWt in #541,
the fields of the onion passed to the  htlc_accepted_hook might not be
set. To avoid any unnecessary panics we make them optional and handle an
unset field in the lsp plugin.

Signed-off-by: Peter Neuroth <[email protected]>
  • Loading branch information
nepet committed Nov 25, 2024
1 parent 6176468 commit 4be92a9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions libs/gl-plugin/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use serde_json::Value;
struct Onion {
payload: tlv::SerializedTlvStream,
short_channel_id: Option<ShortChannelId>,
forward_msat: Amount,
outgoing_cltv_value: u32,
forward_msat: Option<Amount>,
outgoing_cltv_value: Option<u32>,
#[serde(deserialize_with = "from_hex")]
shared_secret: Vec<u8>,
#[serde(deserialize_with = "from_hex")]
Expand Down Expand Up @@ -59,7 +59,18 @@ pub async fn on_htlc_accepted(plugin: Plugin, v: Value) -> Result<Value, anyhow:
log::debug!("Decoded {:?}", &req);

let htlc_amt = req.htlc.amount_msat;
let onion_amt = req.onion.forward_msat;
let onion_amt = match req.onion.forward_msat {
Some(a) => a,
None => {
// An onion without an `amt_to_forward` is unorthodox and can not
// be processed by this plugin. Skip it.
return Ok(serde_json::to_value(HtlcAcceptedResponse {
result: "continue".to_string(),
..Default::default()
})
.unwrap());
}
};

let res = if htlc_amt.msat() < onion_amt.msat() {
log::info!(
Expand Down

0 comments on commit 4be92a9

Please sign in to comment.