Skip to content

Commit fff174e

Browse files
committed
BOLT 2: upgrade protocol on reestablish.
This is the simplest upgrade mechanism I could come up with. It's ready for option_anchors_zero_fee_htlc_tx, too. Signed-off-by: Rusty Russell <[email protected]>
1 parent a9db80e commit fff174e

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

02-peer-protocol.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,19 @@ messages are), they are independent of requirements here.
11841184
* [`u64`:`next_revocation_number`]
11851185
* [`32*byte`:`your_last_per_commitment_secret`]
11861186
* [`point`:`my_current_per_commitment_point`]
1187+
* [`channel_reestablish_tlvs`:`tlvs`]
1188+
1189+
1. `tlv_stream`: `channel_reestablish_tlvs`
1190+
2. types:
1191+
1. type: 1 (`channel_features`)
1192+
2. data:
1193+
* [`...*byte`:`features`]
1194+
1. type: 3 (`upgrades_available`)
1195+
2. data:
1196+
* [`...*byte`:`features`]
1197+
1. type: 5 (`upgrades_wanted`)
1198+
2. data:
1199+
* [`...*byte`:`features`]
11871200

11881201
`next_commitment_number`: A commitment number is a 48-bit
11891202
incrementing counter for each commitment transaction; counters
@@ -1388,6 +1401,101 @@ fall-behind detection. An implementation can offer both, however, and
13881401
fall back to the `option_data_loss_protect` behavior if
13891402
`option_static_remotekey` is not negotiated.
13901403

1404+
### Upgrading Channels
1405+
1406+
Upgrading channels (e.g. enabling `option_static_remotekey` for a
1407+
channel where it was not negotiated originally) is possible at
1408+
reconnection time if both implementations support it.
1409+
1410+
Both peers indicate what upgrades are available, and if they both
1411+
offer an upgrade either peer wants, then the upgrade is performed
1412+
following any reestablish retransmissions and corresponding
1413+
commitments which bring the channel into a symmetrical state with no
1414+
updates outstanding.
1415+
1416+
Once both peers indicate things are quiescent by sending
1417+
`update_upgrade`, the channel features are considered upgraded and a
1418+
normal `commiment_signed` cycle occurs with the new upgrade in place.
1419+
1420+
In case of disconnection it's possible that one peer will consider the
1421+
channel upgraded and the other not. For this reason (and potentially
1422+
better diagnostics in future) , they indicate what the current channel
1423+
features are on reconnect: the "more upgraded" one applies immediately
1424+
in this case.
1425+
1426+
Channel features are currently defined as:
1427+
- `option_static_remotekey`
1428+
- `option_anchor_outputs` (requires `option_static_remotekey`)
1429+
1430+
1. type: 40 (`update_upgrade`)
1431+
2. data:
1432+
* [`channel_id`:`channel_id`]
1433+
* [`u16`:`flen`]
1434+
* [`flen*byte`:`features`]
1435+
1436+
#### Requirements
1437+
1438+
A node sending `channel_reestablish`:
1439+
- if it sets `channel_features`:
1440+
- MUST set the channel features which currently apply to the channel.
1441+
- if it sets `upgrades_available`
1442+
- MUST set `channel_features`
1443+
- MUST set it to a set of channel features not in `channel_features`.
1444+
- if it sets `upgrades_wanted`:
1445+
- MUST set it to a single channel feature NOT in `channel_features`, plus any required features which are also not in `channel_features`.
1446+
- MUST NOT set any bits not in `upgrades_available`.
1447+
1448+
A node receiving `channel_reestablish`:
1449+
- if `channel_features` has more bits set than the sent `channel_features`:
1450+
- if the additional bits are not in the sent `upgrades_available`:
1451+
- MUST fail the upgrade
1452+
- otherwise:
1453+
- MUST consider the received `channel_features` as the current features of the channel.
1454+
- otherwise, if `channel_features` has fewer bits set than the sent `channel_features`:
1455+
- if the missing bits are not in the sent `upgrades_available`:
1456+
- MUST fail the upgrade
1457+
- otherwise:
1458+
- MUST consider the sent `channel_features` as the current features of the channel.
1459+
- if either peer sets a bit in `upgrades_wanted` which is also in both peers' `upgrades_available`:
1460+
- if `channel_features` modified by `upgrades_wanted` does not have required features:
1461+
- MUST fail the upgrade.
1462+
- MUST send `update_upgrade` with the new `channel_features` after any retransmissions required by `channel_reestablish` and as soon as there are no outstanding updates on either commitment transaction.
1463+
1464+
A node receiving `update_upgrade`:
1465+
- if the `features` is not the same as the one it sent (or will send):
1466+
- MUST fail the upgrade
1467+
1468+
When a node has both sent and received `update_upgrade`:
1469+
- MUST consider the channel features to be those sent in `update_upgrade`.
1470+
- if it has a lower SEC1-encoded node_id than its peer:
1471+
- MUST send `commitment_signed` (using the new channel features).
1472+
1473+
#### Rationale
1474+
1475+
It is generally simpler to have both sides synchronized when upgrades
1476+
occur: by indicating that an upgrade is desired and available, both
1477+
sides know to perform the upgrade as soon as this is the case. In
1478+
practice most upgrades happen by restarting software which implies a
1479+
reconnect cycle anyway.
1480+
1481+
The modification of bits is actually quite tricky: a channel which has
1482+
`option_static_remotekey` needs only set `option_anchor_outputs` in
1483+
`upgrades_wanted`, but one with neither would set both.
1484+
1485+
A node which only offered `option_anchor_outputs` as an upgrade would
1486+
only set that in `upgrades_available`, to avoid indicating that an
1487+
upgrade only to `option_static_remotekey` was available.
1488+
1489+
There's weasel wording around how `channel_features` combines with
1490+
`upgrades_wanted` ("modified by") since future channel features may
1491+
turn off existing features they conflict with. This will be defined
1492+
by them.
1493+
1494+
Finally, the `update_upgrade` features field is technically redundant,
1495+
but a useful sanity check and diagnostic that both sides are now
1496+
entering the same state. It also allows us to continue to enforce the
1497+
rule that commitment_signed must include an update.
1498+
13911499
# Authors
13921500

13931501
[ FIXME: Insert Author List ]

0 commit comments

Comments
 (0)