X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fonion_payment.rs;h=0886bf8f2f44a610db0fccabf3fcc7d11de87869;hb=e4e6e09b672dc929b4d8571975bd923a7a4486be;hp=00843d5e4e93d0ec11feb609e9d5009c98e85203;hpb=a634fd1dad468e4af51b508b3a0245f9655d129e;p=rust-lightning diff --git a/lightning/src/ln/onion_payment.rs b/lightning/src/ln/onion_payment.rs index 00843d5e..0886bf8f 100644 --- a/lightning/src/ln/onion_payment.rs +++ b/lightning/src/ln/onion_payment.rs @@ -11,7 +11,7 @@ use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1}; use crate::blinded_path; use crate::blinded_path::payment::{PaymentConstraints, PaymentRelay}; use crate::chain::channelmonitor::{HTLC_FAIL_BACK_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS}; -use crate::ln::PaymentHash; +use crate::ln::types::PaymentHash; use crate::ln::channelmanager::{BlindedFailure, BlindedForward, CLTV_FAR_FAR_AWAY, HTLCFailureMsg, MIN_CLTV_EXPIRY_DELTA, PendingHTLCInfo, PendingHTLCRouting}; use crate::ln::features::BlindedHopFeatures; use crate::ln::msgs; @@ -20,11 +20,13 @@ use crate::ln::onion_utils::{HTLCFailReason, INVALID_ONION_BLINDING}; use crate::sign::{NodeSigner, Recipient}; use crate::util::logger::Logger; +#[allow(unused_imports)] use crate::prelude::*; + use core::ops::Deref; /// Invalid inbound onion payment. -#[derive(Debug)] +#[derive(Clone, Debug, Hash, PartialEq, Eq)] pub struct InboundHTLCErr { /// BOLT 4 error code. pub err_code: u16, @@ -129,17 +131,18 @@ pub(super) fn create_recv_pending_htlc_info( ) -> Result { let ( payment_data, keysend_preimage, custom_tlvs, onion_amt_msat, onion_cltv_expiry, - payment_metadata, requires_blinded_error + payment_metadata, payment_context, requires_blinded_error ) = match hop_data { msgs::InboundOnionPayload::Receive { payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat, cltv_expiry_height, payment_metadata, .. } => (payment_data, keysend_preimage, custom_tlvs, sender_intended_htlc_amt_msat, - cltv_expiry_height, payment_metadata, false), + cltv_expiry_height, payment_metadata, None, false), msgs::InboundOnionPayload::BlindedReceive { sender_intended_htlc_amt_msat, total_msat, cltv_expiry_height, payment_secret, - intro_node_blinding_point, payment_constraints, .. + intro_node_blinding_point, payment_constraints, payment_context, keysend_preimage, + custom_tlvs } => { check_blinded_payment_constraints( sender_intended_htlc_amt_msat, cltv_expiry, &payment_constraints @@ -152,8 +155,9 @@ pub(super) fn create_recv_pending_htlc_info( } })?; let payment_data = msgs::FinalOnionHopData { payment_secret, total_msat }; - (Some(payment_data), None, Vec::new(), sender_intended_htlc_amt_msat, cltv_expiry_height, - None, intro_node_blinding_point.is_none()) + (Some(payment_data), keysend_preimage, custom_tlvs, + sender_intended_htlc_amt_msat, cltv_expiry_height, None, Some(payment_context), + intro_node_blinding_point.is_none()) } msgs::InboundOnionPayload::Forward { .. } => { return Err(InboundHTLCErr { @@ -232,11 +236,13 @@ pub(super) fn create_recv_pending_htlc_info( payment_metadata, incoming_cltv_expiry: onion_cltv_expiry, custom_tlvs, + requires_blinded_error, } } else if let Some(data) = payment_data { PendingHTLCRouting::Receive { payment_data: data, payment_metadata, + payment_context, incoming_cltv_expiry: onion_cltv_expiry, phantom_shared_secret, custom_tlvs, @@ -498,8 +504,7 @@ mod tests { use bitcoin::hashes::Hash; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey}; - use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret}; - use crate::ln::ChannelId; + use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret}; use crate::ln::channelmanager::RecipientOnionFields; use crate::ln::features::{ChannelFeatures, NodeFeatures}; use crate::ln::msgs; @@ -531,7 +536,7 @@ mod tests { let path = Path { hops, blinded_tail: None, }; let onion_keys = super::onion_utils::construct_onion_keys(&secp_ctx, &path, &session_priv).unwrap(); let (onion_payloads, ..) = super::onion_utils::build_onion_payloads( - &path, total_amt_msat, recipient_onion, cur_height + 1, &Some(keysend_preimage) + &path, total_amt_msat, &recipient_onion, cur_height + 1, &Some(keysend_preimage) ).unwrap(); assert!(super::onion_utils::construct_onion_packet(