Commit graph

2197 commits

Author SHA1 Message Date
Valentine Wallace
3d4735cc0a
Don't include below-dust inbound HTLCs in commit tx fee calculation
Also remove part of the holding cell channel reserve test that's newly failing but
a bit of a redundant test anyway.
2021-02-18 13:09:17 -05:00
Matt Corallo
de58bcf271
Merge pull request #795 from TheBlueMatt/2021-02-features-bindings
Map Features objects in bindings
2021-02-18 09:54:59 -08:00
Matt Corallo
414e62230e
Merge pull request #789 from TheBlueMatt/2021-02-chansigner-util-fns
Add util fn for creating a Transaction from spendable outputs
2021-02-18 09:37:00 -08:00
Matt Corallo
954e66ed08 Update auto-generated bindings 2021-02-18 12:31:29 -05:00
Matt Corallo
0a9a7c5d73 [bindings] Silence c-bindings-gen compile warnings 2021-02-18 12:28:25 -05:00
Matt Corallo
6f5f27e901 [bindings] Handle impl Clone like impl ::core::clone::Clone 2021-02-18 12:28:25 -05:00
Matt Corallo
cdbe8333fa [bindings] Drop manual implementations of Features conversion
We now handle features properly in our own resolution, and these
appear to be self-inconsistent in some cases.
2021-02-18 12:28:25 -05:00
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
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