Skip to content

Commit cada867

Browse files
committed
Include 0FC channels in anchor channel checks
1 parent cf044ac commit cada867

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ where
12661266
}
12671267
}
12681268

1269-
let anchor_channel = channel_type.requires_anchors_zero_fee_htlc_tx();
1269+
let anchor_channel = crate::requires_anchor_channel_type(&channel_type);
12701270
let required_reserve_sats = crate::new_channel_anchor_reserve_sats(
12711271
&self.config,
12721272
&counterparty_node_id,

src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ use lightning_background_processor::process_events_async;
163163
pub use lightning_invoice;
164164
pub use lightning_liquidity;
165165
pub use lightning_types;
166-
use lightning_types::features::NodeFeatures as LdkNodeFeatures;
166+
use lightning_types::features::{
167+
ChannelTypeFeatures, InitFeatures, NodeFeatures as LdkNodeFeatures,
168+
};
167169
use liquidity::LiquiditySource;
168170
use lnurl_auth::LnurlAuth;
169171
use logger::{log_debug, log_error, log_info, log_trace, LdkLogger, Logger};
@@ -219,6 +221,19 @@ impl LeakChecker {
219221
}
220222
}
221223

224+
fn peer_may_negotiate_anchor_channel_type(
225+
config: &Config, their_init_features: &InitFeatures,
226+
) -> bool {
227+
their_init_features.supports_anchors_zero_fee_htlc_tx()
228+
|| (config.anchor_channels_config.enable_zero_fee_commitments
229+
&& their_init_features.supports_anchor_zero_fee_commitments())
230+
}
231+
232+
fn requires_anchor_channel_type(channel_type: &ChannelTypeFeatures) -> bool {
233+
channel_type.requires_anchors_zero_fee_htlc_tx()
234+
|| channel_type.requires_anchor_zero_fee_commitments()
235+
}
236+
222237
/// The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
223238
///
224239
/// Needs to be initialized and instantiated through [`Builder::build`].
@@ -1387,7 +1402,7 @@ impl Node {
13871402
.peer_by_node_id(peer_node_id)
13881403
.ok_or(Error::ConnectionFailed)?
13891404
.init_features;
1390-
let anchor_channel = init_features.supports_anchors_zero_fee_htlc_tx();
1405+
let anchor_channel = peer_may_negotiate_anchor_channel_type(&self.config, &init_features);
13911406
Ok(new_channel_anchor_reserve_sats(&self.config, peer_node_id, anchor_channel))
13921407
}
13931408

@@ -2450,7 +2465,7 @@ pub(crate) fn total_anchor_channels_reserve_sats(
24502465
.contains(&c.counterparty.node_id)
24512466
&& c.channel_shutdown_state
24522467
.map_or(true, |s| s != ChannelShutdownState::ShutdownComplete)
2453-
&& c.channel_type.as_ref().map_or(false, |t| t.requires_anchors_zero_fee_htlc_tx())
2468+
&& c.channel_type.as_ref().map_or(false, requires_anchor_channel_type)
24542469
})
24552470
.count() as u64
24562471
* config.anchor_channels_config.per_channel_reserve_sats

src/liquidity/service/lsps2.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,14 @@ where
452452
total_anchor_channels_reserve_sats(&self.channel_manager, &self.config);
453453
let spendable_amount_sats =
454454
self.wallet.get_spendable_amount_sats(cur_anchor_reserve_sats).unwrap_or(0);
455-
let required_funds_sats = channel_amount_sats
456-
+ if init_features.supports_anchors_zero_fee_htlc_tx()
457-
&& !self
458-
.config
459-
.anchor_channels_config
460-
.trusted_peers_no_reserve
461-
.contains(&their_network_key)
462-
{
463-
self.config.anchor_channels_config.per_channel_reserve_sats
464-
} else {
465-
0
466-
};
455+
let anchor_channel =
456+
crate::peer_may_negotiate_anchor_channel_type(&self.config, &init_features);
457+
let additional_reserve_required = crate::new_channel_anchor_reserve_sats(
458+
&self.config,
459+
&their_network_key,
460+
anchor_channel,
461+
);
462+
let required_funds_sats = channel_amount_sats + additional_reserve_required;
467463
if spendable_amount_sats < required_funds_sats {
468464
log_error!(self.logger,
469465
"Unable to create channel due to insufficient funds. Available: {}sats, Required: {}sats",

src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl ChannelDetails {
649649
value: LdkChannelDetails, anchor_channels_config: &AnchorChannelsConfig,
650650
) -> Self {
651651
let reserve_type = value.channel_type.as_ref().map(|channel_type| {
652-
if channel_type.requires_anchors_zero_fee_htlc_tx() {
652+
if crate::requires_anchor_channel_type(channel_type) {
653653
if anchor_channels_config
654654
.trusted_peers_no_reserve
655655
.contains(&value.counterparty.node_id)

0 commit comments

Comments
 (0)