Commit graph

1998 commits

Author SHA1 Message Date
bmancini55
34271fb750 Add send message events for gossip_queries
This change enables initiating gossip queries with a peer using the
SendMessageEvent enum. Specifically we add an event for sending
query_channel_range to discover the existance of channels and an event
for sending query_short_channel_ids to request routing gossip messages
for a set of channels. These events are handled inside the process_events
method of PeerManager which sends the serialized message to the peer.
2020-12-09 15:02:22 -05:00
bmancini55
3220f3b182 Add gossip_queries messages to wire decoding
To enable gossip_queries message decoding, this commit implements the
wire module's Encoding trait for each message type. It also adds these
messages to the wire module's Message enum and the read function to
enable decoding of a buffer.
2020-12-01 17:18:24 -05:00
bmancini55
5af299e7d8 Add gossip_queries feature flag
Support for the gossip_queries feature flag (bits 6/7) is added to the
Features struct. This feature is available in the Init and Node
contexts. The gossip_queries feature is not fully implemented so this
feature is disabled when sent to peers in the Init message.
2020-12-01 17:18:24 -05:00
Matt Corallo
a008464417
Merge pull request #760 from TheBlueMatt/2020-11-0.0.12
Bump lightning-net-tokio crate version.
2020-11-24 15:19:11 -08:00
Matt Corallo
f3774050aa Bump lightning-net-tokio crate version. 2020-11-24 17:55:56 -05:00
Matt Corallo
773c2d1dc3
Merge pull request #759 from TheBlueMatt/2020-11-0.0.12
Bump version to 0.0.12
2020-11-24 14:14:16 -08:00
Matt Corallo
84716ff481
Merge pull request #758 from TheBlueMatt/2020-11-bindings-fix
Split `NetworkGraph` message handling fns into unsigned and signed (+update bindings)
2020-11-24 14:07:52 -08:00
Matt Corallo
ccd4a7acaa Update auto-generated bindings with new NetworkGraph API 2020-11-24 16:45:36 -05:00
Matt Corallo
4aa8e9cda7 Bump version to 0.0.12 2020-11-24 16:35:20 -05:00
Matt Corallo
3b6f7f1199 Split NetworkGraph message handling fns into unsigned and signed
This takes the now-public `NetworkGraph` message handling functions
and splits them all into two methods - one which takes a required
Secp256k1 context and verifies signatures and one which takes only
the unsigned part of the message and does not take a Secp256k1
context.

This both clarifies the public API as well as simplifies it, all
without duplicating code.

Finally, this adds an assertion in the Router fuzzer to make sure
the constants used for message deserialization are correct.
2020-11-24 16:33:33 -05:00
Matt Corallo
d9c03f26f9 Move UTXO-lookup into pub utility function from RoutingMsgHandler
This makes the public utility methods in `NetworkGraph` able to do
UTXO lookups ala `NetworkMsgHandler`'s `RoutingMessageHandler`
implementation, slightly simplifying the public interface.

We also take this opportunity to verify signatures before calling
out to UTXO lookups, under the "do actions in order of
cheapest-to-most-expensive to reduce DoS surface" principle.
2020-11-24 14:00:02 -05:00
Matt Corallo
9642356d9a Finally drop travis entirely.
It seems travis isn't even bothering to spawn our jobs anymore, and
Github CI has been pretty stable, so just drop Travis entirely.
2020-11-24 11:42:03 -05:00
Matt Corallo
fc7df54f8d
Merge pull request #748 from TheBlueMatt/2020-11-router-fuzzer
Make router_target a bit easier for fuzzers to explore and fix two found bugs
2020-11-24 08:36:14 -08:00
Matt Corallo
b56b4add6a [fuzz] Make router_target a bit easier for fuzzers to explore
It turns out (somewhat obviously) that expecting a fuzzer to
correctly build multiple signatures which verify against multiple
public keys in the same message was a bit too daunting, so we now
skip message signatures in routing messages.

We also take this opportunity to simplify the target itself somewhat,
avoiding reading public keys over and over and instead generating
routes to all the public keys that appeared in messages while running.
2020-11-24 11:04:11 -05:00
Matt Corallo
c53d8a3596 Expose manual-update methods in NetworkGraph.
These functions were created but previously not exported, however
they are useful if we want to skip signature checking when accepting
routing messages (which we really should be doing in the routing
fuzzer).
2020-11-24 11:04:11 -05:00
Matt Corallo
3c4a0c1fb3
Merge pull request #750 from TheBlueMatt/2020-11-dup-chan-id-crash
Do not generate a channel-closed mon update for never-signed chans
2020-11-23 14:28:11 -08:00
Matt Corallo
36063eeadc Don't create chan-closed mon update for outbound never-signed chans
Like the previous commit for channel-closed monitor updates for
inbound channels during processing of a funding_created message,
this resolves a more general issue for closing outbound channels
which have sent a funding_created but not yet received a
funding_signed.

This issue was also detected by full_stack_target.

To make similar issues easier to detect in testing and fuzzing, an
additional assertion is added to panic on updates to a channel
monitor before registering it.
2020-11-23 17:00:07 -05:00
Matt Corallo
22de94afdd Do not generate a channel-closed mon update for never-signed chans
The full_stack_target managed to find a bug where, if we receive
a funding_created message which has a channel_id identical to an
existing channel, we'll end up
 (a) having the monitor update for the new channel fail (due to
     duplicate outpoint),
 (b) creating a monitor update for the new channel as we
     force-close it,
 (c) panicing due to the force-close monitor update is applied to
     the original channel and is considered out-of-order.

Obviously we shouldn't be creating a force-close monitor update for
a channel which can never appear on chain, so we do that here and
add a test which previously failed and checks a few
duplicate-channel-id cases.
2020-11-23 17:00:07 -05:00
Matt Corallo
423073dfe5 [netgraph] Do not allow capacity_sats * 1000 to overflow-panic
In updating the router fuzzer, it discovered that a remote peer can
cause us to overflow while multiplying the channel capacity value.
Since the value should never exceed 21 million BTC, we just add a
check for that.
2020-11-23 13:52:51 -05:00
Matt Corallo
50b348c4fa [router] Fix + test routing via next/last-hop hints only
We had code in the router to support sending a payment via a single
hop across channels exclusively provided by the next-/last-hop hints.
However, in updating the fuzzer, I noted that this case not only
didn't work, but paniced in some cases.

Here, we both fix the panic, as well as write a new test which
ensures we don't break support for such routing in the future.
2020-11-23 13:52:51 -05:00
Matt Corallo
52673d480e
Merge pull request #749 from TheBlueMatt/2020-11-bindings-clones
Bindings Updates for #681 and more Clones
2020-11-23 10:43:09 -08:00
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