@@ -7,7 +7,7 @@ use crate::ln::chan_utils::{
7
7
} ;
8
8
use crate :: ln:: channel:: {
9
9
get_holder_selected_channel_reserve_satoshis, Channel , FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE ,
10
- MIN_AFFORDABLE_HTLC_COUNT ,
10
+ MIN_AFFORDABLE_HTLC_COUNT , MIN_CHAN_DUST_LIMIT_SATOSHIS ,
11
11
} ;
12
12
use crate :: ln:: channelmanager:: { PaymentId , RAACommitmentOrder } ;
13
13
use crate :: ln:: functional_test_utils:: * ;
@@ -16,6 +16,7 @@ use crate::ln::onion_utils::{self, AttributionData};
16
16
use crate :: ln:: outbound_payment:: RecipientOnionFields ;
17
17
use crate :: routing:: router:: PaymentParameters ;
18
18
use crate :: sign:: ecdsa:: EcdsaChannelSigner ;
19
+ use crate :: sign:: tx_builder:: { SpecTxBuilder , TxBuilder } ;
19
20
use crate :: types:: features:: ChannelTypeFeatures ;
20
21
use crate :: types:: payment:: PaymentPreimage ;
21
22
use crate :: util:: config:: UserConfig ;
@@ -772,16 +773,22 @@ pub fn test_basic_channel_reserve() {
772
773
}
773
774
774
775
#[ xtest( feature = "_externalize_tests" ) ]
775
- pub fn test_fee_spike_violation_fails_htlc ( ) {
776
+ fn test_fee_spike_violation_fails_htlc ( ) {
777
+ do_test_fee_spike_buffer ( None , true )
778
+ }
779
+ pub fn do_test_fee_spike_buffer ( cfg : Option < UserConfig > , htlc_fails : bool ) {
776
780
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
777
781
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
778
- let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
782
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ cfg . clone ( ) , cfg ] ) ;
779
783
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
780
784
781
785
let node_a_id = nodes[ 0 ] . node . get_our_node_id ( ) ;
782
786
let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
783
787
784
- let chan = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 100000 , 95000000 ) ;
788
+ let chan_amt_sat = 100000 ;
789
+ let push_amt_msat = 95000000 ;
790
+ let chan =
791
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , chan_amt_sat, push_amt_msat) ;
785
792
786
793
let ( mut route, payment_hash, _, payment_secret) =
787
794
get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 1 ] , 3460000 ) ;
@@ -792,11 +799,12 @@ pub fn test_fee_spike_violation_fails_htlc() {
792
799
793
800
let cur_height = nodes[ 1 ] . node . best_block . read ( ) . unwrap ( ) . height + 1 ;
794
801
802
+ let payment_amt_msat = 3460001 ;
795
803
let onion_keys = onion_utils:: construct_onion_keys ( & secp_ctx, & route. paths [ 0 ] , & session_priv) ;
796
804
let recipient_onion_fields = RecipientOnionFields :: secret_only ( payment_secret) ;
797
805
let ( onion_payloads, htlc_msat, htlc_cltv) = onion_utils:: build_onion_payloads (
798
806
& route. paths [ 0 ] ,
799
- 3460001 ,
807
+ payment_amt_msat ,
800
808
& recipient_onion_fields,
801
809
cur_height,
802
810
& None ,
@@ -858,16 +866,15 @@ pub fn test_fee_spike_violation_fails_htlc() {
858
866
859
867
// Build the remote commitment transaction so we can sign it, and then later use the
860
868
// signature for the commitment_signed message.
861
- let local_chan_balance = 1313 ;
862
-
863
869
let accepted_htlc_info = chan_utils:: HTLCOutputInCommitment {
864
870
offered : false ,
865
- amount_msat : 3460001 ,
871
+ amount_msat : payment_amt_msat ,
866
872
cltv_expiry : htlc_cltv,
867
873
payment_hash,
868
874
transaction_output_index : Some ( 1 ) ,
869
875
} ;
870
876
877
+ let local_chan_balance_msat = chan_amt_sat * 1000 - push_amt_msat;
871
878
let commitment_number = INITIAL_COMMITMENT_NUMBER - 1 ;
872
879
873
880
let res = {
@@ -877,15 +884,17 @@ pub fn test_fee_spike_violation_fails_htlc() {
877
884
let channel = get_channel_ref ! ( nodes[ 0 ] , nodes[ 1 ] , per_peer_lock, peer_state_lock, chan. 2 ) ;
878
885
let chan_signer = channel. as_funded ( ) . unwrap ( ) . get_signer ( ) ;
879
886
880
- let commitment_tx = CommitmentTransaction :: new (
887
+ let ( commitment_tx, _stats) = SpecTxBuilder { } . build_commitment_transaction (
888
+ false ,
881
889
commitment_number,
882
890
& remote_point,
883
- 95000 ,
884
- local_chan_balance,
885
- feerate_per_kw,
886
- vec ! [ accepted_htlc_info] ,
887
- & channel. funding ( ) . channel_transaction_parameters . as_counterparty_broadcastable ( ) ,
891
+ & channel. funding ( ) . channel_transaction_parameters ,
888
892
& secp_ctx,
893
+ local_chan_balance_msat,
894
+ vec ! [ accepted_htlc_info] ,
895
+ feerate_per_kw,
896
+ MIN_CHAN_DUST_LIMIT_SATOSHIS ,
897
+ & nodes[ 0 ] . logger ,
889
898
) ;
890
899
let params = & channel. funding ( ) . channel_transaction_parameters ;
891
900
chan_signer
@@ -918,28 +927,35 @@ pub fn test_fee_spike_violation_fails_htlc() {
918
927
} ;
919
928
nodes[ 1 ] . node . handle_revoke_and_ack ( node_a_id, & raa_msg) ;
920
929
expect_pending_htlcs_forwardable ! ( nodes[ 1 ] ) ;
921
- expect_htlc_handling_failed_destinations ! (
922
- nodes[ 1 ] . node. get_and_clear_pending_events( ) ,
923
- & [ HTLCHandlingFailureType :: Receive { payment_hash } ]
924
- ) ;
925
930
926
- let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
927
- assert_eq ! ( events. len( ) , 1 ) ;
928
- // Make sure the HTLC failed in the way we expect.
929
- match events[ 0 ] {
930
- MessageSendEvent :: UpdateHTLCs {
931
- updates : msgs:: CommitmentUpdate { ref update_fail_htlcs, .. } ,
932
- ..
933
- } => {
934
- assert_eq ! ( update_fail_htlcs. len( ) , 1 ) ;
935
- update_fail_htlcs[ 0 ] . clone ( )
936
- } ,
937
- _ => panic ! ( "Unexpected event" ) ,
938
- } ;
939
- nodes[ 1 ] . logger . assert_log ( "lightning::ln::channel" ,
931
+ if htlc_fails {
932
+ expect_htlc_handling_failed_destinations ! (
933
+ nodes[ 1 ] . node. get_and_clear_pending_events( ) ,
934
+ & [ HTLCHandlingFailureType :: Receive { payment_hash } ]
935
+ ) ;
936
+
937
+ let events = nodes[ 1 ] . node . get_and_clear_pending_msg_events ( ) ;
938
+ assert_eq ! ( events. len( ) , 1 ) ;
939
+
940
+ // Make sure the HTLC failed in the way we expect.
941
+ match events[ 0 ] {
942
+ MessageSendEvent :: UpdateHTLCs {
943
+ updates : msgs:: CommitmentUpdate { ref update_fail_htlcs, .. } ,
944
+ ..
945
+ } => {
946
+ assert_eq ! ( update_fail_htlcs. len( ) , 1 ) ;
947
+ update_fail_htlcs[ 0 ] . clone ( )
948
+ } ,
949
+ _ => panic ! ( "Unexpected event" ) ,
950
+ } ;
951
+ nodes[ 1 ] . logger . assert_log ( "lightning::ln::channel" ,
940
952
format ! ( "Attempting to fail HTLC due to fee spike buffer violation in channel {}. Rebalancing is required." , raa_msg. channel_id) , 1 ) ;
941
953
942
- check_added_monitors ( & nodes[ 1 ] , 3 ) ;
954
+ check_added_monitors ( & nodes[ 1 ] , 3 ) ;
955
+ } else {
956
+ expect_payment_claimable ! ( nodes[ 1 ] , payment_hash, payment_secret, payment_amt_msat) ;
957
+ check_added_monitors ( & nodes[ 1 ] , 2 ) ;
958
+ }
943
959
}
944
960
945
961
#[ xtest( feature = "_externalize_tests" ) ]
0 commit comments