Repository navigation
Add disable_outbound_lightning_connections flag
#1064
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 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 |
|---|---|---|
|
|
@@ -203,6 +203,7 @@ impl Default for ForwardedPaymentTrackingMode { | |
| /// |----------------------------------------|--------------------------------------| | ||
| /// | `storage_dir_path` | /tmp/ldk_node/ | | ||
| /// | `network` | Bitcoin | | ||
| /// |`disable_outbound_lightning_connections`| false | | ||
| /// | `listening_addresses` | None | | ||
| /// | `announcement_addresses` | None | | ||
| /// | `node_alias` | None | | ||
|
|
@@ -227,6 +228,12 @@ pub struct Config { | |
| pub storage_dir_path: String, | ||
| /// The used Bitcoin network. | ||
| pub network: Network, | ||
| /// Disables all outbound Lightning peer-to-peer (P2P) connections. | ||
| /// | ||
| /// Inbound connections are controlled separately by | ||
| /// [`Config::listening_addresses`]; set it to `None` to prevent inbound connections as well. | ||
| /// Other networking, including chain synchronization, is unaffected. | ||
| pub disable_outbound_lightning_connections: bool, | ||
|
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. Hmm, maybe this would be better on the builder, rather than a |
||
| /// The addresses on which the node will listen for incoming connections. | ||
| /// | ||
| /// **Note**: We will only allow opening and accepting public channels if the `node_alias` and the | ||
|
|
@@ -304,6 +311,7 @@ impl Default for Config { | |
| Self { | ||
| storage_dir_path: DEFAULT_STORAGE_DIR_PATH.to_string(), | ||
| network: DEFAULT_NETWORK, | ||
| disable_outbound_lightning_connections: false, | ||
| listening_addresses: None, | ||
| announcement_addresses: None, | ||
| trusted_peers_0conf: Vec::new(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ use bitcoin::secp256k1::PublicKey; | |
| use lightning::ln::msgs::SocketAddress; | ||
|
|
||
| use crate::config::TorConfig; | ||
| use crate::logger::{log_debug, log_error, log_info, LdkLogger}; | ||
| use crate::logger::{log_debug, log_error, log_info, log_warn, LdkLogger}; | ||
| use crate::types::{KeysManager, PeerManager}; | ||
| use crate::Error; | ||
|
|
||
|
|
@@ -57,6 +57,7 @@ where | |
| { | ||
| pending_connections: PendingConnections, | ||
| peer_manager: Arc<PeerManager>, | ||
| disable_outbound_lightning_connections: bool, | ||
| tor_proxy_config: Option<TorConfig>, | ||
| keys_manager: Arc<KeysManager>, | ||
| logger: L, | ||
|
|
@@ -67,12 +68,19 @@ where | |
| L::Target: LdkLogger, | ||
| { | ||
| pub(crate) fn new( | ||
| peer_manager: Arc<PeerManager>, tor_proxy_config: Option<TorConfig>, | ||
| keys_manager: Arc<KeysManager>, logger: L, | ||
| peer_manager: Arc<PeerManager>, disable_outbound_lightning_connections: bool, | ||
| tor_proxy_config: Option<TorConfig>, keys_manager: Arc<KeysManager>, logger: L, | ||
| ) -> Self { | ||
| let pending_connections = Mutex::new(HashMap::new()); | ||
|
|
||
| Self { pending_connections, peer_manager, tor_proxy_config, keys_manager, logger } | ||
| Self { | ||
| pending_connections, | ||
| peer_manager, | ||
| disable_outbound_lightning_connections, | ||
| tor_proxy_config, | ||
| keys_manager, | ||
| logger, | ||
| } | ||
| } | ||
|
|
||
| pub(crate) async fn connect_peer_if_necessary( | ||
|
|
@@ -115,6 +123,11 @@ where | |
| async fn do_connect_peer_internal( | ||
| &self, node_id: PublicKey, addr: SocketAddress, | ||
| ) -> Result<(), Error> { | ||
| if self.disable_outbound_lightning_connections { | ||
|
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. Should we add a test for this, i.e., one that sets up some nodes and then restarts with the flag enabled, ensuring that they they don't reconnect? |
||
| log_warn!(self.logger, "Outbound Lightning peer connections are disabled."); | ||
| return Err(Error::ConnectionFailed); | ||
| } | ||
|
|
||
| log_info!(self.logger, "Connecting to peer: {}@{}", node_id, addr); | ||
|
|
||
| match addr { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1294,6 +1294,8 @@ impl Node { | |
| /// Connect to a node on the peer-to-peer network. | ||
| /// | ||
| /// If `persist` is set to `true`, we'll remember the peer and reconnect to it on restart. | ||
| /// Outbound connection attempts fail with [`Error::ConnectionFailed`] if | ||
| /// [`Config::disable_outbound_lightning_connections`] is set. | ||
| pub fn connect( | ||
|
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. Hmm, wouldn't we still want to allow manual overrides? I.e. allow the user to selectively connect peers, e.g., to trigger the channel-reestablish recovery flow? |
||
| &self, node_id: PublicKey, address: SocketAddress, persist: bool, | ||
| ) -> Result<(), Error> { | ||
|
|
||
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.
nit: This has missing whitespace (before, after).