Commit graph

1732 commits

Author SHA1 Message Date
Matt Corallo
e12215ca8a [bindings] Use the same SipHash keys to make C++ header stable 2020-10-21 14:54:51 -04:00
Matt Corallo
35e48cf479 [bindings] Use enum to describe deref'ing needed for Option<> inners 2020-10-21 14:54:51 -04:00
Matt Corallo
d773151e7f Update bindings to latest upstream code 2020-10-21 14:54:51 -04:00
Matt Corallo
353e29aedd Drop the now-unused usizeslice bindings struct 2020-10-21 14:50:22 -04:00
Matt Corallo
a5e7671d1e Update bindings demo apps for new code upstream 2020-10-21 14:50:22 -04:00
Matt Corallo
2342550af5 Move a struct in bindings up to define it before it is used
This is a limitations in the bindings crate, but not one that's
going to be fixed right now.
2020-10-21 14:50:22 -04:00
Matt Corallo
6df3aa76c3 [bindings] Drop one static-lifetime restriction and check success
In general we should stop enforcing that all lifetimes are static
- we may take references from C and its up to reviewing the diff on
the bindings changes and the user(s) to ensure lifetimes are valid.

Also asserts a success criteria that was missed before.
2020-10-21 14:50:22 -04:00
Matt Corallo
4d0cf680ab [bindings] Handle type X = Y aliasing in type resolution
For non-generic type aliases which are meant as convinient aliases
for more complex types, we need to store the aliased type (with all
paths made absolute) and use that in type resolution.

The most code by far is just making all the paths in a type absolute
but its not too bad either.
2020-10-21 14:50:22 -04:00
Matt Corallo
00fb152758 [bindings] Handle ::-prefixed paths in a few places 2020-10-21 14:50:22 -04:00
Matt Corallo
eb7faa85e4 [bindings] Remove some uneccessary no-multi-ident path restrictions 2020-10-21 14:50:22 -04:00
Matt Corallo
bb4115effd [bindings] Avoid guessing whether resolved type is a ref in blocks
In some cases, things which are a Rust Reference (ie slices), we
may still want to map them as a non-reference and need to put a
"mut " in front of the variable name in a function decl. This
worked fine by just checking for the slice case, except that we
are about to add support for type aliases, which no longer match
the naive case.

Instead, we can just have the types module print out the C type and
check if it begins with a '&' to figure out if it is a reference.
2020-10-21 14:50:22 -04:00
Matt Corallo
a14e63e0b3 [bindings] Support mapping slices which contain tuples (with refs)
New work upstream puts tuples in slices, which is a very reasonable
thing to expect, however we don't know how to generate conversions
for such objects. Making it more complicated, upstream changes also
include references to things inside such slices, which requires
special handling to avoid creating dangling references.

This adds support for converting such objects, noting that slices
need to be converted first into Vecs which own their underlying
objects and then need to map any reference types into references.
2020-10-21 14:50:22 -04:00
Matt Corallo
d9a38d1846 [bindings] Give Transaction objects a buffer-is-owned flag.
A lot of our container mapping depends on the `is_owned` flag
which we have for in-crate mapped objects to map references and
non-references into the same container type. Transaction was
mapped to two completely different types (a slice and a Vec type),
which led to a number of edge cases in the bindings generation.
Specifically, I spent a few days trying to map
`[(A, &Transaction)]` properly and came up empty - we map slices
into the same types as Vecs (and rely on the `is_owned` flag to
avoid double-free) and the lack of one for `Transaction` would have
required a special-case in numerous functions.

Instead, we just add a flag in `Transaction` to mirror what we do
for in-crate types and check it before free-ing any underlying
memory.

Note that, sadly, because the c_types objects aren't mapped as a
part of our C++ bindings generation, you have to manually call
`Transaction_free()` even in C++.
2020-10-21 14:50:22 -04:00
Matt Corallo
0719f9af00 [bindings] Add support for Option<T> where T is a mapped trait
When mapping an `Option<T>` where T is a mapped trait, we need to
move out of the `*mut T`, however the current generation results in
a `*const T` and a conversion that just takes a reference to the
pointed-to object. This is because the only place this code was
previously used was for slices, which *do* need a reference.

Additionally, we need to know how to convert `Option` containers
which do not contain an opaque type.

Sadly, the easiest way to get the desired result is to add another
special case in container mapping, keeping the current behavior for
slices, but moving out of the pointed-to object for other types.
2020-10-12 12:17:26 -04:00
Matt Corallo
36e732879a Ignore cbindgen version in latest-bindings-in-git check.
Currently the check_binidngs GitHub CI job always fails when there
is a new cbindgen release because the cbindgen version is in the
generated header file. When the new version doesn't change the
generated header except for the version number, we should ignore
the difference.
2020-10-12 12:17:26 -04:00
Matt Corallo
a1d0dde507 [bindings] Use == null() instead of is_null() to avoid ambiguity
When we have a `Trait` wrapped as an `Option<Trait>`, we called
`<*const Trait>.is_null()` which resulted in rustc trying to take
the most braindead option of dereferencing the whole thing and
hitting a recursive dereference since we
`impl Deref<Target=Trait> for Trait` for all our traits.

