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