Skip to content

Commit

Permalink
channeld: add in RFC notes for max_htlc_dust_exposure_msat
Browse files Browse the repository at this point in the history
And update some behavior to check both sides on receipt of a
update_fee, as per the proposed spec.

lightning/bolts#919
  • Loading branch information
niftynei committed Oct 7, 2021
1 parent a507dae commit d3d31b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
20 changes: 20 additions & 0 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,20 @@ static void send_commit(struct peer *peer)
if (feerate_changes_done(peer->channel->fee_states, false)) {
u8 *msg;

/* BOLT-919 #2:
*
* A sending node:
* - if the `dust_balance_on_counterparty_tx` at the
* new `dust_buffer_feerate` is superior to
* `max_dust_htlc_exposure_msat`:
* - MAY NOT send `update_fee`
* - MAY fail the channel
* - if the `dust_balance_on_holder_tx` at the
* new `dust_buffer_feerate` is superior to
* the `max_dust_htlc_exposure_msat`:
* - MAY NOT send `update_fee`
* - MAY fail the channel
*/
/* Is this feerate update going to push the committed
* htlcs over our allowed dust limits? */
if (!htlc_dust_ok(peer->channel, feerate_target, REMOTE)
Expand Down Expand Up @@ -3269,6 +3283,12 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
failstr = "Too many HTLCs";
goto failed;
case CHANNEL_ERR_DUST_FAILURE:
/* BOLT-919 #2:
* - upon an outgoing HTLC:
* - if a HTLC's `amount_msat` is inferior the counterparty's...
* - SHOULD NOT send this HTLC
* - SHOULD fail this HTLC if it's forwarded
*/
failwiremsg = towire_temporary_channel_failure(inmsg, get_local_channel_update(inmsg, peer));
failstr = "HTLC too dusty, allowed dust limit reached";
goto failed;
Expand Down
22 changes: 21 additions & 1 deletion channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,18 @@ static enum channel_add_err add_htlc(struct channel *channel,

if (amount_msat_greater(htlc_dust_amt,
channel->config[LOCAL].max_dust_htlc_exposure_msat)) {
/* BOLT-919 #2:
* A node:
* - upon an incoming HTLC:
* - if a HTLC's `amount_msat` is inferior to the
* counterparty's `dust_limit_satoshis` plus the HTLC-timeout fee
* at the `dust_buffer_feerate`: ...
* - SHOULD fail this HTLC once it's committed
* - SHOULD NOT reveal a preimage for this HTLC
*/
/* Note: Marking this as 'fail_immediate' and
* NOT returning an ERR will fail this HTLC
* once it's committed */
htlc->fail_immediate = true;
if (err_immediate_failures)
return CHANNEL_ERR_DUST_FAILURE;
Expand Down Expand Up @@ -1284,7 +1296,15 @@ bool channel_update_feerate(struct channel *channel, u32 feerate_per_kw)
if (!can_opener_afford_feerate(channel, feerate_per_kw))
return false;

if (!htlc_dust_ok(channel, feerate_per_kw, REMOTE))
/* BOLT-919 #2:
* - if the `dust_balance_on_holder_tx` at the
* new `dust_buffer_feerate` is superior to
* the `max_dust_htlc_exposure_msat`:
* ...
* - MAY fail the channel
*/
if (!htlc_dust_ok(channel, feerate_per_kw, REMOTE) ||
!htlc_dust_ok(channel, feerate_per_kw, LOCAL))
return false;

status_debug("Setting %s feerate to %u",
Expand Down
6 changes: 5 additions & 1 deletion common/htlc_trim.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ bool htlc_is_trimmed(enum side htlc_owner,

u32 htlc_trim_feerate_ceiling(u32 feerate_per_kw)
{
/* Add the greater of 1.25x or 2530 sat/kw */
/* BOLT-919 #2:
*
* `dust_buffer_feerate` is defined as the maximum
* of either 2530 sats per kWU or 125% of the
* current `feerate_per_kw`. */
return max(feerate_per_kw + feerate_per_kw / 4,
feerate_per_kw + HTLC_FEE_MIN_RANGE);
}

0 comments on commit d3d31b9

Please sign in to comment.