Skip to content

Commit e6b657e

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 8572fdf commit e6b657e

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
@@ -2119,8 +2119,8 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21192119
},
21202120
};
21212121

2122-
let pending_forward_info = match next_hop {
2123-
onion_utils::Hop::Receive(next_hop_data) => {
2122+
macro_rules! get_recv_pending_htlc_status {
2123+
($hop_data: expr) => {{
21242124
// OUR PAYMENT!
21252125
// final_expiry_too_soon
21262126
// We have to have some headroom to broadcast on chain if we have the preimage, so make sure
@@ -2132,15 +2132,11 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21322132
return_err!("The final CLTV expiry is too soon to handle", 17, &[0;0]);
21332133
}
21342134
// final_incorrect_htlc_amount
2135-
if next_hop_data.amt_to_forward > msg.amount_msat {
2135+
if $hop_data.amt_to_forward > msg.amount_msat {
21362136
return_err!("Upstream node sent less than we were supposed to receive in payment", 19, &byte_utils::be64_to_array(msg.amount_msat));
21372137
}
2138-
// final_incorrect_cltv_expiry
2139-
if next_hop_data.outgoing_cltv_value != msg.cltv_expiry {
2140-
return_err!("Upstream node set CLTV to the wrong value", 18, &byte_utils::be32_to_array(msg.cltv_expiry));
2141-
}
21422138

2143-
let routing = match next_hop_data.format {
2139+
let routing = match $hop_data.format {
21442140
msgs::OnionHopDataFormat::Legacy { .. } => return_err!("We require payment_secrets", 0x4000|0x2000|3, &[0;0]),
21452141
msgs::OnionHopDataFormat::NonFinalNode { .. } => return_err!("Got non final data with an HMAC of 0", 0x4000 | 22, &[0;0]),
21462142
msgs::OnionHopDataFormat::FinalNode { payment_data, keysend_preimage } => {
@@ -2181,9 +2177,19 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
21812177
routing,
21822178
payment_hash: msg.payment_hash.clone(),
21832179
incoming_shared_secret: shared_secret,
2184-
amt_to_forward: next_hop_data.amt_to_forward,
2185-
outgoing_cltv_value: next_hop_data.outgoing_cltv_value,
2180+
amt_to_forward: $hop_data.amt_to_forward,
2181+
outgoing_cltv_value: $hop_data.outgoing_cltv_value,
21862182
})
2183+
}}
2184+
}
2185+
2186+
let pending_forward_info = match next_hop {
2187+
onion_utils::Hop::Receive(next_hop_data) => {
2188+
// final_incorrect_cltv_expiry
2189+
if next_hop_data.outgoing_cltv_value != msg.cltv_expiry {
2190+
return_err!("Upstream node set CLTV to the wrong value", 18, &byte_utils::be32_to_array(msg.cltv_expiry));
2191+
}
2192+
get_recv_pending_htlc_status!(next_hop_data)
21872193
},
21882194
onion_utils::Hop::Forward { next_hop_data, next_hop_hmac, new_packet_bytes } => {
21892195
let mut new_pubkey = msg.onion_routing_packet.public_key.unwrap();

0 commit comments

Comments
 (0)