Skip to content

Commit 27bc80c

Browse files
committed
Add LSPS2ServiceConfig::allow_client_0reserve
This setting allows LSPS2 services to open 0-reserve channels to their clients.
1 parent 2502910 commit 27bc80c

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/liquidity.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ pub struct LSPS2ServiceConfig {
142142
///
143143
/// [`bLIP-52`]: https://github.com/lightning/blips/blob/master/blip-0052.md#trust-models
144144
pub client_trusts_lsp: bool,
145+
/// When set, clients will be allowed to spend their entire balance in the channel. This
146+
/// allows clients to try to steal your funds with no financial penalty, so this should only
147+
/// be set if you trust your clients.
148+
pub allow_client_0reserve: bool,
145149
}
146150

147151
pub(crate) struct LiquiditySourceBuilder<L: Deref>
@@ -786,22 +790,38 @@ where
786790
config.channel_config.forwarding_fee_base_msat = 0;
787791
config.channel_config.forwarding_fee_proportional_millionths = 0;
788792

789-
match self.channel_manager.create_channel(
790-
their_network_key,
791-
channel_amount_sats,
792-
0,
793-
user_channel_id,
794-
None,
795-
Some(config),
796-
) {
793+
let result = if service_config.allow_client_0reserve {
794+
self.channel_manager.create_channel_to_trusted_peer_0reserve(
795+
their_network_key,
796+
channel_amount_sats,
797+
0,
798+
user_channel_id,
799+
None,
800+
Some(config),
801+
)
802+
} else {
803+
self.channel_manager.create_channel(
804+
their_network_key,
805+
channel_amount_sats,
806+
0,
807+
user_channel_id,
808+
None,
809+
Some(config),
810+
)
811+
};
812+
813+
match result {
797814
Ok(_) => {},
798815
Err(e) => {
799816
// TODO: We just silently fail here. Eventually we will need to remember
800817
// the pending requests and regularly retry opening the channel until we
801818
// succeed.
819+
let zero_reserve_string =
820+
if service_config.allow_client_0reserve { "0reserve " } else { "" };
802821
log_error!(
803822
self.logger,
804-
"Failed to open LSPS2 channel to {}: {:?}",
823+
"Failed to open LSPS2 {}channel to {}: {:?}",
824+
zero_reserve_string,
805825
their_network_key,
806826
e
807827
);

tests/integration_tests_rust.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,7 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) {
17051705
min_channel_opening_fee_msat: 0,
17061706
max_client_to_self_delay: 1024,
17071707
client_trusts_lsp,
1708+
allow_client_0reserve: false,
17081709
};
17091710

17101711
let service_config = random_config(true);
@@ -2023,6 +2024,7 @@ async fn lsps2_client_trusts_lsp() {
20232024
min_channel_opening_fee_msat: 0,
20242025
max_client_to_self_delay: 1024,
20252026
client_trusts_lsp: true,
2027+
allow_client_0reserve: false,
20262028
};
20272029

20282030
let service_config = random_config(true);
@@ -2197,6 +2199,7 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() {
21972199
min_channel_opening_fee_msat: 0,
21982200
max_client_to_self_delay: 1024,
21992201
client_trusts_lsp: false,
2202+
allow_client_0reserve: false,
22002203
};
22012204

22022205
let service_config = random_config(true);

0 commit comments

Comments
 (0)