Set HTLCPreviousHopData::blinded for blinded received HTLCs.
authorValentine Wallace <vwallace@protonmail.com>
Thu, 26 Oct 2023 22:52:29 +0000 (18:52 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Tue, 12 Dec 2023 22:10:23 +0000 (17:10 -0500)
Will be used in the next commit(s) to let us know to fail blinded received
HTLCs backwards with the malformed and invalid_onion_blinding error per BOLT 4.

lightning/src/ln/channelmanager.rs

index b925d842e9573b767243cbffeac28abe5c4d90f2..107ef72a15f58bdf7ca0c90aecfd35c2e475ed6e 100644 (file)
@@ -201,11 +201,11 @@ pub struct BlindedForward {
 impl PendingHTLCRouting {
        // Used to override the onion failure code and data if the HTLC is blinded.
        fn blinded_failure(&self) -> Option<BlindedFailure> {
-               // TODO: needs update when we support receiving to multi-hop blinded paths
-               if let Self::Forward { blinded: Some(_), .. } = self {
-                       Some(BlindedFailure::FromIntroductionNode)
-               } else {
-                       None
+               // TODO: needs update when we support forwarding blinded HTLCs as non-intro node
+               match self {
+                       Self::Forward { blinded: Some(_), .. } => Some(BlindedFailure::FromIntroductionNode),
+                       Self::Receive { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
+                       _ => None,
                }
        }
 }
@@ -291,7 +291,7 @@ pub(super) enum HTLCForwardInfo {
 }
 
 // Used for failing blinded HTLCs backwards correctly.
-#[derive(Clone, Debug, Hash, PartialEq, Eq)]
+#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
 enum BlindedFailure {
        FromIntroductionNode,
        FromBlindedNode,
@@ -4462,7 +4462,7 @@ where
                                                                                                htlc_id: $htlc.prev_hop.htlc_id,
                                                                                                incoming_packet_shared_secret: $htlc.prev_hop.incoming_packet_shared_secret,
                                                                                                phantom_shared_secret,
-                                                                                               blinded_failure: None,
+                                                                                               blinded_failure,
                                                                                        }), payment_hash,
                                                                                        HTLCFailReason::reason(0x4000 | 15, htlc_msat_height_data),
                                                                                        HTLCDestination::FailedPayment { payment_hash: $payment_hash },