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