Commit graph

2036 commits

Author SHA1 Message Date
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
95d0fe99ee Rename output descriptor types for some clarity
Both Miron and Val suggested naming tweaks in their reviews, so
clarifying things some would be good.
2021-02-16 16:36:11 -05:00
Matt Corallo
8dbadd1045 Clarify docs on revocation_pubkey in DynamicP2WSHOutputDescriptor 2021-02-16 15:58:02 -05:00
Matt Corallo
0df01c140e Drop stale and cleanup TODO entries in keysinterface 2021-02-16 15:58:02 -05:00
Matt Corallo
72186db8a7 Switch to calling new KeysManager output-spending fn in tests 2021-02-16 15:58:02 -05:00
Matt Corallo
325a021903 Add util fn for creating a Transaction from spendable outputs
This adds a utility method, `KeysManager::spend_spendable_outputs`,
which constructs a Transaction from a given set of
`SpendableOutputDescriptor`s, deriving relevant keys as needed.

It also adds methods which can sign individual inputs where
channel-specific key derivation is required to
`InMemoryChannelKeys`, making it easy to sign transaction inputs
when a custom `KeysInterface` is used with `InMemoryChannelKeys`.
2021-02-16 15:58:02 -05:00
Matt Corallo
294cba45cc Add utility function to add a change output to a transaction 2021-02-16 15:58:02 -05:00
Matt Corallo
4552c3df48 Drop dup txn in test_dynamic_spendable_outputs_local_htlc_success_tx
Previously, test_dynamic_spendable_outputs_local_htlc_success_tx
called connect_block with two identical transactions, which
resulted in duplicate SpendableOutputs Events back-to-back. This
is a test issue as such a block_connected call represents an
invalid block.
2021-02-16 15:58:02 -05:00
Matt Corallo
c60812bffb Drop unused Network argument to KeysManager::new().
KeyManager::new() took a bitcoin::Network parameter which needs to
be passed to the BIP 32 Extended Key constructor, but because we
never write out the BIP 32 serialization, it isn't used. Instead,
we just pass a dummy value into `ExtendedPrivKey`, dropping the
unused argument to KeysManager::new().
2021-02-16 15:58:02 -05:00
Matt Corallo
e7784a6fa5 f fix typos val caught 2021-02-16 15:58:02 -05:00
Matt Corallo
a21decf0db Struct-ify SpendableOutputDescriptor entries relevant to channels
Both SpendableOutputDescriptor::DynamicOutputP2WSH and
SpendableOutputDescriptor::StaticOutputCounterpartyPayment are
relevant only in the context of a given channel, making them
candidates for being passed into helper functions in
`InMemoryChannelKeys`. This moves them into their own structs so
that they can later be used standalone.
2021-02-16 12:40:06 -05:00
Matt Corallo
311555a191 [tests] Correct witness len calc in StaticOutputCounterpartyPayment
We previously counted 35 bytes for a length + public key, but in
reality they are never larger than 34 bytes - 33 for the key and 1
for the push length.
2021-02-16 12:40:06 -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