Skip to content

Commit 98daab4

Browse files
committed
Pass FinalOnionHopData to payment verify by reference, not clone
1 parent d4487f0 commit 98daab4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ mod inbound_payment {
236236
/// [`KeysInterface::get_inbound_payment_key_material`]: crate::chain::keysinterface::KeysInterface::get_inbound_payment_key_material
237237
/// [`create_inbound_payment`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment
238238
/// [`create_inbound_payment_for_hash`]: crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash
239-
pub(super) fn verify<L: Deref>(payment_hash: PaymentHash, payment_data: msgs::FinalOnionHopData, highest_seen_timestamp: u64, keys: &ExpandedKey, logger: &L) -> Result<Option<PaymentPreimage>, ()>
239+
pub(super) fn verify<L: Deref>(payment_hash: PaymentHash, payment_data: &msgs::FinalOnionHopData, highest_seen_timestamp: u64, keys: &ExpandedKey, logger: &L) -> Result<Option<PaymentPreimage>, ()>
240240
where L::Target: Logger
241241
{
242242
let (iv_bytes, metadata_bytes) = decrypt_metadata(payment_data.payment_secret, keys);
@@ -3270,7 +3270,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32703270
hash_map::Entry::Vacant(_) => {
32713271
match claimable_htlc.onion_payload {
32723272
OnionPayload::Invoice(ref payment_data) => {
3273-
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) {
3273+
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) {
32743274
Ok(payment_preimage) => payment_preimage,
32753275
Err(()) => {
32763276
fail_htlc!(claimable_htlc);
@@ -7110,15 +7110,15 @@ mod tests {
71107110
// payment verification fails as expected.
71117111
let mut bad_payment_hash = payment_hash.clone();
71127112
bad_payment_hash.0[0] += 1;
7113-
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) {
7113+
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) {
71147114
Ok(_) => panic!("Unexpected ok"),
71157115
Err(()) => {
71167116
nodes[0].logger.assert_log_contains("lightning::ln::channelmanager::inbound_payment".to_string(), "Failing HTLC with user-generated payment_hash".to_string(), 1);
71177117
}
71187118
}
71197119

71207120
// Check that using the original payment hash succeeds.
7121-
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());
7121+
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());
71227122
}
71237123
}
71247124

0 commit comments

Comments
 (0)