@@ -14,23 +14,23 @@ use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1414#[ allow( unused_imports) ]
1515use crate :: prelude:: * ;
1616
17- use bitcoin:: hashes:: hmac:: Hmac ;
18- use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
19- use crate :: blinded_path:: { BlindedHop , BlindedPath , Direction , IntroductionNode , NodeIdLookUp } ;
2017use crate :: blinded_path:: utils;
18+ use crate :: blinded_path:: { BlindedHop , BlindedPath , Direction , IntroductionNode , NodeIdLookUp } ;
19+ use crate :: crypto:: streams:: ChaChaPolyReadAdapter ;
2120use crate :: io;
2221use crate :: io:: Cursor ;
2322use crate :: ln:: channelmanager:: PaymentId ;
2423use crate :: ln:: msgs:: DecodeError ;
2524use crate :: ln:: onion_utils;
26- use crate :: types:: payment:: PaymentHash ;
2725use crate :: offers:: nonce:: Nonce ;
2826use crate :: onion_message:: packet:: ControlTlvs ;
2927use crate :: routing:: gossip:: { NodeId , ReadOnlyNetworkGraph } ;
3028use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
31- use crate :: crypto :: streams :: ChaChaPolyReadAdapter ;
29+ use crate :: types :: payment :: PaymentHash ;
3230use crate :: util:: scid_utils;
3331use crate :: util:: ser:: { FixedLengthReader , LengthReadableArgs , Readable , Writeable , Writer } ;
32+ use bitcoin:: hashes:: hmac:: Hmac ;
33+ use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
3434
3535use core:: mem;
3636use core:: ops:: Deref ;
@@ -55,8 +55,12 @@ impl Readable for BlindedMessagePath {
5555impl BlindedMessagePath {
5656 /// Create a one-hop blinded path for a message.
5757 pub fn one_hop < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
58- recipient_node_id : PublicKey , context : MessageContext , entropy_source : ES , secp_ctx : & Secp256k1 < T >
59- ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
58+ recipient_node_id : PublicKey , context : MessageContext , entropy_source : ES ,
59+ secp_ctx : & Secp256k1 < T > ,
60+ ) -> Result < Self , ( ) >
61+ where
62+ ES :: Target : EntropySource ,
63+ {
6064 Self :: new ( & [ ] , recipient_node_id, context, entropy_source, secp_ctx)
6165 }
6266
@@ -68,20 +72,28 @@ impl BlindedMessagePath {
6872 pub fn new < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
6973 intermediate_nodes : & [ MessageForwardNode ] , recipient_node_id : PublicKey ,
7074 context : MessageContext , entropy_source : ES , secp_ctx : & Secp256k1 < T > ,
71- ) -> Result < Self , ( ) > where ES :: Target : EntropySource {
75+ ) -> Result < Self , ( ) >
76+ where
77+ ES :: Target : EntropySource ,
78+ {
7279 let introduction_node = IntroductionNode :: NodeId (
73- intermediate_nodes. first ( ) . map_or ( recipient_node_id, |n| n. node_id )
80+ intermediate_nodes. first ( ) . map_or ( recipient_node_id, |n| n. node_id ) ,
7481 ) ;
7582 let blinding_secret_bytes = entropy_source. get_secure_random_bytes ( ) ;
76- let blinding_secret = SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
83+ let blinding_secret =
84+ SecretKey :: from_slice ( & blinding_secret_bytes[ ..] ) . expect ( "RNG is busted" ) ;
7785
7886 Ok ( Self ( BlindedPath {
7987 introduction_node,
8088 blinding_point : PublicKey :: from_secret_key ( secp_ctx, & blinding_secret) ,
8189 blinded_hops : blinded_hops (
82- secp_ctx, intermediate_nodes, recipient_node_id,
83- context, & blinding_secret,
84- ) . map_err ( |_| ( ) ) ?,
90+ secp_ctx,
91+ intermediate_nodes,
92+ recipient_node_id,
93+ context,
94+ & blinding_secret,
95+ )
96+ . map_err ( |_| ( ) ) ?,
8597 } ) )
8698 }
8799
@@ -97,9 +109,9 @@ impl BlindedMessagePath {
97109 if let Some ( node_info) = network_graph. node ( & node_id) {
98110 if let Some ( ( scid, channel_info) ) = node_info
99111 . channels
100- . iter ( )
101- . filter_map ( |scid| network_graph. channel ( * scid) . map ( |info| ( * scid, info) ) )
102- . min_by_key ( |( scid, _) | scid_utils:: block_from_scid ( * scid) )
112+ . iter ( )
113+ . filter_map ( |scid| network_graph. channel ( * scid) . map ( |info| ( * scid, info) ) )
114+ . min_by_key ( |( scid, _) | scid_utils:: block_from_scid ( * scid) )
103115 {
104116 let direction = if node_id == channel_info. node_one {
105117 Direction :: NodeOne
@@ -117,7 +129,7 @@ impl BlindedMessagePath {
117129 /// Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e.,
118130 /// it is found in the network graph).
119131 pub fn public_introduction_node_id < ' a > (
120- & self , network_graph : & ' a ReadOnlyNetworkGraph
132+ & self , network_graph : & ' a ReadOnlyNetworkGraph ,
121133 ) -> Option < & ' a NodeId > {
122134 self . 0 . public_introduction_node_id ( network_graph)
123135 }
@@ -144,7 +156,7 @@ impl BlindedMessagePath {
144156 ///
145157 /// Will only modify `self` when returning `Ok`.
146158 pub fn advance_path_by_one < NS : Deref , NL : Deref , T > (
147- & mut self , node_signer : & NS , node_id_lookup : & NL , secp_ctx : & Secp256k1 < T >
159+ & mut self , node_signer : & NS , node_id_lookup : & NL , secp_ctx : & Secp256k1 < T > ,
148160 ) -> Result < ( ) , ( ) >
149161 where
150162 NS :: Target : NodeSigner ,
@@ -158,28 +170,31 @@ impl BlindedMessagePath {
158170 let mut reader = FixedLengthReader :: new ( & mut s, encrypted_control_tlvs. len ( ) as u64 ) ;
159171 match ChaChaPolyReadAdapter :: read ( & mut reader, rho) {
160172 Ok ( ChaChaPolyReadAdapter {
161- readable : ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override } )
173+ readable : ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override } ) ,
162174 } ) => {
163175 let next_node_id = match next_hop {
164176 NextMessageHop :: NodeId ( pubkey) => pubkey,
165- NextMessageHop :: ShortChannelId ( scid) => match node_id_lookup. next_node_id ( scid) {
177+ NextMessageHop :: ShortChannelId ( scid) => match node_id_lookup. next_node_id ( scid)
178+ {
166179 Some ( pubkey) => pubkey,
167180 None => return Err ( ( ) ) ,
168181 } ,
169182 } ;
170183 let mut new_blinding_point = match next_blinding_override {
171184 Some ( blinding_point) => blinding_point,
172- None => {
173- onion_utils:: next_hop_pubkey ( secp_ctx, self . 0 . blinding_point ,
174- control_tlvs_ss. as_ref ( ) ) . map_err ( |_| ( ) ) ?
175- }
185+ None => onion_utils:: next_hop_pubkey (
186+ secp_ctx,
187+ self . 0 . blinding_point ,
188+ control_tlvs_ss. as_ref ( ) ,
189+ )
190+ . map_err ( |_| ( ) ) ?,
176191 } ;
177192 mem:: swap ( & mut self . 0 . blinding_point , & mut new_blinding_point) ;
178193 self . 0 . introduction_node = IntroductionNode :: NodeId ( next_node_id) ;
179194 self . 0 . blinded_hops . remove ( 0 ) ;
180195 Ok ( ( ) )
181196 } ,
182- _ => Err ( ( ) )
197+ _ => Err ( ( ) ) ,
183198 }
184199 }
185200
@@ -189,7 +204,7 @@ impl BlindedMessagePath {
189204
190205 #[ cfg( test) ]
191206 pub fn from_raw (
192- introduction_node_id : PublicKey , blinding_point : PublicKey , blinded_hops : Vec < BlindedHop >
207+ introduction_node_id : PublicKey , blinding_point : PublicKey , blinded_hops : Vec < BlindedHop > ,
193208 ) -> Self {
194209 Self ( BlindedPath {
195210 introduction_node : IntroductionNode :: NodeId ( introduction_node_id) ,
@@ -241,7 +256,7 @@ pub(crate) struct ReceiveTlvs {
241256 /// If `context` is `Some`, it is used to identify the blinded path that this onion message is
242257 /// sending to. This is useful for receivers to check that said blinded path is being used in
243258 /// the right context.
244- pub context : Option < MessageContext >
259+ pub context : Option < MessageContext > ,
245260}
246261
247262impl Writeable for ForwardTlvs {
@@ -480,20 +495,24 @@ pub(super) fn blinded_hops<T: secp256k1::Signing + secp256k1::Verification>(
480495 secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ MessageForwardNode ] ,
481496 recipient_node_id : PublicKey , context : MessageContext , session_priv : & SecretKey ,
482497) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
483- let pks = intermediate_nodes. iter ( ) . map ( |node| node. node_id )
498+ let pks = intermediate_nodes
499+ . iter ( )
500+ . map ( |node| node. node_id )
484501 . chain ( core:: iter:: once ( recipient_node_id) ) ;
485- let tlvs = pks. clone ( )
502+ let tlvs = pks
503+ . clone ( )
486504 . skip ( 1 ) // The first node's TLVs contains the next node's pubkey
487505 . zip ( intermediate_nodes. iter ( ) . map ( |node| node. short_channel_id ) )
488506 . map ( |( pubkey, scid) | match scid {
489507 Some ( scid) => NextMessageHop :: ShortChannelId ( scid) ,
490508 None => NextMessageHop :: NodeId ( pubkey) ,
491509 } )
492- . map ( |next_hop| ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } ) )
493- . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
510+ . map ( |next_hop| {
511+ ControlTlvs :: Forward ( ForwardTlvs { next_hop, next_blinding_override : None } )
512+ } )
513+ . chain ( core:: iter:: once ( ControlTlvs :: Receive ( ReceiveTlvs { context : Some ( context) } ) ) ) ;
494514
495515 let path = pks. zip ( tlvs) ;
496516
497517 utils:: construct_blinded_hops ( secp_ctx, path, session_priv)
498518}
499-
0 commit comments