Skip to content

Commit 4e72af0

Browse files
committed
Negotiate 0FC channels if the anchor config is set
1 parent 9537b27 commit 4e72af0

3 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,17 @@ pub struct Config {
171171
/// used to send pre-flight probes.
172172
pub probing_liquidity_limit_multiplier: u64,
173173
/// Configuration options pertaining to Anchor channels, i.e., channels for which the
174-
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
174+
/// `option_zero_fee_commitments` or `option_anchors_zero_fee_htlc_tx` channel type is
175+
/// negotiated.
175176
///
176177
/// Please refer to [`AnchorChannelsConfig`] for further information on Anchor channels.
177178
///
178179
/// If set to `Some`, we'll try to open new channels with Anchors enabled, i.e., new channels
179-
/// will be negotiated with the `option_anchors_zero_fee_htlc_tx` channel type if supported by
180-
/// the counterparty. Note that this won't prevent us from opening non-Anchor channels if the
181-
/// counterparty doesn't support `option_anchors_zero_fee_htlc_tx`. If set to `None`, new
182-
/// channels will be negotiated with the legacy `option_static_remotekey` channel type only.
180+
/// will be negotiated with the `option_zero_fee_commitments` channel type first, then the
181+
/// `option_anchors_zero_fee_htlc_tx` channel type if supported by the counterparty. Note
182+
/// that this won't prevent us from opening non-Anchor channels if the counterparty doesn't
183+
/// support `option_anchors_zero_fee_htlc_tx`. If set to `None`, new channels will be
184+
/// negotiated with the legacy `option_static_remotekey` channel type only.
183185
///
184186
/// **Note:** If set to `None` *after* some Anchor channels have already been
185187
/// opened, no dedicated emergency on-chain reserve will be maintained for these channels,
@@ -282,7 +284,7 @@ impl Default for HumanReadableNamesConfig {
282284
}
283285

284286
/// Configuration options pertaining to 'Anchor' channels, i.e., channels for which the
285-
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
287+
/// `option_zero_fee_commitments` or `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
286288
///
287289
/// Prior to the introduction of Anchor channels, the on-chain fees paying for the transactions
288290
/// issued on channel closure were pre-determined and locked-in at the time of the channel
@@ -404,6 +406,8 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
404406
user_config.channel_handshake_limits.force_announced_channel_preference = false;
405407
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx =
406408
config.anchor_channels_config.is_some();
409+
user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments =
410+
config.anchor_channels_config.is_some();
407411
user_config.reject_inbound_splices = false;
408412

409413
if may_announce_channel(config).is_err() {

tests/common/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,10 +1408,9 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
14081408
let node_a_outbound_capacity_msat = node_a.list_channels()[0].outbound_capacity_msat;
14091409
let node_a_reserve_msat =
14101410
node_a.list_channels()[0].unspendable_punishment_reserve.unwrap() * 1000;
1411-
// TODO: Zero-fee commitment channels are anchor channels, but do not allocate any
1412-
// funds to the anchor, so this will need to be updated when we ship these channels
1413-
// in ldk-node.
1414-
let node_a_anchors_msat = if expect_anchor_channel { 2 * 330 * 1000 } else { 0 };
1411+
// If we expect an anchor channel, this will be a 0FC channel, so no funds will be
1412+
// allocated to the anchor.
1413+
let node_a_anchors_msat = 0;
14151414
let funding_amount_msat = node_a.list_channels()[0].channel_value_sats * 1000;
14161415
// Node B does not have any reserve, so we only subtract a few items on node A's
14171416
// side to arrive at node B's capacity

tests/integration_tests_rust.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,17 +1023,12 @@ async fn splice_channel() {
10231023
let user_channel_id_b = expect_channel_ready_event!(node_b, node_a.node_id());
10241024

10251025
let opening_transaction_fee_sat = 156;
1026-
let closing_transaction_fee_sat = 614;
1027-
let anchor_output_sat = 330;
10281026

10291027
assert_eq!(
10301028
node_a.list_balances().total_onchain_balance_sats,
10311029
premine_amount_sat - 4_000_000 - opening_transaction_fee_sat
10321030
);
1033-
assert_eq!(
1034-
node_a.list_balances().total_lightning_balance_sats,
1035-
4_000_000 - closing_transaction_fee_sat - anchor_output_sat
1036-
);
1031+
assert_eq!(node_a.list_balances().total_lightning_balance_sats, 4_000_000);
10371032
assert_eq!(node_b.list_balances().total_lightning_balance_sats, 0);
10381033

10391034
// Test that splicing and payments fail when there are insufficient funds
@@ -1101,10 +1096,7 @@ async fn splice_channel() {
11011096
// Mine a block to give time for the HTLC to resolve
11021097
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 1).await;
11031098

1104-
assert_eq!(
1105-
node_a.list_balances().total_lightning_balance_sats,
1106-
4_000_000 - closing_transaction_fee_sat - anchor_output_sat + amount_msat / 1000
1107-
);
1099+
assert_eq!(node_a.list_balances().total_lightning_balance_sats, 4_000_000 + amount_msat / 1000);
11081100
assert_eq!(
11091101
node_b.list_balances().total_lightning_balance_sats,
11101102
expected_splice_in_lightning_balance_sat - amount_msat / 1000
@@ -1138,7 +1130,7 @@ async fn splice_channel() {
11381130
);
11391131
assert_eq!(
11401132
node_a.list_balances().total_lightning_balance_sats,
1141-
4_000_000 - closing_transaction_fee_sat - anchor_output_sat - expected_splice_out_fee_sat
1133+
4_000_000 - expected_splice_out_fee_sat
11421134
);
11431135
}
11441136

0 commit comments

Comments
 (0)