Skip to content

Commit 93909f6

Browse files
authored
Merge pull request #950 from rustyrussell/guilt/soft-errors
Really: BOLT 1: introduce warning messages, reduce requirements to send (hard) errors
2 parents 58287e2 + 8032f70 commit 93909f6

File tree

6 files changed

+134
-69
lines changed

6 files changed

+134
-69
lines changed

00-introduction.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ See [BOLT #11: Invoice Protocol for Lightning Payments](11-payment-encoding.md)
132132
* _See related: [closing transaction](#closing-transaction), [funding transaction](#funding-transaction), [penalty transaction](#penalty-transaction)_
133133
* _See types: [revoked commitment transaction](#revoked-commitment-transaction)_
134134

135+
* #### *Fail the channel*:
136+
* This is a forced close of the channel. Very early on (before
137+
opening), this may not require any action but forgetting the
138+
existence of the channel. Usually it requires signing and
139+
broadcasting the latest commitment transaction, although during
140+
mutual close it can also be performed by signing and broadcasting a
141+
mutual close transaction. See [BOLT #5](05-onchain.md#failing-a-channel).
142+
143+
* #### *Close the connection*:
144+
* This means closing communication with the peer (such as closing
145+
the TCP socket). It does not imply closing any channels with the
146+
peer, but does cause the discarding of uncommitted state for
147+
connections with channels: see [BOLT #2](02-peer-protocol.md#message-retransmission).
148+
135149
* #### *Final node*:
136150
* The final recipient of a packet that is routing a payment from an *[origin node](#origin-node)* through some number of *[hops](#hop)*. It is also the final *[receiving peer](#receiving-peer)* in a chain.
137151
* _See category: [node](#node)_

01-messaging.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ All data fields are unsigned big-endian unless otherwise specified.
1717
* [Fundamental Types](#fundamental-types)
1818
* [Setup Messages](#setup-messages)
1919
* [The `init` Message](#the-init-message)
20-
* [The `error` Message](#the-error-message)
20+
* [The `error` and `warning` Messages](#the-error-and-warning-messages)
2121
* [Control Messages](#control-messages)
2222
* [The `ping` and `pong` Messages](#the-ping-and-pong-messages)
2323
* [Appendix A: BigSize Test Vectors](#appendix-a-bigsize-test-vectors)
@@ -285,11 +285,11 @@ The receiving node:
285285
- upon receiving unknown _odd_ feature bits that are non-zero:
286286
- MUST ignore the bit.
287287
- upon receiving unknown _even_ feature bits that are non-zero:
288-
- MUST fail the connection.
288+
- MUST close the connection.
289289
- upon receiving `networks` containing no common chains
290-
- MAY fail the connection.
290+
- MAY close the connection.
291291
- if the feature vector does not set all known, transitive dependencies:
292-
- MUST fail the connection.
292+
- MUST close the connection.
293293

294294
#### Rationale
295295

@@ -306,7 +306,7 @@ support a single network, the `networks` fields avoids nodes
306306
erroneously believing they will receive updates about their preferred
307307
network, or that they can open channels.
308308

309-
### The `error` Message
309+
### The `error` and `warning` Messages
310310

311311
For simplicity of diagnosis, it's often useful to tell a peer that something is incorrect.
312312

@@ -316,7 +316,11 @@ For simplicity of diagnosis, it's often useful to tell a peer that something is
316316
* [`u16`:`len`]
317317
* [`len*byte`:`data`]
318318

319-
The 2-byte `len` field indicates the number of bytes in the immediately following field.
319+
1. type: 1 (`warning`)
320+
2. data:
321+
* [`channel_id`:`channel_id`]
322+
* [`u16`:`len`]
323+
* [`len*byte`:`data`]
320324

321325
#### Requirements
322326

@@ -331,24 +335,31 @@ The fundee node:
331335
- MUST use `temporary_channel_id` in lieu of `channel_id`.
332336

333337
A sending node:
334-
- when sending `error`:
335-
- MUST fail the channel referred to by the error message.
336338
- SHOULD send `error` for protocol violations or internal errors that make channels unusable or that make further communication unusable.
337339
- SHOULD send `error` with the unknown `channel_id` in reply to messages of type `32`-`255` related to unknown channels.
340+
- when sending `error`:
341+
- MUST fail the channel(s) referred to by the error message.
342+
- MAY set `channel_id` to all zero to indicate all channels.
343+
- when sending `warning`:
344+
- MAY set `channel_id` to all zero if the warning is not related to a specific channel.
345+
- MAY close the connection after sending.
338346
- MAY send an empty `data` field.
339347
- when failure was caused by an invalid signature check:
340348
- SHOULD include the raw, hex-encoded transaction in reply to a `funding_created`, `funding_signed`, `closing_signed`, or `commitment_signed` message.
341-
- when `channel_id` is 0:
342-
- MUST fail all channels with the receiving node.
343-
- MUST close the connection.
344-
- MUST set `len` equal to the length of `data`.
345349

346350
The receiving node:
347351
- upon receiving `error`:
348-
- MUST fail the channel referred to by the error message, if that channel is with the sending node.
349-
- if no existing channel is referred to by the message:
352+
- if `channel_id` is all zero:
353+
- MUST fail all channels with the sending node.
354+
- otherwise:
355+
- MUST fail the channel referred to by `channel_id`, if that channel is with the sending node.
356+
- upon receiving `warning`:
357+
- SHOULD log the message for later diagnosis.
358+
- MAY disconnect.
359+
- MAY reconnect after some delay to retry.
360+
- MAY attempt `shutdown` if permitted at this point.
361+
- if no existing channel is referred to by `channel_id`:
350362
- MUST ignore the message.
351-
- MUST truncate `len` to the remainder of the packet (if it's larger).
352363
- if `data` is not composed solely of printable ASCII characters (For reference: the printable character set includes byte values 32 through 126, inclusive):
353364
- SHOULD NOT print out `data` verbatim.
354365

@@ -359,6 +370,11 @@ if the connection is simply dropped, then the peer may retry the
359370
connection. It's also useful to describe protocol violations for
360371
diagnosis, as this indicates that one peer has a bug.
361372

373+
On the other hand, overuse of error messages has lead to
374+
implementations ignoring them (to avoid an otherwise expensive channel
375+
break), so the "warning" message was added to allow some degree of
376+
retry or recovery for spurious errors.
377+
362378
It may be wise not to distinguish errors in production settings, lest
363379
it leak information — hence, the optional `data` field.
364380

@@ -394,7 +410,7 @@ A node sending a `ping` message:
394410
- MUST NOT set `ignored` to sensitive data such as secrets or portions of initialized
395411
memory.
396412
- if it doesn't receive a corresponding `pong`:
397-
- MAY terminate the network connection,
413+
- MAY close the network connection,
398414
- and MUST NOT fail the channels in this case.
399415

400416
A node sending a `pong` message:
@@ -410,7 +426,7 @@ A node receiving a `ping` message:
410426

411427
A node receiving a `pong` message:
412428
- if `byteslen` does not correspond to any `ping`'s `num_pong_bytes` value it has sent:
413-
- MAY fail the channels.
429+
- MAY close the connection.
414430

415431
### Rationale
416432

02-peer-protocol.md

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ The sender:
392392

393393
The recipient:
394394
- if `signature` is incorrect OR non-compliant with LOW-S-standard rule<sup>[LOWS](https://github.com/bitcoin/bitcoin/pull/6769)</sup>:
395-
- MUST fail the channel.
395+
- MUST send a `warning` and close the connection, or send an
396+
`error` and fail the channel.
396397

397398
#### Rationale
398399

@@ -438,7 +439,8 @@ The sender MUST set:
438439

439440
The recipient:
440441
- if `signature` is incorrect OR non-compliant with LOW-S-standard rule<sup>[LOWS](https://github.com/bitcoin/bitcoin/pull/6769)</sup>:
441-
- MUST fail the channel.
442+
- MUST send a `warning` and close the connection, or send an
443+
`error` and fail the channel.
442444
- MUST NOT broadcast the funding transaction before receipt of a valid `funding_signed`.
443445
- on receipt of a valid `funding_signed`:
444446
- SHOULD broadcast the funding transaction.
@@ -484,7 +486,7 @@ A non-funding node (fundee):
484486
transaction after a timeout of 2016 blocks.
485487

486488
From the point of waiting for `funding_locked` onward, either node MAY
487-
fail the channel if it does not receive a required response from the
489+
send an `error` and fail the channel if it does not receive a required response from the
488490
other node after a reasonable timeout.
489491

490492
#### Rationale
@@ -558,14 +560,15 @@ A sending node:
558560

559561
A receiving node:
560562
- if it hasn't received a `funding_signed` (if it is a funder) or a `funding_created` (if it is a fundee):
561-
- SHOULD fail the connection
563+
- SHOULD send an `error` and fail the channel.
562564
- if the `scriptpubkey` is not in one of the above forms:
563-
- SHOULD fail the connection.
565+
- SHOULD send a `warning`.
564566
- if it hasn't sent a `funding_locked` yet:
565567
- MAY reply to a `shutdown` message with a `shutdown`
566568
- once there are no outstanding updates on the peer, UNLESS it has already sent a `shutdown`:
567569
- MUST reply to a `shutdown` message with a `shutdown`
568570
- if both nodes advertised the `option_upfront_shutdown_script` feature, and the receiving node received a non-zero-length `shutdown_scriptpubkey` in `open_channel` or `accept_channel`, and that `shutdown_scriptpubkey` is not equal to `scriptpubkey`:
571+
- MAY send a `warning`.
569572
- MUST fail the connection.
570573

571574
#### Rationale
@@ -647,7 +650,8 @@ The sending node:
647650
The receiving node:
648651
- if the `signature` is not valid for either variant of closing transaction
649652
specified in [BOLT #3](03-transactions.md#closing-transaction) OR non-compliant with LOW-S-standard rule<sup>[LOWS](https://github.com/bitcoin/bitcoin/pull/6769)</sup>:
650-
- MUST fail the connection.
653+
- MUST send a `warning` and close the connection, or send an
654+
`error` and fail the channel.
651655
- if `fee_satoshis` is equal to its previously sent `fee_satoshis`:
652656
- SHOULD sign and broadcast the final closing transaction.
653657
- MAY close the connection.
@@ -673,7 +677,8 @@ The receiving node:
673677
- MUST propose a `fee_satoshis` in the overlap between received and (about-to-be) sent `fee_range`.
674678
- otherwise, if `fee_satoshis` is not strictly between its last-sent `fee_satoshis`
675679
and its previously-received `fee_satoshis`, UNLESS it has since reconnected:
676-
- SHOULD fail the connection.
680+
- SHOULD send a `warning` and close the connection, or send an
681+
`error` and fail the channel.
677682
- otherwise, if the receiver agrees with the fee:
678683
- SHOULD reply with a `closing_signed` with the same `fee_satoshis` value.
679684
- otherwise:
@@ -888,6 +893,7 @@ An offering node:
888893
- MUST NOT offer an HTLC with a timeout deadline before its `cltv_expiry`.
889894
- if an HTLC which it offered is in either node's current
890895
commitment transaction, AND is past this timeout deadline:
896+
- SHOULD send an `error` to the receiving peer (if connected).
891897
- MUST fail the channel.
892898

893899
A fulfilling node:
@@ -896,6 +902,7 @@ A fulfilling node:
896902
- MUST fail (and not forward) an HTLC whose fulfillment deadline is already past.
897903
- if an HTLC it has fulfilled is in either node's current commitment
898904
transaction, AND is past this fulfillment deadline:
905+
- SHOULD send an `error` to the offering peer (if connected).
899906
- MUST fail the channel.
900907

901908
### Adding an HTLC: `update_add_htlc`
@@ -959,19 +966,24 @@ been received). It MUST continue incrementing instead.
959966

960967
A receiving node:
961968
- receiving an `amount_msat` equal to 0, OR less than its own `htlc_minimum_msat`:
962-
- SHOULD fail the channel.
969+
- SHOULD send a `warning` and close the connection, or send an
970+
`error` and fail the channel.
963971
- receiving an `amount_msat` that the sending node cannot afford at the current `feerate_per_kw` (while maintaining its channel reserve and any `to_local_anchor` and `to_remote_anchor` costs):
964-
- SHOULD fail the channel.
972+
- SHOULD send a `warning` and close the connection, or send an
973+
`error` and fail the channel.
965974
- if a sending node adds more than receiver `max_accepted_htlcs` HTLCs to
966975
its local commitment transaction, OR adds more than receiver `max_htlc_value_in_flight_msat` worth of offered HTLCs to its local commitment transaction:
967-
- SHOULD fail the channel.
976+
- SHOULD send a `warning` and close the connection, or send an
977+
`error` and fail the channel.
968978
- if sending node sets `cltv_expiry` to greater or equal to 500000000:
969-
- SHOULD fail the channel.
979+
- SHOULD send a `warning` and close the connection, or send an
980+
`error` and fail the channel.
970981
- MUST allow multiple HTLCs with the same `payment_hash`.
971982
- if the sender did not previously acknowledge the commitment of that HTLC:
972983
- MUST ignore a repeated `id` value after a reconnection.
973984
- if other `id` violations occur:
974-
- MAY fail the channel.
985+
- MAY send a `warning` and close the connection, or send an
986+
`error` and fail the channel.
975987

976988
The `onion_routing_packet` contains an obfuscated list of hops and instructions for each hop along the path.
977989
It commits to the HTLC by setting the `payment_hash` as associated data, i.e. includes the `payment_hash` in the computation of HMACs.
@@ -1057,13 +1069,16 @@ A node:
10571069

10581070
A receiving node:
10591071
- if the `id` does not correspond to an HTLC in its current commitment transaction:
1060-
- MUST fail the channel.
1072+
- MUST send a `warning` and close the connection, or send an
1073+
`error` and fail the channel.
10611074
- if the `payment_preimage` value in `update_fulfill_htlc`
10621075
doesn't SHA256 hash to the corresponding HTLC `payment_hash`:
1063-
- MUST fail the channel.
1076+
- MUST send a `warning` and close the connection, or send an
1077+
`error` and fail the channel.
10641078
- if the `BADONION` bit in `failure_code` is not set for
10651079
`update_fail_malformed_htlc`:
1066-
- MUST fail the channel.
1080+
- MUST send a `warning` and close the connection, or send an
1081+
`error` and fail the channel.
10671082
- if the `sha256_of_onion` in `update_fail_malformed_htlc` doesn't match the
10681083
onion it sent:
10691084
- MAY retry or choose an alternate error response.
@@ -1122,12 +1137,15 @@ fee changes).
11221137
A receiving node:
11231138
- once all pending updates are applied:
11241139
- if `signature` is not valid for its local commitment transaction OR non-compliant with LOW-S-standard rule <sup>[LOWS](https://github.com/bitcoin/bitcoin/pull/6769)</sup>:
1125-
- MUST fail the channel.
1140+
- MUST send a `warning` and close the connection, or send an
1141+
`error` and fail the channel.
11261142
- if `num_htlcs` is not equal to the number of HTLC outputs in the local
11271143
commitment transaction:
1128-
- MUST fail the channel.
1144+
- MUST send a `warning` and close the connection, or send an
1145+
`error` and fail the channel.
11291146
- if any `htlc_signature` is not valid for the corresponding HTLC transaction OR non-compliant with LOW-S-standard rule <sup>[LOWS](https://github.com/bitcoin/bitcoin/pull/6769)</sup>:
1130-
- MUST fail the channel.
1147+
- MUST send a `warning` and close the connection, or send an
1148+
`error` and fail the channel.
11311149
- MUST respond with a `revoke_and_ack` message.
11321150

11331151
#### Rationale
@@ -1181,9 +1199,10 @@ A sending node:
11811199

11821200
A receiving node:
11831201
- if `per_commitment_secret` is not a valid secret key or does not generate the previous `per_commitment_point`:
1184-
- MUST fail the channel.
1202+
- MUST send an `error` and fail the channel.
11851203
- if the `per_commitment_secret` was not generated by the protocol in [BOLT #3](03-transactions.md#per-commitment-secret-requirements):
1186-
- MAY fail the channel.
1204+
- MAY send a `warning` and close the connection, or send an
1205+
`error` and fail the channel.
11871206

11881207
A node:
11891208
- MUST NOT broadcast old (revoked) commitment transactions,
@@ -1225,12 +1244,15 @@ The node _not responsible_ for paying the Bitcoin fee:
12251244

12261245
A receiving node:
12271246
- if the `update_fee` is too low for timely processing, OR is unreasonably large:
1228-
- SHOULD fail the channel.
1247+
- MUST send a `warning` and close the connection, or send an
1248+
`error` and fail the channel.
12291249
- if the sender is not responsible for paying the Bitcoin fee:
1230-
- MUST fail the channel.
1250+
- MUST send a `warning` and close the connection, or send an
1251+
`error` and fail the channel.
12311252
- if the sender cannot afford the new fee rate on the receiving node's
12321253
current commitment transaction:
1233-
- SHOULD fail the channel,
1254+
- SHOULD send a `warning` and close the connection, or send an
1255+
`error` and fail the channel.
12341256
- but MAY delay this check until the `update_fee` is committed.
12351257

12361258
#### Rationale
@@ -1357,10 +1379,10 @@ A node:
13571379
- if `next_commitment_number` is not 1 greater than the
13581380
commitment number of the last `commitment_signed` message the receiving
13591381
node has sent:
1360-
- SHOULD fail the channel.
1382+
- SHOULD send an `error` and fail the channel.
13611383
- if it has not sent `commitment_signed`, AND `next_commitment_number`
13621384
is not equal to 1:
1363-
- SHOULD fail the channel.
1385+
- SHOULD send an `error` and fail the channel.
13641386
- if `next_revocation_number` is equal to the commitment number of
13651387
the last `revoke_and_ack` the receiving node sent, AND the receiving node
13661388
hasn't already received a `closing_signed`:
@@ -1372,10 +1394,10 @@ A node:
13721394
- otherwise:
13731395
- if `next_revocation_number` is not equal to 1 greater than the
13741396
commitment number of the last `revoke_and_ack` the receiving node has sent:
1375-
- SHOULD fail the channel.
1397+
- SHOULD send an `error` and fail the channel.
13761398
- if it has not sent `revoke_and_ack`, AND `next_revocation_number`
13771399
is not equal to 0:
1378-
- SHOULD fail the channel.
1400+
- SHOULD send an `error` and fail the channel.
13791401

13801402
A receiving node:
13811403
- if `option_static_remotekey` or `option_anchors` applies to the commitment
@@ -1387,7 +1409,7 @@ A node:
13871409
- SHOULD fail the channel.
13881410
- otherwise:
13891411
- if `your_last_per_commitment_secret` does not match the expected values:
1390-
- SHOULD fail the channel.
1412+
- SHOULD send an `error` and fail the channel.
13911413
- otherwise, if it supports `option_data_loss_protect`:
13921414
- if `next_revocation_number` is greater than expected above, AND
13931415
`your_last_per_commitment_secret` is correct for that
@@ -1398,7 +1420,7 @@ A node:
13981420
should the sending node broadcast its commitment transaction on-chain.
13991421
- otherwise (`your_last_per_commitment_secret` or `my_current_per_commitment_point`
14001422
do not match the expected values):
1401-
- SHOULD fail the channel.
1423+
- SHOULD send an `error` and fail the channel.
14021424

14031425
A node:
14041426
- MUST NOT assume that previously-transmitted messages were lost,

03-transactions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ contribute to fees.
484484

485485
A node:
486486
- if the resulting fee rate is too low:
487-
- MAY fail the channel.
487+
- MAY send a `warning` and close the connection, or send an
488+
`error` and fail the channel.
488489

489490
## Dust Limits
490491

@@ -2507,4 +2508,3 @@ before subtraction of:
25072508
![Creative Commons License](https://i.creativecommons.org/l/by/4.0/88x31.png "License CC-BY")
25082509
<br>
25092510
This work is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
2510-

05-onchain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ A node:
7474
reorganizations.
7575
- upon the funding transaction being spent, if the channel is NOT already
7676
closed:
77+
- MAY send a descriptive `error`.
7778
- SHOULD fail the channel.
78-
- MAY send a descriptive error packet.
7979
- SHOULD ignore invalid transactions.
8080

8181
## Rationale

0 commit comments

Comments
 (0)