|
47 | 47 | //!
|
48 | 48 | //! let node_id = PublicKey::from_str("NODE_ID").unwrap();
|
49 | 49 | //! let node_addr = SocketAddress::from_str("IP_ADDR:PORT").unwrap();
|
50 |
| -//! node.connect_open_channel(node_id, node_addr, 10000, None, None, false).unwrap(); |
| 50 | +//! node.open_channel(node_id, node_addr, 10000, None, None).unwrap(); |
51 | 51 | //!
|
52 | 52 | //! let event = node.wait_next_event();
|
53 | 53 | //! println!("EVENT: {:?}", event);
|
|
63 | 63 | //! [`build`]: Builder::build
|
64 | 64 | //! [`start`]: Node::start
|
65 | 65 | //! [`stop`]: Node::stop
|
66 |
| -//! [`connect_open_channel`]: Node::connect_open_channel |
| 66 | +//! [`open_channel`]: Node::open_channel |
| 67 | +//! [`open_announced_channel`]: Node::open_announced_channel |
67 | 68 | //! [`send`]: Bolt11Payment::send
|
68 | 69 | //!
|
69 | 70 | #![cfg_attr(not(feature = "uniffi"), deny(missing_docs))]
|
@@ -114,15 +115,17 @@ pub use io::utils::generate_entropy_mnemonic;
|
114 | 115 | #[cfg(feature = "uniffi")]
|
115 | 116 | use uniffi_types::*;
|
116 | 117 |
|
| 118 | +pub use builder::sanitize_alias; |
117 | 119 | #[cfg(feature = "uniffi")]
|
118 | 120 | pub use builder::ArcedNodeBuilder as Builder;
|
119 | 121 | pub use builder::BuildError;
|
120 | 122 | #[cfg(not(feature = "uniffi"))]
|
121 | 123 | pub use builder::NodeBuilder as Builder;
|
122 | 124 |
|
123 | 125 | use config::{
|
124 |
| - default_user_config, LDK_WALLET_SYNC_TIMEOUT_SECS, NODE_ANN_BCAST_INTERVAL, |
125 |
| - PEER_RECONNECTION_INTERVAL, RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL, RGS_SYNC_INTERVAL, |
| 126 | + can_announce_channel, default_user_config, LDK_WALLET_SYNC_TIMEOUT_SECS, |
| 127 | + NODE_ANN_BCAST_INTERVAL, PEER_RECONNECTION_INTERVAL, |
| 128 | + RESOLVED_CHANNEL_MONITOR_ARCHIVAL_INTERVAL, RGS_SYNC_INTERVAL, |
126 | 129 | WALLET_SYNC_INTERVAL_MINIMUM_SECS,
|
127 | 130 | };
|
128 | 131 | use connection::ConnectionManager;
|
@@ -601,7 +604,8 @@ impl Node {
|
601 | 604 | let bcast_logger = Arc::clone(&self.logger);
|
602 | 605 | let bcast_ann_timestamp = Arc::clone(&self.latest_node_announcement_broadcast_timestamp);
|
603 | 606 | let mut stop_bcast = self.stop_sender.subscribe();
|
604 |
| - let node_alias = self.config().node_alias; |
| 607 | + let node_alias = self.config.node_alias.clone(); |
| 608 | + let can_announce_channel = can_announce_channel(&self.config); |
605 | 609 | runtime.spawn(async move {
|
606 | 610 | // We check every 30 secs whether our last broadcast is NODE_ANN_BCAST_INTERVAL away.
|
607 | 611 | #[cfg(not(test))]
|
@@ -646,17 +650,19 @@ impl Node {
|
646 | 650 |
|
647 | 651 | let addresses = bcast_config.listening_addresses.clone().unwrap_or(Vec::new());
|
648 | 652 | let alias = node_alias.clone().map(|alias| {
|
649 |
| - let mut buf = [0_u8; 32]; |
650 |
| - buf[..alias.as_bytes().len()].copy_from_slice(alias.as_bytes()); |
651 |
| - buf |
| 653 | + alias.0 |
652 | 654 | });
|
653 | 655 |
|
654 |
| - if addresses.is_empty() || alias.is_none() { |
| 656 | + if !can_announce_channel { |
655 | 657 | // Skip if we are not listening on any addresses or if the node alias is not set.
|
656 | 658 | continue;
|
657 | 659 | }
|
658 | 660 |
|
659 |
| - bcast_pm.broadcast_node_announcement([0; 3], alias.unwrap(), addresses); |
| 661 | + if let Some(node_alias) = alias { |
| 662 | + bcast_pm.broadcast_node_announcement([0; 3], node_alias, addresses); |
| 663 | + } else { |
| 664 | + continue |
| 665 | + } |
660 | 666 |
|
661 | 667 | let unix_time_secs_opt =
|
662 | 668 | SystemTime::now().duration_since(UNIX_EPOCH).ok().map(|d| d.as_secs());
|
@@ -1189,10 +1195,9 @@ impl Node {
|
1189 | 1195 | /// opening the channel.
|
1190 | 1196 | ///
|
1191 | 1197 | /// Returns a [`UserChannelId`] allowing to locally keep track of the channel.
|
1192 |
| - pub fn connect_open_channel( |
| 1198 | + fn connect_open_channel( |
1193 | 1199 | &self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: u64,
|
1194 | 1200 | push_to_counterparty_msat: Option<u64>, channel_config: Option<ChannelConfig>,
|
1195 |
| - announce_channel: bool, |
1196 | 1201 | ) -> Result<UserChannelId, Error> {
|
1197 | 1202 | let rt_lock = self.runtime.read().unwrap();
|
1198 | 1203 | if rt_lock.is_none() {
|
@@ -1254,12 +1259,13 @@ impl Node {
|
1254 | 1259 | }
|
1255 | 1260 |
|
1256 | 1261 | let mut user_config = default_user_config(&self.config);
|
1257 |
| - user_config.channel_handshake_config.announced_channel = announce_channel; |
| 1262 | + let can_announce_channel = can_announce_channel(&self.config); |
| 1263 | + user_config.channel_handshake_config.announced_channel = can_announce_channel; |
1258 | 1264 | user_config.channel_config = (channel_config.unwrap_or_default()).clone().into();
|
1259 | 1265 | // We set the max inflight to 100% for private channels.
|
1260 | 1266 | // FIXME: LDK will default to this behavior soon, too, at which point we should drop this
|
1261 | 1267 | // manual override.
|
1262 |
| - if !announce_channel { |
| 1268 | + if !can_announce_channel { |
1263 | 1269 | user_config
|
1264 | 1270 | .channel_handshake_config
|
1265 | 1271 | .max_inbound_htlc_value_in_flight_percent_of_channel = 100;
|
@@ -1292,6 +1298,38 @@ impl Node {
|
1292 | 1298 | }
|
1293 | 1299 | }
|
1294 | 1300 |
|
| 1301 | + /// Opens a channel with a peer. |
| 1302 | + pub fn open_channel( |
| 1303 | + &self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: u64, |
| 1304 | + push_to_counterparty_msat: Option<u64>, channel_config: Option<Arc<ChannelConfig>>, |
| 1305 | + ) -> Result<UserChannelId, Error> { |
| 1306 | + self.connect_open_channel( |
| 1307 | + node_id, |
| 1308 | + address, |
| 1309 | + channel_amount_sats, |
| 1310 | + push_to_counterparty_msat, |
| 1311 | + channel_config, |
| 1312 | + ) |
| 1313 | + } |
| 1314 | + |
| 1315 | + /// Opens an announced channel with a peer. |
| 1316 | + pub fn open_announced_channel( |
| 1317 | + &self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: u64, |
| 1318 | + push_to_counterparty_msat: Option<u64>, channel_config: Option<Arc<ChannelConfig>>, |
| 1319 | + ) -> Result<UserChannelId, Error> { |
| 1320 | + if !can_announce_channel(&self.config) { |
| 1321 | + return Err(Error::OpenAnnouncedChannelFailed); |
| 1322 | + } |
| 1323 | + |
| 1324 | + self.open_channel( |
| 1325 | + node_id, |
| 1326 | + address, |
| 1327 | + channel_amount_sats, |
| 1328 | + push_to_counterparty_msat, |
| 1329 | + channel_config, |
| 1330 | + ) |
| 1331 | + } |
| 1332 | + |
1295 | 1333 | /// Manually sync the LDK and BDK wallets with the current chain state and update the fee rate
|
1296 | 1334 | /// cache.
|
1297 | 1335 | ///
|
|
0 commit comments