Commit graph

294 commits

Author SHA1 Message Date
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
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
Jeffrey Czyz
819a8653af
Move channelmonitor.rs from ln to chain module
Given the chain::Watch interface is defined in terms of ChannelMonitor
and ChannelMonitorUpdateErr, move channelmonitor.rs from the ln module
to the chain module.
2020-09-30 22:41:52 -07:00
Jeffrey Czyz
98bc46beb9
Replace WatchEventProvider with chain::Filter
WatchEventProvider served as a means for replacing ChainWatchInterface.
However, it requires users to explicitly fetch WatchEvents, even if not
interested in them. Replace WatchEventProvider by chain::Filter, which
is an optional member of ChainMonitor. If set, interesting transactions
and output spends are registered such that blocks containing them can be
retrieved from a chain source in an efficient manner.

This is useful when the chain source is not a full node. For Electrum,
it allows for pre-filtered blocks. For BIP157/158, it serves as a means
to match against compact filters.
2020-09-30 22:40:33 -07:00
Jeffrey Czyz
1599a13643
Remove ChainListener
BlockNotifier was removed in the previous commit, thus ChainListener is
no longer needed. Instead, anything needing chain events should be
notified directly.
2020-09-30 22:40:12 -07:00
Jeffrey Czyz
851283d9e5
Remove Key parameter from ChainMonitor
ChainMonitor's template Key parameter was meant to allow supporting
both local monitoring, where Key=OutPoint, and watchtowers, where Key=
(PublicKey, u32). Use OutPoint directly since the watchtower case will
not be supported this way.
2020-09-30 22:39:55 -07:00
Jeffrey Czyz
6662e959c8
Rename SimpleManyChannelMonitor to ChainMonitor
ManyChannelMonitor was renamed chain::Watch in the previous commit. Use
a more concise name for an implementation that monitors the chain for
channel activity. Future work will parameterize the struct to allow for
different varieties of persistence. Thus, users usually will be able to
use ChainMonitor directly rather than implementing a chain::Watch that
wraps it.
2020-09-30 22:39:55 -07:00
Jeffrey Czyz
801b775a7d
Replace ManyChannelMonitor with chain::Watch
Rename ManyChannelMonitor to chain::Watch and move to chain/mod.rs,
where chain-related interfaces live. Update the documentation for
clarity and to conform to rustdoc formatting.
2020-09-30 22:39:39 -07:00
Jeffrey Czyz
3ee6a27bc6
Replace ChainWatchInterface in NetGraphMsgHandler
ChainWatchInterface was intended as an interface for watching rather
than accessing the chain. Remove get_chain_utxo and add chain::Access
trait for this behavior. Wrap it with an Option in NetGraphMsgHandler in
order to simplify the error interface.
2020-09-30 22:39:38 -07:00
Jeffrey Czyz
87398be293
Remove ChainWatchInterface from channelmonitor.rs
Use of ChainWatchInterface was replaced with WatchEvent in the previous
commit. Remove it from the parameterization of SimpleManyChannelMonitor
since it is no longer needed.
2020-09-30 22:39:12 -07:00
Jeffrey Czyz
a7b2eb6d98
Remove ChainWatchInterface from BlockNotifier
ChainListeners should be independent of each other, but in practice this
is not the case because ChainWatchInterface introduces a dependency
between them. Push ChainWatchInterface down into the ChainListener
implementations where needed. Update ChainListener's block_connected
method to take a slice of the form &[(usize, &Transaction)] where each
transaction is paired with its position within the block.
2020-09-24 10:21:54 -07:00
Matt Corallo
343aacc50c
Merge pull request #684 from bmancini55/gossip_queries
Adding gossip_queries messages and serializations
2020-09-14 13:45:12 -07:00
bmancini55
10e818ac53 Adding fuzzers for gossip_queries messages
This commit adds ser/deser fuzzers for five new structs in ln::msgs used
for gossip_queries.
2020-09-14 16:19:32 -04:00
Antoine Riard
00d063df5c Overhaul ChannelMonitor/OnchainTxHandler to new nomenclature 2020-09-14 14:39:47 -04:00
Matt Corallo
b9707da138 Update to latest upstream rust-bitcoin 2020-09-10 16:20:01 -04:00
Matt Corallo
3defcc8962
Merge pull request #676 from TheBlueMatt/2020-08-c-bindings-cleanups-3
Pre-C-Bindings Cleanups #3
2020-08-26 08:14:34 -07:00
Matt Corallo
af69fae97b
Merge pull request #674 from TheBlueMatt/2020-08-keyif-rand-names
Simplify + clarify random-bytes-fetching from KeysInterface
2020-08-26 08:07:58 -07:00
Matt Corallo
2ff4ae782e Give ChannelManagerReadArgs HashMap-of-monitors ownership
Its somewhat awkward that ChannelManagerReadArgs requires a mutable
reference to a HashMap of ChannelMonitors, forcing the callsite to
define a scope for the HashMap which they almost certainly won't use
after deserializing the ChannelManager. Worse, to map the current
version to C bindings, we'd need to also create a HashMap binding,
which is overkill for just this one use.