Instead, we can be explicit and just compare the pointer directly
with `std::ptr::null()` which avoids this.
2020-10-12 12:17:26 -04:00
Matt Corallo
fe279c4034 [bindings] Include a GenericTypes context in more places
A few places got a None in the previous commit to avoid increasing
the diff size. However, it makes sense to have GenericTypes contexts
there, so we pipe them through the neccessary places.
2020-10-12 12:17:26 -04:00
Matt Corallo
8a2513f84b [bindings] Push generic resolution into resolve_path
Like the previous commit pushing into maybe_resolve_path, this
makes generic resolution a part of type resolution everywhere.
2020-10-12 12:17:26 -04:00
Matt Corallo
b7f7aba2e7 [bindings] Push generic resolution into maybe_resolve_path
This pushes down the logic to check if a given Path is, in fact,
a reference to a generic into the common maybe_resolve_path instead
of doing it redundantly in a few different places. Net loss of LoC.
2020-10-12 12:17:26 -04:00
Matt Corallo
16b9309e7c Support use ident; in bindings
Somehow we'd never had any cases of it and it requires an extra
(trivial) match arm.
2020-10-12 12:17:26 -04:00
Matt Corallo
8b8a97c6aa Add README note about key validity assertions at the FFI boundary 2020-10-12 12:17:26 -04:00
Matt Corallo
df778b605a
Merge pull request #738 from TheBlueMatt/2020-10-opt-test
Fix passing -O1 to build from `cargo test`
2020-10-10 15:21:11 -07:00
Matt Corallo
04dbf1f2ba
Merge pull request #740 from rloomba/rloomba/trivial-clippy-fixes
trivial clippy warning fixes
2020-10-09 08:29:56 -07:00
Ryan Loomba
c8e49aa398 trivial changes to fix clippy::write_with_newline warnings 2020-10-08 16:06:03 -07:00
Matt Corallo
52121ea97e
Merge pull request #739 from rloomba/rloomba/add-clippy-to-travis
Add clippy to Travis integration
2020-10-08 11:21:00 -07:00
Ryan Loomba
262172cddb add linting to Github CI 2020-10-08 10:47:49 -07:00
Ryan Loomba
426c5b227d add clippy to travis integration 2020-10-08 09:59:52 -07:00
Ryan Loomba
1276cc72de fix all clippy::redundant_field_names warnings 2020-10-07 11:20:21 -07:00
Matt Corallo
e808d50b9d Fix passing -O1 to build from cargo test
In 9e03087d6a we started setting
`opt-level` only on profile.test and not profile.dev. When that
commit was authored I tested only that rustc was being called with
opt-level set in its flags, not that the resulted run ran at the
speed I expected. It seems profile.test isn't applied properly to
dependencies or so, resulting in tests running much slower than
they do at profile.dev.opt-level=1.
2020-10-05 14:24:41 -04:00
Matt Corallo
f35a5ce659
Merge pull request #734 from TheBlueMatt/2020-10-ci-no-git-conf
Don't let CI fail to check commits b/c git isn't configured in CI
2020-10-05 10:27:35 -07:00
Matt Corallo
856648614e
Merge pull request #722 from TheBlueMatt/2020-09-broken-fn
Drop the redundant/broken `ChannelMonitor::get_monitored_outpoints`
2020-10-05 09:50:08 -07:00
Matt Corallo
8e99800329 Drop now-unused Vec of outpoints in remote-commitment-tx-tracking
This nearly fully reverts 6f08779b04,
removing the extra data storage that it added.
2020-10-05 12:19:41 -04:00
Matt Corallo
a162840ffd Drop the redundant/broken ChannelMonitor::get_monitored_outpoints
In review of the final doc changes in #649, I noticed there
appeared to be redundant monitored-outpoints function in
`ChannelMonitor` - `get_monitored_outpoints()` and
`get_outputs_to_watch()`.

