Skip to content

Commit 91fbda6

Browse files
toadlyBroodlerustyrussell
authored andcommitted
BOLT 4: seperate error messages from requirements
1 parent 08f23a7 commit 91fbda6

File tree

1 file changed

+86
-65
lines changed

1 file changed

+86
-65
lines changed

04-onion-routing.md

Lines changed: 86 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -633,161 +633,182 @@ channel.
633633
The failure message encapsulated in `failuremsg` has an identical format as
634634
a normal message: a 2-byte type `failure_code` followed by data applicable
635635
to that type. Following is a list of the currently supported `failure_code`
636-
values and their associated use cases.
636+
values and their required use cases.
637637

638638
Notice that the `failure_code`s are not of the same type as other message types,
639639
defined in other BOLTs, as they are not sent directly on the transport layer
640640
but are instead wrapped inside return packets.
641641
The numeric values for the `failure_code` may therefore reuse values, that are
642642
also assigned to other message types, without any danger of causing collisions.
643643

644-
An erring node:
645-
- MUST select one of these codes when creating an error message.
646-
- MUST include the appropriate data for that particular error type.
647-
- if there is more than one error:
648-
- SHOULD select the first error it encounters from the list below.
649-
650644
The top byte of `failure_code` can be read as a set of flags:
651645
* 0x8000 (BADONION): unparsable onion encrypted by sending peer
652646
* 0x4000 (PERM): permanent failure (otherwise transient)
653647
* 0x2000 (NODE): node failure (otherwise channel)
654648
* 0x1000 (UPDATE): new channel update enclosed
655649

656-
Any _erring node_ MAY return one of the following errors:
657-
658-
If the `realm` byte is unknown:
659650
1. type: PERM|1 (`invalid_realm`)
660651

661-
If an otherwise unspecified transient error occurs for the entire node:
662652
1. type: NODE|2 (`temporary_node_failure`)
663653

664-
If an otherwise unspecified permanent error occurs for the entire node:
665654
1. type: PERM|NODE|2 (`permanent_node_failure`)
666655

667-
If a node has requirements advertised in its `node_announcement` `features`
668-
which were NOT included in the onion:
669656
1. type: PERM|NODE|3 (`required_node_feature_missing`)
670657

671-
A _forwarding node_ MAY, but a _final node_ MUST NOT, return one of the following
672-
errors:
673-
674-
If the onion `version` byte is unknown:
675658
1. type: BADONION|PERM|4 (`invalid_onion_version`)
676659
2. data:
677660
* [`32`:`sha256_of_onion`]
678661

679-
If the onion HMAC is incorrect:
680662
1. type: BADONION|PERM|5 (`invalid_onion_hmac`)
681663
2. data:
682664
* [`32`:`sha256_of_onion`]
683665

684-
If the ephemeral key in the onion is unparsable:
685666
1. type: BADONION|PERM|6 (`invalid_onion_key`)
686667
2. data:
687668
* [`32`:`sha256_of_onion`]
688669

689-
If an otherwise unspecified, transient error occurs in the outgoing channel
690-
(i.e. during forwarding to its receiving peer), e.g. channel capacity reached,
691-
too many in-flight HTLCs, etc.:
692670
1. type: UPDATE|7 (`temporary_channel_failure`)
693671
2. data:
694672
* [`2`:`len`]
695673
* [`len`:`channel_update`]
696674

697-
If an otherwise unspecified, permanent error occurs during forwarding to its
698-
receiving peer (e.g. channel recently closed):
699675
1. type: PERM|8 (`permanent_channel_failure`)
700676

701-
If the outgoing channel has requirements advertised in its
702-
`channel_announcement` `features` which were NOT included in the onion:
703677
1. type: PERM|9 (`required_channel_feature_missing`)
704678

705-
If the receiving peer specified by the onion is NOT known:
706679
1. type: PERM|10 (`unknown_next_peer`)
707680

708-
If the HTLC amount is less than the currently specified minimum amount, the
709-
amount of the incoming HTLC and the current channel setting for the outgoing
710-
channel are reported:
711681
1. type: UPDATE|11 (`amount_below_minimum`)
712682
2. data:
713683
* [`8`:`htlc_msat`]
714684
* [`2`:`len`]
715685
* [`len`:`channel_update`]
716686

