Skip to content

Commit d5c9e9b

Browse files
committed
upgrade: spell out upgrade possibilities.
Riffing on @Roasbeef's categorization of explicit "channel types", this use a simple subtype, and define the current channel types (for now, just consisting of odd feature bits). Also spell out the potential issues with back-to-back upgrades, and workarounds if you were to even have this issue. Signed-off-by: Rusty Russell <[email protected]>
1 parent 6c11ed7 commit d5c9e9b

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

02-peer-protocol.md

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ operation, and closing.
2626
* [Completing the Transition to the Updated State: `revoke_and_ack`](#completing-the-transition-to-the-updated-state-revoke_and_ack)
2727
* [Updating Fees: `update_fee`](#updating-fees-update_fee)
2828
* [Message Retransmission: `channel_reestablish` message](#message-retransmission)
29+
* [Upgrading Channels](#upgrading-channels)
2930
* [Authors](#authors)
3031

3132
# Channel
@@ -1243,22 +1244,30 @@ messages are), they are independent of requirements here.
12431244
1. type: 1 (`next_to_send`)
12441245
2. data:
12451246
* [`tu64`:`commitment_number`]
1246-
1. type: 3 (`desired_features`)
1247+
1. type: 3 (`desired_type`)
12471248
2. data:
1248-
* [`...*byte`:`features`]
1249-
1. type: 5 (`current_features`)
1249+
* [`channel_type`:`type`]
1250+
1. type: 5 (`current_type`)
12501251
2. data:
1251-
* [`...*byte`:`features`]
1252-
1. type: 7 (`upgradable_features`)
1252+
* [`channel_type`:`type`]
1253+
1. type: 7 (`upgradable`)
12531254
2. data:
1254-
* [`...*byte`:`features`]
1255+
* [`...*channel_type`:`upgrades`]
1256+
1257+
1. subtype: `channel_type`
1258+
2. data:
1259+
* [`u16`:`len`]
1260+
* [`len*byte`:`features`]
12551261

12561262
`next_commitment_number`: A commitment number is a 48-bit
12571263
incrementing counter for each commitment transaction; counters
12581264
are independent for each peer in the channel and start at 0.
12591265
They're only explicitly relayed to the other node in the case of
12601266
re-establishment, otherwise they are implicit.
12611267

1268+
See [Upgrading Channels](#upgrading-channels) for the requirements
1269+
of some of the optional fields.
1270+
12621271
### Requirements
12631272

12641273
A funding node:
@@ -1473,29 +1482,23 @@ channel upgraded and the other not. But this will eventually be
14731482
resolved: the channel cannot progress until both sides have received
14741483
`channel_reestablish` anyway.
14751484

1476-
Channel features are currently defined as:
1477-
- `option_static_remotekey`
1478-
- `option_anchor_outputs`
1485+
Channel features are explicitly enumerated as `channel_type`
1486+
bitfields, using odd features bits. The currently defined types are:
1487+
- no features (no bits set)
1488+
- `option_static_remotekey` (bit 13)
1489+
- `option_anchor_outputs` and `option_static_remotekey` (bits 21 and 13)
1490+
- `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 23 and 13)
14791491

14801492
#### Requirements
14811493

1482-
A node writing a `features` field:
1483-
- MUST set features using odd bits if an upgrade is optional.
1484-
- Otherwise, MUST close the connection (and MAY fail the channel) if the upgrade fails.
1485-
- MUST NOT set dependent features for any feature, unless that feature is also upgradable separately.
1486-
1487-
A node reading a `features` field:
1488-
- SHOULD close the connection if there is an even bit it does not understand.
1489-
- Otherwise, SHOULD treat odd and even bits the same.
1490-
14911494
A node sending `channel_reestablish`, if it supports upgrading channels:
14921495
- MUST set `next_to_send` the commitment number of the next `commitment_signed` it expects to send.
14931496
- if it initiated the channel:
1494-
- MUST set `desired_features` to the features it wants for the channel.
1495-
- MUST set `desired_features` equal to or an upgrade from the current channel features.
1497+
- MUST set `desired_type` to the channel_type it wants for the channel.
14961498
- otherwise:
1497-
- MUST set `current_features` to the features which could be upgraded for the channel.
1498-
- MUST set `upgradable_features` to the features which could be upgraded for the channel.
1499+
- MUST set `current_type` to the current channel_type of the channel.
1500+
- MUST set `upgradable` to the channel types it could change to.
1501+
- MAY not set `upgradable` if it would be empty.
14991502

15001503
A node receiving `channel_reestablish`:
15011504
- if it has to retransmit `commitment_signed` or `revoke_and_ack`:
@@ -1505,10 +1508,12 @@ A node receiving `channel_reestablish`:
15051508
- if updates are pending on either sides' commitment transaction:
15061509
- MUST consider the channel feature change failed.
15071510
- otherwise:
1508-
- if `desired_features` is a valid combination of `current_features`, either modified or not by `upgradable_features`:
1509-
- MUST consider the channel features to be `desired_features`.
1510-
- otherwise (including if there is no `current_features` or `upgradable_features`:
1511+
- if `desired_type` matches `current_type` or any `upgradable` `upgrades`:
1512+
- MUST consider the channel type to be `desired_type`.
1513+
- otherwise:
15111514
- MUST consider the channel feature change failed.
1515+
- if there is a `current_type` field:
1516+
- MUST consider the channel type to be `current_type`.
15121517

15131518
#### Rationale
15141519

@@ -1517,11 +1522,6 @@ sent a new set of updates and `commitment_signed` which we didn't see
15171522
before disconnection (i.e. retransmissions are incoming). Existing logic
15181523
already tells us if we need to send retransmissions.
15191524

1520-
A node may decide only to offer `option_anchor_outputs` as an upgrade,
1521-
without supporting `option_static_remotekey` alone, even though
1522-
`option_anchor_outputs` implies it. This why dependent features are
1523-
not flagged explicitly.
1524-
15251525
If reconnection is aborted, there are four possibilities: both side
15261526
receive the `channel_reestablish` and are upgraded, neither side
15271527
receives the `channel_reestablish` and neither are upgraded, and the
@@ -1530,20 +1530,19 @@ this is fine as long as it is resolved before any channel operations
15301530
are attempted (all of which require successful exchange of
15311531
`channel_reestablish` messages).
15321532

1533-
If only the initiator is upgraded, it will reflect this upgrade in the
1534-
next `desired_features`, causing the non-initiator to upgrade. If
1535-
only the non-initiator is upgraded, it will be reflected in
1536-
`current_features` and the combination of `current_features` and
1537-
`upgradable_features` will match `desired_features` and the initiator
1538-
will consider itself upgraded.
1539-
1540-
There are, however, theoretical cases where a second upgrade is
1541-
attempted immediately following (i.e. the non-initiator doesn't even
1542-
think the first one occurred), or incompatible upgrades are attempted,
1543-
which could cause desynchronization on these cases. This could be
1544-
avoided after the first upgrade by the sending an `update_fee` at the
1545-
current feerate followed by a `commitment_signed`, which has the
1546-
effect of forcing synchronization.
1533+
On reconnect, if only the initiator is upgraded, it will reflect this
1534+
upgrade in the next `desired_type`, causing the non-initiator to
1535+
upgrade. If only the non-initiator is upgraded, it will be reflected
1536+
in `current_type` and the initiator will consider itself upgraded.
1537+
1538+
There can be desynchronization across multiple upgrades. Both nodes
1539+
start on channel_type A, initiator sets `desired_type` B, receives
1540+
`channel_reestablish` from A which has B in `upgradable`, but B
1541+
doesn't receive `channel_reestablish`. On reconnect, initiator tries
1542+
to upgrade again, setting `desired_type` to C, which is not in B's
1543+
`upgradable` so fails. This is why, on such a failed upgrade, the
1544+
initiator considers the `current_type` given by the non-initiator to
1545+
be canonical.
15471546

15481547
# Authors
15491548

0 commit comments

Comments
 (0)