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

[0.0.123-bindings] Bindings changes for 0.0.123 #3062

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

Bindings specific changes, including #3061.

Now that `ChannelId` has useful constructors and methods we need
to start exposing it to bindings users rather than relying on using
`[u8; 32]`.
This avoids the bindings trying to figure out what a
`lightning::prelude::Vec` is rather than matching it as a `Vec`.
`Amount` is less than two pointers long, so there's no reason it
shouldn't be `Copy`. Further, because its an enum, bindings can't
map a reference to it in an `Option`. Thus, here, we simply make it
`Copy` and return it in `Option`s rather than a reference to it.
@TheBlueMatt TheBlueMatt force-pushed the 2024-04-123-bindings branch from 62fce5a to 7ac5b46 Compare May 12, 2024 00:26
This is required for bindings as passing types from Rust to GC'd
languages can't map the concept of a type that has a lifetime of
the called function but instead needs to clone for safety.
This is required for GC'd languages which need to be able to clone
in order to pass owned objects to Rust.
@TheBlueMatt TheBlueMatt force-pushed the 2024-04-123-bindings branch from 7ac5b46 to 3ef8211 Compare May 13, 2024 17:31
This matches our normal API semantics and allows, for example,
`Arc`s to `EntropySource`s.
@@ -34,6 +34,8 @@ use core::ops::Deref;

use crate::prelude::*;

use core::ops::Deref;
Copy link
Contributor

Choose a reason for hiding this comment

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

Little confused about 4cab9cb. The message doesn't seem to match the change and then it is reverted in the next commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh oops its just an old commit that didn't get dropped during the rebase, dropped.

///
/// Thus, this method should be polled regularly to detect messages await such a direct
/// connection.
fn get_and_clear_connections_needed(&self) -> Vec<(PublicKey, Vec<SocketAddress>)>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have this return Vec<Event> given #2973 expands the type of events returned?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could, indeed, but we've done this for a release already so I'd kinda rather we just do it in the next one?

pub fn as_array(&self) -> &[u8; PUBLIC_KEY_SIZE] {
pub fn as_array(&self) -> &[u8; 33] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed? Seems unrelated to the rest of the commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the bindings doesn't know how to parse constants out of CONSTANTS :/

TheBlueMatt and others added 16 commits May 14, 2024 20:46
While there's not really much harm in requiring a `Clone`able
reference (they almost always are), it does make our bindings
struggle a bit as they don't support multi-trait bounds (as it
would require synthesizing a new C trait, which the bindings don't
do automatically). Luckily, there's really no reason for it, and we
can just call the `DefaultMessageRouter` directly when we want to
route a message.
...as the bindings generation does not currently have the ability
to map a reference to a `NodeId` inside a tuple.
Bindings can't handle references in return types, so reduce the
visibility to pub(crate).
The bindings currently get confused by the implicit `Sign` type, so
we temporarily remove it on the `impl` here.
Re-exports in Rust make `use` statements a little shorter, but for
otherwise don't materially change a crate's API. Sadly, the C
bindings generator currently can't figure out re-exports, but it
also exports everything into one global namespace, so it doesn't
matter much anyway.
Having struct fields with references to other structs is tough in
our bindings logic, but even worse if the fields are in an enum.
Its simplest to just take the clone penalty here.
The scorer currently relies on an associated type for the fee
parameters. This isn't supportable at all in bindings, and for
lack of a better option we simply hard-code the parameter for all
scorers  to `ProbabilisticScoringFeeParameters`.
These are not expressible in C/most languages, and thus must be
hidden.
Rather than `ChannelMonitor` only being clonable when the signer is
clonable, we require all signers to be clonable and then make all
`ChannelMonitor`s clonable.
`OnionMessageHandler`s are expected to regularly release a set of
nodes which we need to directly connect to to deliver onion
messages. In order to do so, they currently extend
`EventsProvider`, returning that set as `Event::ConnectionNeeded`s.

While this works fine in Rust, the `EventsProvider` interface
doesn't map well in bindings due to it taking a flexible trait impl
as a method argument.

Instead, here, we convert `OnionMessageHandler` to include a single
function which returns nodes in the form of a `node_id` and
`Vec<SocketAddress>`. This is a bit simpler, if less flexible, API,
and while largely equivalent, is easier to map in bindings.
As we cannot express slices without inner references in bindings
wrappers.
@TheBlueMatt TheBlueMatt force-pushed the 2024-04-123-bindings branch from e7e551c to 4f8f9b4 Compare May 14, 2024 20:48
@TheBlueMatt
Copy link
Collaborator Author

Dropped commits that totaled empty, no diff.

@TheBlueMatt TheBlueMatt merged commit 9b523d9 into lightningdevkit:0.0.123-bindings May 14, 2024
2 of 16 checks passed
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.

2 participants