Skip to content

Commit c2a0adc

Browse files
nepetcdecker
authored andcommitted
plugin: Make onion fields optional
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]>
1 parent 6176468 commit c2a0adc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

libs/gl-plugin/src/lsp.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use serde_json::Value;
1515
struct Onion {
1616
payload: tlv::SerializedTlvStream,
1717
short_channel_id: Option<ShortChannelId>,
18-
forward_msat: Amount,
19-
outgoing_cltv_value: u32,
18+
forward_msat: Option<Amount>,
19+
outgoing_cltv_value: Option<u32>,
2020
#[serde(deserialize_with = "from_hex")]
2121
shared_secret: Vec<u8>,
2222
#[serde(deserialize_with = "from_hex")]
@@ -59,7 +59,18 @@ pub async fn on_htlc_accepted(plugin: Plugin, v: Value) -> Result<Value, anyhow:
5959
log::debug!("Decoded {:?}", &req);
6060

6161
let htlc_amt = req.htlc.amount_msat;
62-
let onion_amt = req.onion.forward_msat;
62+
let onion_amt = match req.onion.forward_msat {
63+
Some(a) => a,
64+
None => {
65+
// An onion without an `amt_to_forward` is unorthodox and can not
66+
// be processed by this plugin. Skip it.
67+
return Ok(serde_json::to_value(HtlcAcceptedResponse {
68+
result: "continue".to_string(),
69+
..Default::default()
70+
})
71+
.unwrap());
72+
}
73+
};
6374

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

0 commit comments

Comments
 (0)