Commit graph

1927 commits

Author SHA1 Message Date
Matt Corallo
a387badfe8 [bindings] Handle generic-ized impl blocks by concretizing them
This handles, for example, the `impl<X: Y> for Features<X>` blocks
which are generic across a number of different contexts. We do so
by walking the set of structs which alias Features and then walking
their generic arguments to check that they meet the bounds
specified in the impl block. For each alias which does, we create
a dummy, explicit, `impl XFeatures` block with the same content as
the original and recurse.
2021-02-18 12:28:25 -05:00
Matt Corallo
842d2f6ce7 [bindings] Resolve type aliases mapped as opaque types
We already map type aliases which alias private types as opaque,
but we don't resolve them like we would any other opaque type,
preventing conversion printing or type use.
2021-02-18 12:28:25 -05:00
Matt Corallo
f3ce70660d [bindings] Track structs impling traits, incl priv traits 2021-02-18 12:28:25 -05:00
Matt Corallo
b49781e8d8 [bindings] Allow resolution of private types in some cases
We need this specifically for resolving the
features::sealed::Context trait which is inside the non-pub
`sealed` module.
2021-02-18 12:28:25 -05:00
Matt Corallo
61f5e79062 Drop a useless import and use Self in return values in Features
`Result` is in the standard prelude, so no need to ever use it.

Sadly, returning a Features<T> in the `impl Futures {}` block
will confuse our new alias-impl-printing logic, as we end up
running through the normal impl-block-printing logic as if we had
an explicit `impl ConcreteFeatures` block.
2021-02-18 12:28:25 -05:00
Matt Corallo
3bbecbef21 [bindings] Use new ImportResolver during first AST pass
This removes some redundant logic and ensures we handle more
import-resolution cases in both contexts.
2021-02-18 12:28:25 -05:00
Matt Corallo
494e0fd8a0 [bindings] Track all declared types in ImportResolver construction
This allows an ImportResolver to handle more than imports, allowing
ident resolution of objects constructed in the same module.
2021-02-18 12:28:25 -05:00
Matt Corallo
dd1ca585b3 [bindings] Extract import resolution logic into a separate struct
This will allow us to reuse the same ident-resolution logic both
during the initial AST pass and during the second conversion pass.
2021-02-18 12:28:25 -05:00
Matt Corallo
0dcc937bf1 Update demo C++ bindings example for new bindings 2021-02-18 12:28:25 -05:00
Matt Corallo
be74b366d2 Gen bindings with rustc --pretty=expanded instead of reading files
Instead of walking individual rust files and reading the AST from
those, we instead call
`RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded`
and let it create one giant lib.rs which we can parse as a whole.
This allows us to parse a post-macro crate, working with structs
and functions created inside macros just fine. It does require
handling a few things that we didn't previously, most notably Clone
via `impl ::core::clone::Clone` blocks instead of just looking for
`#![derive(Clone)]`.

This ends up resolving a few types slightly differently, resulting
in different bindings, but only in ways which don't impact the
runtime.
2021-02-18 12:28:25 -05:00
Matt Corallo
9e596e2460 [bindings] Use resolved, not local ident in generic mangling
In traits with associated types which are returned in generics (ie
`trait T { type A: B; fn c() -> Result<Self::A, ()> {} }`), we
created a new generic mapping with the local type name (in this
case A) instead of using the real type (in this case B). This is
confusing as it results in generic manglings that don't reference
the real type (eg `LDKCResult_ChanKeySignerDecodeErrorZ`) and
may have multiple generic definitions that are identical.

