@@ -1129,7 +1129,7 @@ impl Node {
11291129 fn open_channel_inner (
11301130 & self , node_id : PublicKey , address : SocketAddress , channel_amount_sats : FundingAmount ,
11311131 push_to_counterparty_msat : Option < u64 > , channel_config : Option < ChannelConfig > ,
1132- announce_for_forwarding : bool ,
1132+ announce_for_forwarding : bool , set_0reserve : bool ,
11331133 ) -> Result < UserChannelId , Error > {
11341134 if !* self . is_running . read ( ) . unwrap ( ) {
11351135 return Err ( Error :: NotRunning ) ;
@@ -1197,25 +1197,46 @@ impl Node {
11971197 self . keys_manager . get_secure_random_bytes ( ) [ ..16 ] . try_into ( ) . unwrap ( ) ,
11981198 ) ;
11991199
1200- match self . channel_manager . create_channel (
1201- peer_info. node_id ,
1202- channel_amount_sats,
1203- push_msat,
1204- user_channel_id,
1205- None ,
1206- Some ( user_config) ,
1207- ) {
1200+ let result = if set_0reserve {
1201+ self . channel_manager . create_channel_to_trusted_peer_0reserve (
1202+ peer_info. node_id ,
1203+ channel_amount_sats,
1204+ push_msat,
1205+ user_channel_id,
1206+ None ,
1207+ Some ( user_config) ,
1208+ )
1209+ } else {
1210+ self . channel_manager . create_channel (
1211+ peer_info. node_id ,
1212+ channel_amount_sats,
1213+ push_msat,
1214+ user_channel_id,
1215+ None ,
1216+ Some ( user_config) ,
1217+ )
1218+ } ;
1219+
1220+ let zero_reserve_string = if set_0reserve { "0reserve " } else { "" } ;
1221+
1222+ match result {
12081223 Ok ( _) => {
12091224 log_info ! (
12101225 self . logger,
1211- "Initiated channel creation with peer {}. " ,
1226+ "Initiated {}channel creation with peer {}. " ,
1227+ zero_reserve_string,
12121228 peer_info. node_id
12131229 ) ;
12141230 self . peer_store . add_peer ( peer_info) ?;
12151231 Ok ( UserChannelId ( user_channel_id) )
12161232 } ,
12171233 Err ( e) => {
1218- log_error ! ( self . logger, "Failed to initiate channel creation: {:?}" , e) ;
1234+ log_error ! (
1235+ self . logger,
1236+ "Failed to initiate {}channel creation: {:?}" ,
1237+ zero_reserve_string,
1238+ e
1239+ ) ;
12191240 Err ( Error :: ChannelCreationFailed )
12201241 } ,
12211242 }
@@ -1291,6 +1312,7 @@ impl Node {
12911312 push_to_counterparty_msat,
12921313 channel_config,
12931314 false ,
1315+ false ,
12941316 )
12951317 }
12961318
@@ -1331,6 +1353,7 @@ impl Node {
13311353 push_to_counterparty_msat,
13321354 channel_config,
13331355 true ,
1356+ false ,
13341357 )
13351358 }
13361359
@@ -1359,6 +1382,7 @@ impl Node {
13591382 push_to_counterparty_msat,
13601383 channel_config,
13611384 false ,
1385+ false ,
13621386 )
13631387 }
13641388
@@ -1396,6 +1420,70 @@ impl Node {
13961420 push_to_counterparty_msat,
13971421 channel_config,
13981422 true ,
1423+ false ,
1424+ )
1425+ }
1426+
1427+ /// Connect to a node and open a new unannounced channel, in which the target node can
1428+ /// spend its entire balance.
1429+ ///
1430+ /// This channel allows the target node to try to steal your funds with no financial
1431+ /// penalty, so this channel should only be opened to nodes you trust.
1432+ ///
1433+ /// Disconnects and reconnects are handled automatically.
1434+ ///
1435+ /// If `push_to_counterparty_msat` is set, the given value will be pushed (read: sent) to the
1436+ /// channel counterparty on channel open. This can be useful to start out with the balance not
1437+ /// entirely shifted to one side, therefore allowing to receive payments from the getgo.
1438+ ///
1439+ /// If Anchor channels are enabled, this will ensure the configured
1440+ /// [`AnchorChannelsConfig::per_channel_reserve_sats`] is available and will be retained before
1441+ /// opening the channel.
1442+ ///
1443+ /// Returns a [`UserChannelId`] allowing to locally keep track of the channel.
1444+ ///
1445+ /// [`AnchorChannelsConfig::per_channel_reserve_sats`]: crate::config::AnchorChannelsConfig::per_channel_reserve_sats
1446+ pub fn open_0reserve_channel (
1447+ & self , node_id : PublicKey , address : SocketAddress , channel_amount_sats : u64 ,
1448+ push_to_counterparty_msat : Option < u64 > , channel_config : Option < ChannelConfig > ,
1449+ ) -> Result < UserChannelId , Error > {
1450+ self . open_channel_inner (
1451+ node_id,
1452+ address,
1453+ FundingAmount :: Exact { amount_sats : channel_amount_sats } ,
1454+ push_to_counterparty_msat,
1455+ channel_config,
1456+ false ,
1457+ true ,
1458+ )
1459+ }
1460+
1461+ /// Connect to a node and open a new unannounced channel, using all available on-chain funds
1462+ /// minus fees and anchor reserves. The target node will be able to spend its entire channel
1463+ /// balance.
1464+ ///
1465+ /// This channel allows the target node to try to steal your funds with no financial
1466+ /// penalty, so this channel should only be opened to nodes you trust.
1467+ ///
1468+ /// Disconnects and reconnects are handled automatically.
1469+ ///
1470+ /// If `push_to_counterparty_msat` is set, the given value will be pushed (read: sent) to the
1471+ /// channel counterparty on channel open. This can be useful to start out with the balance not
1472+ /// entirely shifted to one side, therefore allowing to receive payments from the getgo.
1473+ ///
1474+ /// Returns a [`UserChannelId`] allowing to locally keep track of the channel.
1475+ pub fn open_0reserve_channel_with_all (
1476+ & self , node_id : PublicKey , address : SocketAddress , push_to_counterparty_msat : Option < u64 > ,
1477+ channel_config : Option < ChannelConfig > ,
1478+ ) -> Result < UserChannelId , Error > {
1479+ self . open_channel_inner (
1480+ node_id,
1481+ address,
1482+ FundingAmount :: Max ,
1483+ push_to_counterparty_msat,
1484+ channel_config,
1485+ false ,
1486+ true ,
13991487 )
14001488 }
14011489
0 commit comments