Skip to content

Commit 14f70fb

Browse files
niftyneicdecker
authored andcommitted
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 ae6b6b8 commit 14f70fb

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
@@ -1292,6 +1292,20 @@ static void send_commit(struct peer *peer)
12921292
if (feerate_changes_done(peer->channel->fee_states, false)) {
12931293
u8 *msg;
12941294

1295+
/* BOLT-919 #2:
1296+
*
1297+
* A sending node:
1298+
* - if the `dust_balance_on_counterparty_tx` at the
1299+
* new `dust_buffer_feerate` is superior to
1300+
* `max_dust_htlc_exposure_msat`:
1301+
* - MAY NOT send `update_fee`
1302+
* - MAY fail the channel
1303+
* - if the `dust_balance_on_holder_tx` at the
1304+
* new `dust_buffer_feerate` is superior to
1305+
* the `max_dust_htlc_exposure_msat`:
1306+
* - MAY NOT send `update_fee`
1307+
* - MAY fail the channel
1308+
*/
12951309
/* Is this feerate update going to push the committed
12961310
* htlcs over our allowed dust limits? */
12971311
if (!htlc_dust_ok(peer->channel, feerate_target, REMOTE)
@@ -3369,6 +3383,12 @@ static void handle_offer_htlc(struct peer *peer, const u8 *inmsg)
33693383
failstr = "Too many HTLCs";
33703384
goto failed;
33713385
case CHANNEL_ERR_DUST_FAILURE:
3386+
/* BOLT-919 #2:
3387+
* - upon an outgoing HTLC:
3388+
* - if a HTLC's `amount_msat` is inferior the counterparty's...
3389+
* - SHOULD NOT send this HTLC
3390+
* - SHOULD fail this HTLC if it's forwarded
3391+
*/
33723392
failwiremsg = towire_temporary_channel_failure(inmsg, get_local_channel_update(inmsg, peer));
33733393
failstr = "HTLC too dusty, allowed dust limit reached";
33743394
goto failed;

channeld/full_channel.c

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

802802
if (amount_msat_greater(htlc_dust_amt,
803803
channel->config[LOCAL].max_dust_htlc_exposure_msat)) {
804+
/* BOLT-919 #2:
805+
* A node:
806+
* - upon an incoming HTLC:
807+
* - if a HTLC's `amount_msat` is inferior to the
808+
* counterparty's `dust_limit_satoshis` plus the HTLC-timeout fee
809+
* at the `dust_buffer_feerate`: ...
810+
* - SHOULD fail this HTLC once it's committed
811+
* - SHOULD NOT reveal a preimage for this HTLC
812+
*/
813+
/* Note: Marking this as 'fail_immediate' and
814+
* NOT returning an ERR will fail this HTLC
815+
* once it's committed */
804816
htlc->fail_immediate = true;
805817
if (err_immediate_failures)
806818
return CHANNEL_ERR_DUST_FAILURE;
@@ -1281,7 +1293,15 @@ bool channel_update_feerate(struct channel *channel, u32 feerate_per_kw)
12811293
if (!can_opener_afford_feerate(channel, feerate_per_kw))
12821294
return false;
12831295

1284-
if (!htlc_dust_ok(channel, feerate_per_kw, REMOTE))
1296+
/* BOLT-919 #2:
1297+
* - if the `dust_balance_on_holder_tx` at the
1298+
* new `dust_buffer_feerate` is superior to
1299+
* the `max_dust_htlc_exposure_msat`:
1300+
* ...
1301+
* - MAY fail the channel
1302+
*/
1303+
if (!htlc_dust_ok(channel, feerate_per_kw, REMOTE) ||
1304+
!htlc_dust_ok(channel, feerate_per_kw, LOCAL))
12851305
return false;
12861306

12871307
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)