Skip to content

Commit d71face

Browse files
committed
Allow pushing some msats on channel open
1 parent b124eca commit d71face

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626

2727
node.sync_wallets().unwrap();
2828

29-
node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, false).unwrap();
29+
node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, None, false).unwrap();
3030

3131
let invoice = Invoice::from_str("INVOICE_STR").unwrap();
3232
node.send_payment(invoice).unwrap();

src/lib.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//!
4545
//! node.sync_wallets().unwrap();
4646
//!
47-
//! node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, false).unwrap();
47+
//! node.connect_open_channel("NODE_ID@PEER_ADDR:PORT", 10000, None, false).unwrap();
4848
//!
4949
//! let invoice = Invoice::from_str("INVOICE_STR").unwrap();
5050
//! node.send_payment(invoice).unwrap();
@@ -841,11 +841,18 @@ impl Node {
841841
self.channel_manager.list_channels()
842842
}
843843

844-
/// Connect to a node and open a new channel. Disconnects and re-connects are handled automatically
844+
/// Connect to a node and opens a new channel.
845845
///
846-
/// Returns a temporary channel id
846+
/// Disconnects and reconnects are handled automatically.
847+
///
848+
/// If `push_to_counterparty_msat` is set, the given value will be pushed (read: sent) to the
849+
/// channel counterparty on channel open. This can be useful to start out with the balance not
850+
/// entirely shifted to one side, therefore allowing to receive payments from the getgo.
851+
///
852+
/// Returns a temporary channel id.
847853
pub fn connect_open_channel(
848-
&self, node_pubkey_and_address: &str, channel_amount_sats: u64, announce_channel: bool,
854+
&self, node_pubkey_and_address: &str, channel_amount_sats: u64,
855+
push_to_counterparty_msat: Option<u64>, announce_channel: bool,
849856
) -> Result<(), Error> {
850857
let runtime_lock = self.running.read().unwrap();
851858
if runtime_lock.is_none() {
@@ -895,12 +902,13 @@ impl Node {
895902
..Default::default()
896903
};
897904

905+
let push_msat = push_to_counterparty_msat.unwrap_or(0);
898906
let user_channel_id: u128 = rand::thread_rng().gen::<u128>();
899907

900908
match self.channel_manager.create_channel(
901909
peer_info.pubkey,
902910
channel_amount_sats,
903-
0,
911+
push_msat,
904912
user_channel_id,
905913
Some(user_config),
906914
) {

src/test/functional_tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn channel_full_cycle() {
3333

3434
println!("\nA -- connect_open_channel -> B");
3535
let node_b_addr = format!("{}@{}", node_b.node_id(), node_b.listening_address().unwrap());
36-
node_a.connect_open_channel(&node_b_addr, 50000, true).unwrap();
36+
node_a.connect_open_channel(&node_b_addr, 80_000, Some(40_000 * 1000), true).unwrap();
3737

3838
expect_event!(node_a, ChannelPending);
3939

@@ -56,8 +56,8 @@ fn channel_full_cycle() {
5656
node_b.sync_wallets().unwrap();
5757

5858
let node_a_balance = node_a.on_chain_balance().unwrap();
59-
assert!(node_a_balance.get_spendable() < 50000);
60-
assert!(node_a_balance.get_spendable() > 40000);
59+
assert!(node_a_balance.get_spendable() < 20000);
60+
assert!(node_a_balance.get_spendable() > 15000);
6161
assert_eq!(node_b.on_chain_balance().unwrap().get_spendable(), 100000);
6262

6363
expect_event!(node_a, ChannelReady);
@@ -176,8 +176,8 @@ fn channel_full_cycle() {
176176
node_a.sync_wallets().unwrap();
177177
node_b.sync_wallets().unwrap();
178178

179-
assert!(node_a.on_chain_balance().unwrap().get_spendable() > 90000);
180-
assert_eq!(node_b.on_chain_balance().unwrap().get_spendable(), 103234);
179+
assert!(node_a.on_chain_balance().unwrap().get_spendable() > 50000);
180+
assert_eq!(node_b.on_chain_balance().unwrap().get_spendable(), 143234);
181181

182182
node_a.stop().unwrap();
183183
println!("\nA stopped");
@@ -216,7 +216,7 @@ fn channel_open_fails_when_funds_insufficient() {
216216
let node_b_addr = format!("{}@{}", node_b.node_id(), node_b.listening_address().unwrap());
217217
assert_eq!(
218218
Err(Error::InsufficientFunds),
219-
node_a.connect_open_channel(&node_b_addr, 120000, true)
219+
node_a.connect_open_channel(&node_b_addr, 120000, None, true)
220220
);
221221
}
222222

0 commit comments

Comments
 (0)