Skip to content

Commit c43db96

Browse files
committed
Reduce the maximum allowed counterparty dust limit to 546 sat/vbyte
546 sat/vbyte is the current default dust limit on most implementations, matching the network dust limit for P2SH outputs. Implementations don't currently appear to send any larger dust limits, and allowing a larger dust limit implies higher payment failure risk, so we'd like to be as tight as we can here.
1 parent 8fad498 commit c43db96

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lightning/src/ln/channel.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,15 @@ pub const ANCHOR_OUTPUT_VALUE_SATOSHI: u64 = 330;
555555
/// it's 2^24.
556556
pub const MAX_FUNDING_SATOSHIS: u64 = 1 << 24;
557557

558-
/// Maximum counterparty `dust_limit_satoshis` allowed. 2 * standard dust threshold on p2wsh output
559-
/// Scales up on Bitcoin Core's proceeding policy with dust outputs. A typical p2wsh output is 43
560-
/// bytes to which Core's `GetDustThreshold()` sums up a minimal spend of 67 bytes (even if
561-
/// a p2wsh witnessScript might be *effectively* smaller), `dustRelayFee` is set to 3000sat/kb, thus
562-
/// 110 * 3000 / 1000 = 330. Per-protocol rules, all time-sensitive outputs are p2wsh, a value of
563-
/// 330 sats is the lower bound desired to ensure good propagation of transactions. We give a bit
564-
/// of margin to our counterparty and pick up 660 satoshis as an accepted `dust_limit_satoshis`
565-
/// upper bound to avoid negotiation conflicts with other implementations.
566-
pub const MAX_DUST_LIMIT_SATOSHIS: u64 = 2 * 330;
558+
/// The maximum network dust limit for standard script formats. This currently represents the
559+
/// minimum output value for a P2SH output before Bitcoin Core 22 considers the entire
560+
/// transaction non-standard and thus refuses to relay it.
561+
/// We also use this as the maximum counterparty `dust_limit_satoshis` allowed, given many
562+
/// implementations use this value for their dust limit today.
563+
pub const MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS: u64 = 546;
564+
565+
/// The maximum channel dust limit we will accept from our counterparty.
566+
pub const MAX_CHAN_DUST_LIMIT_SATOSHIS: u64 = MAX_STD_OUTPUT_DUST_LIMIT_SATOSHIS;
567567

568568
/// The dust limit is used for both the commitment transaction outputs as well as the closing
569569
/// transactions. For cooperative closing transactions, we require segwit outputs, though accept
@@ -847,8 +847,8 @@ impl<Signer: Sign> Channel<Signer> {
847847
if msg.dust_limit_satoshis < MIN_DUST_LIMIT_SATOSHIS {
848848
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is less than the implementation limit ({})", msg.dust_limit_satoshis, MIN_DUST_LIMIT_SATOSHIS)));
849849
}
850-
if msg.dust_limit_satoshis > MAX_DUST_LIMIT_SATOSHIS {
851-
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.dust_limit_satoshis, MAX_DUST_LIMIT_SATOSHIS)));
850+
if msg.dust_limit_satoshis > MAX_CHAN_DUST_LIMIT_SATOSHIS {
851+
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.dust_limit_satoshis, MAX_CHAN_DUST_LIMIT_SATOSHIS)));
852852
}
853853

854854
// Convert things into internal flags and prep our state:
@@ -1621,8 +1621,8 @@ impl<Signer: Sign> Channel<Signer> {
16211621
if msg.dust_limit_satoshis < MIN_DUST_LIMIT_SATOSHIS {
16221622
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is less than the implementation limit ({})", msg.dust_limit_satoshis, MIN_DUST_LIMIT_SATOSHIS)));
16231623
}
1624-
if msg.dust_limit_satoshis > MAX_DUST_LIMIT_SATOSHIS {
1625-
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.dust_limit_satoshis, MAX_DUST_LIMIT_SATOSHIS)));
1624+
if msg.dust_limit_satoshis > MAX_CHAN_DUST_LIMIT_SATOSHIS {
1625+
return Err(ChannelError::Close(format!("dust_limit_satoshis ({}) is greater than the implementation limit ({})", msg.dust_limit_satoshis, MAX_CHAN_DUST_LIMIT_SATOSHIS)));
16261626
}
16271627
if msg.minimum_depth > config.peer_channel_config_limits.max_minimum_depth {
16281628
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/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5830,7 +5830,7 @@ fn bolt2_open_channel_sane_dust_limit() {
58305830
let push_msat=10001;
58315831
nodes[0].node.create_channel(nodes[1].node.get_our_node_id(), channel_value_satoshis, push_msat, 42, None).unwrap();
58325832
let mut node0_to_1_send_open_channel = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, nodes[1].node.get_our_node_id());
5833-
node0_to_1_send_open_channel.dust_limit_satoshis = 661;
5833+
node0_to_1_send_open_channel.dust_limit_satoshis = 547;
58345834
node0_to_1_send_open_channel.channel_reserve_satoshis = 100001;
58355835

58365836
nodes[1].node.handle_open_channel(&nodes[0].node.get_our_node_id(), InitFeatures::known(), &node0_to_1_send_open_channel);
@@ -5841,7 +5841,7 @@ fn bolt2_open_channel_sane_dust_limit() {
58415841
},
58425842
_ => panic!("Unexpected event"),
58435843
};
5844-
assert_eq!(err_msg.data, "dust_limit_satoshis (661) is greater than the implementation limit (660)");
5844+
assert_eq!(err_msg.data, "dust_limit_satoshis (547) is greater than the implementation limit (546)");
58455845
}
58465846

58475847
// Test that if we fail to send an HTLC that is being freed from the holding cell, and the HTLC

0 commit comments

Comments
 (0)