-
Notifications
You must be signed in to change notification settings - Fork 130
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
663864a
d44c10e
2502910
27bc80c
e0146c3
9125870
aa005f4
c1e1b51
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,83 @@ impl Node { | |
| push_to_counterparty_msat, | ||
| channel_config, | ||
| true, | ||
| false, | ||
| ) | ||
| } | ||
|
|
||
| /// Connect to a node and open a new unannounced, zero-reserve channel. | ||
| /// | ||
| /// Zero-reserve channels allow the channel counterparty to try to steal your funds with | ||
| /// no financial penalty, so zero-reserve channels should only be opened to parties you | ||
| /// trust. | ||
| /// | ||
| /// Note that this only allows *the counterparty* to spend *their* entire balance in the | ||
| /// the channel; whether *you* are allowed to spend your own full balance is the | ||
| /// counterparty's decision. See [`Config::trusted_peers_0conf_0reserve`] if the | ||
| /// counterparty would like to set zero-reserve on your own balance as well. | ||
| /// | ||
| /// 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. | ||
| /// | ||
| /// [`Config::trusted_peers_0conf_0reserve`]: crate::config::Config::trusted_peers_0conf_0reserve | ||
| /// [`AnchorChannelsConfig::per_channel_reserve_sats`]: crate::config::AnchorChannelsConfig::per_channel_reserve_sats | ||
| pub fn open_0reserve_channel( | ||
|
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. If we go ahead with these new APIs, they need to be exposed in
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. Done below
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, zero-reserve channel, using all available | ||
| /// on-chain funds minus fees and anchor reserves. | ||
| /// | ||
| /// Zero-reserve channels allow the channel counterparty to try to steal your funds with | ||
| /// no financial penalty, so zero-reserve channels should only be opened to parties you | ||
| /// trust. | ||
| /// | ||
| /// Note that this only allows *the counterparty* to spend *their* entire balance in the | ||
| /// the channel; whether *you* are allowed to spend your own full balance is the | ||
| /// counterparty's decision. See [`Config::trusted_peers_0conf_0reserve`] if the | ||
| /// counterparty would like to set zero-reserve on your own balance as well. | ||
| /// | ||
| /// 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. | ||
| /// | ||
| /// [`Config::trusted_peers_0conf_0reserve`]: crate::config::Config::trusted_peers_0conf_0reserve | ||
| 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, | ||
| ) | ||
| } | ||
|
|
||
|
|
||
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.
Hmm, given the potentially very different usecases, I'm still not sure whether it makes sense to mix the two concepts like this. Should this maybe be a
HashMap<PublicKey, TrustedChannelFeatures>to allow finer-grained control?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.
mainbranch this list already applies only to inbound channels.TrustedChannelFeatures::ZeroConfZeroReservein the hashmap, we would actually discard theZeroConfbit for outbound channels, would this be a source of confusion ? "Hey I set my peer to trusted, and opened a channel to that peer, why is it not 0conf ?"open_0reserve_channel."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 me and you want to open a 0 reserve channel to eachother, but don't want to accept 0 conf from eachother. Would
open_0reserve_channelwork? Or when I doopen_0reserve_channelwill your node just reject it because its not in the list?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.
when alice calls
open_0reserve_channel, she allows bob to spend his entire balance. Bob will accept regardless of whether Alice is on his "trusted peers" list.If Bob has placed alice on his "trusted peers" list, bob in turn allows alice to spend her entire balance, and at the moment, allows alice to start immediately using the channel with 0-conf.
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.
Added this in the commit below