@@ -17,7 +17,9 @@ use super::async_payments::AsyncPaymentsMessage;
17
17
use super :: dns_resolution:: DNSResolverMessage ;
18
18
use super :: messenger:: CustomOnionMessageHandler ;
19
19
use super :: offers:: OffersMessage ;
20
- use crate :: blinded_path:: message:: { BlindedMessagePath , ForwardTlvs , NextMessageHop , ReceiveTlvs } ;
20
+ use crate :: blinded_path:: message:: {
21
+ BlindedMessagePath , DummyTlv , ForwardTlvs , NextMessageHop , ReceiveTlvs , UnauthenticatedDummyTlv ,
22
+ } ;
21
23
use crate :: crypto:: streams:: { ChaChaPolyReadAdapter , ChaChaPolyWriteAdapter } ;
22
24
use crate :: ln:: msgs:: DecodeError ;
23
25
use crate :: ln:: onion_utils;
@@ -111,6 +113,8 @@ impl LengthReadable for Packet {
111
113
pub ( super ) enum Payload < T : OnionMessageContents > {
112
114
/// This payload is for an intermediate hop.
113
115
Forward ( ForwardControlTlvs ) ,
116
+ /// This payload is dummy, and is inteded to be peeled.
117
+ Dummy ( DummyControlTlvs ) ,
114
118
/// This payload is for the final hop.
115
119
Receive { control_tlvs : ReceiveControlTlvs , reply_path : Option < BlindedMessagePath > , message : T } ,
116
120
}
@@ -204,6 +208,11 @@ pub(super) enum ForwardControlTlvs {
204
208
Unblinded ( ForwardTlvs ) ,
205
209
}
206
210
211
+ pub ( super ) enum DummyControlTlvs {
212
+ /// See [`ForwardControlTlvs::Unblinded`]
213
+ Unblinded ( DummyTlv ) ,
214
+ }
215
+
207
216
/// Receive control TLVs in their blinded and unblinded form.
208
217
pub ( super ) enum ReceiveControlTlvs {
209
218
/// See [`ForwardControlTlvs::Blinded`].
@@ -234,6 +243,10 @@ impl<T: OnionMessageContents> Writeable for (Payload<T>, [u8; 32]) {
234
243
let write_adapter = ChaChaPolyWriteAdapter :: new ( self . 1 , & control_tlvs) ;
235
244
_encode_varint_length_prefixed_tlv ! ( w, { ( 4 , write_adapter, required) } )
236
245
} ,
246
+ Payload :: Dummy ( DummyControlTlvs :: Unblinded ( control_tlvs) ) => {
247
+ let write_adapter = ChaChaPolyWriteAdapter :: new ( self . 1 , & control_tlvs) ;
248
+ _encode_varint_length_prefixed_tlv ! ( w, { ( 4 , write_adapter, required) } )
249
+ } ,
237
250
Payload :: Receive {
238
251
control_tlvs : ReceiveControlTlvs :: Unblinded ( control_tlvs) ,
239
252
reply_path,
@@ -310,6 +323,9 @@ impl<H: CustomOnionMessageHandler + ?Sized, L: Logger + ?Sized> ReadableArgs<(Sh
310
323
}
311
324
Ok ( Payload :: Forward ( ForwardControlTlvs :: Unblinded ( tlvs) ) )
312
325
} ,
326
+ Some ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Dummy ( tlvs) } ) => {
327
+ Ok ( Payload :: Dummy ( DummyControlTlvs :: Unblinded ( tlvs) ) )
328
+ } ,
313
329
Some ( ChaChaPolyReadAdapter { readable : ControlTlvs :: Receive ( tlvs) } ) => {
314
330
Ok ( Payload :: Receive {
315
331
control_tlvs : ReceiveControlTlvs :: Unblinded ( tlvs) ,
@@ -328,6 +344,8 @@ impl<H: CustomOnionMessageHandler + ?Sized, L: Logger + ?Sized> ReadableArgs<(Sh
328
344
pub ( crate ) enum ControlTlvs {
329
345
/// This onion message is intended to be forwarded.
330
346
Forward ( ForwardTlvs ) ,
347
+ /// This onion message is a dummy, and is intended to be peeled.
348
+ Dummy ( DummyTlv ) ,
331
349
/// This onion message is intended to be received.
332
350
Receive ( ReceiveTlvs ) ,
333
351
}
@@ -343,6 +361,7 @@ impl Readable for ControlTlvs {
343
361
( 4 , next_node_id, option) ,
344
362
( 8 , next_blinding_override, option) ,
345
363
( 65537 , context, option) ,
364
+ ( 65539 , authentication, option) ,
346
365
} ) ;
347
366
348
367
let next_hop = match ( short_channel_id, next_node_id) {
@@ -352,18 +371,16 @@ impl Readable for ControlTlvs {
352
371
( None , None ) => None ,
353
372
} ;
354
373
355
- let valid_fwd_fmt = next_hop. is_some ( ) ;
356
- let valid_recv_fmt = next_hop. is_none ( ) && next_blinding_override. is_none ( ) ;
357
-
358
- let payload_fmt = if valid_fwd_fmt {
359
- ControlTlvs :: Forward ( ForwardTlvs {
360
- next_hop : next_hop. unwrap ( ) ,
361
- next_blinding_override,
362
- } )
363
- } else if valid_recv_fmt {
364
- ControlTlvs :: Receive ( ReceiveTlvs { context } )
365
- } else {
366
- return Err ( DecodeError :: InvalidValue ) ;
374
+ let payload_fmt = match ( next_hop, next_blinding_override, authentication) {
375
+ ( Some ( hop) , _, None ) => {
376
+ ControlTlvs :: Forward ( ForwardTlvs { next_hop : hop, next_blinding_override } )
377
+ } ,
378
+ ( None , None , Some ( auth) ) => {
379
+ let tlv = DummyTlv { dummy_tlv : UnauthenticatedDummyTlv { } , authentication : auth } ;
380
+ ControlTlvs :: Dummy ( tlv)
381
+ } ,
382
+ ( None , None , None ) => ControlTlvs :: Receive ( ReceiveTlvs { context } ) ,
383
+ _ => return Err ( DecodeError :: InvalidValue ) ,
367
384
} ;
368
385
369
386
Ok ( payload_fmt)
@@ -374,6 +391,7 @@ impl Writeable for ControlTlvs {
374
391
fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
375
392
match self {
376
393
Self :: Forward ( tlvs) => tlvs. write ( w) ,
394
+ Self :: Dummy ( tlvs) => tlvs. write ( w) ,
377
395
Self :: Receive ( tlvs) => tlvs. write ( w) ,
378
396
}
379
397
}
0 commit comments