Skip to content

Commit fda5a04

Browse files
TheBlueMattandozw
authored andcommitted
Pass FinalOnionHopData to payment verify by reference, not clone
1 parent 637fb88 commit fda5a04

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,7 +3195,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
31953195
hash_map::Entry::Vacant(_) => {
31963196
match claimable_htlc.onion_payload {
31973197
OnionPayload::Invoice(ref payment_data) => {
3198-
let payment_preimage = match inbound_payment::verify(payment_hash, payment_data.clone(), self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, &self.logger) {
3198+
let payment_preimage = match inbound_payment::verify(payment_hash, &payment_data, self.highest_seen_timestamp.load(Ordering::Acquire) as u64, &self.inbound_payment_key, &self.logger) {
31993199
Ok(payment_preimage) => payment_preimage,
32003200
Err(()) => {
32013201
fail_htlc!(claimable_htlc);
@@ -7312,15 +7312,15 @@ mod tests {
73127312
// payment verification fails as expected.
73137313
let mut bad_payment_hash = payment_hash.clone();
73147314
bad_payment_hash.0[0] += 1;
7315-
match inbound_payment::verify(bad_payment_hash, payment_data.clone(), nodes[0].node.highest_seen_timestamp.load(Ordering::Acquire) as u64, &nodes[0].node.inbound_payment_key, &nodes[0].logger) {
7315+
match inbound_payment::verify(bad_payment_hash, &payment_data, nodes[0].node.highest_seen_timestamp.load(Ordering::Acquire) as u64, &nodes[0].node.inbound_payment_key, &nodes[0].logger) {
73167316
Ok(_) => panic!("Unexpected ok"),
73177317
Err(()) => {
73187318
nodes[0].logger.assert_log_contains("lightning::ln::inbound_payment".to_string(), "Failing HTLC with user-generated payment_hash".to_string(), 1);
73197319
}
73207320
}
73217321

73227322
// Check that using the original payment hash succeeds.
7323-
assert!(inbound_payment::verify(payment_hash, payment_data, nodes[0].node.highest_seen_timestamp.load(Ordering::Acquire) as u64, &nodes[0].node.inbound_payment_key, &nodes[0].logger).is_ok());
7323+
assert!(inbound_payment::verify(payment_hash, &payment_data, nodes[0].node.highest_seen_timestamp.load(Ordering::Acquire) as u64, &nodes[0].node.inbound_payment_key, &nodes[0].logger).is_ok());
73247324
}
73257325
}
73267326

lightning/src/ln/inbound_payment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn construct_payment_secret(iv_bytes: &[u8; IV_LEN], metadata_bytes: &[u8; METAD
200200
/// [`KeysInterface::get_inbound_payment_key_material`]: crate::chain::keysinterface::KeysInterface::get_inbound_payment_key_material
201201
/// [`create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
202202
/// [`create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
203-
pub(super) fn verify<L: Deref>(payment_hash: PaymentHash, payment_data: msgs::FinalOnionHopData, highest_seen_timestamp: u64, keys: &ExpandedKey, logger: &L) -> Result<Option<PaymentPreimage>, ()>
203+
pub(super) fn verify<L: Deref>(payment_hash: PaymentHash, payment_data: &msgs::FinalOnionHopData, highest_seen_timestamp: u64, keys: &ExpandedKey, logger: &L) -> Result<Option<PaymentPreimage>, ()>
204204
where L::Target: Logger
205205
{
206206
let (iv_bytes, metadata_bytes) = decrypt_metadata(payment_data.payment_secret, keys);

0 commit comments

Comments
 (0)