@@ -24,7 +24,7 @@ use crate::ln::types::ChannelId;
24
24
use crate::types::payment::{PaymentPreimage, PaymentSecret, PaymentHash};
25
25
use crate::ln::channel::{CONCURRENT_INBOUND_HTLC_FEE_BUFFER, FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE, MIN_AFFORDABLE_HTLC_COUNT, get_holder_selected_channel_reserve_satoshis, OutboundV1Channel, InboundV1Channel, COINBASE_MATURITY, ChannelPhase};
26
26
use crate::ln::channelmanager::{self, PaymentId, RAACommitmentOrder, RecipientOnionFields, BREAKDOWN_TIMEOUT, ENABLE_GOSSIP_TICKS, DISABLE_GOSSIP_TICKS, MIN_CLTV_EXPIRY_DELTA};
27
- use crate::ln::channel::{DISCONNECT_PEER_AWAITING_RESPONSE_TICKS, ChannelError};
27
+ use crate::ln::channel::{ANCHOR_OUTPUT_VALUE_SATOSHI, DISCONNECT_PEER_AWAITING_RESPONSE_TICKS, ChannelError};
28
28
use crate::ln::{chan_utils, onion_utils};
29
29
use crate::ln::chan_utils::{commitment_tx_base_weight, COMMITMENT_TX_WEIGHT_PER_HTLC, OFFERED_HTLC_SCRIPT_WEIGHT, htlc_success_tx_weight, htlc_timeout_tx_weight, HTLCOutputInCommitment};
30
30
use crate::routing::gossip::{NetworkGraph, NetworkUpdate};
@@ -673,28 +673,49 @@ fn test_update_fee_vanilla() {
673
673
check_added_monitors!(nodes[1], 1);
674
674
}
675
675
676
- #[test]
677
- fn test_update_fee_that_funder_cannot_afford() {
676
+ pub fn do_test_update_fee_that_funder_cannot_afford(channel_type_features: ChannelTypeFeatures) {
678
677
let chanmon_cfgs = create_chanmon_cfgs(2);
679
678
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
680
- let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
679
+
680
+ let mut default_config = test_default_channel_config();
681
+ if channel_type_features == ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies() {
682
+ default_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx = true;
683
+ // this setting is also needed to create an anchor channel
684
+ default_config.manually_accept_inbound_channels = true;
685
+ }
686
+
687
+ let node_chanmgrs = create_node_chanmgrs(
688
+ 2,
689
+ &node_cfgs,
690
+ &[Some(default_config.clone()), Some(default_config.clone())],
691
+ );
692
+
681
693
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
682
694
let channel_value = 5000;
683
695
let push_sats = 700;
684
696
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, channel_value, push_sats * 1000);
685
697
let channel_id = chan.2;
686
698
let secp_ctx = Secp256k1::new();
687
- let default_config = UserConfig::default();
688
699
let bs_channel_reserve_sats = get_holder_selected_channel_reserve_satoshis(channel_value, &default_config);
689
700
690
- let channel_type_features = ChannelTypeFeatures::only_static_remote_key();
701
+ let (anchor_outputs_value_sats, outputs_num_no_htlcs) =
702
+ if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
703
+ (ANCHOR_OUTPUT_VALUE_SATOSHI * 2, 4)
704
+ } else {
705
+ (0, 2)
706
+ };
691
707
692
708
// Calculate the maximum feerate that A can afford. Note that we don't send an update_fee
693
709
// CONCURRENT_INBOUND_HTLC_FEE_BUFFER HTLCs before actually running out of local balance, so we
694
710
// calculate two different feerates here - the expected local limit as well as the expected
695
711
// remote limit.
696
- let feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000 / (commitment_tx_base_weight(&channel_type_features) + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC)) as u32;
697
- let non_buffer_feerate = ((channel_value - bs_channel_reserve_sats - push_sats) * 1000 / commitment_tx_base_weight(&channel_type_features)) as u32;
712
+ let feerate =
713
+ ((channel_value - bs_channel_reserve_sats - push_sats - anchor_outputs_value_sats) * 1000
714
+ / (commitment_tx_base_weight(&channel_type_features)
715
+ + CONCURRENT_INBOUND_HTLC_FEE_BUFFER as u64 * COMMITMENT_TX_WEIGHT_PER_HTLC)) as u32;
716
+ let non_buffer_feerate =
717
+ ((channel_value - bs_channel_reserve_sats - push_sats - anchor_outputs_value_sats) * 1000
718
+ / commitment_tx_base_weight(&channel_type_features)) as u32;
698
719
{
699
720
let mut feerate_lock = chanmon_cfgs[0].fee_estimator.sat_per_kw.lock().unwrap();
700
721
*feerate_lock = feerate;
@@ -711,8 +732,8 @@ fn test_update_fee_that_funder_cannot_afford() {
711
732
{
712
733
let commitment_tx = get_local_commitment_txn!(nodes[1], channel_id)[0].clone();
713
734
714
- //We made sure neither party's funds are below the dust limit and there are no HTLCs here
715
- assert_eq!(commitment_tx.output.len(), 2 );
735
+ // We made sure neither party's funds are below the dust limit and there are no HTLCs here
736
+ assert_eq!(commitment_tx.output.len(), outputs_num_no_htlcs );
716
737
let total_fee: u64 = commit_tx_fee_msat(feerate, 0, &channel_type_features) / 1000;
717
738
let mut actual_fee = commitment_tx.output.iter().fold(0, |acc, output| acc + output.value.to_sat());
718
739
actual_fee = channel_value - actual_fee;
@@ -771,7 +792,7 @@ fn test_update_fee_that_funder_cannot_afford() {
771
792
let commitment_tx = CommitmentTransaction::new_with_auxiliary_htlc_data(
772
793
INITIAL_COMMITMENT_NUMBER - 1,
773
794
push_sats,
774
- channel_value - push_sats - commit_tx_fee_msat(non_buffer_feerate + 4, 0, &channel_type_features) / 1000,
795
+ channel_value - push_sats - anchor_outputs_value_sats - commit_tx_fee_msat(non_buffer_feerate + 4, 0, &channel_type_features) / 1000,
775
796
local_funding, remote_funding,
776
797
commit_tx_keys.clone(),
777
798
non_buffer_feerate + 4,
@@ -808,6 +829,14 @@ fn test_update_fee_that_funder_cannot_afford() {
808
829
[nodes[0].node.get_our_node_id()], channel_value);
809
830
}
810
831
832
+ #[test]
833
+ pub fn test_update_fee_that_funder_cannot_afford() {
834
+ do_test_update_fee_that_funder_cannot_afford(ChannelTypeFeatures::only_static_remote_key());
835
+ do_test_update_fee_that_funder_cannot_afford(
836
+ ChannelTypeFeatures::anchors_zero_htlc_fee_and_dependencies(),
837
+ );
838
+ }
839
+
811
840
#[test]
812
841
fn test_update_fee_with_fundee_update_add_htlc() {
813
842
let chanmon_cfgs = create_chanmon_cfgs(2);
0 commit comments