diff --git a/src/htlc_manager.rs b/src/htlc_manager.rs index 1d81f10..6dff2ab 100644 --- a/src/htlc_manager.rs +++ b/src/htlc_manager.rs @@ -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; @@ -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. @@ -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(), diff --git a/src/messages.rs b/src/messages.rs index b4d4680..f608611 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -15,8 +15,7 @@ pub struct HtlcAcceptedRequest { pub struct Onion { pub payload: SerializedTlvStream, pub short_channel_id: Option, - pub forward_msat: u64, - pub outgoing_cltv_value: u32, + pub forward_msat: Option, pub total_msat: Option, } @@ -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, }, },