Skip to content

Commit 9ce31a5

Browse files
committed
Negotiate 0FC channels if configured
1 parent 9c4a1fd commit 9ce31a5

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ pub struct Config {
188188
/// used to send pre-flight probes.
189189
pub probing_liquidity_limit_multiplier: u64,
190190
/// Configuration options pertaining to Anchor channels, i.e., channels for which the
191-
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
191+
/// `option_zero_fee_commitments` or `option_anchors_zero_fee_htlc_tx` channel type is
192+
/// negotiated.
192193
///
193194
/// Please refer to [`AnchorChannelsConfig`] for further information on Anchor channels.
194195
pub anchor_channels_config: AnchorChannelsConfig,
@@ -287,7 +288,7 @@ impl Default for HumanReadableNamesConfig {
287288
}
288289

289290
/// Configuration options pertaining to 'Anchor' channels, i.e., channels for which the
290-
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
291+
/// `option_zero_fee_commitments` or `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
291292
///
292293
/// Prior to the introduction of Anchor channels, the on-chain fees paying for the transactions
293294
/// issued on channel closure were pre-determined and locked-in at the time of the channel
@@ -421,6 +422,8 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
421422
// will mostly be relevant for inbound channels.
422423
let mut user_config = UserConfig::default();
423424
user_config.channel_handshake_limits.force_announced_channel_preference = false;
425+
user_config.channel_handshake_config.negotiate_anchor_zero_fee_commitments =
426+
config.anchor_channels_config.enable_zero_fee_commitments;
424427
user_config.reject_inbound_splices = false;
425428

426429
if may_announce_channel(config).is_err() {

tests/common/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ pub(crate) fn random_node_alias() -> Option<NodeAlias> {
382382
pub(crate) fn random_config() -> TestConfig {
383383
let mut node_config = Config::default();
384384

385+
// We want 0FC channels to be negotiated half the time, 0.49 is good enough
386+
let zero_fee_commitments = rand::random_bool(0.7);
387+
println!("Negotiating zero-fee commitment channels: {}", zero_fee_commitments);
388+
node_config.anchor_channels_config.enable_zero_fee_commitments = zero_fee_commitments;
389+
385390
node_config.network = Network::Regtest;
386391
println!("Setting network: {}", node_config.network);
387392

@@ -1579,10 +1584,8 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
15791584
let node_a_outbound_capacity_msat = node_a.list_channels()[0].outbound_capacity_msat;
15801585
let node_a_reserve_msat =
15811586
node_a.list_channels()[0].unspendable_punishment_reserve.unwrap() * 1000;
1582-
// TODO: Zero-fee commitment channels are anchor channels, but do not allocate any
1583-
// funds to the anchor, so this will need to be updated when we ship these channels
1584-
// in ldk-node.
1585-
let node_a_anchors_msat = if expect_anchor_channel { 2 * 330 * 1000 } else { 0 };
1587+
let zero_fee_commitments = node_a.list_channels()[0].feerate_sat_per_1000_weight == 0;
1588+
let node_a_anchors_msat = if zero_fee_commitments { 0 } else { 2 * 330 * 1000 };
15861589
let funding_amount_msat = node_a.list_channels()[0].channel_value_sats * 1000;
15871590
// Node B does not have any reserve, so we only subtract a few items on node A's
15881591
// side to arrive at node B's capacity

tests/integration_tests_rust.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,9 @@ async fn splice_channel() {
15431543
let user_channel_id_b = expect_channel_ready_event!(node_b, node_a.node_id());
15441544

15451545
let opening_transaction_fee_sat = 156;
1546-
let closing_transaction_fee_sat = 614;
1547-
let anchor_output_sat = 330;
1546+
let zero_fee_commitments = node_a.list_channels()[0].feerate_sat_per_1000_weight == 0;
1547+
let closing_transaction_fee_sat = if zero_fee_commitments { 0 } else { 614 };
1548+
let anchor_output_sat = if zero_fee_commitments { 0 } else { 330 };
15481549

15491550
assert_eq!(
15501551
node_a.list_balances().total_onchain_balance_sats,

0 commit comments

Comments
 (0)