717-
If the HTLC does NOT pay a sufficient fee, the amount of the incoming HTLC and
718-
the current channel setting for the outgoing channel are reported:
719687
1. type: UPDATE|12 (`fee_insufficient`)
720688
2. data:
721689
* [`8`:`htlc_msat`]
722690
* [`2`:`len`]
723691
* [`len`:`channel_update`]
724692

725-
If the `outgoing_cltv_value` does NOT match the `update_add_htlc`'s
726-
`cltv_expiry` minus the `cltv_expiry_delta` for the outgoing channel, the
727-
`cltv_expiry` and the current channel setting for the outgoing channel are
728-
reported:
729693
1. type: UPDATE|13 (`incorrect_cltv_expiry`)
730694
2. data:
731695
* [`4`:`cltv_expiry`]
732696
* [`2`:`len`]
733697
* [`len`:`channel_update`]
734698

735-
If the `cltv_expiry` is too near, the current channel setting for the
736-
outgoing channel are reported:
737699
1. type: UPDATE|14 (`expiry_too_soon`)
738700
2. data:
739701
* [`2`:`len`]
740702
* [`len`:`channel_update`]
741703

742-
If the `cltv_expiry` is unreasonably far in the future, its also possible to
743-
report an error:
744704
1. type: 21 (`expiry_too_far`)
745705

746-
If the channel is disabled, the current channel setting for the outgoing
747-
channel are reported:
748706
1. type: UPDATE|20 (`channel_disabled`)
749707
2. data:
750708
* [`2`: `flags`]
751709
* [`2`:`len`]
752710
* [`len`:`channel_update`]
711+
[FIXME: is it important that 20 and 21 remain in this order or can they be moved to end of list?]
753712

754-
The _final node_ MAY, but an _intermediate hop_ MUST NOT, return one of the
755-
following errors:
756-
- if the payment hash has already been paid:
757-
- MAY treat the payment hash as unknown.
758-
- MAY succeed in accepting the HTLC.
759-
- if the amount paid is less than the amount expected:
760-
- MUST fail the HTLC.
761-
762-
If the payment hash is unknown, the _final node_ MUST fail the HTLC:
763713
1. type: PERM|15 (`unknown_payment_hash`)
764714

765-
If the amount paid is more than twice the amount expected, the _final node_
766-
SHOULD fail the HTLC. Note: this allows the origin node to reduce information
767-
leakage by altering the amount while not allowing for accidental gross
768-
overpayment:
769715
1. type: PERM|16 (`incorrect_payment_amount`)
770716

771-
If the `cltv_expiry` value is too near the present, the _final node_ MUST fail
772-
the HTLC:
773717
1. type: 17 (`final_expiry_too_soon`)
774718

775-
If the `outgoing_cltv_value` does NOT correspond with the `cltv_expiry` from
776-
the final node's HTLC:
777719
1. type: 18 (`final_incorrect_cltv_expiry`)
778720
2. data:
779721
* [`4`:`cltv_expiry`]
780722

781-
If the `amt_to_forward` is greater than the `incoming_htlc_amt` from the
782-
final node's HTLC:
783723
1. type: 19 (`final_incorrect_htlc_amount`)
784724
2. data:
785-
* [`4`:`incoming_htlc_amt`]
725+
* [`4`:`incoming_htlc_amt`]
786726

787-
[TODO: Restore edited text and move the definitions of the structures into its own section, then turn the words describing each one into requirements]
727+
### Requirements
788728

