Commit graph

268 commits

Author SHA1 Message Date
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
Matt Corallo
882db714de Make ChainWatchInterface::filter_block return only idxes, not refs
Instead of making the filter_block fn in the ChainWatchInterface
trait return both a list of indexes of transaction positions within
the block and references to the transactions themselves, return
only the list of indexes and then build the reference list at the
callsite.

While this may be slightly less effecient from a memory locality
perspective, it shouldn't be materially different.

This should make it more practical to generate bindings for
filter_block as it no longer needs to reference Rust Transaction
objects that are contained in a Rust Block object (which we'd
otherwise just pass over the FFI in fully-serialized form).
2020-06-23 16:12:55 -04:00
Valentine Wallace
f91718722a
Switch all feerate u64's to u32's.
The protocol only allows a u32, so if we received or sent something
larger it would be an issue (though it's unlikely).
2020-06-15 21:52:52 -04:00
Valentine Wallace
4c655b2281
Use our actual feerate in open_channel messages, not a new one
When we were sending an open_channel messages we were asking the
feerate estimator for a new value instead of using the one we had.
If the feerate estimator gave a different value than the one it did
when we created the Channel struct, we'd start out-of-sync with our
counterparty and blow up on funding_signed. Even worse, the
ConfirmationTarget used was different, so its highly likely they
would disagree.

Also remove newly unused fee estimator parameter from get_open-channel
API.

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2020-06-15 18:22:33 -04:00
Valentine Wallace
17ccab4f4a
Update chanmon fuzzer to include small payment actions.
This change should allow the fuzzer to catch more edge cases, such as
channel reserve checks that cut it close when sending payments.
2020-06-15 15:51:15 -04:00
Matt Corallo
2087032e7a
Merge pull request #620 from TheBlueMatt/2020-05-pre-bindings-cleanups
Pre-C Bindings Cleanup
2020-05-28 19:34:42 +00:00
Antoine Riard
2f4f0aa766 Extend KeysInterface with derive_channel_keys
A dynamic-p2wsh-output like `to_local` on local commitment/HTLC txn
require a signature from delayed_payment_key to be spend. Instead of
sending private key in descriptor, we ask for spender to derive again
the corresponding ChannelKeys based on key state, uniquely identifying
a channel and encompassing its unique start data.

Descriptor modification is done in next commit.
2020-05-28 04:21:46 -04:00
Matt Corallo
9d4b6e762c Return a ChannelManager instead of result from ChannelManager::new()
We never actually fail, so we can just drop the Result type.
2020-05-22 14:28:56 -04:00
Matt Corallo
fab5d7e0ae Make RoutingMessageHandler a generic Deref instead of an Arc
We also update to use single idents when referencing the Deref=*
types since the automated code generator is pretty braindead.

This also moves some test utils out of peer_handler.rs and into
util::test_utils to standardize things a little bit, which we need
to concretize the PeerHandler types used in testing.
2020-05-22 14:28:13 -04:00
Matt Corallo
6afda60d88 Make ManyChannelMonitor Keys an associated type
Instead of using a raw generic type, an associted type allows us
to have explicit docs on the type, which is nice. More importantly,
however, our automated bindings generator knows how to read
associated types but not raw generics.

Also, our bindings generator expects things which are referenced to
have already been defined, so we move ManyChannelMonitor below the
ChannelMonitor definition.
2020-05-22 13:59:14 -04:00
Matt Corallo
8ade071d56 Drop OutPoint::new since the struct is all pub
This makes it easier for our automated bindings generator to
function as it tries to automatically create a ::new if the struct
contains only pub elements who's type is convertible.
2020-05-17 23:24:41 -04:00
Valentine Wallace
222f0cbdd2
PeerManager Logger Arc --> Deref 2020-05-17 13:02:32 -04:00
Valentine Wallace
87126b391b
ChannelManager+Router++ Logger Arc --> Deref
This caused a bunch of cascading changes, including
passing loggers down to Channels in function calls
rather than having each Channel have a pointer to the
ChannelManager's Logger (which was a circular reference).
Other structs that the Channel had passed its Logger to also
had their loggers removed. Other newly unused Loggers were
also removed, especially when keeping them would've caused
a bunch of extra test changes to be necessary, e.g. with
the ChainWatchInterfaceUtil's Logger.
2020-05-17 12:33:43 -04:00
Matt Corallo
b1c80970e9 Fix some new indentation nits 2020-05-12 14:16:43 -04:00
Gleb Naumenko
e553d2c2c0 Split routing from getting network messages 2020-05-12 09:27:11 -04:00
Gleb Naumenko
5bd7f24634 Move router to a separate module 2020-05-12 09:27:11 -04:00
Matt Corallo
babf0af30b Require option_static_remotekey in channel/channelmonitor.
This simplifies channelmonitor quite nicely (as expected) as we
never have to be concerned with learning data in a DataLossProtect
which is require for us to claim our funds from the latest remote
commitment transaction.
2020-05-05 21:42:36 -04:00
Matt Corallo
9098240e34
Merge pull request #590 from jkczyz/2020-04-feature-flags
Features module improvements
2020-04-29 18:49:39 +00:00
Jeffrey Czyz
9dd2be15e9 Remove duplicate specification of features
Features for a given context are duplicated throughout the features
module. Use a macro for defining a Context and the applicable features
such that features only need to be defined for a Context in one place.
The Context provides bitmasks for selecting known and unknown feature
flags.

BOLT 1 and BOLT 9 refer to features as "known" if a peer understands
them. They also use the term "supported" to mean either optional or
required.

Update the features module to use similar terminology.
- Define contexts in terms of required and optional features rather than
  just supported features
- Define known features as those that are optional or required
- Rename supported() constructor to known()

For completeness, clear_optional_bit for each feature is now called
clear_bits and clears both optional and required bits.
2020-04-29 11:09:23 -07:00
Dr. Maxim Orlovsky
dde344a51d Adopting (W)PubkeyHash types 2020-04-29 12:37:57 +02:00
Dr. Maxim Orlovsky
27079e04d7 Adopting new bitcoin hash types and crate version 2020-04-29 12:37:46 +02:00
Dr. Maxim Orlovsky
eff8af2110 BDR: Linearizing secp256k1 deps 2020-04-28 16:17:44 +02:00
Dr. Maxim Orlovsky
4909d3cd6a Bitcoin deps refactoring (BDR): Linearizing bitcoin_hash deps 2020-04-28 16:17:42 +02:00
Matt Corallo
4dc0dd17c0
Merge pull request #579 from ariard/2020-04-sanitize-cltv-delay
Sanititze and document incoming HTLC cltv_expiry handling
2020-04-24 22:50:45 +00:00
Antoine Riard
886223a313 Sanitize outgoing HTLC cltv_value 2020-04-24 18:31:07 -04:00
Matt Corallo
ecb94689bf Include color when building fuzz targets in CI 2020-04-24 17:35:18 -04:00
Matt Corallo
764e6e71e3 Disable timeout for full_stack_target runs in CI
It seems we've recently been seeing sporadic long-running
full_stack_target cases when running honggfuzz in CI. These
shouldn't be killed (as its possible they hit an error or a deadlock,
especially since the longest-running tests probably have the most
coverage).
2020-04-24 16:56:20 -04:00