Skip to content

Commit 1cf1e6f

Browse files
authored
Merge pull request #788 from benthecarman/open-channel-all
Add ability to open channel / splice with all on-chain funds
2 parents 8cd670f + 56730e9 commit 1cf1e6f

File tree

6 files changed

+672
-130
lines changed

6 files changed

+672
-130
lines changed

bindings/ldk_node.udl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,14 @@ interface Node {
103103
[Throws=NodeError]
104104
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
105105
[Throws=NodeError]
106+
UserChannelId open_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
107+
[Throws=NodeError]
108+
UserChannelId open_announced_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
109+
[Throws=NodeError]
106110
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
107111
[Throws=NodeError]
112+
void splice_in_with_all([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);
113+
[Throws=NodeError]
108114
void splice_out([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, [ByRef]Address address, u64 splice_amount_sats);
109115
[Throws=NodeError]
110116
void close_channel([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id);

src/event.rs

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,52 +1164,45 @@ where
11641164
}
11651165

11661166
let anchor_channel = channel_type.requires_anchors_zero_fee_htlc_tx();
1167-
if anchor_channel {
1168-
if let Some(anchor_channels_config) =
1169-
self.config.anchor_channels_config.as_ref()
1170-
{
1171-
let cur_anchor_reserve_sats = crate::total_anchor_channels_reserve_sats(
1172-
&self.channel_manager,
1173-
&self.config,
1174-
);
1175-
let spendable_amount_sats = self
1176-
.wallet
1177-
.get_spendable_amount_sats(cur_anchor_reserve_sats)
1178-
.unwrap_or(0);
1179-
1180-
let required_amount_sats = if anchor_channels_config
1181-
.trusted_peers_no_reserve
1182-
.contains(&counterparty_node_id)
1183-
{
1184-
0
1185-
} else {
1186-
anchor_channels_config.per_channel_reserve_sats
1187-
};
1167+
if anchor_channel && self.config.anchor_channels_config.is_none() {
1168+
log_error!(
1169+
self.logger,
1170+
"Rejecting inbound channel from peer {} due to Anchor channels being disabled.",
1171+
counterparty_node_id,
1172+
);
1173+
self.channel_manager
1174+
.force_close_broadcasting_latest_txn(
1175+
&temporary_channel_id,
1176+
&counterparty_node_id,
1177+
"Channel request rejected".to_string(),
1178+
)
1179+
.unwrap_or_else(|e| {
1180+
log_error!(self.logger, "Failed to reject channel: {:?}", e)
1181+
});
1182+
return Ok(());
1183+
}
11881184

1189-
if spendable_amount_sats < required_amount_sats {
1190-
log_error!(
1191-
self.logger,
1192-
"Rejecting inbound Anchor channel from peer {} due to insufficient available on-chain reserves. Available: {}/{}sats",
1193-
counterparty_node_id,
1194-
spendable_amount_sats,
1195-
required_amount_sats,
1196-
);
1197-
self.channel_manager
1198-
.force_close_broadcasting_latest_txn(
1199-
&temporary_channel_id,
1200-
&counterparty_node_id,
1201-
"Channel request rejected".to_string(),
1202-
)
1203-
.unwrap_or_else(|e| {
1204-
log_error!(self.logger, "Failed to reject channel: {:?}", e)
1205-
});
1206-
return Ok(());
1207-
}
1208-
} else {
1185+
let required_reserve_sats = crate::new_channel_anchor_reserve_sats(
1186+
&self.config,
1187+
&counterparty_node_id,
1188+
anchor_channel,
1189+
);
1190+
1191+
if required_reserve_sats > 0 {
1192+
let cur_anchor_reserve_sats = crate::total_anchor_channels_reserve_sats(
1193+
&self.channel_manager,
1194+
&self.config,
1195+
);
1196+
let spendable_amount_sats =
1197+
self.wallet.get_spendable_amount_sats(cur_anchor_reserve_sats).unwrap_or(0);
1198+
1199+
if spendable_amount_sats < required_reserve_sats {
12091200
log_error!(
12101201
self.logger,
1211-
"Rejecting inbound channel from peer {} due to Anchor channels being disabled.",
1202+
"Rejecting inbound Anchor channel from peer {} due to insufficient available on-chain reserves. Available: {}/{}sats",
12121203
counterparty_node_id,
1204+
spendable_amount_sats,
1205+
required_reserve_sats,
12131206
);
12141207
self.channel_manager
12151208
.force_close_broadcasting_latest_txn(

0 commit comments

Comments
 (0)