Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
`Event::PaymentClaimable`.

## Feature and API updates
- All `Node::open_channel` variants now take an optional `FeeRate` (after
`push_to_counterparty_msat`) that, when set, is used for the channel's funding transaction instead of the internal fee estimation. For the
`_with_all` variants it also determines the rate at which the maximum funding amount is
computed. When unset, behavior is unchanged.
- Language-binding `Mnemonic` objects can be generated or constructed from entropy and expose
their words, word indices, word count, entropy, checksum, and passphrase-derived seed.
- `Node::list_payments` is now paginated: it takes an optional `PageToken` and returns a
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {

let node_id = PublicKey::from_str("NODE_ID").unwrap();
let node_addr = SocketAddress::from_str("IP_ADDR:PORT").unwrap();
node.open_channel(node_id, node_addr, 10000, None, None).unwrap();
node.open_channel(node_id, node_addr, 10000, None, None, None).unwrap();

let event = node.wait_next_event();
println!("EVENT: {:?}", event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class LibraryTest {
assertEquals(100000uL, totalBalance1)
assertEquals(100000uL, totalBalance2)

node1.openChannel(nodeId2, listenAddress2, 50000u, null, null)
node1.openChannel(nodeId2, listenAddress2, 50000u, null, null, null)

val channelPendingEvent1 = node1.waitNextEvent()
println("Got event: $channelPendingEvent1")
Expand Down
12 changes: 6 additions & 6 deletions bindings/ldk_node.udl
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ interface Node {
[Throws=NodeError]
void disconnect(PublicKey node_id);
[Throws=NodeError]
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
UserChannelId open_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, FeeRate? fee_rate, ChannelConfig? channel_config);
[Throws=NodeError]
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
UserChannelId open_announced_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, FeeRate? fee_rate, ChannelConfig? channel_config);
[Throws=NodeError]
UserChannelId open_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
UserChannelId open_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, FeeRate? fee_rate, ChannelConfig? channel_config);
[Throws=NodeError]
UserChannelId open_announced_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
UserChannelId open_announced_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, FeeRate? fee_rate, ChannelConfig? channel_config);
[Throws=NodeError]
UserChannelId open_0reserve_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
UserChannelId open_0reserve_channel(PublicKey node_id, SocketAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, FeeRate? fee_rate, ChannelConfig? channel_config);
[Throws=NodeError]
UserChannelId open_0reserve_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, ChannelConfig? channel_config);
UserChannelId open_0reserve_channel_with_all(PublicKey node_id, SocketAddress address, u64? push_to_counterparty_msat, FeeRate? fee_rate, ChannelConfig? channel_config);
[Throws=NodeError]
void splice_in([ByRef]UserChannelId user_channel_id, PublicKey counterparty_node_id, u64 splice_amount_sats);
[Throws=NodeError]
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/src/ldk_node/test_ldk_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def fund_nodes(node_1, node_2, esplora_endpoint, amount_sats=100000):
node_2.sync_wallets()

def open_channel_and_wait_ready(node_1, node_2, node_id_2, listening_address_2, esplora_endpoint, channel_amount_sats=50000):
node_1.open_channel(node_id_2, listening_address_2, channel_amount_sats, None, None)
node_1.open_channel(node_id_2, listening_address_2, channel_amount_sats, None, None, None)

channel_pending_event_1 = expect_event(node_1, Event.CHANNEL_PENDING)
expect_event(node_2, Event.CHANNEL_PENDING)
Expand Down
1 change: 1 addition & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,7 @@ fn build_with_store_internal(
node_metrics,
om_mailbox,
async_payments_role,
pending_funding_fee_rates: Arc::new(Mutex::new(std::collections::HashMap::new())),
#[cfg(feature = "unified-payments")]
hrn_resolver,
prober,
Expand Down
16 changes: 14 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

use core::future::Future;
use core::task::{Poll, Waker};
use std::collections::VecDeque;
use std::collections::{HashMap, VecDeque};
use std::ops::Deref;
use std::sync::{Arc, Mutex};

use bitcoin::blockdata::locktime::absolute::LockTime;
use bitcoin::secp256k1::PublicKey;
use bitcoin::{Amount, OutPoint};
use bitcoin::{Amount, FeeRate, OutPoint};
use lightning::blinded_path::message::NextMessageHop;
use lightning::events::bump_transaction::BumpTransactionEvent;
#[cfg(not(feature = "uniffi"))]
Expand Down Expand Up @@ -574,6 +574,7 @@ where
runtime: Arc<Runtime>,
logger: L,
config: Arc<Config>,
pending_funding_fee_rates: Arc<Mutex<HashMap<u128, FeeRate>>>,
}

