-
Notifications
You must be signed in to change notification settings - Fork 266
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
Use CLTV as tie-breaker for offered htlc output sorting #790
Conversation
eclair-core/src/main/scala/fr/acinq/eclair/channel/Commitments.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #790 +/- ##
==========================================
+ Coverage 86.20% 86.44% +0.23%
==========================================
Files 119 119
Lines 9202 9219 +17
Branches 390 400 +10
==========================================
+ Hits 7933 7969 +36
+ Misses 1269 1250 -19
|
Let's bring back this PR to life! 👻 |
I still finds this too complex, and it does not fix the hack we introduced with the "outputs already used" set. I think instead we should address this in 2 steps:
To implement the first step, when we build the commit tx and HTLC txs:
WDYT ? |
I agree it's too complex, i initially tried to link outputs with HTLCs with the type alias but it's clearly not readable enough. I like the suggestion of creating a stronger link between the |
I have an idea for that, I'll open a PR so we can discuss it |
I'm curious to see your proposal :), in any case i just pushed mine in f646576. It removes both the type alias for |
I've updated my code to use some of your ideas and published it there https://github.com/ACINQ/eclair/tree/link-committx-outputs |
f646576
to
2f97a5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This touches some very important parts of the protocol, before merging this we must make sure we've done extensive testing with lnd and c-lightning for identical HTLCs. Once we're close to merging it, can you please list the E2E tests done?
eclair-core/src/main/scala/fr/acinq/eclair/transactions/CommitmentSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/channel/states/StateTestsHelperMethods.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/transactions/TransactionsSpec.scala
Outdated
Show resolved
Hide resolved
b3e42f9
to
dddac35
Compare
I think we should re-do the E2E test once we agree on the changes to the code (IIRC i did some test after opening the PR but it has passed a year now), also there is lightning/bolts#539 that can help with interop testing. |
Commit 453c7d0 applies the new naming, if there isn't other feedback we can go ahead with testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went more in-depth, and now it makes much more sense to me.
I think it's a great clean-up, I like it!
Let's discuss my current comments and then I think we can start compat' testing.
eclair-core/src/test/scala/fr/acinq/eclair/transactions/TestVectorsSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/transactions/TestVectorsSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/transactions/TransactionsSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/transactions/TransactionsSpec.scala
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/transactions/TransactionsSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/test/scala/fr/acinq/eclair/transactions/TransactionsSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Let's do E2E tests and it's all good on my side 🚀
I'll do some tests on my side right now and will report back.
eclair-core/src/main/scala/fr/acinq/eclair/transactions/CommitmentSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
I've finished my compatibility testing. |
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
517ed54
to
d4703fc
Compare
Following yesterday's conversation and hoping to get everyone on board i'm proposing to type |
We are going in the right direction (pun intended), but the |
How do we store a |
eclair-core/src/main/scala/fr/acinq/eclair/transactions/CommitmentSpec.scala
Show resolved
Hide resolved
If it's only needed in the codecs, that's an enum we can put closer to the codec code? Or we keep that enum here and use it only for the codec. |
We now use a small hierarchy of classes to represent HTLC directions. There is also a type alias for a collection of commitment output links.
748acd4
to
f59111a
Compare
Last update only addresses the PR feedback, i will push another commit for the removal of |
eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/CommitmentSpec.scala
Show resolved
Hide resolved
val htlcCodec: Codec[DirectedHtlc] = ( | ||
("direction" | directionCodec) :: | ||
("add" | updateAddHtlcCodec)).as[DirectedHtlc] | ||
("add" | updateAddHtlcCodec)).xmap( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you get the result of the directionCodec
here? I think we have some codecs that do that, I'll look around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Told you it had the potential to be rabbit hole-y 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually your proposal works fine, I like it. I just find the indentation a bit confusing, what about:
val htlcCodec: Codec[DirectedHtlc] = (("direction" | directionCodec) :: ("add" | updateAddHtlcCodec)).xmap(
{
case IN :: add :: HNil => IncomingHtlc(add)
case OUT :: add :: HNil => OutgoingHtlc(add)
},
{
htlc => htlc.direction :: htlc.add :: HNil
}
)
And we should put the import shapeless.::
at the top of the file IMHO, not a big fan of scattering imports in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do, i also don't like the scattered imports but i'd make an exception for shapeless.::
if imported at the top of the file it's very hard to understand what ::
does if it's from scala's collection or shapeless.
Can we postpone the removal of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for this long-standing work!
If you don't have time in the next few days, I can work on the leftover refactoring we mentioned.
I think i can work on the refactoring, by the way before merging this PR i'd like to do a final E2E test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing non-reg tests for the codec change, a failure here could be catastrophic.
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/wire/ChannelCodecs.scala
Outdated
Show resolved
Hide resolved
At 60ba2e4 i applied the latest feedback by @pm47 (including the non-reg test). I also tested the compatibility with CL and it went okay (i compared the commitment transactions after adding HTLCs with same amount and preimage but different CLTV), i didn't test with LND master yet as there is a known issue that is being fixed. |
eclair-core/src/test/scala/fr/acinq/eclair/wire/ChannelCodecsSpec.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/transactions/Transactions.scala
Show resolved
Hide resolved
#1360) * removed the `Direction` class * improved the non-reg test for htlcs - check actual content instead of only success and roundtrip - use randomized data for all fields instead of all-zero - check the remaining data, not only the decoded value (codecs are chained so a regression here will cause the next codec to fail) Co-Authored-By: Bastien Teinturier <[email protected]>
Fixes lightning/bolts#448 , by using the CLTV value from the htlc-timeout-tx when sorting the htlc_sigs in the commit_signature message.