@@ -211,14 +211,14 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
211
211
}
212
212
213
213
impl msgs:: ChannelUpdate {
214
- fn dummy ( ) -> msgs:: ChannelUpdate {
214
+ fn dummy ( short_channel_id : u64 ) -> msgs:: ChannelUpdate {
215
215
use bitcoin:: secp256k1:: ffi:: Signature as FFISignature ;
216
216
use bitcoin:: secp256k1:: Signature ;
217
217
msgs:: ChannelUpdate {
218
218
signature : Signature :: from ( unsafe { FFISignature :: new ( ) } ) ,
219
219
contents : msgs:: UnsignedChannelUpdate {
220
220
chain_hash : BlockHash :: hash ( & vec ! [ 0u8 ] [ ..] ) ,
221
- short_channel_id : 0 ,
221
+ short_channel_id,
222
222
timestamp : 0 ,
223
223
flags : 0 ,
224
224
cltv_expiry_delta : 0 ,
@@ -435,13 +435,14 @@ fn test_onion_failure() {
435
435
run_onion_failure_test ( "invalid_onion_key" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| { msg. onion_routing_packet . public_key = Err ( secp256k1:: Error :: InvalidPublicKey ) ; } , ||{ } , true ,
436
436
Some ( BADONION |PERM |6 ) , None , None ) ;
437
437
438
+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
438
439
run_onion_failure_test_with_fail_intercept ( "temporary_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
439
440
msg. amount_msat -= 1 ;
440
441
} , |msg| {
441
442
let session_priv = SecretKey :: from_slice ( & [ 3 ; 32 ] ) . unwrap ( ) ;
442
443
let onion_keys = onion_utils:: construct_onion_keys ( & Secp256k1 :: new ( ) , & route. paths [ 0 ] , & session_priv) . unwrap ( ) ;
443
- msg. reason = onion_utils:: build_first_hop_failure_packet ( & onion_keys[ 0 ] . shared_secret [ ..] , UPDATE |7 , & ChannelUpdate :: dummy ( ) . encode_with_len ( ) [ ..] ) ;
444
- } , ||{ } , true , Some ( UPDATE |7 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( ) } ) , Some ( channels [ 0 ] . 0 . contents . short_channel_id ) ) ;
444
+ msg. reason = onion_utils:: build_first_hop_failure_packet ( & onion_keys[ 0 ] . shared_secret [ ..] , UPDATE |7 , & ChannelUpdate :: dummy ( short_channel_id ) . encode_with_len ( ) [ ..] ) ;
445
+ } , ||{ } , true , Some ( UPDATE |7 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id ) } ) , Some ( short_channel_id) ) ;
445
446
446
447
let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
447
448
run_onion_failure_test_with_fail_intercept ( "permanent_channel_failure" , 100 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
@@ -469,11 +470,12 @@ fn test_onion_failure() {
469
470
run_onion_failure_test ( "unknown_next_peer" , 0 , & nodes, & bogus_route, & payment_hash, & payment_secret, |_| { } , ||{ } , true , Some ( PERM |10 ) ,
470
471
Some ( NetworkUpdate :: ChannelClosed { short_channel_id, is_permanent : true } ) , Some ( short_channel_id) ) ;
471
472
473
+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
472
474
let amt_to_forward = nodes[ 1 ] . node . channel_state . lock ( ) . unwrap ( ) . by_id . get ( & channels[ 1 ] . 2 ) . unwrap ( ) . get_counterparty_htlc_minimum_msat ( ) - 1 ;
473
475
let mut bogus_route = route. clone ( ) ;
474
476
let route_len = bogus_route. paths [ 0 ] . len ( ) ;
475
477
bogus_route. paths [ 0 ] [ route_len-1 ] . fee_msat = amt_to_forward;
476
- run_onion_failure_test ( "amount_below_minimum" , 0 , & nodes, & bogus_route, & payment_hash, & payment_secret, |_| { } , ||{ } , true , Some ( UPDATE |11 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( ) } ) , Some ( channels [ 0 ] . 0 . contents . short_channel_id ) ) ;
478
+ run_onion_failure_test ( "amount_below_minimum" , 0 , & nodes, & bogus_route, & payment_hash, & payment_secret, |_| { } , ||{ } , true , Some ( UPDATE |11 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id ) } ) , Some ( short_channel_id) ) ;
477
479
478
480
// Test a positive test-case with one extra msat, meeting the minimum.
479
481
bogus_route. paths [ 0 ] [ route_len-1 ] . fee_msat = amt_to_forward + 1 ;
@@ -493,12 +495,13 @@ fn test_onion_failure() {
493
495
msg. cltv_expiry -= 1 ;
494
496
} , || { } , true , Some ( UPDATE |13 ) , Some ( NetworkUpdate :: ChannelClosed { short_channel_id, is_permanent : true } ) , Some ( short_channel_id) ) ;
495
497
498
+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
496
499
run_onion_failure_test ( "expiry_too_soon" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
497
500
let height = msg. cltv_expiry - CLTV_CLAIM_BUFFER - LATENCY_GRACE_PERIOD_BLOCKS + 1 ;
498
501
connect_blocks ( & nodes[ 0 ] , height - nodes[ 0 ] . best_block_info ( ) . 1 ) ;
499
502
connect_blocks ( & nodes[ 1 ] , height - nodes[ 1 ] . best_block_info ( ) . 1 ) ;
500
503
connect_blocks ( & nodes[ 2 ] , height - nodes[ 2 ] . best_block_info ( ) . 1 ) ;
501
- } , ||{ } , true , Some ( UPDATE |14 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( ) } ) , Some ( channels [ 0 ] . 0 . contents . short_channel_id ) ) ;
504
+ } , ||{ } , true , Some ( UPDATE |14 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id ) } ) , Some ( short_channel_id) ) ;
502
505
503
506
run_onion_failure_test ( "unknown_payment_hash" , 2 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || {
504
507
nodes[ 2 ] . node . fail_htlc_backwards ( & payment_hash) ;
@@ -537,11 +540,12 @@ fn test_onion_failure() {
537
540
}
538
541
} , true , Some ( 19 ) , None , Some ( channels[ 1 ] . 0 . contents . short_channel_id ) ) ;
539
542
543
+ let short_channel_id = channels[ 1 ] . 0 . contents . short_channel_id ;
540
544
run_onion_failure_test ( "channel_disabled" , 0 , & nodes, & route, & payment_hash, & payment_secret, |_| { } , || {
541
545
// disconnect event to the channel between nodes[1] ~ nodes[2]
542
546
nodes[ 1 ] . node . peer_disconnected ( & nodes[ 2 ] . node . get_our_node_id ( ) , false ) ;
543
547
nodes[ 2 ] . node . peer_disconnected ( & nodes[ 1 ] . node . get_our_node_id ( ) , false ) ;
544
- } , true , Some ( UPDATE |20 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( ) } ) , Some ( channels [ 0 ] . 0 . contents . short_channel_id ) ) ;
548
+ } , true , Some ( UPDATE |20 ) , Some ( NetworkUpdate :: ChannelUpdateMessage { msg : ChannelUpdate :: dummy ( short_channel_id ) } ) , Some ( short_channel_id) ) ;
545
549
reconnect_nodes ( & nodes[ 1 ] , & nodes[ 2 ] , ( false , false ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( 0 , 0 ) , ( false , false ) ) ;
546
550
547
551
run_onion_failure_test ( "expiry_too_far" , 0 , & nodes, & route, & payment_hash, & payment_secret, |msg| {
0 commit comments