Skip to content

Commit 1faa642

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 439c635 commit 1faa642

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

.aspell.en.pws

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,6 @@ sats
389389
quiesce
390390
quiescing
391391
SomeThing
392+
retransmissions
393+
upgradable
394+
desynchronization

02-peer-protocol.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,22 @@ messages are), they are independent of requirements here.
12251225
* [`u64`:`next_revocation_number`]
12261226
* [`32*byte`:`your_last_per_commitment_secret`]
12271227
* [`point`:`my_current_per_commitment_point`]
1228+
* [`channel_reestablish_tlvs`:`tlvs`]
1229+
1230+
1. `tlv_stream`: `channel_reestablish_tlvs`
1231+
2. types:
1232+
1. type: 1 (`next_to_send`)
1233+
2. data:
1234+
* [`tu64`:`commitment_number`]
1235+
1. type: 3 (`desired_features`)
1236+
2. data:
1237+
* [`...*byte`:`features`]
1238+
1. type: 5 (`current_features`)
1239+
2. data:
1240+
* [`...*byte`:`features`]
1241+
1. type: 7 (`upgradable_features`)
1242+
2. data:
1243+
* [`...*byte`:`features`]
12281244

12291245
`next_commitment_number`: A commitment number is a 48-bit
12301246
incrementing counter for each commitment transaction; counters
@@ -1429,6 +1445,95 @@ fall-behind detection. An implementation can offer both, however, and
14291445
fall back to the `option_data_loss_protect` behavior if
14301446
`option_static_remotekey` is not negotiated.
14311447

1448+
### Upgrading Channels
1449+
1450+
Upgrading channels (e.g. enabling `option_static_remotekey` for a
1451+
channel where it was not negotiated originally) is possible at
1452+
reconnection time if both implementations support it.
1453+
1454+
For simplicity, upgrades are proposed by the original initiator of the
1455+
channel, and can only occur on channels with no pending updates and no
1456+
retransmissions on reconnection. This can be achieved explicitly
1457+
using the [quiescence protocol](#channel-quiescence).
1458+
1459+
In case of disconnection where one peer doesn't receive
1460+
`channel_reestablish` it's possible that one peer will consider the
1461+
channel upgraded and the other not. But this will eventually be
1462+
resolved: the channel cannot progress until both sides have received
1463+
`channel_reestablish` anyway.
1464+
1465+
Channel features are currently defined as:
1466+
- `option_static_remotekey`
1467+
- `option_anchor_outputs`
1468+
1469+
#### Requirements
1470+
1471+
A node writing a `features` field:
1472+
- MUST set features using odd bits if an upgrade is optional.
1473+
- Otherwise, MUST close the connection (and MAY fail the channel) if the upgrade fails.
1474+
- MUST NOT set dependent features for any feature, unless that feature is also upgradable separately.
1475+
1476+
A node reading a `features` field:
1477+
- SHOULD close the connection if there is an even bit it does not understand.
1478+
- Otherwise, SHOULD treat odd and even bits the same.
1479+
1480+
A node sending `channel_reestablish`, if it supports upgrading channels:
1481+
- MUST set `next_to_send` the commitment number of the next `commitment_signed` it expects to send.
1482+
- if it initiated the channel:
1483+
- MUST set `desired_features` to the features it wants for the channel.
1484+
- MUST set `desired_features` equal to or an upgrade from the current channel features.
1485+
- otherwise:
1486+
- MUST set `current_features` to the features which could be upgraded for the channel.
1487+
- MUST set `upgradable_features` to the features which could be upgraded for the channel.
1488+
1489+
A node receiving `channel_reestablish`:
1490+
- if it has to retransmit `commitment_signed` or `revoke_and_ack`:
1491+
- MUST consider the channel feature change failed.
1492+
- if `next_to_send` is missing, or not equal to the `next_commitment_number` it sent:
1493+
- MUST consider the channel feature change failed.
1494+
- if updates are pending on either sides' commitment transaction:
1495+
- MUST consider the channel feature change failed.
1496+
- otherwise:
1497+
- if `desired_features` is a valid combination of `current_features`, either modified or not by `upgradable_features`:
1498+
- MUST consider the channel features to be `desired_features`.
1499+
- otherwise (including if there is no `current_features` or `upgradable_features`:
1500+
- MUST consider the channel feature change failed.
1501+
1502+
#### Rationale
1503+
1504+
The new `next_to_send` counter is needed to indicate that the peer
1505+
sent a new set of updates and `commitment_signed` which we didn't see
1506+
before disconnection (i.e. retransmissions are incoming). Existing logic
1507+
already tells us if we need to send retransmissions.
1508+
1509+
A node may decide only to offer `option_anchor_outputs` as an upgrade,
1510+
without supporting `option_static_remotekey` alone, even though
1511+
`option_anchor_outputs` implies it. This why dependent features are
1512+
not flagged explicitly.
1513+
1514+
If reconnection is aborted, there are four possibilities: both side
1515+
receive the `channel_reestablish` and are upgraded, neither side
1516+
receives the `channel_reestablish` and neither are upgraded, and the
1517+
two cases where one side is upgraded and the other is not. Note that
1518+
this is fine as long as it is resolved before any channel operations
1519+
are attempted (all of which require successful exchange of
1520+
`channel_reestablish` messages).
1521+
1522+
If only the initiator is upgraded, it will reflect this upgrade in the
1523+
next `desired_features`, causing the non-initiator to upgrade. If
1524+
only the non-initiator is upgraded, it will be reflected in
1525+
`current_features` and the combination of `current_features` and
1526+
`upgradable_features` will match `desired_features` and the initiator
1527+
will consider itself upgraded.
1528+
1529+
There are, however, theoretical cases where a second upgrade is
1530+
attempted immediately following (i.e. the non-initiator doesn't even
1531+
think the first one occurred), or incompatible upgrades are attempted,
1532+
which could cause desynchronization on these cases. This could be
1533+
avoided after the first upgrade by the sending an `update_fee` at the
1534+
current feerate followed by a `commitment_signed`, which has the
1535+
effect of forcing synchronization.
1536+
14321537
# Authors
14331538

14341539
[ FIXME: Insert Author List ]

0 commit comments

Comments
 (0)