Instead, we now use the final ident in the resolved mapping. The
biggest win is `LDKCResult_ChanKeySignerDecodeErrorZ` changing to
`CResult_ChannelKeysDecodeErrorZ`. However, there are several types
where `secp256k1::Error` was imported as `SecpError` and types like
`LDKCResult_SecretKeySecpErrorZ` are now
`LDKCResult_SecretKeyErrorZ` instead. Still, the type of the error
field remains `LDKSecp256k1Error`, which should avoid any confusion.
2021-02-18 12:28:25 -05:00
Matt Corallo
10c45786ab [bindings] Drop some significantly-overly-verbose logging in gen 2021-02-18 12:28:25 -05:00
Matt Corallo
2088f4bec3
Merge pull request #786 from TheBlueMatt/2021-02-chansigner-util
Expand documentation and fields in SpendableOutputDescriptors
2021-02-16 09:33:37 -08:00
Matt Corallo
09f37ae89b
Merge pull request #797 from TheBlueMatt/2021-02-no-addr-order
Drop address ordering enforcement in NodeAnnouncement deser
2021-02-16 08:05:26 -08:00
Matt Corallo
1c8401490f
Merge pull request #798 from TheBlueMatt/2021-02-route-bench 2021-02-15 15:32:10 -08:00
Matt Corallo
454e01d30e Fetch network graph cache and run benchmarks on CI 2021-02-15 16:51:51 -05:00
Matt Corallo
2ae6b3fad4 Add a trivial benchmark of calculating routes on today's graph
Sadly rust upstream never really figured out the benchmark story,
and it looks like the API we use here may not be long for this
world. Luckily, we can switch to criterion with largely the same
API if that happens before upstream finishes ongoing work with the
custom test framework stuff.

Sadly, it requires fetching the current network graph, which I did
using Val's route-testing script written to test the MPP router.
2021-02-15 16:51:51 -05:00
Matt Corallo
d873e72789 Allow gossip messages to have 1KB of uninterpreted data and relay 2021-02-15 16:45:22 -05:00
Matt Corallo
35bb2d0085 Drop trailing semicolons which rustc nightly generates warnings for 2021-02-15 15:17:25 -05:00
Matt Corallo
06342a30b1 Adapt C++ bindings demo to new API and keys (new funding tx) 2021-02-12 18:59:01 -05:00
Matt Corallo
e9d819dce8 Update auto-generated bindings 2021-02-12 18:58:59 -05:00
Matt Corallo
7dbced3f28 Slightly expand documentation on KeysInterface
Specifically, this notes when methods can or can not return the
same value on each call.
2021-02-12 18:57:20 -05:00
Matt Corallo
36cc5814c1 Expand documentation and fields in SpendableOutputDescriptors
This adds a channel_value_satoshis field to
SpendableOutputDescriptors as it is required to recreate our
InMemoryChannelKeys. It also slightly expands documentation.
2021-02-12 18:57:20 -05:00
Matt Corallo
e885d0a774 Swap key_derivation_params (u64, u64) for channel_keys_id [u8; 32]
Instead of `key_derivation_params` being a rather strange type, we
call it `channel_keys_id` and give it a generic 32 byte array. This
should be much clearer for users and also more flexible.
2021-02-12 18:57:20 -05:00
Matt Corallo
8dd08bd962 Drop address ordering enforcement in NodeAnnouncement deser
It seems many other nodes never bothered to enforce these
requirements, so there's little reason that we should either.

cc https://github.com/lightningnetwork/lightning-rfc/pull/842
2021-02-12 16:43:25 -05:00
Matt Corallo
879e309c12
Merge pull request #788 from TheBlueMatt/2020-02-concrete-bindings
Concretize bindings templates
2021-02-10 20:31:43 -08:00
Matt Corallo
c2fd68377c Update auto-generated bindings 2021-02-10 22:38:51 -05:00
Matt Corallo
75d71cead3 Add additional Clone derives
The only API change outside of additional derives is to change
the inner field in `DecodeError::Io()` to an `std::io::ErrorKind`
instead of an `std::io::Error`. While `std::io::Error` obviously
makes more sense in context, it doesn't support Clone, and the
inner error largely doesn't have a lot of value on its own.
2021-02-10 22:34:19 -05:00
Matt Corallo
03a6a243ac [bindings] Allow cloning opaque types when inner is NULL
Previously we'd segfault trying to deref the NULL page, but there
is no reason to not simply clone by creating another opaque instance
with a null inner. This comes up specifically when cloning
ChannelSigners as the pubkeys instance is NULL on construction
before get_pubkeys is called.
2021-02-10 22:25:10 -05:00
Matt Corallo
ac70f278cb [C++ bindings] Update demo app due to removed TupleTempl generics 2021-02-10 22:25:10 -05:00
Matt Corallo
7c8da3ba04 [bindings] Drop some stale code from bindings generic generation 2021-02-10 22:25:10 -05:00
Matt Corallo
faad5124cf [bindings] Move to manual write-out for Tuples, too 2021-02-10 22:25:10 -05:00
Matt Corallo
7dd9d6f40c [bindings] Move to manual write-out for Vec, too 2021-02-10 22:25:10 -05:00
Matt Corallo
c5c2d464ba [bindings] Concretize Result types without type aliasing
While the type aliasing trick works great for cbindgen,
wasm_bindgen doesn't support it and requires fully-concrete types.
In order to better support wasm_bindgen in the future, we do so
here, adding a function which manually writes out almost the exact
thing which was templated previously in concrete form.

