-
Notifications
You must be signed in to change notification settings - Fork 407
Use Infallible for the unconstructable default custom message type #1094
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 Infallible for the unconstructable default custom message type #1094
Conversation
bc4d8b9
to
0f031a1
Compare
Codecov Report
@@ Coverage Diff @@
## main #1094 +/- ##
==========================================
- Coverage 90.73% 90.71% -0.02%
==========================================
Files 65 65
Lines 34315 34318 +3
==========================================
- Hits 31136 31132 -4
- Misses 3179 3186 +7
Continue to review full report at Codecov.
|
When we landed custom messages, we used the empty tuple for the custom message type for `IgnoringMessageHandler`. This was fine, except that we also implemented `Writeable` to panic when writing a `()`. Later, we added support for anchor output construction in CommitmentTransaction, signified by setting a field to `Some(())`, which is serialized as-is. This causes us to panic when writing a `CommitmentTransaction` with `opt_anchors` set. Note that we never set it inside of LDK, but downstream users may. Instead, we implement `Writeable` to write nothing for `()` and use `core::convert::Infallible` for the default custom message type as it is, appropriately, unconstructable. This also makes it easier to implement various things in bindings, as we can always assume `Infallible`-conversion logic is unreachable.
0f031a1
to
e82318d
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.
ACK e82318d
ce8237a
to
401d035
Compare
Oops, realized I should push one more commit to clean up generic bounds. |
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.
ACK 401d035
Associated types in C bindings is somewhat of a misnomer - we concretize each trait to a single struct. Thus, different trait implementations must still have the same type, which defeats the point of associated types. In this particular case, however, we can reasonably special-case the `Infallible` type, as an instance of it existing implies something has gone horribly wrong. In order to help our bindings code figure out how to do so when referencing a parent trait's associated type, we specify the explicit type in the implementation method signature.
Heh, sorry, pushed one last commit and now the bindings are fully auto-generating - this one is a bit of a hack to help the bindings generator, but its a trivial change and we really need to ship 0.0.101 ASAP, so I figure just land it. |
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.
Love it! Nicely fixed.
When we landed custom messages, we used the empty tuple for the
custom message type for
IgnoringMessageHandler
. This was fine,except that we also implemented
Writeable
to panic when writinga
()
. Later, we added support for anchor output construction inCommitmentTransaction, signified by setting a field to
Some(())
,which is serialized as-is.
This causes us to panic when writing a
CommitmentTransaction
with
opt_anchors
set. Note that we never set it inside of LDK,but downstream users may.
Instead, we implement
Writeable
to write nothing for()
and usecore::convert::Infallible
for the default custom message type asit is, appropriately, unconstructable.
This also makes it easier to implement various things in bindings,
as we can always assume
Infallible
-conversion logic isunreachable.