Skip to content

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

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.

@TheBlueMatt TheBlueMatt added this to the 0.0.101 milestone Sep 22, 2021
@TheBlueMatt TheBlueMatt force-pushed the 2021-09-type-explicit-bounds branch from bc4d8b9 to 0f031a1 Compare September 22, 2021 19:32
@codecov
Copy link

codecov bot commented Sep 22, 2021

Codecov Report

Merging #1094 (ab49e41) into main (e12d88d) will decrease coverage by 0.01%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
lightning/src/ln/wire.rs 59.45% <0.00%> (-0.24%) ⬇️
lightning/src/util/ser.rs 89.14% <0.00%> (-0.69%) ⬇️
lightning/src/ln/peer_handler.rs 45.88% <50.00%> (-0.07%) ⬇️
lightning/src/ln/functional_tests.rs 97.37% <0.00%> (-0.05%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e12d88d...ab49e41. Read the comment docs.

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.
@TheBlueMatt TheBlueMatt force-pushed the 2021-09-type-explicit-bounds branch from 0f031a1 to e82318d Compare September 22, 2021 22:01
Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

ACK e82318d

@TheBlueMatt TheBlueMatt force-pushed the 2021-09-type-explicit-bounds branch from ce8237a to 401d035 Compare September 22, 2021 23:46
@TheBlueMatt
Copy link
Collaborator Author

Oops, realized I should push one more commit to clean up generic bounds.

Copy link
Contributor

@jkczyz jkczyz left a 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.
@TheBlueMatt
Copy link
Collaborator Author

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.

Copy link
Contributor

@arik-so arik-so left a 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.

@TheBlueMatt TheBlueMatt merged commit 64bf483 into lightningdevkit:main Sep 23, 2021
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