As a nice side-effect, we no longer have to allocate and free a u8
for generic parameters which were `()` (though we still do in some
conversion functions, which we can get rid of when we similarly
concretize all generics fully).
2021-02-10 22:24:16 -05:00
Matt Corallo
f5e0e228fd [bindings] Keep track of all types which derive[Clone] 2021-02-10 22:24:16 -05:00
Matt Corallo
ee07a73b82 [bindings] Add additional clone methods on manually-defined types 2021-02-10 22:24:16 -05:00
Matt Corallo
c35002fa9c
Merge pull request #787 from TheBlueMatt/2021-02-check-close-source 2021-02-10 09:09:53 -08:00
Matt Corallo
bd8382a4d3 Fix documentation on PeerHandleError 2021-02-09 19:06:00 -05:00
Matt Corallo
d3f61c0ad7 Add test for error message hangline resulting in force-close 2021-02-09 19:04:54 -05:00
Matt Corallo
61164afb2b Check the PK of the source of an error before closing chans from it
When we receive an error message from a peer, it can indicate a
channel which we should close. However, we previously did not
check that the counterparty who sends us such a message is the
counterparty with whom we have the channel, allowing any
connected peer to make us force-close any channel we have as long
as they know the channel id.

This commit simply changes the force-close logic to check that the
sender matches the channel's counterparty node_id, though as noted
in #105, we eventually need to change the indexing anyway to allow
absurdly terrible peers to open channels with us.

Found during review of #777.
2021-02-09 19:04:54 -05:00
Matt Corallo
6dcb7c4d05
Merge pull request #793 from galderz/t_double_validation_792 2021-02-05 06:17:46 -08:00
Galder Zamarreño
048e862a4b Unknown bits feature only needs to be validated once #792 2021-02-05 13:29:56 +01:00
Matt Corallo
89be6254ae
Merge pull request #790 from bmancini55/sync_complete
Interpret sync_complete in reply_channel_range
2021-02-04 09:18:52 -08:00
Matt Corallo
b67ec5a273
Merge pull request #774 from jkczyz/2021-01-http-client
HTTP-based block source clients
2021-02-04 09:16:14 -08:00
Jeffrey Czyz
85fdfaaa9c
Implement BlockSource for REST and RPC clients
Interprets HTTP responses as either binary or JSON format, which are
then converted to the appropriate data types.
2021-02-04 07:38:42 -08:00
Jeffrey Czyz
6ca3b8ed49
Add REST and RPC clients to lightning-block-sync
Implements a simple HTTP client that can issue GET and POST requests.
Used to implement REST and RPC clients, respectively. Both clients
support either blocking or non-blocking I/O.
2021-02-04 07:38:42 -08:00
bmancini55
77690fada2 Interpret sync_complete in reply_channel_range
LN Spec PR #826 changes full_information to indicate completion of a
sequence of reply_channel_range messages.
2021-02-04 09:19:02 -05:00
Jeffrey Czyz
9860646e73
Add lightning-block-sync package and library
Defines an interface and related types for fetching block headers and
data from a block source (e.g., Bitcoin Core). Used to keep lightning in
sync with chain activity.
2021-02-03 17:45:54 -08:00
Matt Corallo
e4b516dd8a
Merge pull request #768 from TheBlueMatt/2020-12-chanman-bindings-deser
Expose ChannelManager/Monitor read methods in bindings
2021-02-03 07:43:34 -08:00
Matt Corallo
5d045de8be [bindings] Fix genbindings.sh compile issues on OSX
There were two issues on OSX - we need to give gcc the clang
warnings flags because `gcc` *is* clang on OSX and we missed an
`-std=c++11` on one of the clang++ calls, causing compile failures.
2021-02-03 10:11:35 -05:00