Skip to content

Commit 99ec2e3

Browse files
committed
Pass FinalOnionHopData to payment verify by reference, not clone
1 parent c7f52f3 commit 99ec2e3

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);
@@ -3274,7 +3274,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
32743274
hash_map::Entry::Vacant(_) => {
32753275
match claimable_htlc.onion_payload {
32763276
OnionPayload::Invoice(ref payment_data) => {
3277-
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) {
3277+
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) {
32783278
Ok(payment_preimage) => payment_preimage,
32793279
Err(()) => {
32803280
fail_htlc!(claimable_htlc);
@@ -7126,15 +7126,15 @@ mod tests {
71267126
// payment verification fails as expected.
71277127
let mut bad_payment_hash = payment_hash.clone();
71287128
bad_payment_hash.0[0] += 1;
7129-
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) {
7129+
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) {
71307130
Ok(_) => panic!("Unexpected ok"),
71317131
Err(()) => {
71327132
nodes[0].logger.assert_log_contains("lightning::ln::channelmanager::inbound_payment".to_string(), "Failing HTLC with user-generated payment_hash".to_string(), 1);
71337133
}
71347134
}
71357135

71367136
// Check that using the original payment hash succeeds.
7137-
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());
7137+
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());
71387138
}
71397139
}
71407140

0 commit comments

Comments
 (0)