Skip to content

Commit bf9cdb9

Browse files
channelmanager::decode_update_add_htlc: pull pending status creation into macro
This will be used in upcoming commit(s) to facilitate decoding multiple onion layers for multi-node payment receive
1 parent 03d84cb commit bf9cdb9

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,8 +1798,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
17981798
},
17991799
};
18001800

1801-
let pending_forward_info = match next_hop {
1802-
onion_utils::Hop::Receive(next_hop_data) => {
1801+
macro_rules! get_recv_pending_htlc_status {
1802+
($hop_data: expr) => {{
18031803
// OUR PAYMENT!
18041804
// final_expiry_too_soon
18051805
// We have to have some headroom to broadcast on chain if we have the preimage, so make sure
@@ -1811,15 +1811,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18111811
return_err!("The final CLTV expiry is too soon to handle", 17, &[0;0]);
18121812
}
18131813
// final_incorrect_htlc_amount
1814-
if next_hop_data.amt_to_forward > msg.amount_msat {
1814+
if $hop_data.amt_to_forward > msg.amount_msat {
18151815
return_err!("Upstream node sent less than we were supposed to receive in payment", 19, &byte_utils::be64_to_array(msg.amount_msat));
18161816
}
1817-
// final_incorrect_cltv_expiry
1818-
if next_hop_data.outgoing_cltv_value != msg.cltv_expiry {
1819-
return_err!("Upstream node set CLTV to the wrong value", 18, &byte_utils::be32_to_array(msg.cltv_expiry));
1820-
}
18211817

1822-
let routing = match next_hop_data.format {
1818+
let routing = match $hop_data.format {
18231819
msgs::OnionHopDataFormat::Legacy { .. } => return_err!("We require payment_secrets", 0x4000|0x2000|3, &[0;0]),
18241820
msgs::OnionHopDataFormat::NonFinalNode { .. } => return_err!("Got non final data with an HMAC of 0", 0x4000 | 22, &[0;0]),
18251821
msgs::OnionHopDataFormat::FinalNode { payment_data, keysend_preimage } => {
@@ -1860,9 +1856,19 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
18601856
routing,
18611857
payment_hash: msg.payment_hash.clone(),
18621858
incoming_shared_secret: shared_secret,
1863-
amt_to_forward: next_hop_data.amt_to_forward,
1864-
outgoing_cltv_value: next_hop_data.outgoing_cltv_value,
1859+
amt_to_forward: $hop_data.amt_to_forward,
1860+
outgoing_cltv_value: $hop_data.outgoing_cltv_value,
18651861
})
1862+
}}
1863+
}
1864+
1865+
let pending_forward_info = match next_hop {
1866+
onion_utils::Hop::Receive(next_hop_data) => {
1867+
// final_incorrect_cltv_expiry
1868+
if next_hop_data.outgoing_cltv_value != msg.cltv_expiry {
1869+
return_err!("Upstream node set CLTV to the wrong value", 18, &byte_utils::be32_to_array(msg.cltv_expiry));
1870+
}
1871+
get_recv_pending_htlc_status!(next_hop_data)
18661872
},
18671873
onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
18681874
let mut new_pubkey = msg.onion_routing_packet.public_key.unwrap();

0 commit comments

Comments
 (0)