@@ -949,7 +949,7 @@ impl ChannelManager {
949
949
if msg. onion_routing_packet . version != 0 {
950
950
//TODO: Spec doesn't indicate if we should only hash hop_data here (and in other
951
951
//sha256_of_onion error data packets), or the entire onion_routing_packet. Either way,
952
- //the hash doesn't really serve any purpuse - in the case of hashing all data, the
952
+ //the hash doesn't really serve any purpose - in the case of hashing all data, the
953
953
//receiving node would have to brute force to figure out which version was put in the
954
954
//packet by the node that send us the message, in the case of hashing the hop_data, the
955
955
//node knows the HMAC matched, so they already know what is there...
@@ -3222,7 +3222,7 @@ mod tests {
3222
3222
use util:: logger:: Logger ;
3223
3223
use util:: ser:: { Writeable , Writer , ReadableArgs } ;
3224
3224
use util:: config:: UserConfig ;
3225
-
3225
+ use util :: rng ;
3226
3226
use bitcoin:: util:: hash:: { BitcoinHash , Sha256dHash } ;
3227
3227
use bitcoin:: blockdata:: block:: { Block , BlockHeader } ;
3228
3228
use bitcoin:: blockdata:: transaction:: { Transaction , TxOut } ;
@@ -7532,4 +7532,58 @@ mod tests {
7532
7532
assert_eq ! ( msg. channel_id, channel_id) ;
7533
7533
} else { panic ! ( "Unexpected result" ) ; }
7534
7534
}
7535
+
7536
+ #[ test]
7537
+ ///Test that forwarding an onion packet with version other than 0 fails
7538
+ fn test_bolt4_onion_packet_version_error ( ) {
7539
+ let nodes = create_network ( 3 ) ;
7540
+
7541
+ let chan_1 = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
7542
+ let chan_2 = create_announced_chan_between_nodes ( & nodes, 1 , 2 ) ;
7543
+
7544
+ let expected_route = vec ! ( & nodes[ 1 ] , & nodes[ 2 ] ) ;
7545
+ let value = 1000000 ;
7546
+
7547
+ let our_payment_preimage = route_payment ( & nodes[ 0 ] , & expected_route, value) . 0 ;
7548
+ let route = nodes[ 0 ] . router . get_route ( & expected_route. last ( ) . unwrap ( ) . node . get_our_node_id ( ) , None , & Vec :: new ( ) , value, TEST_FINAL_CLTV ) . unwrap ( ) ;
7549
+
7550
+ let secp_ctx = Secp256k1 :: new ( ) ;
7551
+ let session_priv = SecretKey :: from_slice ( & secp_ctx, & {
7552
+ let mut session_key = [ 0 ; 32 ] ;
7553
+ rng:: fill_bytes ( & mut session_key) ;
7554
+ session_key
7555
+ } ) . expect ( "RNG is bad!" ) ;
7556
+
7557
+ let cur_height = nodes[ 0 ] . node . latest_block_height . load ( Ordering :: Acquire ) as u32 + 1 ;
7558
+
7559
+ let onion_keys = ChannelManager :: construct_onion_keys ( & secp_ctx, & route, & session_priv) . unwrap ( ) ;
7560
+
7561
+ let ( onion_payloads, htlc_msat, htlc_cltv) = ChannelManager :: build_onion_payloads ( & route, cur_height) . unwrap ( ) ;
7562
+ let mut onion_packet = ChannelManager :: construct_onion_packet ( onion_payloads, onion_keys, & our_payment_preimage) ;
7563
+
7564
+ onion_packet. version = 1 ;
7565
+
7566
+ let mut channel_state = nodes[ 0 ] . node . channel_state . lock ( ) . unwrap ( ) ;
7567
+ let ( update_add, commitment_signed, chan_monitor) = {
7568
+ let chan = channel_state. by_id . get_mut ( & chan_1. 2 ) . unwrap ( ) ;
7569
+ chan. send_htlc_and_commit ( htlc_msat, our_payment_preimage. clone ( ) , htlc_cltv, super :: channel_held_info:: HTLCSource :: OutboundRoute {
7570
+ route : route. clone ( ) ,
7571
+ session_priv : session_priv. clone ( ) ,
7572
+ first_hop_htlc_msat : htlc_msat,
7573
+ } , onion_packet) . unwrap ( ) . unwrap ( ) //.map_err(|he| APIError::ChannelUnavailable{err: he.err}).unwrap()
7574
+ } ;
7575
+
7576
+ println ! ( "Mesg: {:?}" , update_add. onion_routing_packet. version) ;
7577
+
7578
+ let res = nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & update_add) ;
7579
+ //This does create a PendingHTLCStatus::Fail situation that seems is maybe sent back to the node
7580
+ //and is finally handled in channel::revoke_and_ack(...)
7581
+
7582
+ println ! ( "Bolt4: {:?}" , res) ;
7583
+
7584
+
7585
+ assert ! ( false ) ;
7586
+ }
7587
+
7535
7588
}
7589
+
0 commit comments