-
Notifications
You must be signed in to change notification settings - Fork 129
Enable 0conf and 0reserve on channels with trusted peers #853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1128,7 +1128,7 @@ impl Node { | |
| fn open_channel_inner( | ||
| &self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: FundingAmount, | ||
| push_to_counterparty_msat: Option<u64>, channel_config: Option<ChannelConfig>, | ||
| announce_for_forwarding: bool, | ||
| announce_for_forwarding: bool, set_0reserve: bool, | ||
| ) -> Result<UserChannelId, Error> { | ||
| if !*self.is_running.read().unwrap() { | ||
| return Err(Error::NotRunning); | ||
|
|
@@ -1196,25 +1196,46 @@ impl Node { | |
| self.keys_manager.get_secure_random_bytes()[..16].try_into().unwrap(), | ||
| ); | ||
|
|
||
| match self.channel_manager.create_channel( | ||
| peer_info.node_id, | ||
| channel_amount_sats, | ||
| push_msat, | ||
| user_channel_id, | ||
| None, | ||
| Some(user_config), | ||
| ) { | ||
| let result = if set_0reserve { | ||
| self.channel_manager.create_channel_to_trusted_peer_0reserve( | ||
| peer_info.node_id, | ||
| channel_amount_sats, | ||
| push_msat, | ||
| user_channel_id, | ||
| None, | ||
| Some(user_config), | ||
| ) | ||
| } else { | ||
| self.channel_manager.create_channel( | ||
| peer_info.node_id, | ||
| channel_amount_sats, | ||
| push_msat, | ||
| user_channel_id, | ||
| None, | ||
| Some(user_config), | ||
| ) | ||
| }; | ||
|
|
||
| let zero_reserve_string = if set_0reserve { "0reserve " } else { "" }; | ||
|
|
||
| match result { | ||
| Ok(_) => { | ||
| log_info!( | ||
| self.logger, | ||
| "Initiated channel creation with peer {}. ", | ||
| "Initiated {}channel creation with peer {}. ", | ||
| zero_reserve_string, | ||
| peer_info.node_id | ||
| ); | ||
| self.peer_store.add_peer(peer_info)?; | ||
| Ok(UserChannelId(user_channel_id)) | ||
| }, | ||
| Err(e) => { | ||
| log_error!(self.logger, "Failed to initiate channel creation: {:?}", e); | ||
| log_error!( | ||
| self.logger, | ||
| "Failed to initiate {}channel creation: {:?}", | ||
| zero_reserve_string, | ||
| e | ||
| ); | ||
| Err(Error::ChannelCreationFailed) | ||
| }, | ||
| } | ||
|
|
@@ -1290,6 +1311,7 @@ impl Node { | |
| push_to_counterparty_msat, | ||
| channel_config, | ||
| false, | ||
| false, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -1330,6 +1352,7 @@ impl Node { | |
| push_to_counterparty_msat, | ||
| channel_config, | ||
| true, | ||
| false, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -1358,6 +1381,7 @@ impl Node { | |
| push_to_counterparty_msat, | ||
| channel_config, | ||
| false, | ||
| false, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -1395,6 +1419,70 @@ impl Node { | |
| push_to_counterparty_msat, | ||
| channel_config, | ||
| true, | ||
| false, | ||
| ) | ||
| } | ||
|
|
||
| /// Connect to a node and open a new unannounced channel, in which the target node can | ||
| /// spend its entire balance. | ||
| /// | ||
| /// This channel allows the target node to try to steal your funds with no financial | ||
| /// penalty, so this channel should only be opened to nodes you trust. | ||
| /// | ||
| /// Disconnects and reconnects are handled automatically. | ||
| /// | ||
| /// If `push_to_counterparty_msat` is set, the given value will be pushed (read: sent) to the | ||
| /// channel counterparty on channel open. This can be useful to start out with the balance not | ||
| /// entirely shifted to one side, therefore allowing to receive payments from the getgo. | ||
| /// | ||
| /// If Anchor channels are enabled, this will ensure the configured | ||
| /// [`AnchorChannelsConfig::per_channel_reserve_sats`] is available and will be retained before | ||
| /// opening the channel. | ||
| /// | ||
| /// Returns a [`UserChannelId`] allowing to locally keep track of the channel. | ||
| /// | ||
| /// [`AnchorChannelsConfig::per_channel_reserve_sats`]: crate::config::AnchorChannelsConfig::per_channel_reserve_sats | ||
| pub fn open_0reserve_channel( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are getting a combinatorial explosion with these
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed offline, we retain separate calls for now, and will ship your |
||
| &self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: u64, | ||
| push_to_counterparty_msat: Option<u64>, channel_config: Option<ChannelConfig>, | ||
| ) -> Result<UserChannelId, Error> { | ||
| self.open_channel_inner( | ||
| node_id, | ||
| address, | ||
| FundingAmount::Exact { amount_sats: channel_amount_sats }, | ||
| push_to_counterparty_msat, | ||
| channel_config, | ||
| false, | ||
| true, | ||
| ) | ||
| } | ||
|
|
||
| /// Connect to a node and open a new unannounced channel, using all available on-chain funds | ||
| /// minus fees and anchor reserves. The target node will be able to spend its entire channel | ||
| /// balance. | ||
| /// | ||
| /// This channel allows the target node to try to steal your funds with no financial | ||
| /// penalty, so this channel should only be opened to nodes you trust. | ||
| /// | ||
| /// Disconnects and reconnects are handled automatically. | ||
| /// | ||
| /// If `push_to_counterparty_msat` is set, the given value will be pushed (read: sent) to the | ||
| /// channel counterparty on channel open. This can be useful to start out with the balance not | ||
| /// entirely shifted to one side, therefore allowing to receive payments from the getgo. | ||
| /// | ||
| /// Returns a [`UserChannelId`] allowing to locally keep track of the channel. | ||
| pub fn open_0reserve_channel_with_all( | ||
| &self, node_id: PublicKey, address: SocketAddress, push_to_counterparty_msat: Option<u64>, | ||
| channel_config: Option<ChannelConfig>, | ||
| ) -> Result<UserChannelId, Error> { | ||
| self.open_channel_inner( | ||
| node_id, | ||
| address, | ||
| FundingAmount::Max, | ||
| push_to_counterparty_msat, | ||
| channel_config, | ||
| false, | ||
| true, | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -142,6 +142,10 @@ pub struct LSPS2ServiceConfig { | |||||||||||||||||
| /// | ||||||||||||||||||
| /// [`bLIP-52`]: https://github.com/lightning/blips/blob/master/blip-0052.md#trust-models | ||||||||||||||||||
| pub client_trusts_lsp: bool, | ||||||||||||||||||
| /// When set, clients that we open channels to will be allowed to spend their entire channel | ||||||||||||||||||
| /// balance. This allows clients to try to steal your funds with no financial penalty, so | ||||||||||||||||||
| /// this should only be set if you trust your clients. | ||||||||||||||||||
| pub allow_client_0reserve: bool, | ||||||||||||||||||
|
Comment on lines
+145
to
+148
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this wording kinda suggests that all channels opened to these clients will be effected but in reality it is only the channels we open to them.
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, might be good to slightly improve docs further in a follow-up. |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| pub(crate) struct LiquiditySourceBuilder<L: Deref> | ||||||||||||||||||
|
|
@@ -786,22 +790,38 @@ where | |||||||||||||||||
| config.channel_config.forwarding_fee_base_msat = 0; | ||||||||||||||||||
| config.channel_config.forwarding_fee_proportional_millionths = 0; | ||||||||||||||||||
|
|
||||||||||||||||||
| match self.channel_manager.create_channel( | ||||||||||||||||||
| their_network_key, | ||||||||||||||||||
| channel_amount_sats, | ||||||||||||||||||
| 0, | ||||||||||||||||||
| user_channel_id, | ||||||||||||||||||
| None, | ||||||||||||||||||
| Some(config), | ||||||||||||||||||
| ) { | ||||||||||||||||||
| let result = if service_config.allow_client_0reserve { | ||||||||||||||||||
| self.channel_manager.create_channel_to_trusted_peer_0reserve( | ||||||||||||||||||
| their_network_key, | ||||||||||||||||||
| channel_amount_sats, | ||||||||||||||||||
| 0, | ||||||||||||||||||
| user_channel_id, | ||||||||||||||||||
| None, | ||||||||||||||||||
| Some(config), | ||||||||||||||||||
| ) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| self.channel_manager.create_channel( | ||||||||||||||||||
| their_network_key, | ||||||||||||||||||
| channel_amount_sats, | ||||||||||||||||||
| 0, | ||||||||||||||||||
| user_channel_id, | ||||||||||||||||||
| None, | ||||||||||||||||||
| Some(config), | ||||||||||||||||||
| ) | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| match result { | ||||||||||||||||||
| Ok(_) => {}, | ||||||||||||||||||
| Err(e) => { | ||||||||||||||||||
| // TODO: We just silently fail here. Eventually we will need to remember | ||||||||||||||||||
| // the pending requests and regularly retry opening the channel until we | ||||||||||||||||||
| // succeed. | ||||||||||||||||||
| let zero_reserve_string = | ||||||||||||||||||
| if service_config.allow_client_0reserve { "0reserve " } else { "" }; | ||||||||||||||||||
| log_error!( | ||||||||||||||||||
| self.logger, | ||||||||||||||||||
| "Failed to open LSPS2 channel to {}: {:?}", | ||||||||||||||||||
| "Failed to open LSPS2 {}channel to {}: {:?}", | ||||||||||||||||||
| zero_reserve_string, | ||||||||||||||||||
| their_network_key, | ||||||||||||||||||
| e | ||||||||||||||||||
| ); | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1705,6 +1705,7 @@ async fn do_lsps2_client_service_integration(client_trusts_lsp: bool) { | |
| min_channel_opening_fee_msat: 0, | ||
| max_client_to_self_delay: 1024, | ||
| client_trusts_lsp, | ||
| allow_client_0reserve: false, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should def. add a test coverage for the new APIs in a follow-up (preferably a new 0-reserve specific test, maybe (also?) a full-cycle variant like we do for 0conf?). |
||
| }; | ||
|
|
||
| let service_config = random_config(true); | ||
|
|
@@ -2023,6 +2024,7 @@ async fn lsps2_client_trusts_lsp() { | |
| min_channel_opening_fee_msat: 0, | ||
| max_client_to_self_delay: 1024, | ||
| client_trusts_lsp: true, | ||
| allow_client_0reserve: false, | ||
| }; | ||
|
|
||
| let service_config = random_config(true); | ||
|
|
@@ -2197,6 +2199,7 @@ async fn lsps2_lsp_trusts_client_but_client_does_not_claim() { | |
| min_channel_opening_fee_msat: 0, | ||
| max_client_to_self_delay: 1024, | ||
| client_trusts_lsp: false, | ||
| allow_client_0reserve: false, | ||
| }; | ||
|
|
||
| let service_config = random_config(true); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go ahead with these new APIs, they need to be exposed in
uniffibindings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done below