Skip to content

Commit a3d6b5a

Browse files
author
Antoine Riard
committed
Replace config max counterpary dust_limit_satoshis by a constant.
Current Bitcoin Core's policy will reject a p2wsh as a dust if it's under 330 satoshis. A typical p2wsh output is 43 bytes big to which Core's `GetDustThreshold()` sums up a minimal spend of 67 bytes (even if a p2wsh witnessScript might be smaller). `dustRelayFee` is set to 3000 sat/kb, thus 110 * 3000 / 1000 = 330. As all time-sensitive outputs are p2wsh, a value of 330 sat is the lower bound desired to ensure good propagation of transactions. We give a bit margin to our counterparty and pick up 660 satoshis as an accepted `dust_limit_satoshis` upper bound. As this reasoning is tricky and error-prone we hardcode it instead of letting the user picking up a non-sense value.
1 parent 8b4ea56 commit a3d6b5a

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,9 @@ pub const COMMITMENT_TX_WEIGHT_PER_HTLC: u64 = 172;
444444
/// it's 2^24.
445445
pub const MAX_FUNDING_SATOSHIS: u64 = 1 << 24;
446446

447+
/// Maximum counterparty `dust_limit_satoshis` allowed. 2 * standard dust threshold on p2wsh output
448+
pub const MAX_DUST_LIMIT_SATOSHIS: u64 = 2 * 330;
449+
447450
/// Used to return a simple Error back to ChannelManager. Will get converted to a
448451
/// msgs::ErrorAction::SendErrorMessage or msgs::ErrorAction::IgnoreError as appropriate with our
449452
/// channel_id in ChannelManager.
@@ -690,8 +693,8 @@ impl<Signer: Sign> Channel<Signer> {
690693
if msg.dust_limit_satoshis < config.peer_channel_config_limits.min_dust_limit_satoshis {
691694
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is less than the user specified limit ({})", msg.dust_limit_satoshis, config.peer_channel_config_limits.min_dust_limit_satoshis)));
692695
}
693-
if msg.dust_limit_satoshis > config.peer_channel_config_limits.max_dust_limit_satoshis {
694-
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the user specified limit ({})", msg.dust_limit_satoshis, config.peer_channel_config_limits.max_dust_limit_satoshis)));
696+
if msg.dust_limit_satoshis > MAX_DUST_LIMIT_SATOSHIS {
697+
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.dust_limit_satoshis, MAX_DUST_LIMIT_SATOSHIS)));
695698
}
696699

697700
// Convert things into internal flags and prep our state:
@@ -1429,8 +1432,8 @@ impl<Signer: Sign> Channel<Signer> {
14291432
if msg.dust_limit_satoshis < config.peer_channel_config_limits.min_dust_limit_satoshis {
14301433
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is less than the user specified limit ({})", msg.dust_limit_satoshis, config.peer_channel_config_limits.min_dust_limit_satoshis)));
14311434
}
1432-
if msg.dust_limit_satoshis > config.peer_channel_config_limits.max_dust_limit_satoshis {
1433-
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the user specified limit ({})", msg.dust_limit_satoshis, config.peer_channel_config_limits.max_dust_limit_satoshis)));
1435+
if msg.dust_limit_satoshis > MAX_DUST_LIMIT_SATOSHIS {
1436+
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.dust_limit_satoshis, MAX_DUST_LIMIT_SATOSHIS)));
14341437
}
14351438
if msg.minimum_depth > config.peer_channel_config_limits.max_minimum_depth {
14361439
return Err(ChannelError::Close(format!("We consider the minimum depth to be unreasonably large. Expected minimum: ({}). Actual: ({})", config.peer_channel_config_limits.max_minimum_depth, msg.minimum_depth)));

lightning/src/util/config.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ pub struct ChannelHandshakeLimits {
105105
///
106106
/// Default value: 546, the current dust limit on the Bitcoin network.
107107
pub min_dust_limit_satoshis: u64,
108-
/// Maximum allowed threshold above which outputs will not be generated in their commitment
109-
/// transactions.
110-
/// HTLCs below this amount plus HTLC transaction fees are not enforceable on-chain.
111-
///
112-
/// Default value: u64::max_value.
113-
pub max_dust_limit_satoshis: u64,
114108
/// Before a channel is usable the funding transaction will need to be confirmed by at least a
115109
/// certain number of blocks, specified by the node which is not the funder (as the funder can
116110
/// assume they aren't going to double-spend themselves).
@@ -143,7 +137,6 @@ impl Default for ChannelHandshakeLimits {
143137
max_channel_reserve_satoshis: <u64>::max_value(),
144138
min_max_accepted_htlcs: 0,
145139
min_dust_limit_satoshis: 546,
146-
max_dust_limit_satoshis: <u64>::max_value(),
147140
max_minimum_depth: 144,
148141
force_announced_channel_preference: true,
149142
their_to_self_delay: MAX_LOCAL_BREAKDOWN_TIMEOUT,

0 commit comments

Comments
 (0)