Instead, we just give the ReadArgs struct ownership of the HashMap
and add a constructor which fills the HashMap for you.
2020-08-25 21:26:48 -04:00
Matt Corallo
de8c5dc76d Use slices to references not slices of concrete objects in pub API
Because the C bindings maps objects into new structs which contain
only a pointer to the underlying (immovable) Rust type, it cannot
create a list of Rust types which are contiguous in memory. Thus,
in order to allow C clients to call certain Rust functions, we have
to use &[&Type] not &[Type]. This commit fixes this issue for the
get_route function.
2020-08-25 17:09:51 -04:00
Valentine Wallace
ad18c4d853
Add commitment transaction broadcast as a ChannelMonitor event
To do this, we replace get_and_clear_pending_htlcs_updated with
get_and_clear_pending_monitor_events, and which still transmits HTLCUpdates
as before, but now also transmits a new MonitorEvent::CommitmentTxBroadcasted
event when a channel's commitment transaction is broadcasted.
2020-08-25 16:37:49 -04:00
Matt Corallo
6497465762 Simplify + clarify random-bytes-fetching from KeysInterface
Due to a desire to be able to override temporary channel IDs and
onion keys, KeysInterface had two separate fetch-random-32-bytes
interfaces - an onion-key specific version which fetched 2 random
32 byte strings and a temporary-channel-id specific version.

It turns out, we never actually need to override both at once (as
creating a new channel and sending an outbound payment are always
separate top-level calls), so there's no reason to add two
functions to the interface when both really do the same thing.
2020-08-23 19:39:59 -04:00
Matt Corallo
4395b92cc8 Relicense as dual Apache-2.0 + MIT
This changes the LICENSE file and adds license headers to most files
to relicense under dual Apache-2.0 and MIT. This is helpful in that
we retain the patent grant issued under Apache-2.0-licensed work,
avoiding some sticky patent issues, while still allowing users who
are more comfortable with the simpler MIT license to use that.

See https://github.com/rust-bitcoin/rust-lightning/issues/659 for
relicensing statements from code authors.
2020-08-10 21:12:44 -04:00
Gleb Naumenko
8b4f6e8861 Add htlc_maximum_msat field 2020-07-27 14:06:16 +03:00
Gleb Naumenko
b8fc761dc1 Update comment for test_msg_hole 2020-07-24 10:19:45 +03:00
Matt Corallo
5c370232eb Use usize for transaction-position-in-block values
We use them largely as indexes into a Vec<Transaction> so there's
little reason for them to be u32s. Instead, use them as usize
everywhere.

We also take this opportunity to add range checks before
short_channel_id calculation, as we could otherwise end up with a
bogus short_channel_id due to an output index out of range.
2020-06-23 16:12:55 -04:00
Matt Corallo
7fc07b39a6 Drop unused import in fuzz router.rs 2020-06-23 16:12:55 -04:00
Matt Corallo
bcd65bed7b Take &NetworkGraph as input in get_route, not a NetGraphMsgHandler
This was just an oversight when route calculation was split up into
parts - it makes no sense for get_route to require that we have a
full route message handler, only a network graph (which can always
be accessed from a NetGraphMsgHandler anyway).
2020-06-23 16:12:55 -04:00