@@ -17,7 +17,7 @@ use util::enforcing_trait_impls::EnforcingChannelKeys;
17
17
use util:: test_utils;
18
18
use util:: events:: { Event , EventsProvider , MessageSendEvent , MessageSendEventsProvider } ;
19
19
use util:: errors:: APIError ;
20
- use util:: ser:: { Writeable , ReadableArgs } ;
20
+ use util:: ser:: { Writeable , Writer , ReadableArgs } ;
21
21
use util:: config:: UserConfig ;
22
22
use util:: logger:: Logger ;
23
23
@@ -43,7 +43,7 @@ use std::collections::{BTreeSet, HashMap, HashSet};
43
43
use std:: default:: Default ;
44
44
use std:: sync:: { Arc , Mutex } ;
45
45
use std:: sync:: atomic:: Ordering ;
46
- use std:: mem;
46
+ use std:: { mem, io } ;
47
47
48
48
use rand:: { thread_rng, Rng } ;
49
49
@@ -4827,6 +4827,20 @@ impl msgs::ChannelUpdate {
4827
4827
}
4828
4828
}
4829
4829
4830
+ struct BogusOnionHopData {
4831
+ data : Vec < u8 >
4832
+ }
4833
+ impl BogusOnionHopData {
4834
+ fn new ( orig : msgs:: OnionHopData ) -> Self {
4835
+ Self { data : orig. encode ( ) }
4836
+ }
4837
+ }
4838
+ impl Writeable for BogusOnionHopData {
4839
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
4840
+ writer. write_all ( & self . data [ ..] )
4841
+ }
4842
+ }
4843
+
4830
4844
#[ test]
4831
4845
fn test_onion_failure ( ) {
4832
4846
use ln:: msgs:: ChannelUpdate ;
@@ -4854,8 +4868,12 @@ fn test_onion_failure() {
4854
4868
let cur_height = nodes[ 0 ] . node . latest_block_height . load ( Ordering :: Acquire ) as u32 + 1 ;
4855
4869
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route, & session_priv) . unwrap ( ) ;
4856
4870
let ( mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route, cur_height) . unwrap ( ) ;
4857
- onion_payloads[ 0 ] . format = msgs:: OnionHopDataFormat :: BogusRealm ( 3 ) ;
4858
- msg. onion_routing_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4871
+ let mut new_payloads = Vec :: new ( ) ;
4872
+ for payload in onion_payloads. drain ( ..) {
4873
+ new_payloads. push ( BogusOnionHopData :: new ( payload) ) ;
4874
+ }
4875
+ new_payloads[ 0 ] . data [ 0 ] = 1 ;
4876
+ msg. onion_routing_packet = onion_utils:: construct_onion_packet_bogus_hopdata ( new_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4859
4877
} , ||{ } , true , Some ( PERM |1 ) , Some ( msgs:: HTLCFailChannelUpdate :: ChannelClosed { short_channel_id : channels[ 1 ] . 0 . contents . short_channel_id , is_permanent : true } ) ) ; //XXX incremented channels idx here
4860
4878
4861
4879
// final node failure
@@ -4864,8 +4882,12 @@ fn test_onion_failure() {
4864
4882
let cur_height = nodes[ 0 ] . node . latest_block_height . load ( Ordering :: Acquire ) as u32 + 1 ;
4865
4883
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route, & session_priv) . unwrap ( ) ;
4866
4884
let ( mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route, cur_height) . unwrap ( ) ;
4867
- onion_payloads[ 1 ] . format = msgs:: OnionHopDataFormat :: BogusRealm ( 3 ) ;
4868
- msg. onion_routing_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4885
+ let mut new_payloads = Vec :: new ( ) ;
4886
+ for payload in onion_payloads. drain ( ..) {
4887
+ new_payloads. push ( BogusOnionHopData :: new ( payload) ) ;
4888
+ }
4889
+ new_payloads[ 1 ] . data [ 0 ] = 1 ;
4890
+ msg. onion_routing_packet = onion_utils:: construct_onion_packet_bogus_hopdata ( new_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4869
4891
} , ||{ } , false , Some ( PERM |1 ) , Some ( msgs:: HTLCFailChannelUpdate :: ChannelClosed { short_channel_id : channels[ 1 ] . 0 . contents . short_channel_id , is_permanent : true } ) ) ;
4870
4892
4871
4893
// the following three with run_onion_failure_test_with_fail_intercept() test only the origin node
0 commit comments