impl<L: Deref + Clone + Sync + Send + 'static> EventHandler<L>
Expand All @@ -590,6 +591,7 @@ where
keys_manager: Arc<KeysManager>, static_invoice_store: Option<StaticInvoiceStore>,
onion_messenger: Arc<OnionMessenger>, om_mailbox: Option<Arc<OnionMessageMailbox>>,
prober: Option<Arc<Prober>>, runtime: Arc<Runtime>, logger: L, config: Arc<Config>,
pending_funding_fee_rates: Arc<Mutex<HashMap<u128, FeeRate>>>,
) -> Self {
Self {
event_queue,
Expand All @@ -611,6 +613,7 @@ where
runtime,
logger,
config,
pending_funding_fee_rates,
}
}

Expand Down Expand Up @@ -750,6 +753,10 @@ where
let cur_height = self.channel_manager.current_best_block().height;
let locktime = LockTime::from_height(cur_height).unwrap_or(LockTime::ZERO);

// Look up and remove any pending fee-rate override for this channel.
let fee_rate_override =
self.pending_funding_fee_rates.lock().expect("lock").remove(&user_channel_id);

// Sign the final funding transaction and broadcast it.
let channel_amount = Amount::from_sat(channel_value_satoshis);
let funding_transaction = self
Expand All @@ -759,6 +766,7 @@ where
channel_amount,
confirmation_target,
locktime,
fee_rate_override,
)
.await;
match funding_transaction {
Expand Down Expand Up @@ -1935,6 +1943,10 @@ where
} => {
log_info!(self.logger, "Channel {} closed due to: {}", channel_id, reason);

// Clean up any funding fee-rate override still pending if the channel went
// away before the funding transaction was generated.
self.pending_funding_fee_rates.lock().expect("lock").remove(&user_channel_id);

// `counterparty_node_id` has been set on every `ChannelClosed` since LDK 0.0.117.
let counterparty_node_id = counterparty_node_id
.expect("counterparty_node_id is always set since LDK 0.0.117");
Expand Down
16 changes: 16 additions & 0 deletions src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ pub fn maybe_wrap<T>(ldk_type: impl Into<T>) -> std::sync::Arc<T> {
std::sync::Arc::new(ldk_type.into())
}

#[cfg(feature = "uniffi")]
pub(crate) type FfiFeeRate = std::sync::Arc<bitcoin::FeeRate>;

#[cfg(feature = "uniffi")]
pub(crate) fn maybe_map_fee_rate_opt(fee_rate: Option<FfiFeeRate>) -> Option<bitcoin::FeeRate> {
fee_rate.map(|f| *f)
}

#[cfg(not(feature = "uniffi"))]
pub fn maybe_deref<T>(value: &T) -> &T {
value
Expand All @@ -45,3 +53,11 @@ pub fn maybe_try_convert_enum<T>(value: &T) -> Result<&T, crate::error::Error> {
pub fn maybe_wrap<T>(value: T) -> T {
value
}

#[cfg(not(feature = "uniffi"))]
pub(crate) type FfiFeeRate = bitcoin::FeeRate;

#[cfg(not(feature = "uniffi"))]
pub(crate) fn maybe_map_fee_rate_opt(fee_rate: Option<FfiFeeRate>) -> Option<bitcoin::FeeRate> {
fee_rate
}
Loading
Loading