In 6f08779b04,
get_monitored_outpoints() was added, with its behavior largely the
same as today's - only returning the set of remote commitment txn
outputs that we've learned about on-chain. This is clearly not
sufficient, and in 73dce207dd,
`get_outputs_to_watch` was added which was overly cautious to
ensure nothing was missed. Still, the author of 73dce207dd
(me) seemed entirely unaware of the work in 6f08779b04
(also me), despite the function being the literal next function in
the same file. This is presumably because it was assumed that
`get_monitored_outpoints` referred to oupoints for which we should
monitor for spends of (which is true), while `get_outputs_to_watch`
referred to outpouts which we should monitor for the transaction
containing said output (which is not true), or something of that
nature. Specifically, it is the expected behavior that the only
time we care about `Filter::register_tx` is for the funding
transaction (which we aren't aware of the inputs of), but for all
other transactions we register interest on the basis of an outpoint
in the previous transaction (ie via `Filter::register_output`).

Here we drop the broken-on-day-one `get_monitored_outpoints()`
version, but assert in testing that the values which it would return
are all present in `get_outputs_to_watch()`.
2020-10-05 12:19:41 -04:00
Matt Corallo
45a558b170
Merge pull request #716 from TheBlueMatt/2020-09-fee-tests
(Fix and) Test that txn pay at least a minimum relay fee in functional tests
2020-10-05 09:18:51 -07:00
Matt Corallo
3219926258 Test that txn pay at least a minimum relay fee in functional tests
This also pays a fee on the transactions we generate in response to
SpendableOutputDescriptors in tests.

This fixes the known issues in #630, though we should test for
standardness in other ways as well.
2020-10-05 11:54:24 -04:00
Matt Corallo
b43a7e3ef3 Fix feerate calculation on closing transactions
This resolves a number of bugs around how we calculate feerates on
closing transactions:

 * We previously calculated the weight wrong both by always
   counting two outputs instead of counting the number of outputs
   that actually exist in the closing transaction and by not
   counting the witness redeemscript.
 * We use assertions to check the calculated weight matches what we
   actually build (with debug_assertions for variable-length sigs).
 * As an additional sanity check, we really should check that the
   transaction had at least min-relay-fee when we were the channel
   initator.
2020-10-05 11:32:30 -04:00
Matt Corallo
6366fc7154 Fix max fee_satoshis constant to be 21 million, not 2.1 million.
Though hopefully we never see a fee of 2.1 million BTC, either...
2020-10-05 11:32:30 -04:00
Matt Corallo
89e40fe224 Don't let CI fail to check commits b/c git isn't configured in CI
This fixes #733 by just setting a dummy git name/email before
calling `git rebase` in CI.
2020-10-02 16:37:37 -04:00
Matt Corallo
937d1d8bae
Merge pull request #731 from TheBlueMatt/2020-10-fix-big-lock
Actually hold the total_consistency_lock instead of take-and-drop
2020-10-02 11:53:48 -07:00
Matt Corallo
7d38c2530a
Merge pull request #730 from TheBlueMatt/2020-09-no-rescan
Drop last bits of rescan as its too complicated to be worth having
2020-10-02 11:22:44 -07:00
Matt Corallo
ddebf36eae Actually hold the total_consistency_lock instead of take-and-drop
It was noticed (via clippy) by @casey that we were taking and then
immediately dropping the total_consistency_lock because `let _ =`
doesn't actually bind the response to anything. This appears to be
a consequence of wanting `if let Some(_) =` to not hold a ref to
the contained value at all, but is relatively surprising to me.
2020-10-02 12:51:25 -04:00
Matt Corallo
2bd571d2f9 Drop last bits of rescan as its too complicated to be worth having
Previously, we had a concept of "rescaning" blocks when we detected
a need to monitor for a new set of outputs in future blocks while
connecting a block. In such cases, we'd need to possibly learn about
these new spends later in the *same block*, requiring clients who
filter blocks to get a newly-filtered copy of the same block. While
redoing the chain access API, it became increasingly clear this was
an overly complicated API feature, and it seems likely most clients
will not use it anyway.

Further, any client who *does* filter blocks can simply update their
filtering algorithm to include any descendants of matched
transactions in the filter results, avoiding the need for rescan
support entirely.

Thus, it was decided that we'd move forward without rescan support
in #649, however to avoid significant further changes in the
already-large 649, we decided to fully remove support in a
follow-up.

Here, we remove the API features that existed for rescan and fix
the few tests to not rely on it.

After this commit, we now only ever have one possible version of
block connection transactions, making it possible to be
significantly more confident in our test coverage actually
capturing all realistic scenarios.
2020-10-02 12:36:46 -04:00
Matt Corallo
b627aa6e7c Drop stale comment about a rescan that doesn't happen in tests 2020-10-02 12:36:46 -04:00
Matt Corallo
e48f8e3f33
Merge pull request #729 from casey/readme
Add content to readme
2020-10-02 09:02:15 -07:00
Matt Corallo
1c118ed371 Fix capitalization Gleb suggested 2020-10-02 11:16:22 -04:00
Casey Rodarmor
dbda949b69
Clarify that lightning-net-tokio does networking only 2020-10-01 20:55:31 -07:00
Casey Rodarmor
7c07ca0056
Reword first paragraph and add tagline 2020-10-01 20:28:41 -07:00
Casey Rodarmor
0393b00478
Add content to readme
- Change header to "Rust-Lightning"
- Add crate and documentation badges
- Add introductory paragraph
- Move previous intro content under "Status" heading
2020-10-01 19:36:17 -07:00
Matt Corallo
8fb4a3ddc2
Merge pull request #649 from jkczyz/2020-06-refactor-chain-listener
Refactor chain monitoring
2020-10-01 11:10:13 -07:00
Jeffrey Czyz
6cd6816cd7
Merge branch '2020-06-refactor-chain-listener-move-chainmonitor' into 2020-06-refactor-chain-listener 2020-10-01 09:35:05 -07:00