Commit graph

419 commits

Author SHA1 Message Date
Matt Corallo
e6c922803f
Merge pull request #844 from sr-gi/843-ln-signing
Adds lightning message signing/verification/pk_recovery
2021-04-20 00:45:30 +00:00
Matt Corallo
7c9302f6a7
Fix a number of bugs in zbase32 and add a fuzzer which caught them. 2021-04-16 07:35:03 +02:00
Jeffrey Czyz
5610ca193d
Combine ChannelManager's block hash and height
There is a possible race condition when both the latest block hash and
height are needed. Combine these in one struct and place them behind a
single lock.
2021-04-14 12:57:04 -07:00
Matt Corallo
8088e4ba15
Merge pull request #856 from TheBlueMatt/2021-03-check-tx
Take the full funding transaction from the user on generation
2021-04-10 20:27:24 +00:00
Matt Corallo
3f2efcdfa7 Take the full funding transaction from the user on generation
Instead of relying on the user to ensure the funding transaction is
correct (and panicing when it is confirmed), we should check it is
correct when it is generated. By taking the full funding transaciton
from the user on generation, we can also handle broadcasting for
them instead of doing so via an event.
2021-04-09 19:59:06 -04:00
Matt Corallo
e23c270720
Merge pull request #838 from TheBlueMatt/2021-03-skip-blocks
Make `Channel`'s block connection API more electrum-friendly
2021-04-05 22:12:45 +00:00
Matt Corallo
47ad3d6bd8 Handle 1-conf funding_locked in channel no matter the event order
See comment in the diff for more details
2021-04-05 17:33:04 -04:00
Matt Corallo
c88b707ac2 Drop ChannelManager::block_disconnected() entirely
It is now entirely redundant with ChannelManager::update_best_block
and is still accessible via `Listen::block_disconnected`.
2021-04-05 17:33:04 -04:00
Matt Corallo
a15c8541dc Make the ChannelManager::block_connected API more electrum-friendly
See the similar commit that operates on `Channel`'s internal API
for more details on the reasoning.
2021-04-05 17:33:04 -04:00
Matt Corallo
d015ff250e Fix two new compiler warnings in fuzz
This fixes two trivial compiler warnings in fuzz that point to
broken usage of explicit `panic!()`s.
2021-03-30 23:21:54 -04:00
Matt Corallo
b2c5e3aedb Add assertions for in-order block [dis]connection in ChannelManager
Sadly the connected-in-order tests have to be skipped in our normal
test suite as many tests violate it. Luckily we can still enforce
it in the tests which run in other crates.

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2021-03-19 23:32:38 -04:00
Valentine Wallace
c318ad87e0
Expose counterparty forwarding info in ChannelDetails.
Useful for constructing route hints for private channels in invoices.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Antoine Riard <ariard@student.42.fr>
2021-03-17 17:36:26 -04:00
Matt Corallo
9e57364a89 Add an Option<>al InvoiceFeatures object for the payee in get_route
We currently only use it to override the graph-specific features
returned in the route, though we should also use it to enable or
disable MPP.

Note that tests which relied on MPP behavior have had all of their
get_route calls upgraded to provide the MPP flag.
2021-03-08 17:19:23 -05:00
Jeffrey Czyz
d28fa54edb
Parameterize ChannelManager::new with a block hash
When ChannelMonitors are persisted, they need to store the most recent
block hash seen. However, for newly created channels the default block
hash is used. If persisted before a block is connected, the funding
output may be missed when syncing after a restart. Instead, initialize
ChannelManager with a "birthday" hash so it can be used later when
creating channels.
2021-03-05 15:44:54 -08:00
Jeffrey Czyz
4cd2e4e94b
Revert "Merge pull request #819 from TheBlueMatt/2021-03-810-rebased"
This reverts commit 793de5fe69, reversing
changes made to 03a5189651.
2021-03-05 13:35:07 -08:00
Matt Corallo
4894d52d30 Merge pull request #646 from naumenkogs/2020-06-router-mpp
MPP on the router side
2021-03-02 20:33:08 -05:00
Valentine Wallace
7c8e740b6e Change ChannelMonitor deserialization to return an optional blockhash.
See previous commit msg for details.
2021-03-02 14:30:56 -05:00
Valentine Wallace
ee995a3a55 Change ChannelManager deserialization to return an optional blockhash
If the ChannelManager never receives any blocks, it'll return a default blockhash
on deserialization. It's preferable for this to be an Option instead.
2021-03-02 14:30:56 -05:00
Jeffrey Czyz
b0978a86be
Move ChannelMonitor state behind a Mutex
ChainMonitor accesses a set of ChannelMonitors behind a single Mutex.
As a result, update_channel operations cannot be parallelized. It also
requires using a RefCell around a ChannelMonitor when implementing
chain::Listen.

