Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify onion message codec #2060

Merged
merged 1 commit into from
Nov 9, 2021
Merged

Simplify onion message codec #2060

merged 1 commit into from
Nov 9, 2021

Conversation

t-bast
Copy link
Member

@t-bast t-bast commented Nov 9, 2021

This PR was quite a trip. It started because I realized after merging #1957 that since the sphinx packet doesn't really use a prefix, but rather a mix of prefix and suffix (since the mac is encoded after the payload), I actually wasn't sure the _ - 66, _ + 66 trick was correct.

So I dived into the tests and added new ones playing with length more extensively, and I ended up with some failing tests. At some point I thought our bytes32 codec was the culprit, so I added tests for that, but it turned out it wasn't the culprit (but I think it's worth keeping the tests, we didn't have enough coverage there). It took me quite a while to realize that it was actually my test that wasn't correctly written 🤕

Now everything is green, we have more coverage (in particular for the remaining bytes / not enough bytes cases) and I think the codec is simpler to understand, let me know what you think.

Note that the previous codec was correct, it did pass all tests, but I found it harder to understand (scodec wizardry).

The scodec magic was quite hard to read, and the use of the prefix wasn't
very intuitive since Sphinx uses both a prefix and a suffix.

Also added more codec tests.
@t-bast t-bast requested a review from thomash-acinq November 9, 2021 14:21
@codecov-commenter
Copy link

Codecov Report

Merging #2060 (036ce10) into master (333e9ef) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2060      +/-   ##
==========================================
- Coverage   87.57%   87.57%   -0.01%     
==========================================
  Files         165      165              
  Lines       12696    12694       -2     
  Branches      555      553       -2     
==========================================
- Hits        11119    11117       -2     
  Misses       1577     1577              
Impacted Files Coverage Δ
...a/fr/acinq/eclair/wire/protocol/MessageOnion.scala 100.00% <100.00%> (ø)
...cala/fr/acinq/eclair/payment/relay/NodeRelay.scala 95.93% <0.00%> (-1.63%) ⬇️
...main/scala/fr/acinq/eclair/io/PeerConnection.scala 84.16% <0.00%> (-0.42%) ⬇️
...c/main/scala/fr/acinq/eclair/channel/Channel.scala 87.86% <0.00%> (+0.07%) ⬆️
...cinq/eclair/channel/publish/MempoolTxMonitor.scala 84.81% <0.00%> (+2.53%) ⬆️

Copy link
Member

@thomash-acinq thomash-acinq left a comment

Choose a reason for hiding this comment

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

Yes, it's a lot simpler. That's what I wanted to do but couldn't find a way to do it.

@t-bast t-bast merged commit 6cc37cb into master Nov 9, 2021
@t-bast t-bast deleted the onion-message-codec branch November 9, 2021 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants