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