Skip to content

Commit 0aad750

Browse files
fix: expose min_funding_satoshis via Config
Add `min_funding_sats` to `Config` and map it to LDK's `ChannelHandshakeLimits::min_funding_satoshis`. Use a plain `u64` with an explicit default and cover both the default and override behavior with a unit test so operators can enforce a higher minimum inbound channel funding amount. Fixes #842 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> AI-assisted-by: Codex
1 parent 63c7f9b commit 0aad750

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

src/config.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const DEFAULT_LDK_WALLET_SYNC_INTERVAL_SECS: u64 = 30;
2828
const DEFAULT_FEE_RATE_CACHE_UPDATE_INTERVAL_SECS: u64 = 60 * 10;
2929
const DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER: u64 = 3;
3030
const DEFAULT_ANCHOR_PER_CHANNEL_RESERVE_SATS: u64 = 25_000;
31+
const DEFAULT_MIN_FUNDING_SATS: u64 = 1_000;
3132

3233
// The default timeout after which we abort a wallet syncing operation.
3334
const DEFAULT_BDK_WALLET_SYNC_TIMEOUT_SECS: u64 = 60;
@@ -125,6 +126,7 @@ pub(crate) const LNURL_AUTH_TIMEOUT_SECS: u64 = 15;
125126
/// | `node_alias` | None |
126127
/// | `trusted_peers_0conf` | [] |
127128
/// | `probing_liquidity_limit_multiplier` | 3 |
129+
/// | `min_funding_sats` | 1000 |
128130
/// | `anchor_channels_config` | Some(..) |
129131
/// | `route_parameters` | None |
130132
/// | `tor_config` | None |
@@ -167,6 +169,15 @@ pub struct Config {
167169
/// Channels with available liquidity less than the required amount times this value won't be
168170
/// used to send pre-flight probes.
169171
pub probing_liquidity_limit_multiplier: u64,
172+
/// The minimum funding amount in satoshis that we require from channel counterparties when
173+
/// they open inbound channels to us.
174+
///
175+
/// Channels with funding below this value will be rejected.
176+
///
177+
/// Please refer to [`ChannelHandshakeLimits::min_funding_satoshis`] for further details.
178+
///
179+
/// [`ChannelHandshakeLimits::min_funding_satoshis`]: lightning::util::config::ChannelHandshakeLimits::min_funding_satoshis
180+
pub min_funding_sats: u64,
170181
/// Configuration options pertaining to Anchor channels, i.e., channels for which the
171182
/// `option_anchors_zero_fee_htlc_tx` channel type is negotiated.
172183
///
@@ -210,6 +221,7 @@ impl Default for Config {
210221
announcement_addresses: None,
211222
trusted_peers_0conf: Vec::new(),
212223
probing_liquidity_limit_multiplier: DEFAULT_PROBING_LIQUIDITY_LIMIT_MULTIPLIER,
224+
min_funding_sats: DEFAULT_MIN_FUNDING_SATS,
213225
anchor_channels_config: Some(AnchorChannelsConfig::default()),
214226
tor_config: None,
215227
route_parameters: None,
@@ -339,6 +351,7 @@ pub(crate) fn default_user_config(config: &Config) -> UserConfig {
339351
// will mostly be relevant for inbound channels.
340352
let mut user_config = UserConfig::default();
341353
user_config.channel_handshake_limits.force_announced_channel_preference = false;
354+
user_config.channel_handshake_limits.min_funding_satoshis = config.min_funding_sats;
342355
user_config.channel_handshake_config.negotiate_anchors_zero_fee_htlc_tx =
343356
config.anchor_channels_config.is_some();
344357
user_config.reject_inbound_splices = false;
@@ -637,7 +650,9 @@ pub enum AsyncPaymentsRole {
637650
mod tests {
638651
use std::str::FromStr;
639652

640-
use super::{may_announce_channel, AnnounceError, Config, NodeAlias, SocketAddress};
653+
use super::{
654+
default_user_config, may_announce_channel, AnnounceError, Config, NodeAlias, SocketAddress,
655+
};
641656

642657
#[test]
643658
fn node_announce_channel() {
@@ -684,4 +699,18 @@ mod tests {
684699
}
685700
assert!(may_announce_channel(&node_config).is_ok());
686701
}
702+
703+
#[test]
704+
fn min_funding_sats_configures_user_config() {
705+
let mut node_config = Config::default();
706+
let user_config = default_user_config(&node_config);
707+
assert_eq!(
708+
user_config.channel_handshake_limits.min_funding_satoshis,
709+
node_config.min_funding_sats
710+
);
711+
712+
node_config.min_funding_sats = 42_000;
713+
let user_config = default_user_config(&node_config);
714+
assert_eq!(user_config.channel_handshake_limits.min_funding_satoshis, 42_000);
715+
}
687716
}

0 commit comments

Comments
 (0)