Skip to content

Commit a7075f7

Browse files
committed
multi: add resource bucketing for HTLC slots and liquidity
1 parent a049b79 commit a7075f7

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

02-peer-protocol.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,10 @@ is destined, is described in [BOLT #4](04-onion-routing.md).
995995
1. type: 0 (`blinding_point`)
996996
2. data:
997997
* [`point`:`blinding`]
998-
998+
1. type: 1 (`endorsed`)
999+
2. data:
1000+
* [`byte`:`endorsed`]
1001+
9991002
#### Requirements
10001003

10011004
A sending node:
@@ -1033,6 +1036,10 @@ A sending node:
10331036
- MUST increase the value of `id` by 1 for each successive offer.
10341037
- if it is relaying a payment inside a blinded route:
10351038
- MUST set `blinding_point` (see [Route Blinding](04-onion-routing.md#route-blinding))
1039+
- if it is the original source of the HTLC:
1040+
- SHOULD set `endorsed` to `1`.
1041+
- otherwise:
1042+
- SHOULD set `endorsed` as described in [Bolt 4](04-onion-routing.md#resource-bucketing).
10361043

10371044
`id` MUST NOT be reset to 0 after the update is complete (i.e. after `revoke_and_ack` has
10381045
been received). It MUST continue incrementing instead.
@@ -1059,6 +1066,8 @@ A receiving node:
10591066
`error` and fail the channel.
10601067
- if `blinding_point` is provided:
10611068
- MUST use the corresponding blinded private key to decrypt the `onion_routing_packet` (see [Route Blinding](04-onion-routing.md#route-blinding))
1069+
- if `endorsed` is provided:
1070+
- SHOULD interpret `endorsed` as described in [Bolt 4](04-onion-routing.md#resource-bucketing).
10621071

10631072
The `onion_routing_packet` contains an obfuscated list of hops and instructions for each hop along the path.
10641073
It commits to the HTLC by setting the `payment_hash` as associated data, i.e. includes the `payment_hash` in the computation of HMACs.

04-onion-routing.md

+113
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ A node:
5353
* [Route Blinding](#route-blinding)
5454
* [Accepting and Forwarding a Payment](#accepting-and-forwarding-a-payment)
5555
* [Non-strict Forwarding](#non-strict-forwarding)
56+
* [Resource Bucketing](#resource-bucketing)
5657
* [Payload for the Last Node](#payload-for-the-last-node)
5758
* [Shared Secret](#shared-secret)
5859
* [Blinding Ephemeral Keys](#blinding-ephemeral-keys)
@@ -62,6 +63,7 @@ A node:
6263
* [Returning Errors](#returning-errors)
6364
* [Failure Messages](#failure-messages)
6465
* [Receiving Failure Codes](#receiving-failure-codes)
66+
* [Recommendations for Reputation](#recommendations-for-reputation)
6567
* [Test Vector](#test-vector)
6668
* [Returning Errors](#returning-errors)
6769
* [References](#references)
@@ -635,6 +637,35 @@ Alternatively, implementations may choose to apply non-strict forwarding only to
635637
like-policy channels to ensure their expected fee revenue does not deviate by
636638
using an alternate channel.
637639

640+
## Resource Bucketing
641+
642+
When making the decision to forward a payment on its outgoing channel, a node
643+
MAY choose to limit its exposure to HTLCs that put it at risk of a denial of
644+
service attack.
645+
* `unknown_allocation_slots`: defines the number of HTLC slots allocated to
646+
unknown traffic (default: 50% of remote peer's `max_accepted_htlcs`).
647+
* `unknown_allocation_liquidity`: defines the amount of the channel balance
648+
that is allocated to unknown traffic (default: 50% of remote peer's
649+
`max_htlc_value_in_flight_msat`.
650+
651+
A node implementing resource bucketing limits exposure on its outgoing channel:
652+
- MUST choose `unknown_allocation_slots` <= the remote channel peer's
653+
`max_accepted_htlcs`.
654+
- MUST choose `unknown_allocation_liquidity` <= the remote channel peer's
655+
`max_htlc_value_in_flight_msat`.
656+
- If `endorsed` is set to 1 in the incoming `update_add_htlc` AND the HTLC
657+
is from a node that the forwarding node considers to have good local
658+
reputation (see [Recommendations for Reputation](#recommendations-for-reputation)):
659+
- SHOULD proceed with forwarding the HTLC.
660+
- SHOULD set `endorsed` to 1 in the outgoing `update_add_htlc`.
661+
- Otherwise, the HTLC is classified as `unknown`:
662+
- If `unknown_allocation_slots` HTLC slots are occupied by other `unknown` HTLCs:
663+
- SHOULD return `temporary_channel_failure` as specified in [Failure Messages](#failure-messages).
664+
- If `unknown_allocation_liquidity` satoshis of liquidity are locked in
665+
other `unknown` HTLCs:
666+
- SHOULD return `temporary_channel_failure` as specified in [Failure Messages](#failure-messages).
667+
- SHOULD set `endorsed` to 0 in the outgoing `update_add_htlc`.
668+
638669
## Payload for the Last Node
639670

640671
When building the route, the origin node MUST use a payload for
@@ -1407,6 +1438,88 @@ The _origin node_:
14071438
- MAY use the data specified in the various failure types for debugging
14081439
purposes.
14091440

1441+
## Recommendations for Reputation
1442+
1443+
Local reputation is used by forwarding nodes to decide whether to endorse a HTLC
1444+
on their outgoing link. Nodes MAY use any metric of their choosing to classify
1445+
a peer as having "good" reputation, though a poor choice of reputation scoring
1446+
metric will affect their downstream reputation.
1447+
1448+
Peers build reputation by forwarding successful HTLCs that resolve quickly, and
1449+
lose reputation if they endorse failing or slow-resolving HTLCs. Reputation is
1450+
only _negatively_ affected if an endorsed HTLC resolves undesirably, to holds
1451+
nodes accountable for their endorsement signal while still allowing them to
1452+
forward unendorsed HTLCs that they are not certain about.
1453+
1454+
HTLC resolution time is assessed relative to a threshold that the node
1455+
considers to be a reasonable amount of time for a HTLC to resolve:
1456+
- `resolution_period`: the amount of time a HTLC is allowed to resolve in that
1457+
is classified as "good" behavior (default: 10 seconds).
1458+
- `resolution_time`: the time elapsed between `update_add_htlc` and its
1459+
resolution (`update_fulfill_hltc` / `update_fail_hltc` /
1460+
`update_fail_malformed_htlc`).
1461+
1462+
Each HTLC's contribution to reputation is expressed by its `effective_fees`
1463+
which capture the fees that it paid and the opportunity cost that its
1464+
`resolution_time` incurred.
1465+
- `fees`: the fees paid by a forwarded HTLC (as described in [BOLT #7](07-routing-gossip.md#htlc-fees),
1466+
equal to 0 if the HTLC was failed).
1467+
- `opportunity_cost`: 'ceil ( (resolution_time - resolution_period) / resolution_period) * fees`
1468+
1469+
Given that `resolution_time` will be > 0 in practice, `opportunity_cost` is 0
1470+
for HTLCs that resolve within `resolution_period`, and charges the `fees` that
1471+
the HTLC would have earned per period it is held thereafter. This cost accounts
1472+
for the slot and liquidity that could have otherwise been paid for by
1473+
successful, fast resolving HTLCs during the `resolution_time` the HTLC was
1474+
locked in the channel.
1475+
1476+
For every incoming HLTC a peer has forwarded through a node, its `effective_fees`
1477+
are calculated as follows:
1478+
- if `endorsed` = 1 in `update_add_htlc`:
1479+
- `effective_fees` = `fees` - `opportunity_cost`
1480+
- otherwise:
1481+
- if successfully resolved AND `resolution_time` <= `resolution_period`
1482+
- `effective_fees` = `fees`
1483+
- otherwise:
1484+
- `effective_fees` = 0
1485+
1486+
The `effective_fees` that a peer has paid our node are compared to our total
1487+
routing revenue to classify a peer's reputation as "good" or "neutral". This
1488+
relates the fees that must be paid to earn "good" reputation to the damage that
1489+
can be done by abusing it.
1490+
1491+
Routing revenue is assessed over a sliding window, so that reputation
1492+
classification is related to the node's current routing activity. Nodes MAY
1493+
choose a window per their preferences - shorter windows being more reactive to
1494+
recent routing patterns, and longer windows aggregating trends over time.
1495+
1496+
- `routing_window`: the period of time in which total routing revenue is
1497+
assessed (default: 10 minutes * the maximum number of blocks in the future a
1498+
HTLC's expiry height can fall before the node will send `expiry_too_far`, as
1499+
outlined in [Failure Messages](#failure-messages)).
1500+
- `routing_revenue`: the sum of all fees paid to the node to forward HTLCs
1501+
over the interval [ `now` - `routing_window` ; `now` ].
1502+
1503+
The total `effective_fees` that an individual peer has generated are assessed
1504+
over a longer period of time to relate its reputation classification to the
1505+
routing activity of the node (represented by `routing_revenue`).
1506+
1507+
- `reputation_window`: the period of time over which the node's `effective_fees`
1508+
are calculated to classify its reputation (recommended default = 10 * `routing_window`).
1509+
- `reputation_revenue`: the total `effective_fees` of HTLCs forwarded by the peer
1510+
over the interval [ `now` - `reputation_window` ; `now` ].
1511+
1512+
A peer is classified as having "good" local reputation iff `reputation_revenue` >= `routing_revenue`,
1513+
otherwise the peer's reputation is classified as "neutral".
1514+
1515+
### Rationale
1516+
If a HTLC is endorsed by a peer they have signaled that they expect the HTLC
1517+
to resolve honestly, so will be held accountable for the manner in which they
1518+
resolve. By contrast, if a HTLC was not endorsed by the upstream peer, it
1519+
should not have a negative impact on reputation. In the case where one of
1520+
these "unknown" HTLCs succeeds within the reasonable resolution threshold, the
1521+
peer is still credited with fees because the HTLC resolved desirably.
1522+
14101523
# Test Vector
14111524

14121525
## Returning Errors

0 commit comments

Comments
 (0)