Skip to content

Pre-C-Bindings Cleanups #3 #676

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

Hopefully this is the last of them given we're getting close on the C bindings PR. See individual commits for details.

@TheBlueMatt TheBlueMatt force-pushed the 2020-08-c-bindings-cleanups-3 branch from 2331bc5 to 6cc8fc6 Compare August 25, 2020 19:23
@codecov
Copy link

codecov bot commented Aug 25, 2020

Codecov Report

Merging #676 into master will increase coverage by 0.03%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #676      +/-   ##
==========================================
+ Coverage   91.35%   91.38%   +0.03%     
==========================================
  Files          35       35              
  Lines       21723    21736      +13     
==========================================
+ Hits        19844    19864      +20     
+ Misses       1879     1872       -7     
Impacted Files Coverage Δ
lightning/src/chain/chaininterface.rs 91.93% <ø> (ø)
lightning/src/routing/network_graph.rs 91.17% <62.50%> (-0.27%) ⬇️
lightning/src/ln/channelmonitor.rs 95.49% <90.90%> (-0.08%) ⬇️
lightning/src/chain/keysinterface.rs 95.04% <100.00%> (ø)
lightning/src/ln/chan_utils.rs 95.97% <100.00%> (ø)
lightning/src/ln/channel.rs 87.17% <100.00%> (ø)
lightning/src/ln/channelmanager.rs 85.26% <100.00%> (ø)
lightning/src/ln/functional_test_utils.rs 94.81% <100.00%> (+0.15%) ⬆️
lightning/src/ln/functional_tests.rs 97.15% <100.00%> (+0.17%) ⬆️
lightning/src/ln/onchaintx.rs 93.75% <100.00%> (ø)
... and 5 more

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 501974d...d224c1d. Read the comment docs.

There are a few cases where the upcoming C bindings don't know how
to handle something which depends on something defined later in the
file. Instead of adding another pass to the C bindings generator,
it is much simpler to just reorder structs.
This makes it a little easier to write C bindings generation as
we only have to handle one case instead of both.
This avoids one case the bindings generation hasn't bothered to
handle by simply importing types that are referred to.
Instead of using the explicit type which is being returned, refer
to them as Self::AssociatedType, to make clear to the bindings what
type of thing is being returned.
Because the C bindings maps objects into new structs which contain
only a pointer to the underlying (immovable) Rust type, it cannot
create a list of Rust types which are contiguous in memory. Thus,
in order to allow C clients to call certain Rust functions, we have
to use &[&Type] not &[Type]. This commit fixes this issue for the
get_route function.
Lightning OutPoints only have 16 bits to express the output index
instead of Bitcoin's 32 bits, implying that some outputs are
possibly not expressible as lightning OutPoints. However, such
OutPoints can never be hit within the lightning protocol, and must
be on-chain spam sent by a third party wishing to donate us money.
Still, in order to do so, the third party would need to fill nearly
an entire block with garbage, so this case should be relatively
safe.

A new comment in channelmonitor explains the reasoning a bit
further.
@TheBlueMatt TheBlueMatt force-pushed the 2020-08-c-bindings-cleanups-3 branch from 6cc8fc6 to 44b8197 Compare August 25, 2020 21:15
@jkczyz jkczyz self-requested a review August 25, 2020 22:57
use ln::msgs;
use ln::msgs::UnsignedChannelAnnouncement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you open an issue to fix the underlying problem in the bindings generation? Sometimes using the module prefix is preferable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its somewhat awkward that ChannelManagerReadArgs requires a mutable
reference to a HashMap of ChannelMonitors, forcing the callsite to
define a scope for the HashMap which they almost certainly won't use
after deserializing the ChannelManager. Worse, to map the current
version to C bindings, we'd need to also create a HashMap binding,
which is overkill for just this one use.

Instead, we just give the ReadArgs struct ownership of the HashMap
and add a constructor which fills the HashMap for you.
The C bindings automatically create a _new() function for structs
which contain only pub fields which we know how to map. This
conflicts with the actual TxCreationKeys::new() function, so we
simply rename it to capture its nature as a derivation function.
In order to calculate a route, it is likely that users need to take
a read()-lock on NetGraphMsgHandler::network_graph. This is not
possible naively from C bindings, as Rust's native RwLock is not
exposed.

Thus, we provide a simple wrapper around the RwLockReadGuard and
expose simple accessor methods.
@TheBlueMatt TheBlueMatt force-pushed the 2020-08-c-bindings-cleanups-3 branch from 44b8197 to d224c1d Compare August 26, 2020 01:28
@TheBlueMatt TheBlueMatt merged commit 3defcc8 into lightningdevkit:master Aug 26, 2020
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