@@ -18,7 +18,7 @@ use util::enforcing_trait_impls::EnforcingChannelKeys;
18
18
use util:: test_utils;
19
19
use util:: events:: { Event , EventsProvider , MessageSendEvent , MessageSendEventsProvider } ;
20
20
use util:: errors:: APIError ;
21
- use util:: ser:: { Writeable , ReadableArgs } ;
21
+ use util:: ser:: { Writeable , Writer , ReadableArgs } ;
22
22
use util:: config:: UserConfig ;
23
23
use util:: logger:: Logger ;
24
24
@@ -44,7 +44,7 @@ use std::collections::{BTreeSet, HashMap, HashSet};
44
44
use std:: default:: Default ;
45
45
use std:: sync:: { Arc , Mutex } ;
46
46
use std:: sync:: atomic:: Ordering ;
47
- use std:: mem;
47
+ use std:: { mem, io } ;
48
48
49
49
use rand:: { thread_rng, Rng } ;
50
50
@@ -4853,6 +4853,20 @@ impl msgs::ChannelUpdate {
4853
4853
}
4854
4854
}
4855
4855
4856
+ struct BogusOnionHopData {
4857
+ data : Vec < u8 >
4858
+ }
4859
+ impl BogusOnionHopData {
4860
+ fn new ( orig : msgs:: OnionHopData ) -> Self {
4861
+ Self { data : orig. encode ( ) }
4862
+ }
4863
+ }
4864
+ impl Writeable for BogusOnionHopData {
4865
+ fn write < W : Writer > ( & self , writer : & mut W ) -> Result < ( ) , io:: Error > {
4866
+ writer. write_all ( & self . data [ ..] )
4867
+ }
4868
+ }
4869
+
4856
4870
#[ test]
4857
4871
fn test_onion_failure ( ) {
4858
4872
use ln:: msgs:: ChannelUpdate ;
@@ -4880,8 +4894,12 @@ fn test_onion_failure() {
4880
4894
let cur_height = nodes[ 0 ] . node . latest_block_height . load ( Ordering :: Acquire ) as u32 + 1 ;
4881
4895
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route, & session_priv) . unwrap ( ) ;
4882
4896
let ( mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route, cur_height) . unwrap ( ) ;
4883
- onion_payloads[ 0 ] . format = msgs:: OnionHopDataFormat :: BogusRealm ( 3 ) ;
4884
- msg. onion_routing_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4897
+ let mut new_payloads = Vec :: new ( ) ;
4898
+ for payload in onion_payloads. drain ( ..) {
4899
+ new_payloads. push ( BogusOnionHopData :: new ( payload) ) ;
4900
+ }
4901
+ new_payloads[ 0 ] . data [ 0 ] = 1 ;
4902
+ msg. onion_routing_packet = onion_utils:: construct_onion_packet_bogus_hopdata ( new_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4885
4903
} , ||{ } , 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
4886
4904
4887
4905
// final node failure
@@ -4890,8 +4908,12 @@ fn test_onion_failure() {
4890
4908
let cur_height = nodes[ 0 ] . node . latest_block_height . load ( Ordering :: Acquire ) as u32 + 1 ;
4891
4909
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route, & session_priv) . unwrap ( ) ;
4892
4910
let ( mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils:: build_onion_payloads ( & route, cur_height) . unwrap ( ) ;
4893
- onion_payloads[ 1 ] . format = msgs:: OnionHopDataFormat :: BogusRealm ( 3 ) ;
4894
- msg. onion_routing_packet = onion_utils:: construct_onion_packet ( onion_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4911
+ let mut new_payloads = Vec :: new ( ) ;
4912
+ for payload in onion_payloads. drain ( ..) {
4913
+ new_payloads. push ( BogusOnionHopData :: new ( payload) ) ;
4914
+ }
4915
+ new_payloads[ 1 ] . data [ 0 ] = 1 ;
4916
+ msg. onion_routing_packet = onion_utils:: construct_onion_packet_bogus_hopdata ( new_payloads, onion_keys, [ 0 ; 32 ] , & payment_hash) ;
4895
4917
} , ||{ } , false , Some ( PERM |1 ) , Some ( msgs:: HTLCFailChannelUpdate :: ChannelClosed { short_channel_id : channels[ 1 ] . 0 . contents . short_channel_id , is_permanent : true } ) ) ;
4896
4918
4897
4919
// the following three with run_onion_failure_test_with_fail_intercept() test only the origin node
0 commit comments