@@ -1768,41 +1768,47 @@ mod fuzzy_internal_msgs {
1768
1768
// These types aren't intended to be pub, but are exposed for direct fuzzing (as we deserialize
1769
1769
// them from untrusted input):
1770
1770
1771
+ pub struct InboundOnionForwardPayload {
1772
+ pub short_channel_id : u64 ,
1773
+ /// The value, in msat, of the payment after this hop's fee is deducted.
1774
+ pub amt_to_forward : u64 ,
1775
+ pub outgoing_cltv_value : u32 ,
1776
+ }
1777
+
1778
+ pub struct InboundOnionReceivePayload {
1779
+ pub payment_data : Option < FinalOnionHopData > ,
1780
+ pub payment_metadata : Option < Vec < u8 > > ,
1781
+ pub keysend_preimage : Option < PaymentPreimage > ,
1782
+ pub custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ,
1783
+ pub sender_intended_htlc_amt_msat : u64 ,
1784
+ pub cltv_expiry_height : u32 ,
1785
+ }
1786
+ pub struct InboundOnionBlindedForwardPayload {
1787
+ pub short_channel_id : u64 ,
1788
+ pub payment_relay : PaymentRelay ,
1789
+ pub payment_constraints : PaymentConstraints ,
1790
+ pub features : BlindedHopFeatures ,
1791
+ pub intro_node_blinding_point : Option < PublicKey > ,
1792
+ pub next_blinding_override : Option < PublicKey > ,
1793
+ }
1794
+ pub struct InboundOnionBlindedReceivePayload {
1795
+ pub sender_intended_htlc_amt_msat : u64 ,
1796
+ pub total_msat : u64 ,
1797
+ pub cltv_expiry_height : u32 ,
1798
+ pub payment_secret : PaymentSecret ,
1799
+ pub payment_constraints : PaymentConstraints ,
1800
+ pub payment_context : PaymentContext ,
1801
+ pub intro_node_blinding_point : Option < PublicKey > ,
1802
+ pub keysend_preimage : Option < PaymentPreimage > ,
1803
+ pub invoice_request : Option < InvoiceRequest > ,
1804
+ pub custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ,
1805
+ }
1806
+
1771
1807
pub enum InboundOnionPayload {
1772
- Forward {
1773
- short_channel_id : u64 ,
1774
- /// The value, in msat, of the payment after this hop's fee is deducted.
1775
- amt_to_forward : u64 ,
1776
- outgoing_cltv_value : u32 ,
1777
- } ,
1778
- Receive {
1779
- payment_data : Option < FinalOnionHopData > ,
1780
- payment_metadata : Option < Vec < u8 > > ,
1781
- keysend_preimage : Option < PaymentPreimage > ,
1782
- custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ,
1783
- sender_intended_htlc_amt_msat : u64 ,
1784
- cltv_expiry_height : u32 ,
1785
- } ,
1786
- BlindedForward {
1787
- short_channel_id : u64 ,
1788
- payment_relay : PaymentRelay ,
1789
- payment_constraints : PaymentConstraints ,
1790
- features : BlindedHopFeatures ,
1791
- intro_node_blinding_point : Option < PublicKey > ,
1792
- next_blinding_override : Option < PublicKey > ,
1793
- } ,
1794
- BlindedReceive {
1795
- sender_intended_htlc_amt_msat : u64 ,
1796
- total_msat : u64 ,
1797
- cltv_expiry_height : u32 ,
1798
- payment_secret : PaymentSecret ,
1799
- payment_constraints : PaymentConstraints ,
1800
- payment_context : PaymentContext ,
1801
- intro_node_blinding_point : Option < PublicKey > ,
1802
- keysend_preimage : Option < PaymentPreimage > ,
1803
- invoice_request : Option < InvoiceRequest > ,
1804
- custom_tlvs : Vec < ( u64 , Vec < u8 > ) > ,
1805
- }
1808
+ Forward ( InboundOnionForwardPayload ) ,
1809
+ Receive ( InboundOnionReceivePayload ) ,
1810
+ BlindedForward ( InboundOnionBlindedForwardPayload ) ,
1811
+ BlindedReceive ( InboundOnionBlindedReceivePayload ) ,
1806
1812
}
1807
1813
1808
1814
pub ( crate ) enum OutboundOnionPayload < ' a > {
@@ -2907,14 +2913,14 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
2907
2913
{
2908
2914
return Err ( DecodeError :: InvalidValue )
2909
2915
}
2910
- Ok ( Self :: BlindedForward {
2916
+ Ok ( Self :: BlindedForward ( InboundOnionBlindedForwardPayload {
2911
2917
short_channel_id,
2912
2918
payment_relay,
2913
2919
payment_constraints,
2914
2920
features,
2915
2921
intro_node_blinding_point,
2916
2922
next_blinding_override,
2917
- } )
2923
+ } ) )
2918
2924
} ,
2919
2925
ChaChaPolyReadAdapter { readable : BlindedPaymentTlvs :: Receive ( receive_tlvs) } => {
2920
2926
let ReceiveTlvs { tlvs, authentication : ( hmac, nonce) } = receive_tlvs;
@@ -2927,7 +2933,7 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
2927
2933
payment_secret, payment_constraints, payment_context,
2928
2934
} = tlvs;
2929
2935
if total_msat. unwrap_or ( 0 ) > MAX_VALUE_MSAT { return Err ( DecodeError :: InvalidValue ) }
2930
- Ok ( Self :: BlindedReceive {
2936
+ Ok ( Self :: BlindedReceive ( InboundOnionBlindedReceivePayload {
2931
2937
sender_intended_htlc_amt_msat : amt. ok_or ( DecodeError :: InvalidValue ) ?,
2932
2938
total_msat : total_msat. ok_or ( DecodeError :: InvalidValue ) ?,
2933
2939
cltv_expiry_height : cltv_value. ok_or ( DecodeError :: InvalidValue ) ?,
@@ -2938,18 +2944,18 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
2938
2944
keysend_preimage,
2939
2945
invoice_request,
2940
2946
custom_tlvs,
2941
- } )
2947
+ } ) )
2942
2948
} ,
2943
2949
}
2944
2950
} else if let Some ( short_channel_id) = short_id {
2945
2951
if payment_data. is_some ( ) || payment_metadata. is_some ( ) || encrypted_tlvs_opt. is_some ( ) ||
2946
2952
total_msat. is_some ( ) || invoice_request. is_some ( )
2947
2953
{ return Err ( DecodeError :: InvalidValue ) }
2948
- Ok ( Self :: Forward {
2954
+ Ok ( Self :: Forward ( InboundOnionForwardPayload {
2949
2955
short_channel_id,
2950
2956
amt_to_forward : amt. ok_or ( DecodeError :: InvalidValue ) ?,
2951
2957
outgoing_cltv_value : cltv_value. ok_or ( DecodeError :: InvalidValue ) ?,
2952
- } )
2958
+ } ) )
2953
2959
} else {
2954
2960
if encrypted_tlvs_opt. is_some ( ) || total_msat. is_some ( ) || invoice_request. is_some ( ) {
2955
2961
return Err ( DecodeError :: InvalidValue )
@@ -2959,14 +2965,14 @@ impl<NS: Deref> ReadableArgs<(Option<PublicKey>, NS)> for InboundOnionPayload wh
2959
2965
return Err ( DecodeError :: InvalidValue ) ;
2960
2966
}
2961
2967
}
2962
- Ok ( Self :: Receive {
2968
+ Ok ( Self :: Receive ( InboundOnionReceivePayload {
2963
2969
payment_data,
2964
2970
payment_metadata : payment_metadata. map ( |w| w. 0 ) ,
2965
2971
keysend_preimage,
2966
2972
sender_intended_htlc_amt_msat : amt. ok_or ( DecodeError :: InvalidValue ) ?,
2967
2973
cltv_expiry_height : cltv_value. ok_or ( DecodeError :: InvalidValue ) ?,
2968
2974
custom_tlvs,
2969
- } )
2975
+ } ) )
2970
2976
}
2971
2977
}
2972
2978
}
@@ -3387,7 +3393,7 @@ mod tests {
3387
3393
use crate :: ln:: types:: ChannelId ;
3388
3394
use crate :: types:: payment:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
3389
3395
use crate :: types:: features:: { ChannelFeatures , ChannelTypeFeatures , InitFeatures , NodeFeatures } ;
3390
- use crate :: ln:: msgs:: { self , FinalOnionHopData , OnionErrorPacket , CommonOpenChannelFields , CommonAcceptChannelFields , OutboundTrampolinePayload , TrampolineOnionPacket } ;
3396
+ use crate :: ln:: msgs:: { self , FinalOnionHopData , OnionErrorPacket , CommonOpenChannelFields , CommonAcceptChannelFields , OutboundTrampolinePayload , TrampolineOnionPacket , InboundOnionForwardPayload , InboundOnionReceivePayload } ;
3391
3397
use crate :: ln:: msgs:: SocketAddress ;
3392
3398
use crate :: routing:: gossip:: { NodeAlias , NodeId } ;
3393
3399
use crate :: util:: ser:: { BigSize , FixedLengthReader , Hostname , LengthReadable , Readable , ReadableArgs , TransactionU16LenLimited , Writeable } ;
@@ -4559,9 +4565,9 @@ mod tests {
4559
4565
4560
4566
let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
4561
4567
let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , ( None , & node_signer) ) . unwrap ( ) ;
4562
- if let msgs:: InboundOnionPayload :: Forward {
4568
+ if let msgs:: InboundOnionPayload :: Forward ( InboundOnionForwardPayload {
4563
4569
short_channel_id, amt_to_forward, outgoing_cltv_value
4564
- } = inbound_msg {
4570
+ } ) = inbound_msg {
4565
4571
assert_eq ! ( short_channel_id, 0xdeadbeef1bad1dea ) ;
4566
4572
assert_eq ! ( amt_to_forward, 0x0badf00d01020304 ) ;
4567
4573
assert_eq ! ( outgoing_cltv_value, 0xffffffff ) ;
@@ -4584,9 +4590,9 @@ mod tests {
4584
4590
4585
4591
let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
4586
4592
let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , ( None , & node_signer) ) . unwrap ( ) ;
4587
- if let msgs:: InboundOnionPayload :: Receive {
4593
+ if let msgs:: InboundOnionPayload :: Receive ( InboundOnionReceivePayload {
4588
4594
payment_data : None , sender_intended_htlc_amt_msat, cltv_expiry_height, ..
4589
- } = inbound_msg {
4595
+ } ) = inbound_msg {
4590
4596
assert_eq ! ( sender_intended_htlc_amt_msat, 0x0badf00d01020304 ) ;
4591
4597
assert_eq ! ( cltv_expiry_height, 0xffffffff ) ;
4592
4598
} else { panic ! ( ) ; }
@@ -4612,7 +4618,7 @@ mod tests {
4612
4618
4613
4619
let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
4614
4620
let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , ( None , & node_signer) ) . unwrap ( ) ;
4615
- if let msgs:: InboundOnionPayload :: Receive {
4621
+ if let msgs:: InboundOnionPayload :: Receive ( InboundOnionReceivePayload {
4616
4622
payment_data : Some ( FinalOnionHopData {
4617
4623
payment_secret,
4618
4624
total_msat : 0x1badca1f
@@ -4621,7 +4627,7 @@ mod tests {
4621
4627
payment_metadata : None ,
4622
4628
keysend_preimage : None ,
4623
4629
custom_tlvs,
4624
- } = inbound_msg {
4630
+ } ) = inbound_msg {
4625
4631
assert_eq ! ( payment_secret, expected_payment_secret) ;
4626
4632
assert_eq ! ( sender_intended_htlc_amt_msat, 0x0badf00d01020304 ) ;
4627
4633
assert_eq ! ( cltv_expiry_height, 0xffffffff ) ;
@@ -4658,7 +4664,7 @@ mod tests {
4658
4664
let encoded_value = msg. encode ( ) ;
4659
4665
let inbound_msg = ReadableArgs :: read ( & mut Cursor :: new ( & encoded_value[ ..] ) , ( None , & node_signer) ) . unwrap ( ) ;
4660
4666
match inbound_msg {
4661
- msgs:: InboundOnionPayload :: Receive { custom_tlvs, .. } => assert ! ( custom_tlvs. is_empty( ) ) ,
4667
+ msgs:: InboundOnionPayload :: Receive ( InboundOnionReceivePayload { custom_tlvs, .. } ) => assert ! ( custom_tlvs. is_empty( ) ) ,
4662
4668
_ => panic ! ( ) ,
4663
4669
}
4664
4670
}
@@ -4682,15 +4688,15 @@ mod tests {
4682
4688
assert_eq ! ( encoded_value, target_value) ;
4683
4689
let node_signer = test_utils:: TestKeysInterface :: new ( & [ 42 ; 32 ] , Network :: Testnet ) ;
4684
4690
let inbound_msg: msgs:: InboundOnionPayload = ReadableArgs :: read ( & mut Cursor :: new ( & target_value[ ..] ) , ( None , & node_signer) ) . unwrap ( ) ;
4685
- if let msgs:: InboundOnionPayload :: Receive {
4691
+ if let msgs:: InboundOnionPayload :: Receive ( InboundOnionReceivePayload {
4686
4692
payment_data : None ,
4687
4693
payment_metadata : None ,
4688
4694
keysend_preimage : None ,
4689
4695
custom_tlvs,
4690
4696
sender_intended_htlc_amt_msat,
4691
4697
cltv_expiry_height : outgoing_cltv_value,
4692
4698
..
4693
- } = inbound_msg {
4699
+ } ) = inbound_msg {
4694
4700
assert_eq ! ( custom_tlvs, expected_custom_tlvs) ;
4695
4701
assert_eq ! ( sender_intended_htlc_amt_msat, 0x0badf00d01020304 ) ;
4696
4702
assert_eq ! ( outgoing_cltv_value, 0xffffffff ) ;
0 commit comments