Moving the Mutex into ChannelMonitor avoids these problems and aligns it
better with other interfaces. Note, however, that get_funding_txo and
get_outputs_to_watch now clone the underlying data rather than returning
references.
2021-03-01 22:12:26 -08:00
Matt Corallo
ea48a5a089 Rebuild full_stack_target test vector for new secp256k1 fuzz req 2021-02-26 23:47:03 -05:00
Matt Corallo
33da665647 Use lowmemory mode for secp256k1 fuzzing, reducing memcpy time 2021-02-26 23:47:03 -05:00
Matt Corallo
4594f6eee5 Use rust-secp256k1 PR 282 and bitcoin_hashes PR 111 in fuzzing 2021-02-26 23:47:03 -05:00
Matt Corallo
a51d5cef58 Update rust-bitcoin 2021-02-26 15:15:18 -05:00
Matt Corallo
523fcb6f3f Change Persist's Sign from an associated type to a generic param 2021-02-19 16:04:19 -05:00
Matt Corallo
ff00f6f886 Rename ChannelKeys -> Sign and generic it consistently
The `ChannelKeys` object really isn't about keys at all anymore,
its all about signing. At the same time, we rename the type aliases
used in traits from both `ChanKeySigner` and `Keys` to just
`Signer` (or, in contexts where Channel isnt clear, `ChanSigner`).
2021-02-19 15:54:41 -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
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
f151c02975
Merge pull request #764 from lightning-signer/revoke-enforcement
Revocation enforcement
2021-01-25 09:06:43 -08:00
Devrandom
142b0d624e Let some tests disable revocation policy check
When simulating a bad actor that broadcasts a revoked tx, the policy check would otherwise panic.
2021-01-21 11:37:28 -08:00
Sergi Delgado Segura
821f6cdd1e
Makes ChannelManager::force_close_channel fail for unknown chan_ids
ChannelManager::force_close_channel does not fail if a non-existing channel id is being passed, making it hard to catch from an API point of view.

Makes force_close_channel return in the same way close_channel does so the user calling the method with an unknown id can be warned.
2021-01-21 16:12:57 +01:00
Devrandom
bd4345d6a2 Fix fuzzing issue with revocation 2021-01-18 17:59:43 -08:00
Matt Corallo
990d1de99a Use KeysInterface::read_chan_signer for all channel keys deser
This drops any direct calls to a generic `ChannelKeys::read()` and
replaces it with the new `KeysInterface::read_chan_signer()`. Still,
under the hood all of our own `KeysInterface::read_chan_signer()`
implementations simply call out to a `Readable::read()` implemention.
2021-01-04 12:40:40 -05:00
Matt Corallo
45d4d26987 Add a new method read_chan_signer to KeysInterface
This adds a new method to the general cross-channel `KeysInterface`
which requires it to handle the deserialization of per-channel
signer objects. This allows the deserialization of per-channel
signers to have more context available, which, in the case of the
C bindings, includes the actual KeysInterface information itself.
2021-01-04 12:40:40 -05:00
Matt Corallo
0f5580afd4 Use Writeable for ChannelMonitor instead of a specific function.
There's no reason to have ChannelMonitor::write_for_disk instead of
just using the Writeable trait anymore. Previously, it was used to
differentiate with `write_for_watchtower`, but support for
watchtower-mode ChannelMonitors was never completed and the partial
bits were removed long ago.

This has the nice benefit of hitting the custom Writeable codepaths
in C bindings instead of trying to hit trait-generics paths.
2021-01-04 12:40:40 -05:00
Gleb Naumenko
368c534679 Store available routing amounts per channel to use it in routing decisions 2020-12-24 13:04:47 +02:00
bmancini55
d183b975da Add genesis block hash to NetworkGraph
This changes adds the genesis block hash as a BlockHash to the
NetworkGraph struct. Making the NetworkGraph aware allows the message
handler to validate the chain_hash for received messages. This change
also adds the hash value to the Writeable and Readable methods.
2020-12-09 15:02:32 -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
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
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
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
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
9c3f3e76e5
Integrate Persist into ChainMonitor.
- The ChainMonitor should:
  Whenever a new channel is added or updated, these updates
  should be conveyed to the persister and persisted to disk.
  Even if the update errors while it's being applied, the
  updated monitor still needs to be persisted.
2020-10-16 11:30:34 -04: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
Jeffrey Czyz
51a5a1a50f
Move ln/channelmonitor.rs to chain/chainmonitor.rs 2020-10-01 08:50:15 -07:00