789-
## Receiving Failure Codes
729+
An _erring node_:
730+
- MUST select one of the above error codes when creating an error message.
731+
- MUST include the appropriate data for that particular error type.
732+
- if there is more than one error:
733+
- SHOULD select the first error it encounters in list above.
734+
735+
Any _erring node_ MAY:
736+
- if the `realm` byte is unknown:
737+
- return an `invalid_realm` error.
738+
- if an otherwise unspecified transient error occurs for the entire node:
739+
- return a `temporary_node_failure` error.
740+
- if an otherwise unspecified permanent error occurs for the entire node:
741+
- return a `permanent_node_failure` error.
742+
- if a node has requirements advertised in its `node_announcement` `features`,
743+
which were NOT included in the onion:
744+
- return a `required_node_feature_missing` error.
745+
746+
A _forwarding node_ MAY, but a _final node_ MUST NOT:
747+
- if the onion `version` byte is unknown:
748+
- return an `invalid_onion_version` error.
749+
- if the onion HMAC is incorrect:
750+
- return an `invalid_onion_hmac` error.
751+
- if the ephemeral key in the onion is unparsable:
752+
- return `invalid_onion_key` error.
753+
- if an otherwise unspecified, transient error occurs in the outgoing channel
754+
(i.e. during forwarding to its receiving peer), e.g. channel capacity reached,
755+
too many in-flight HTLCs, etc.:
756+
- return a `temporary_channel_failure` error.
757+
- if an otherwise unspecified, permanent error occurs during forwarding to its
758+
receiving peer (e.g. channel recently closed):
759+
- return a `permanent_channel_failure` error.
760+
- if the outgoing channel has requirements advertised in its
761+
`channel_announcement` `features`, which were NOT included in the onion:
762+
- return a `required_channel_feature_missing` error.
763+
- if the receiving peer specified by the onion is NOT known:
764+
- return an `unknown_next_peer` error.
765+
- if the HTLC amount is less than the currently specified minimum amount:
766+
- report the amount of the incoming HTLC and the current channel setting for
767+
the outgoing channel.
768+
- return an `amount_below_minimum` error.
769+
- if the HTLC does NOT pay a sufficient fee:
770+
- report the amount of the incoming HTLC and the current channel setting for
771+
the outgoing channel:
772+
- return a `fee_insufficient` error.
773+
- if the `outgoing_cltv_value` does NOT match the `update_add_htlc`'s
774+
`cltv_expiry` minus the `cltv_expiry_delta` for the outgoing channel:
775+
- report the `cltv_expiry` and the current channel setting for the outgoing
776+
channel.
777+
- return an `incorrect_cltv_expiry` error.
778+
- if the `cltv_expiry` is too near:
779+
- report the current channel setting for the outgoing channel.
780+
- return an `expiry_too_soon` error.
781+
- if the `cltv_expiry` is unreasonably far in the future:
782+
- return an `expiry_too_far` error.
783+
- if the channel is disabled:
784+
- report the current channel setting for the outgoing channel:
785+
- return a `channel_disabled` error.
786+
787+
An _intermediate hop_ MUST NOT, but the _final node_:
788+
- if the payment hash has already been paid:
789+
- MAY treat the payment hash as unknown.
790+
- MAY succeed in accepting the HTLC.
791+
- if the amount paid is less than the amount expected:
792+
- MUST fail the HTLC.
793+
- if the payment hash is unknown:
794+
- MUST fail the HTLC.
795+
- MUST return an `unknown_payment_hash` error.
796+
- if the amount paid is more than twice the amount expected:
797+
- SHOULD fail the HTLC.
798+
- SHOULD return an `incorrect_payment_amount` error.
799+
- Note: this allows the origin node to reduce information leakage by
800+
altering the amount while not allowing for accidental gross overpayment.
801+
- if the `cltv_expiry` value is too near the present:
802+
- MUST fail the HTLC.
803+
- MUST return a `final_expiry_too_soon` error.
804+
- if the `outgoing_cltv_value` does NOT correspond with the `cltv_expiry` from
805+
the final node's HTLC:
806+
- [FIXME: MAY|SHOULD|MUST?] return `final_incorrect_cltv_expiry` error.
807+
- if the `amt_to_forward` is greater than the `incoming_htlc_amt` from the
808+
final node's HTLC:
809+
- [FIXME: MAY|SHOULD|MUST?] return a `final_incorrect_htlc_amount` error.
790810

811+
## Receiving Failure Codes
791812

792813
The _origin node_:
793814
- MUST ignore any extra bytes in `failuremsg`.

0 commit comments

Comments
 (0)