1
+ use core:: sync:: atomic:: Ordering ;
2
+
1
3
use bitcoin:: hashes:: Hash ;
2
4
use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
3
- use core:: sync:: atomic:: Ordering ;
4
5
use crate :: events:: { Event , HTLCDestination , MessageSendEvent , MessageSendEventsProvider } ;
5
- use crate :: ln:: { PaymentPreimage , PaymentHash , PaymentSecret } ;
6
+ use crate :: ln:: { self , inbound_payment , PaymentHash , PaymentPreimage , PaymentSecret } ;
6
7
use crate :: ln:: channelmanager:: { HTLCForwardInfo , PaymentId , RecipientOnionFields } ;
7
8
use crate :: ln:: onion_payment:: create_recv_pending_htlc_info;
8
- use crate :: ln:: inbound_payment;
9
9
use crate :: ln:: functional_test_utils:: * ;
10
10
use crate :: ln:: msgs:: { self } ;
11
11
use crate :: ln:: msgs:: ChannelMessageHandler ;
12
12
use crate :: prelude:: * ;
13
13
use crate :: routing:: router:: { PaymentParameters , RouteParameters , find_route} ;
14
14
use crate :: util:: ser:: Writeable ;
15
15
use crate :: util:: test_utils;
16
- use crate :: sign:: EntropySource ;
16
+ use crate :: sign:: { EntropySource , NodeSigner } ;
17
17
18
18
#[ test]
19
19
fn test_keysend_dup_hash_partial_mpp ( ) {
@@ -388,33 +388,41 @@ fn bad_inbound_payment_hash() {
388
388
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
389
389
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
390
390
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
391
+ node_cfgs[ 0 ] . keys_manager . get_inbound_payment_key_material ( ) ;
392
+
393
+ let highest_seen_timestamp = bitcoin:: blockdata:: constants:: genesis_block ( bitcoin:: Network :: Testnet ) . header . time ;
394
+ let node_signer = node_cfgs[ 0 ] . keys_manager ;
395
+ let inbound_pmt_key_material = node_signer. get_inbound_payment_key_material ( ) ;
396
+ let expanded_inbound_key = inbound_payment:: ExpandedKey :: new ( & inbound_pmt_key_material) ;
391
397
392
398
let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ! ( & nodes[ 0 ] ) ;
393
399
let payment_data = msgs:: FinalOnionHopData {
394
400
payment_secret,
395
401
total_msat : 100_000 ,
396
402
} ;
397
403
404
+
398
405
// Ensure that if the payment hash given to `inbound_payment::verify` differs from the original,
399
406
// payment verification fails as expected.
400
407
let mut bad_payment_hash = payment_hash. clone ( ) ;
401
408
bad_payment_hash. 0 [ 0 ] += 1 ;
402
- match inbound_payment:: verify ( bad_payment_hash, & payment_data, nodes [ 0 ] . node . highest_seen_timestamp . load ( Ordering :: Acquire ) as u64 , & nodes [ 0 ] . node . inbound_payment_key , & nodes[ 0 ] . logger ) {
409
+ match inbound_payment:: verify ( bad_payment_hash, & payment_data, highest_seen_timestamp as u64 , & expanded_inbound_key , & nodes[ 0 ] . logger ) {
403
410
Ok ( _) => panic ! ( "Unexpected ok" ) ,
404
411
Err ( ( ) ) => {
405
412
nodes[ 0 ] . logger . assert_log_contains ( "lightning::ln::inbound_payment" , "Failing HTLC with user-generated payment_hash" , 1 ) ;
406
413
}
407
414
}
408
415
409
416
// Check that using the original payment hash succeeds.
410
- assert ! ( inbound_payment:: verify( payment_hash, & payment_data, nodes [ 0 ] . node . highest_seen_timestamp. load ( Ordering :: Acquire ) as u64 , & nodes [ 0 ] . node . inbound_payment_key , & nodes[ 0 ] . logger) . is_ok( ) ) ;
417
+ assert ! ( inbound_payment:: verify( payment_hash, & payment_data, highest_seen_timestamp as u64 , & expanded_inbound_key , & nodes[ 0 ] . logger) . is_ok( ) ) ;
411
418
}
412
419
413
420
#[ test]
414
421
fn reject_excessively_underpaying_htlcs ( ) {
415
422
let chanmon_cfg = create_chanmon_cfgs ( 1 ) ;
416
423
let node_cfg = create_node_cfgs ( 1 , & chanmon_cfg) ;
417
- let node_chanmgr = create_node_chanmgrs ( 1 , & node_cfg, & [ None ] ) ;
424
+ let user_cfg = test_default_channel_config ( ) ;
425
+ let node_chanmgr = create_node_chanmgrs ( 1 , & node_cfg, & [ Some ( user_cfg) ] ) ;
418
426
let node = create_network ( 1 , & node_cfg, & node_chanmgr) ;
419
427
let sender_intended_amt_msat = 100 ;
420
428
let extra_fee_msat = 10 ;
@@ -431,10 +439,10 @@ fn reject_excessively_underpaying_htlcs() {
431
439
// Check that if the amount we received + the penultimate hop extra fee is less than the sender
432
440
// intended amount, we fail the payment.
433
441
let current_height: u32 = node[ 0 ] . node . best_block . read ( ) . unwrap ( ) . height ;
434
- if let Err ( crate :: ln:: channelmanager :: InboundHTLCErr { err_code, .. } ) =
442
+ if let Err ( ln:: onion_payment :: InboundHTLCErr { err_code, .. } ) =
435
443
create_recv_pending_htlc_info ( hop_data, [ 0 ; 32 ] , PaymentHash ( [ 0 ; 32 ] ) ,
436
444
sender_intended_amt_msat - extra_fee_msat - 1 , 42 , None , true , Some ( extra_fee_msat) ,
437
- current_height, node [ 0 ] . node . default_configuration . accept_mpp_keysend )
445
+ current_height, user_cfg . accept_mpp_keysend )
438
446
{
439
447
assert_eq ! ( err_code, 19 ) ;
440
448
} else { panic ! ( ) ; }
@@ -453,14 +461,15 @@ fn reject_excessively_underpaying_htlcs() {
453
461
let current_height: u32 = node[ 0 ] . node . best_block . read ( ) . unwrap ( ) . height ;
454
462
assert ! ( create_recv_pending_htlc_info( hop_data, [ 0 ; 32 ] , PaymentHash ( [ 0 ; 32 ] ) ,
455
463
sender_intended_amt_msat - extra_fee_msat, 42 , None , true , Some ( extra_fee_msat) ,
456
- current_height, node [ 0 ] . node . default_configuration . accept_mpp_keysend) . is_ok( ) ) ;
464
+ current_height, user_cfg . accept_mpp_keysend) . is_ok( ) ) ;
457
465
}
458
466
459
467
#[ test]
460
468
fn test_final_incorrect_cltv ( ) {
461
469
let chanmon_cfg = create_chanmon_cfgs ( 1 ) ;
462
470
let node_cfg = create_node_cfgs ( 1 , & chanmon_cfg) ;
463
- let node_chanmgr = create_node_chanmgrs ( 1 , & node_cfg, & [ None ] ) ;
471
+ let user_cfg = test_default_channel_config ( ) ;
472
+ let node_chanmgr = create_node_chanmgrs ( 1 , & node_cfg, & [ Some ( user_cfg) ] ) ;
464
473
let node = create_network ( 1 , & node_cfg, & node_chanmgr) ;
465
474
466
475
let current_height: u32 = node[ 0 ] . node . best_block . read ( ) . unwrap ( ) . height ;
@@ -474,7 +483,7 @@ fn test_final_incorrect_cltv(){
474
483
} ) ,
475
484
custom_tlvs : Vec :: new ( ) ,
476
485
} , [ 0 ; 32 ] , PaymentHash ( [ 0 ; 32 ] ) , 100 , 23 , None , true , None , current_height,
477
- node [ 0 ] . node . default_configuration . accept_mpp_keysend ) ;
486
+ user_cfg . accept_mpp_keysend ) ;
478
487
479
488
// Should not return an error as this condition:
480
489
// https://github.com/lightning/bolts/blob/4dcc377209509b13cf89a4b91fde7d478f5b46d8/04-onion-routing.md?plain=1#L334
0 commit comments