@@ -27,7 +27,7 @@ use lightning::chain::chaininterface::{BroadcasterInterface,ConfirmationTarget,C
27
27
use lightning:: chain:: keysinterface:: { KeysInterface , InMemoryChannelKeys } ;
28
28
use lightning:: ln:: channelmonitor;
29
29
use lightning:: ln:: channelmonitor:: { ChannelMonitor , ChannelMonitorUpdateErr , HTLCUpdate } ;
30
- use lightning:: ln:: channelmanager:: { ChannelManager , PaymentHash , PaymentPreimage , ChannelManagerReadArgs } ;
30
+ use lightning:: ln:: channelmanager:: { ChannelManager , PaymentHash , PaymentPreimage , PaymentSecret , ChannelManagerReadArgs } ;
31
31
use lightning:: ln:: router:: { Route , RouteHop } ;
32
32
use lightning:: ln:: features:: { ChannelFeatures , InitFeatures , NodeFeatures } ;
33
33
use lightning:: ln:: msgs:: { CommitmentUpdate , ChannelMessageHandler , ErrorAction , UpdateAddHTLC , Init } ;
@@ -447,6 +447,48 @@ pub fn do_test(data: &[u8]) {
447
447
}
448
448
} }
449
449
}
450
+ macro_rules! send_payment_with_secret {
451
+ ( $source: expr, $middle: expr, $dest: expr) => { {
452
+ let payment_hash = Sha256 :: hash( & [ payment_id; 1 ] ) ;
453
+ payment_id = payment_id. wrapping_add( 1 ) ;
454
+ let payment_secret = Sha256 :: hash( & [ payment_id; 1 ] ) ;
455
+ payment_id = payment_id. wrapping_add( 1 ) ;
456
+ if let Err ( _) = $source. send_payment( Route {
457
+ paths: vec![ vec![ RouteHop {
458
+ pubkey: $middle. 0 . get_our_node_id( ) ,
459
+ node_features: NodeFeatures :: empty( ) ,
460
+ short_channel_id: $middle. 1 ,
461
+ channel_features: ChannelFeatures :: empty( ) ,
462
+ fee_msat: 50000 ,
463
+ cltv_expiry_delta: 100 ,
464
+ } , RouteHop {
465
+ pubkey: $dest. 0 . get_our_node_id( ) ,
466
+ node_features: NodeFeatures :: empty( ) ,
467
+ short_channel_id: $dest. 1 ,
468
+ channel_features: ChannelFeatures :: empty( ) ,
469
+ fee_msat: 5000000 ,
470
+ cltv_expiry_delta: 200 ,
471
+ } ] , vec![ RouteHop {
472
+ pubkey: $middle. 0 . get_our_node_id( ) ,
473
+ node_features: NodeFeatures :: empty( ) ,
474
+ short_channel_id: $middle. 1 ,
475
+ channel_features: ChannelFeatures :: empty( ) ,
476
+ fee_msat: 50000 ,
477
+ cltv_expiry_delta: 100 ,
478
+ } , RouteHop {
479
+ pubkey: $dest. 0 . get_our_node_id( ) ,
480
+ node_features: NodeFeatures :: empty( ) ,
481
+ short_channel_id: $dest. 1 ,
482
+ channel_features: ChannelFeatures :: empty( ) ,
483
+ fee_msat: 5000000 ,
484
+ cltv_expiry_delta: 200 ,
485
+ } ] ] ,
486
+ } , PaymentHash ( payment_hash. into_inner( ) ) , & Some ( PaymentSecret ( payment_secret. into_inner( ) ) ) ) {
487
+ // Probably ran out of funds
488
+ test_return!( ) ;
489
+ }
490
+ } }
491
+ }
450
492
451
493
macro_rules! process_msg_events {
452
494
( $node: expr, $corrupt_forward: expr) => { {
@@ -599,12 +641,12 @@ pub fn do_test(data: &[u8]) {
599
641
} ) ;
600
642
for event in events. drain( ..) {
601
643
match event {
602
- events:: Event :: PaymentReceived { payment_hash, .. } => {
644
+ events:: Event :: PaymentReceived { payment_hash, payment_secret , .. } => {
603
645
if claim_set. insert( payment_hash. 0 ) {
604
646
if $fail {
605
- assert!( nodes[ $node] . fail_htlc_backwards( & payment_hash, & None ) ) ;
647
+ assert!( nodes[ $node] . fail_htlc_backwards( & payment_hash, & payment_secret ) ) ;
606
648
} else {
607
- assert!( nodes[ $node] . claim_funds( PaymentPreimage ( payment_hash. 0 ) , & None , 5_000_000 ) ) ;
649
+ assert!( nodes[ $node] . claim_funds( PaymentPreimage ( payment_hash. 0 ) , & payment_secret , 5_000_000 ) ) ;
608
650
}
609
651
}
610
652
} ,
@@ -734,6 +776,8 @@ pub fn do_test(data: &[u8]) {
734
776
nodes[ 2 ] = node_c. clone ( ) ;
735
777
monitor_c = new_monitor_c;
736
778
} ,
779
+ 0x22 => send_payment_with_secret ! ( nodes[ 0 ] , ( & nodes[ 1 ] , chan_a) , ( & nodes[ 2 ] , chan_b) ) ,
780
+ 0x23 => send_payment_with_secret ! ( nodes[ 2 ] , ( & nodes[ 1 ] , chan_b) , ( & nodes[ 0 ] , chan_a) ) ,
737
781
// 0x24 defined above
738
782
_ => test_return ! ( ) ,
739
783
}
0 commit comments