Skip to content

Conversation

@cfromknecht
Copy link
Contributor

Builds on #3465

Modifies the link to return an InvalidOnionPayload failure when it is unable to process a TLV onion payload. In the process, we unify the hop.ErrInvalidPayload failure to include required type failures, and propagate the type back to the caller in the InvalidOnionPayload.

@cfromknecht cfromknecht force-pushed the invalid-onion-payload branch from 70af0ff to 700180a Compare September 5, 2019 19:41
@cfromknecht cfromknecht changed the title Invalid onion payload htlcswitch+lnwire: invalid onion payload Sep 5, 2019
@cfromknecht cfromknecht force-pushed the invalid-onion-payload branch from 700180a to 5c72497 Compare September 9, 2019 20:24
@joostjager
Copy link
Contributor

Do you want to make the change to result_interpretation.go too?

@Roasbeef Roasbeef added error messages htlcswitch spec P2 should be fixed if one has time labels Oct 3, 2019
@Roasbeef Roasbeef added this to the 0.9 milestone Oct 8, 2019
@cfromknecht cfromknecht force-pushed the invalid-onion-payload branch from 5c72497 to 017eb23 Compare October 9, 2019 23:10
@cfromknecht
Copy link
Contributor Author

Do you want to make the change to result_interpretation.go too?

Done

@cfromknecht cfromknecht force-pushed the invalid-onion-payload branch from 017eb23 to 9516e4a Compare October 9, 2019 23:16
Copy link
Contributor

@joostjager joostjager left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figuring out how to map to the failure message isn't very simple. I see a cost now and in the future for keeping that working as good as possible. Why don't we just return no info in the failure message and only add it when this type of debugging becomes essential to have. So many things can't go wrong that you can't find out during dev.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required and Omitted sound like the same thing. Is the real difference that one happens during tlv decode and the other one on the higher level? If that is indeed the case, maybe the names should reflect that. Or just have one of the two.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no they are different, required means that the sender required us to understand a record, but we don't. omitted means that the receiver expected a field that the sender didn't include.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a bit too much? Always returning RequiredViolation here doesn't seem to be bad. Especially because it also requires changes to the tlv parser.

Copy link
Contributor Author

@cfromknecht cfromknecht Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is in some sense overkill, but i think an accurate log message will help debug if things go wrong. perhaps another solution is to not log the final/intermediate info when encountering a required violation? however, many of the new records being added are specific to the hop type, which would make that information more useful.

@joostjager joostjager requested a review from guggero October 24, 2019 08:27
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a high-level pass of the PR, mainly focusing on code quality aspects. Only found a few minor nits.
Nice to see that there are multiple test cases around the changes and the coverage actually increase slightly.
The changes look solid to me though I cannot speak to the possible implications this has in routing.

@cfromknecht cfromknecht force-pushed the invalid-onion-payload branch from ebae32f to 2d34bae Compare October 29, 2019 17:40
@cfromknecht
Copy link
Contributor Author

thanks for the review @guggero!

@cfromknecht cfromknecht force-pushed the invalid-onion-payload branch from 2d34bae to eabcda4 Compare October 29, 2019 17:44
Previously we would not mark a success for the first hop if the fail
source index was 2. We also add a test to assert this behavior.
This commit adds a hop.PayloadViolation enum which encompasses the cases
where the sender omits, includes, or requires a type that causes an
ErrInvalidPayload faiulre.

The existing Omitted bool is converted to this PayloadViolation, and
NewPayloadFromReader is updated to return such a failure with a
RequiredViolation when an unknown required type is detected.

The unit tests are updated to cover the three possible cases of
RequiredViolations, as well as included valid intermediate and final hop
tests.
This commit modifies the link return an InvalidOnionPayload failure when
it cannot parse a TLV payload. The offset is left at zero, since its
unclear how useful it will be in practice and would require some
significant reworkings of the abstractions in the tlv package.

TODO: add unit tests. currently none of the test unit infrastructure is
setup to handle TLV payloads, so this would require implementing a
separate mock iterator for TLV payloads that also supports injecting
invalid payloads. Deferring this non-trival effor till a later date
An InvalidOnionPayload implies that the onion was successfully received
by the reporting node, but that they were unable to extract the
contents. Since we assume our own behavior is correct, this mostly
likely poins to an error in the reporter's implementation or that we
sent an unknown required type. Therefore we only penalize that single
hop, and consider the failure terminal if the receiver reported it.
This commit modifies the NewPayloadFromReader to apply known
presence/omission contraints in the event that the tlv parser returns an
unknown required type failure.

Now that the parser has been modified to finished parsing the stream to
obtain a proper parsed type set, we can accurately apply these higher
level validation checks. This overrides required type failures, such
that they are only returned if the sender properly abided by the
constraints on fields for which we know.

The unit tests are updated to create otherwise valid payloads that then
return unknown required type failures. In one case, a test which
previously returned an unknown required type failure is made to return
an included failure for the sid, indicating the unknown required type 0
is being overruled.
@cfromknecht cfromknecht force-pushed the invalid-onion-payload branch from eabcda4 to cba523a Compare October 31, 2019 04:22
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 📡

@Roasbeef Roasbeef merged commit acd8a6e into lightningnetwork:master Nov 2, 2019
@cfromknecht cfromknecht deleted the invalid-onion-payload branch November 2, 2019 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

error messages htlcswitch P2 should be fixed if one has time spec

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants