@@ -50,11 +50,12 @@ use std::sync::atomic::Ordering;
50
50
use std:: time:: Instant ;
51
51
use std:: mem;
52
52
53
+ const CHAN_CONFIRM_DEPTH : u32 = 100 ;
53
54
fn confirm_transaction ( chain : & chaininterface:: ChainWatchInterfaceUtil , tx : & Transaction , chan_id : u32 ) {
54
55
assert ! ( chain. does_match_tx( tx) ) ;
55
56
let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
56
57
chain. block_connected_checked ( & header, 1 , & [ tx; 1 ] , & [ chan_id; 1 ] ) ;
57
- for i in 2 ..100 {
58
+ for i in 2 ..CHAN_CONFIRM_DEPTH {
58
59
header = BlockHeader { version : 0x20000000 , prev_blockhash : header. bitcoin_hash ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
59
60
chain. block_connected_checked ( & header, i, & [ tx; 0 ] , & [ 0 ; 0 ] ) ;
60
61
}
@@ -6046,6 +6047,49 @@ fn test_static_output_closing_tx() {
6046
6047
check_spends ! ( spend_txn[ 0 ] , closing_tx) ;
6047
6048
}
6048
6049
6050
+ fn do_htlc_claim_local_commitment_only ( use_dust : bool ) {
6051
+ let nodes = create_network ( 2 ) ;
6052
+ let chan = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) ;
6053
+
6054
+ let ( our_payment_preimage, _) = route_payment ( & nodes[ 0 ] , & [ & nodes[ 1 ] ] , if use_dust { 50000 } else { 3000000 } ) ;
6055
+
6056
+ // Claim the payment, but don't deliver A's commitment_signed, resulting in the HTLC only being
6057
+ // present in B's local commitment transaction, but none of A's commitment transactions.
6058
+ assert ! ( nodes[ 1 ] . node. claim_funds( our_payment_preimage) ) ;
6059
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
6060
+
6061
+ let bs_updates = get_htlc_update_msgs ! ( nodes[ 1 ] , nodes[ 0 ] . node. get_our_node_id( ) ) ;
6062
+ nodes[ 0 ] . node . handle_update_fulfill_htlc ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. update_fulfill_htlcs [ 0 ] ) . unwrap ( ) ;
6063
+ let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
6064
+ assert_eq ! ( events. len( ) , 1 ) ;
6065
+ match events[ 0 ] {
6066
+ Event :: PaymentSent { payment_preimage } => {
6067
+ assert_eq ! ( payment_preimage, our_payment_preimage) ;
6068
+ } ,
6069
+ _ => panic ! ( "Unexpected event" ) ,
6070
+ }
6071
+
6072
+ nodes[ 0 ] . node . handle_commitment_signed ( & nodes[ 1 ] . node . get_our_node_id ( ) , & bs_updates. commitment_signed ) . unwrap ( ) ;
6073
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ;
6074
+ let as_updates = get_revoke_commit_msgs ! ( nodes[ 0 ] , nodes[ 1 ] . node. get_our_node_id( ) ) ;
6075
+ nodes[ 1 ] . node . handle_revoke_and_ack ( & nodes[ 0 ] . node . get_our_node_id ( ) , & as_updates. 0 ) . unwrap ( ) ;
6076
+ check_added_monitors ! ( nodes[ 1 ] , 1 ) ;
6077
+
6078
+ let mut header = BlockHeader { version : 0x20000000 , prev_blockhash : Default :: default ( ) , merkle_root : Default :: default ( ) , time : 42 , bits : 42 , nonce : 42 } ;
6079
+ for i in 1 ..TEST_FINAL_CLTV - CLTV_CLAIM_BUFFER + CHAN_CONFIRM_DEPTH + 1 {
6080
+ nodes[ 1 ] . chain_monitor . block_connected_checked ( & header, i, & Vec :: new ( ) , & Vec :: new ( ) ) ;
6081
+ header. prev_blockhash = header. bitcoin_hash ( ) ;
6082
+ }
6083
+ test_txn_broadcast ( & nodes[ 1 ] , & chan, None , if use_dust { HTLCType :: NONE } else { HTLCType :: SUCCESS } ) ;
6084
+ check_closed_broadcast ! ( nodes[ 1 ] ) ;
6085
+ }
6086
+
6087
+ #[ test]
6088
+ fn htlc_claim_local_commitment_only ( ) {
6089
+ do_htlc_claim_local_commitment_only ( true ) ;
6090
+ do_htlc_claim_local_commitment_only ( false ) ;
6091
+ }
6092
+
6049
6093
fn run_onion_failure_test < F1 , F2 > ( _name : & str , test_case : u8 , nodes : & Vec < Node > , route : & Route , payment_hash : & PaymentHash , callback_msg : F1 , callback_node : F2 , expected_retryable : bool , expected_error_code : Option < u16 > , expected_channel_update : Option < HTLCFailChannelUpdate > )
6050
6094
where F1 : for < ' a > FnMut ( & ' a mut msgs:: UpdateAddHTLC ) ,
6051
6095
F2 : FnMut ( ) ,
0 commit comments