Skip to content

Commit ff38155

Browse files
committed
channeld: add in RFC notes for max_htlc_dust_exposure_msat
And update some behavior to check both sides on receipt of a update_fee, as per the proposed spec. lightning/bolts#919
1 parent 3e39179 commit ff38155

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

channeld/channeld.c

+20
Original file line numberDiff line numberDiff line change
@@ -1293,6 +1293,20 @@ static void send_commit(struct peer *peer)
12931293
if (feerate_changes_done(peer->channel->fee_states, false)) {
12941294
u8 *msg;
12951295

1296+
/* BOLT-919 #2:
1297+
*
1298+
* A sending node:
1299+
* - if the `dust_balance_on_counterparty_tx` at the
1300+
* new `dust_buffer_feerate` is superior to
1301+
* `max_dust_htlc_exposure_msat`:
1302+
* - MAY NOT send `update_fee`
1303+
* - MAY fail the channel
1304+
* - if the `dust_balance_on_holder_tx` at the
1305+
* new `dust_buffer_feerate` is superior to
1306+
* the `max_dust_htlc_exposure_msat`:
1307+
* - MAY NOT send `update_fee`
1308+
* - MAY fail the channel
1309+
*/
12961310
/* Is this feerate update going to push the committed
12971311
* htlcs over our allowed dust limits? */
12981312
if (!htlc_dust_ok(peer->channel, feerate_target, REMOTE)
@@ -3269,6 +3283,12 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
32693283
failstr = "Too many HTLCs";
32703284
goto failed;
32713285
case CHANNEL_ERR_DUST_FAILURE:
3286+
/* BOLT-919 #2:
3287+
* - upon an outgoing HTLC:
3288+
* - if a HTLC's `amount_msat` is inferior the counterparty's...
3289+
* - SHOULD NOT send this HTLC
3290+
* - SHOULD fail this HTLC if it's forwarded
3291+
*/
32723292
failwiremsg = towire_temporary_channel_failure(inmsg, get_local_channel_update(inmsg, peer));
32733293
failstr = "HTLC too dusty, allowed dust limit reached";
32743294
goto failed;

channeld/full_channel.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,18 @@ static enum channel_add_err add_htlc(struct channel *channel,
804804

805805
if (amount_msat_greater(htlc_dust_amt,
806806
channel->config[LOCAL].max_dust_htlc_exposure_msat)) {
807+
/* BOLT-919 #2:
808+
* A node:
809+
* - upon an incoming HTLC:
810+
* - if a HTLC's `amount_msat` is inferior to the
811+
* counterparty's `dust_limit_satoshis` plus the HTLC-timeout fee
812+
* at the `dust_buffer_feerate`: ...
813+
* - SHOULD fail this HTLC once it's committed
814+
* - SHOULD NOT reveal a preimage for this HTLC
815+
*/
816+
/* Note: Marking this as 'fail_immediate' and
817+
* NOT returning an ERR will fail this HTLC
818+
* once it's committed */
807819
htlc->fail_immediate = true;
808820
if (err_immediate_failures)
809821
return CHANNEL_ERR_DUST_FAILURE;
@@ -1284,7 +1296,15 @@ bool channel_update_feerate(struct channel *channel, u32 feerate_per_kw)
12841296
if (!can_opener_afford_feerate(channel, feerate_per_kw))
12851297
return false;
12861298

1287-
if (!htlc_dust_ok(channel, feerate_per_kw, REMOTE))
1299+
/* BOLT-919 #2:
1300+
* - if the `dust_balance_on_holder_tx` at the
1301+
* new `dust_buffer_feerate` is superior to
1302+
* the `max_dust_htlc_exposure_msat`:
1303+
* ...
1304+
* - MAY fail the channel
1305+
*/
1306+
if (!htlc_dust_ok(channel, feerate_per_kw, REMOTE) ||
1307+
!htlc_dust_ok(channel, feerate_per_kw, LOCAL))
12881308
return false;
12891309

12901310
status_debug("Setting %s feerate to %u",

common/htlc_trim.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ bool htlc_is_trimmed(enum side htlc_owner,
5050

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

0 commit comments

Comments
 (0)