Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to specify and update ChannelConfig #122

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class LibraryTest {
assertEquals(100000u, totalBalance1)
assertEquals(100000u, totalBalance2)

node1.connectOpenChannel(nodeId2, listenAddress2, 50000u, null, true)
node1.connectOpenChannel(nodeId2, listenAddress2, 50000u, null, null, true)

val channelPendingEvent1 = node1.waitNextEvent()
println("Got event: $channelPendingEvent1")
Expand Down
13 changes: 12 additions & 1 deletion bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ interface LDKNode {
[Throws=NodeError]
void disconnect(PublicKey node_id);
[Throws=NodeError]
void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, boolean announce_channel);
void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
[Throws=NodeError]
void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
[Throws=NodeError]
void update_channel_config([ByRef]ChannelId channel_id, PublicKey counterparty_node_id, [ByRef]ChannelConfig channel_config);
[Throws=NodeError]
void sync_wallets();
[Throws=NodeError]
PaymentHash send_payment([ByRef]Invoice invoice);
Expand Down Expand Up @@ -90,6 +92,7 @@ enum NodeError {
"PaymentSendingFailed",
"ChannelCreationFailed",
"ChannelClosingFailed",
"ChannelConfigUpdateFailed",
"PersistenceFailed",
"WalletOperationFailed",
"OnchainTxSigningFailed",
Expand Down Expand Up @@ -181,6 +184,14 @@ dictionary PeerDetails {
boolean is_connected;
};

dictionary ChannelConfig {
u32 forwarding_fee_proportional_millionths;
u32 forwarding_fee_base_msat;
u16 cltv_expiry_delta;
u64 max_dust_htlc_exposure_msat;
u64 force_close_avoidance_max_fee_satoshis;
};

enum LogLevel {
"Gossip",
"Trace",
Expand Down
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub enum Error {
ChannelCreationFailed,
/// A channel could not be closed.
ChannelClosingFailed,
/// A channel config could not be updated.
ChannelConfigUpdateFailed,
/// Persistence failed.
PersistenceFailed,
/// A wallet operation failed.
Expand Down Expand Up @@ -72,6 +74,7 @@ impl fmt::Display for Error {
Self::PaymentSendingFailed => write!(f, "Failed to send the given payment."),
Self::ChannelCreationFailed => write!(f, "Failed to create channel."),
Self::ChannelClosingFailed => write!(f, "Failed to close channel."),
Self::ChannelConfigUpdateFailed => write!(f, "Failed to update channel config."),
Self::PersistenceFailed => write!(f, "Failed to persist data."),
Self::WalletOperationFailed => write!(f, "Failed to conduct wallet operation."),
Self::OnchainTxSigningFailed => write!(f, "Failed to sign given transaction."),
Expand Down
24 changes: 16 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
//!
//! let node_id = PublicKey::from_str("NODE_ID").unwrap();
//! let node_addr = NetAddress::from_str("IP_ADDR:PORT").unwrap();
//! node.connect_open_channel(node_id, node_addr, 10000, None, false).unwrap();
//! node.connect_open_channel(node_id, node_addr, 10000, None, None, false).unwrap();
//!
//! let event = node.wait_next_event();
//! println!("EVENT: {:?}", event);
Expand Down Expand Up @@ -135,7 +135,7 @@ use lightning::ln::peer_handler::{IgnoringMessageHandler, MessageHandler};
use lightning::ln::{PaymentHash, PaymentPreimage};
use lightning::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};

use lightning::util::config::{ChannelHandshakeConfig, ChannelHandshakeLimits, UserConfig};
use lightning::util::config::{ChannelConfig, ChannelHandshakeConfig, UserConfig};
pub use lightning::util::logger::Level as LogLevel;
use lightning::util::ser::ReadableArgs;

Expand Down Expand Up @@ -1369,7 +1369,8 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
/// Returns a temporary channel id.
pub fn connect_open_channel(
&self, node_id: PublicKey, address: NetAddress, channel_amount_sats: u64,
push_to_counterparty_msat: Option<u64>, announce_channel: bool,
push_to_counterparty_msat: Option<u64>, channel_config: Option<ChannelConfig>,
announce_channel: bool,
) -> Result<(), Error> {
let rt_lock = self.runtime.read().unwrap();
if rt_lock.is_none() {
Expand Down Expand Up @@ -1399,15 +1400,12 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
})?;

let user_config = UserConfig {
channel_handshake_limits: ChannelHandshakeLimits {
// lnd's max to_self_delay is 2016, so we want to be compatible.
their_to_self_delay: 2016,
..Default::default()
},
channel_handshake_limits: Default::default(),
channel_handshake_config: ChannelHandshakeConfig {
announced_channel: announce_channel,
..Default::default()
},
channel_config: channel_config.unwrap_or_default(),
..Default::default()
};

Expand Down Expand Up @@ -1508,6 +1506,16 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
}
}

/// Update the config for a previously opened channel.
pub fn update_channel_config(
&self, channel_id: &ChannelId, counterparty_node_id: PublicKey,
channel_config: &ChannelConfig,
) -> Result<(), Error> {
self.channel_manager
.update_channel_config(&counterparty_node_id, &[channel_id.0], channel_config)
.map_err(|_| Error::ChannelConfigUpdateFailed)
}

/// Send a payement given an invoice.
pub fn send_payment(&self, invoice: &Invoice) -> Result<PaymentHash, Error> {
let rt_lock = self.runtime.read().unwrap();
Expand Down
4 changes: 3 additions & 1 deletion src/test/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn do_channel_full_cycle<K: KVStore + Sync + Send>(
node_b.listening_address().unwrap().into(),
funding_amount_sat,
Some(push_msat),
None,
true,
)
.unwrap();
Expand Down Expand Up @@ -311,7 +312,8 @@ fn channel_open_fails_when_funds_insufficient() {
node_b.listening_address().unwrap().into(),
120000,
None,
true,
None,
true
)
);
}
Expand Down