Skip to content

Commit

Permalink
skip htlcs when forward_msat is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
JssDWt committed Nov 18, 2024
1 parent 2c92023 commit fa754ba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/htlc_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ where
HtlcCheckResult::Response(resp) => return resp,
HtlcCheckResult::Trampoline(trampoline) => *trampoline,
};
let forward_msat = match req.onion.forward_msat {
Some(forward_msat) => forward_msat,
None => {
trace!("onion missing forward_msat, skipping");
return default_response(req);
}
};

{
let mut payments = self.payments.lock().await;
Expand Down Expand Up @@ -148,7 +155,7 @@ where
// the current htlc.
let total_msat = match req.onion.total_msat {
Some(total_msat) => total_msat,
None => req.onion.forward_msat,
None => forward_msat,
};

// Ensure enough fees are paid according to the routing policy.
Expand Down Expand Up @@ -936,8 +943,7 @@ mod tests {
short_channel_id: "0x0x0".parse().unwrap(),
},
onion: Onion {
forward_msat: self.sender_amount,
outgoing_cltv_value: 0,
forward_msat: Some(self.sender_amount),
payload: construct_payload(vec![TlvEntry {
typ: 33001,
value: self.invoice_bytes(),
Expand Down
45 changes: 41 additions & 4 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ pub struct HtlcAcceptedRequest {
pub struct Onion {
pub payload: SerializedTlvStream,
pub short_channel_id: Option<ShortChannelId>,
pub forward_msat: u64,
pub outgoing_cltv_value: u32,
pub forward_msat: Option<u64>,
pub total_msat: Option<u64>,
}

Expand Down Expand Up @@ -295,8 +294,46 @@ mod serialize_cln_messages_tests {
onion: Onion {
payload: SerializedTlvStream::from(vec![]),
short_channel_id: Some("1x2x3".parse().unwrap()),
forward_msat: 42,
outgoing_cltv_value: 500014,
forward_msat: Some(42),
total_msat: None,
},
},
request
)
}

#[test]
fn deserialize_htlc_accepted_request_payload_only() {
let raw = r#"{
"onion": {
"payload": ""
},
"htlc": {
"short_channel_id": "4x5x6",
"id": 27,
"amount_msat": 43,
"cltv_expiry": 500028,
"cltv_expiry_relative": 10,
"payment_hash": "0000000000000000000000000000000000000000000000000000000000000000"
},
"forward_to": "0000000000000000000000000000000000000000000000000000000000000000"
}"#;

let request: HtlcAcceptedRequest = serde_json::from_str(raw).unwrap();
assert_eq!(
HtlcAcceptedRequest {
htlc: Htlc {
short_channel_id: "4x5x6".parse().unwrap(),
id: 27,
amount_msat: 43,
cltv_expiry: 500028,
cltv_expiry_relative: 10,
payment_hash: [0; 32].to_vec()
},
onion: Onion {
payload: SerializedTlvStream::from(vec![]),
short_channel_id: None,
forward_msat: None,
total_msat: None,
},
},
Expand Down

0 comments on commit fa754ba

Please sign in to comment.