Skip to content

Commit 5dd2f6e

Browse files
authored
Merge pull request #122 from tnull/2023-05-expose-update-channel-config
2 parents 5121cad + 831a330 commit 5dd2f6e

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

bindings/kotlin/ldk-node-jvm/lib/src/test/kotlin/org/lightningdevkit/ldknode/LibraryTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class LibraryTest {
120120
assertEquals(100000u, totalBalance1)
121121
assertEquals(100000u, totalBalance2)
122122

123-
node1.connectOpenChannel(nodeId2, listenAddress2, 50000u, null, true)
123+
node1.connectOpenChannel(nodeId2, listenAddress2, 50000u, null, null, true)
124124

125125
val channelPendingEvent1 = node1.waitNextEvent()
126126
println("Got event: $channelPendingEvent1")

bindings/ldk_node.udl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ interface LDKNode {
5555
[Throws=NodeError]
5656
void disconnect(PublicKey node_id);
5757
[Throws=NodeError]
58-
void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, boolean announce_channel);
58+
void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
5959
[Throws=NodeError]
6060
void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
6161
[Throws=NodeError]
62+
void update_channel_config([ByRef]ChannelId channel_id, PublicKey counterparty_node_id, [ByRef]ChannelConfig channel_config);
63+
[Throws=NodeError]
6264
void sync_wallets();
6365
[Throws=NodeError]
6466
PaymentHash send_payment([ByRef]Invoice invoice);
@@ -91,6 +93,7 @@ enum NodeError {
9193
"PaymentSendingFailed",
9294
"ChannelCreationFailed",
9395
"ChannelClosingFailed",
96+
"ChannelConfigUpdateFailed",
9497
"PersistenceFailed",
9598
"WalletOperationFailed",
9699
"OnchainTxSigningFailed",
@@ -182,6 +185,14 @@ dictionary PeerDetails {
182185
boolean is_connected;
183186
};
184187

188+
dictionary ChannelConfig {
189+
u32 forwarding_fee_proportional_millionths;
190+
u32 forwarding_fee_base_msat;
191+
u16 cltv_expiry_delta;
192+
u64 max_dust_htlc_exposure_msat;
193+
u64 force_close_avoidance_max_fee_satoshis;
194+
};
195+
185196
enum LogLevel {
186197
"Gossip",
187198
"Trace",

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub enum Error {
1919
ChannelCreationFailed,
2020
/// A channel could not be closed.
2121
ChannelClosingFailed,
22+
/// A channel config could not be updated.
23+
ChannelConfigUpdateFailed,
2224
/// Persistence failed.
2325
PersistenceFailed,
2426
/// A wallet operation failed.
@@ -72,6 +74,7 @@ impl fmt::Display for Error {
7274
Self::PaymentSendingFailed => write!(f, "Failed to send the given payment."),
7375
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
7476
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
77+
Self::ChannelConfigUpdateFailed => write!(f, "Failed to update channel config."),
7578
Self::PersistenceFailed => write!(f, "Failed to persist data."),
7679
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
7780
Self::OnchainTxSigningFailed => write!(f, "Failed to sign given transaction."),

src/lib.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
//!
4949
//! let node_id = PublicKey::from_str("NODE_ID").unwrap();
5050
//! let node_addr = NetAddress::from_str("IP_ADDR:PORT").unwrap();
51-
//! node.connect_open_channel(node_id, node_addr, 10000, None, false).unwrap();
51+
//! node.connect_open_channel(node_id, node_addr, 10000, None, None, false).unwrap();
5252
//!
5353
//! let event = node.wait_next_event();
5454
//! println!("EVENT: {:?}", event);
@@ -137,7 +137,7 @@ use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};
137137
use lightning::ln::{PaymentHash, PaymentPreimage};
138138
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
139139

140-
use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
140+
use lightning::util::config::{ChannelConfig, ChannelHandshakeConfig, UserConfig};
141141
pub use lightning::util::logger::Level as LogLevel;
142142
use lightning::util::ser::ReadableArgs;
143143

@@ -1371,7 +1371,8 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
13711371
/// Returns a temporary channel id.
13721372
pub fn connect_open_channel(
13731373
&self, node_id: PublicKey, address: NetAddress, channel_amount_sats: u64,
1374-
push_to_counterparty_msat: Option<u64>, announce_channel: bool,
1374+
push_to_counterparty_msat: Option<u64>, channel_config: Option<ChannelConfig>,
1375+
announce_channel: bool,
13751376
) -> Result<(), Error> {
13761377
let rt_lock = self.runtime.read().unwrap();
13771378
if rt_lock.is_none() {
@@ -1401,15 +1402,12 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
14011402
})?;
14021403

14031404
let user_config = UserConfig {
1404-
channel_handshake_limits: ChannelHandshakeLimits {
1405-
// lnd's max to_self_delay is 2016, so we want to be compatible.
1406-
their_to_self_delay: 2016,
1407-
..Default::default()
1408-
},
1405+
channel_handshake_limits: Default::default(),
14091406
channel_handshake_config: ChannelHandshakeConfig {
14101407
announced_channel: announce_channel,
14111408
..Default::default()
14121409
},
1410+
channel_config: channel_config.unwrap_or_default(),
14131411
..Default::default()
14141412
};
14151413

@@ -1510,6 +1508,16 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
15101508
}
15111509
}
15121510

1511+
/// Update the config for a previously opened channel.
1512+
pub fn update_channel_config(
1513+
&self, channel_id: &ChannelId, counterparty_node_id: PublicKey,
1514+
channel_config: &ChannelConfig,
1515+
) -> Result<(), Error> {
1516+
self.channel_manager
1517+
.update_channel_config(&counterparty_node_id, &[channel_id.0], channel_config)
1518+
.map_err(|_| Error::ChannelConfigUpdateFailed)
1519+
}
1520+
15131521
/// Send a payement given an invoice.
15141522
pub fn send_payment(&self, invoice: &Invoice) -> Result<PaymentHash, Error> {
15151523
let rt_lock = self.runtime.read().unwrap();

src/test/functional_tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
8787
node_b.listening_address().unwrap().into(),
8888
funding_amount_sat,
8989
Some(push_msat),
90+
None,
9091
true,
9192
)
9293
.unwrap();
@@ -311,7 +312,8 @@ fn channel_open_fails_when_funds_insufficient() {
311312
node_b.listening_address().unwrap().into(),
312313
120000,
313314
None,
314-
true,
315+
None,
316+
true
315317
)
316318
);
317319
}

0 commit comments

Comments
 (0)