Commit graph

1927 commits

Author SHA1 Message Date
Matt Corallo
9fe3124eb7 Use CARGO_PROFILE_RELEASE_LTO to fix bindings build on new cargo
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
2020-11-23 11:12:49 -05:00
Matt Corallo
722a366fe2 Update auto-generated bindings 2020-11-23 11:12:49 -05:00
Matt Corallo
66f46d4ad3 Update bindings demo for new ChannelMonitor-update API 2020-11-23 11:12:37 -05:00
Matt Corallo
d169966f76 [bindings] Update eq/clone trait fns to take object, not this_arg
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
2020-11-23 11:08:34 -05:00
Matt Corallo
d737111044 derive(Clone) for several pub simple data structs.
There is no reason not to and Clone can be useful especially in the
bindings context.
2020-11-23 11:08:34 -05:00
Matt Corallo
0362972d37 [bindings] Expose a _clone fn for every enum
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
2020-11-23 11:08:34 -05:00
Matt Corallo
29b209ceea [bindings] Expose a _clone fn for every struct that derive(Clone)s 2020-11-23 11:08:34 -05:00
Matt Corallo
faa8ec5c21 [bindings] Fix CVecTempl clone operation behavior.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
2020-11-23 11:08:34 -05:00
Matt Corallo
336cb0828a Update bindings demo for new Transaction::data mut-ness 2020-11-23 11:08:34 -05:00
Matt Corallo
78b4598ff6 [bindings] Make Transaction::data *mut instead of *const
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
2020-11-23 11:08:34 -05:00
Matt Corallo
90b668e426 Update bindings demo for changes from #681 and the Persister trait 2020-11-23 11:08:34 -05:00
Matt Corallo
304471b1c1 [bindings] Support traits with generic arguments (to support #681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in #681.

This adds minimal support for it, fixing code generation on latest
upstream.
2020-11-23 11:08:34 -05:00
Matt Corallo
8f10a1d33d
Merge pull request #753 from TheBlueMatt/2020-11-chanmon_consistency-bits
Tweak and Expand the chanmon_consistency fuzz target
2020-11-23 08:04:45 -08:00
Matt Corallo
6563f7aa5c [fuzz] Check that channels don't get stuck in chanmon_consistency
This adds a new command string in the chanmon_consistency fuzzer
which tests that, once all pending HTLCs are settled, at least one
side of a channel can still send funds.

While this should have caught the recent(ish) spec bug where
channels could get stuck, I did not attempt to reproduce said bug
with this patch.
2020-11-21 12:11:56 -05:00
Matt Corallo
63d4365702 [fuzz] Don't allow HandleError in chanmon_consistency
We should never generate Ignore-action HandleError events anymore
2020-11-21 12:11:56 -05:00
Matt Corallo
943153530d [fuzz] Reduce overuse of macros/Arcs in chanmon_consistency
In previous versions of related commits, the macros in
chanmon_consistency ended up blowing up rustc a bit resulting in
20+GB memory usage and long compile times. Shorter function bodies
by avoiding macros where possible fix this.
2020-11-21 12:11:23 -05:00
Matt Corallo
71d22f7e06 [fuzz] Expand the amounts we can send in chanmon_consistency
This should make it a bit easier for the fuzzer to hit any given
balance breakdown during run as well as tweaks the command strings
to be more bit-pattern friendly.
2020-11-21 12:11:23 -05:00
Matt Corallo
acf68eddef [fuzz] Test chanmon_consistency payment-send errors are sane
Instead of simply always considering a payment-send failure as
acceptable (and aborting fuzzing), we check that a payment send
failure is from a list of errors that we know we can hit, mostly
around maxing out our channel balance.

Critically, we keep going after hitting an error, as there's no
reason channels should get out of sync even if a send fails.
2020-11-21 12:10:24 -05:00
Matt Corallo
4e82003261
Merge pull request #611 from valentinewallace/fix-missing-htlc-claim
Tell ChannelMonitors about HTLCs fulfilled after channel close
2020-11-16 18:15:02 -08:00
Valentine Wallace
6f1a0bf0e4
Claim HTLC output on-chain if preimage is recv'd after force-close
If we receive a preimage for an outgoing HTLC that solves an output on a
backwards force-closed channel, we need to claim the output on-chain.

Note that this commit also gets rid of the channel monitor redundantly setting
`self.counterparty_payment_script` in `check_spend_counterparty_transaction`.

Co-authored-by: Antoine Riard <ariard@student.42.fr>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2020-11-16 15:41:31 -05:00
Valentine Wallace
e70f485011
Split channelmonitor's broadcast_by_holder_state
Now callers will separately retrieve the claim requests/
holder revokable script and the new watched holder outputs.
This will be used in the next commit for times when we
need to get holder claim requests, but don't have access to
the holder commitment transaction.
2020-11-16 15:41:31 -05:00
Valentine Wallace
a3e4f9c967
Extend update_monitor logging
Helpful for debugging. I also included the change in the provide_preimage method
signature which will be used in an upcoming commit, because commit-wise it was
easier to combine the changes.
2020-11-16 15:41:30 -05:00
Valentine Wallace
4ece5fd0f6
Update monitor with preimage after channel close
If the channel is hitting the chain right as we receive a preimage,
previous to this commit the relevant ChannelMonitor would never
learn of this preimage.
2020-11-16 15:41:28 -05:00
Valentine Wallace
50ad627426
Add prev_channel_outpoint to previous hop data
This will be used in upcoming commits to allow us to update a channel
monitor with a preimage after its channel has closed.
2020-11-12 18:52:06 -05:00
Matt Corallo
23a1d7aab5
Merge pull request #721 from TheBlueMatt/2020-09-649-bindings
Bindings Updates for #649
2020-11-12 13:22:54 -08:00
Matt Corallo
3aa0253f8a
Merge pull request #745 from ariard/2020-11-getting-started
Add a Getting Started in CONTRIBUTING.md
2020-11-12 09:59:07 -08:00
Matt Corallo
68827199a2
Merge pull request #746 from valentinewallace/remove-todo
Remove unnecessary todo
2020-11-10 08:34:19 -08:00
Antoine Riard
7e7635d559 Add a Getting Started
Fix by Steve Lee <moneyball@users.noreply.github.com>
2020-11-09 15:53:36 -05:00
Valentine Wallace
8e7b29160b
Remove unnecessary todo
The ChannelMonitor already monitors the chain for counterparties
revealing preimages, and will give the HTLCSources back to the
ChannelManager for claiming. Thus it's unnecessary for the ChannelManager
to monitor these HTLCs itself.

See is_resolving_htlc_output:
- if the counterparty broadcasted and then claimed one of the HTLCs we
  offered them, line 2015 is where the ChannelMonitor gives the ChannelManager
  the HTLC source
- if we broadcasted and they claimed an HTLC we offered them, line 2025 is
  where the ChannelMonitor gives the ChannelManager the HTLC source
2020-11-08 17:22:20 -05:00
Matt Corallo
5988789a2d [bindings] update generated code 2020-10-21 14:54:51 -04:00
Matt Corallo
7e18104414 Update demo.cpp for new tuple code 2020-10-21 14:54:51 -04:00
Matt Corallo
2d0cdbd33e [bindings] Un-Box Tuple mapping
Because the C++ wrappers require being able to memset(0) the C
structs to skip free(), we'd previously mapped tuples with two
pointer indirections. However, because all other types already
support memset(0)'ing to disable free() logic, we can skip the
pointer indirections and the behavior is still correct.
2020-10-21 14:54:51 -04:00
Matt Corallo
65884fffee [bindings] Fix typo in opaque struct docs found by Val 2020-10-21 14:54:51 -04:00
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
9c7c3b9921
Merge pull request #681 from valentinewallace/data-persister-refactor
Add ChannelDataPersister trait and point ChainMonitor to it.
2020-10-16 14:35:33 -07:00
Valentine Wallace
cda8fb7f6f
Fix clippy 2020-10-16 13:41:40 -04:00
Valentine Wallace
fc68afb21b
Rename ChannelMonitor::write_for_disk --> serialize_for_disk
This function does not necessarily write to disk, it can serialize to anything
that implements Writer.
2020-10-16 13:41:39 -04:00
Valentine Wallace
a8e82cb3fb
Test that Persist temp and perm failures behave as expected.
If a persister returns a temporary failure, the channel monitor should be able
to be put on ice and then revived later. If a persister returns a permanent
failure, the channel should be force closed.
2020-10-16 13:41:39 -04:00