Skip to content
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
68 changes: 40 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ demo = []

[dependencies]
# Branch: https://github.com/moneydevkit/ldk-node/tree/lsp-0.7.0_accept-underpaying-htlcs_with_timing_logs
ldk-node = { git = "https://github.com/moneydevkit/ldk-node", rev = "5dce44b6e795560bbf62f49d3648308ce88a0586" }
ldk-node = { git = "https://github.com/moneydevkit/ldk-node", rev = "f13fcead7e02ef4b77489a83854f204de11e902b" }

# Pinned to the same git rev as ldk-node's transitive pull to avoid duplicate
# crate compilation. Verify with `cargo tree -d | grep bitcoin-payment-instructions`.
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/api/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub async fn handle_get_balance(
.map(|ch| ch.outbound_capacity_msat / 1000)
.sum();

let max_withdrawable_sat = client.max_sendable().ok().map(|e| e.amount_msat / 1000);
let max_withdrawable_sat = client.max_sendable(None).ok().map(|e| e.amount_msat / 1000);

Ok(Json(GetBalanceResponse {
balance_sat: lightning_sat,
Expand Down
4 changes: 4 additions & 0 deletions src/daemon/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct SpliceSection {
struct MaxSendableSection {
fee_buffer_bps: Option<u16>,
fee_buffer_floor_sats: Option<u64>,
route_retry_fee_multiplier_bps: Option<u16>,
}

pub struct MdkConfig {
Expand Down Expand Up @@ -190,6 +191,9 @@ pub fn load_config(path: &str) -> io::Result<MdkConfig> {
fee_buffer_floor_sats: s
.fee_buffer_floor_sats
.unwrap_or(defaults.fee_buffer_floor_sats),
route_retry_fee_multiplier_bps: s
.route_retry_fee_multiplier_bps
.unwrap_or(defaults.route_retry_fee_multiplier_bps),
}
}
None => MaxSendableConfig::default(),
Expand Down
24 changes: 19 additions & 5 deletions src/mdk/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::str::FromStr;
use std::sync::Arc;

use bitcoin_payment_instructions::PaymentInstructions;
use chrono::{DateTime, SecondsFormat};
use ldk_node::bitcoin::hashes::sha256;
use ldk_node::bitcoin::hashes::Hash as _;
Expand All @@ -16,7 +17,7 @@ use tokio_util::sync::CancellationToken;

use crate::mdk::error::{MdkError, SpliceError};
use crate::mdk::max_sendable::{
compute_estimate, ChannelSnapshot, MaxSendableConfig, MaxSendableError, MaxSendableEstimate,
self, ChannelSnapshot, MaxSendableConfig, MaxSendableError, MaxSendableEstimate,
};
use crate::mdk::mdk_api::client::MdkApiClient;
use crate::mdk::mdk_api::types::{
Expand Down Expand Up @@ -145,16 +146,29 @@ impl MdkClient {

/// Best-effort estimate of the largest amount that can flow out
/// over Lightning right now, with routing-fee headroom subtracted.
/// Computed inline from `node.list_channels()` on every call so
/// the result reflects in-flight HTLCs and reserve as of *now*.
pub fn max_sendable(&self) -> Result<MaxSendableEstimate, MaxSendableError> {
/// Recomputed from `node.list_channels()` on every call so the
/// result reflects in-flight HTLCs and reserve as of *now*.
///
/// `dest = None` returns a buffer-based estimate; `Some(_)`
/// drives `Node::find_route` and subtracts the real fees. See
/// [`crate::mdk::max_sendable`] for the full dispatch table.
pub fn max_sendable(
&self,
dest: Option<&PaymentInstructions>,
) -> Result<MaxSendableEstimate, MaxSendableError> {
let snaps: Vec<ChannelSnapshot> = self
.node
.list_channels()
.iter()
.map(ChannelSnapshot::from)
.collect();
compute_estimate(&snaps, &self.lsp_pubkey, &self.max_sendable_cfg)
max_sendable::compute_estimate(
dest,
&snaps,
&self.lsp_pubkey,
&self.max_sendable_cfg,
|rp| self.node.find_route(rp).map_err(|e| format!("{e}")),
)
}

/// Splice `amount_sats` of confirmed on-chain funds into the
Expand Down
Loading
Loading