Commit graph

1476 commits

Author SHA1 Message Date
Matt Corallo
c1dc8e39a7
Merge pull request #534 from TheBlueMatt/2020-02-fuzz-on-stable
[travis] Build lightning-net-tokio on Rust 1.39.0+, fuzz on stable
2020-03-04 19:28:23 +00:00
Matt Corallo
c5fb57269f [travis] Build lightning-net-tokio on Rust 1.39.0+, fuzz on stable
This disables building the lightning-net-tokio crate on 1.34.2 on
Travis in anticiption of relying on async/await for
lightning-net-tokio, with the nice side-effect of reducing the
amount of work done on our slowest Travis job.

This also adds 1.39.0 to Travis as that is the new MSRV for
lightning-net-tokio and uses that for codecov generation.

This also moves fuzzing to Rust stable, as honggfuzz broke its MSRV
and it seems likely it will again in the future.
2020-03-04 13:47:25 -05:00
Matt Corallo
27426f84c0
Merge pull request #517 from ccdle12/2020-02-per-channel-config
Add an override optional UserConfig per new outbound channel
2020-02-29 03:10:54 +00:00
Matt Corallo
ce4de5fb52
Merge pull request #507 from moneyball/patch-2
Add project tracking and conventions we want to adopt
2020-02-29 02:59:34 +00:00
Steve Lee
0c5e3510d7
made fixes per val and matt feedback 2020-02-28 17:01:16 -08:00
Christopher Coverdale
53c894bcaa Add an override optional UserConfig per new outbound channel 2020-02-28 22:58:26 +00:00
Matt Corallo
b06dfda7ef
Merge pull request #520 from TheBlueMatt/2020-02-events-in-monitors
Move events into ChannelMonitor from ManyChannelMonitor
2020-02-28 20:10:38 +00:00
Matt Corallo
9ff6f29074 Add comment noting that ChannelMonitor events are serialized 2020-02-28 14:36:02 -05:00
Matt Corallo
0ebf70d6a2 Drop stale doc comment + TODO describing MessageSendEvents 2020-02-28 14:36:02 -05:00
Matt Corallo
26008bbc0b Move events into ChannelMonitor from ManyChannelMonitor
This is the next step after "Move pending-HTLC-updated ChannelMonitor
from ManyChannelMonitor", moving our events into ChannelMonitor as
well and leaving only new-outputs-to-watch in the return value for
ChannelMonitor::block_connected (which is fine as those are
duplicatively tracked in the ChannelMonitor directly, so
losing/replaying them is acceptable).
2020-02-28 14:36:02 -05:00
Matt Corallo
bfd4ac4995 Implement Readable/Writeable for Events
As noted in the docs, Events don't round-trip fully, but round-trip
in a way that is useful for ChannelManagers, specifically some events
don't make sense anymore after a restart.
2020-02-28 14:36:02 -05:00
Matt Corallo
8829d1b80f
Merge pull request #522 from valentinewallace/chanmgr-fee-est-arc-to-deref
Update ChannelManager's FeeEstimator from Arc to Deref.
2020-02-28 19:08:43 +00:00
Matt Corallo
80a0d15648
Merge pull request #521 from TheBlueMatt/2020-02-ping-connection-possible
Dont treat a timer tick as no_connection_possible
2020-02-27 21:12:23 +00:00
Matt Corallo
de24150203 Dont treat a timer tick as no_connection_possible and log
In testing, due to other patches, I managed to flood the send queue
with messages and cause us not to be able to send pings, thus
getting a peer disconnected for ping timeout. To my surprise, this
also force-closed all of my channels with that peeer.

Obviously a ping timeout does not indicate that no future connection
with said peer will be possible, and we shouldn't be force-closing
channels as a result.

This also logs when a peer is disconnected to ping timeout to make
debug easier.
2020-02-27 15:46:52 -05:00
Matt Corallo
440129c6b6 Add logging on receipt of unknown message types.
This should make peer disconnection easier to debug.
2020-02-27 15:46:31 -05:00
Valentine Wallace
f5b5bf2acb
Update ChannelManager's FeeEstimator from Arc to Deref. 2020-02-27 15:27:58 -05:00
Matt Corallo
f328094b49
Merge pull request #518 from valentinewallace/chanmgr-keysmgr-arc-to-deref
multi: update ChannelManager's keys manager from Arc to Deref
2020-02-27 19:29:35 +00:00
Valentine Wallace
bff9982299
multi: update ChannelManager's keys manager from Arc to Deref 2020-02-27 11:55:18 -05:00
Matt Corallo
030c49cf78
Merge pull request #489 from TheBlueMatt/2020-02-chan-updates
Move to a Monitor-Update return from copying around ChannelMonitors
2020-02-27 01:03:28 +00:00
Matt Corallo
08db88c673 Drop TODO which was implemented long ago 2020-02-26 19:15:32 -05:00
Matt Corallo
ab7a0a5431 Drop Clone from ChannelMonitor.
This removes the somewhat-easy-to-misuse Clone from ChannelMonitors,
opening us up to being able to track Events in ChannelMonitors with
less risk of misuse.

Sadly it doesn't remove the Clone requirement for ChannelKeys,
though gets us much closer - we now just need to request a second
copy once when we go to create the ChannelMonitors.
2020-02-26 19:15:32 -05:00
Matt Corallo
3e26bd7a1d Rm ChannelMonitor merge capabilities in favor of explicit add/update
This removes the ability to merge ChannelMonitors in favor of
explicit ChannelMonitorUpdates. It further removes
ChannelManager::test_restore_channel_monitor in favor of the new
ChannelManager::channel_monitor_updated method, which explicitly
confirms a set of updates instead of providing the latest copy of
each ChannelMonitor to the user.

This removes almost all need for Channels to have the latest
channel_monitor, except for broadcasting the latest local state.
2020-02-26 19:15:32 -05:00
Matt Corallo
6caed7df7c Create ChannelMonitors with basic_channel_info and funding_info set
This removes most of the reliance on ChannelMonitor Clone, creating
them in Channel only at the time when we need to start monitoring
the chain.
2020-02-26 19:15:32 -05:00
Matt Corallo
f930fc1886 Use ChannelMonitorUpdate in fallen-behind handling during reestablish
This is a rather huge diff, almost entirely due to removing the
type parameter from ChannelError which was added in
c20e930b31 due to holding the
ChannelKeys in ChannelMonitors.
2020-02-26 19:15:32 -05:00
Matt Corallo
537bd357f9 Set ChannelMonitor basic_channel_info on funding, not on accept
This prepares for only creating the ChannelMonitor on funding by
removing any channel_monitor calls from Channel open/accept-time to
funding-signed time.
2020-02-26 19:15:32 -05:00
Matt Corallo
df5053d396 Use ChannelMonitorUpdates in commitment signing fns in Channel
This is a rather big step towards using the new ChannelMonitorUpdate
flow, using it in the various commitment signing and commitment
update message processing functions in Channel. Becase they all
often call each other, they all have to be updated as a group,
resulting in the somewhat large diff in this commit.

In order to keep the update_ids strictly increasing by one for
ease of use on the user end, we have to play some games with the
latest_monitor_update_id field, though its generally still pretty
readable, and the pattern of "get an update_id at the start, and
use the one we got at the start when returning, irrespective of
what other calls into the Channel during that time did" is
relatively straightforward.
2020-02-26 19:15:32 -05:00
Matt Corallo
569f9038be Impl (de)serialization for bitcoin::Transaction.
There is little risk of misusing this as there's not much in the
way of other ways you may want to serialize bitcoin::Transaction
2020-02-26 19:15:32 -05:00
Matt Corallo
8c69bb11b8 Update Channel::funding_signed to use ChannelMonitorUpdate
This is the first of several steps to update ChannelMonitor updates
to use the new ChannelMonitorUpdate objects, demonstrating how the
new flow works in Channel.
2020-02-26 19:15:32 -05:00
Matt Corallo
3b277cc394 Add types for updating ChannelMonitors without copying them.
This is the first step in migrating ChannelMonitor updating logic
to use incremental Update objects instead of copying the
ChannelMonitors themselves and insert_combine()ing them.

This adds most of the scaffolding and updates relevant comments to
refer to the new architecture, without changing how any actual
updates occur.
2020-02-26 19:15:32 -05:00
Matt Corallo
d271d74bc7 Use Channel::funding_txo instead of its channel_monitor.funding_txo
Currently Channel relies on its own internal channel_monitor copy
to keep track of funding_txo information, which is both a bit
awkward and not ideal if we want to get rid of the ChannelMonitor
copy in Channel.

Instead, just duplicate it (its small) and keep it directly in
Channel, allowing us to remove the (super awkward)
ChannelMonitor::unset_funding_txo().
2020-02-26 17:48:31 -05:00
Matt Corallo
6296eb1c5f Track counterparty's commitment secrets in Channel directly.
In the process of removing a local ChannelMonitor in each Channel,
we need to track our counterpartys' commitment secrets so that we
can check them locally instead of calling our channel monitor to
do that work for us.
2020-02-26 17:48:31 -05:00
Matt Corallo
27be07ba3e Swap out ChannelMonitor remote secret tracking for a struct.
In order to drop the ChannelMonitor from Channel, we need to track
remote per_commitment_secrets outside of the monitor to validate new
ones as they come in.

This just moves the current code from ChannelMonitor into a new
CounterpartyCommitmentSecrets struct in chan_utils.
2020-02-26 17:48:31 -05:00
Matt Corallo
72e32e7af6 Clarify the in-flight HTLC state-tracking structs a bit.
This also renames PendingForwardHTLCInfo to PendingHTLCInfo since
it now also encompasses Pending *Received* HTLCs.
2020-02-26 17:48:31 -05:00
Matt Corallo
3670dd086c
Merge pull request #509 from valentinewallace/chanmgr-tx-broadcaster-to-deref
multi: update ChannelManager tx broadcaster from Arc to Deref
2020-02-26 03:13:16 +00:00
Valentine Wallace
d768cc234e
multi: update ChannelManager tx broadcaster from Arc to Deref 2020-02-25 20:12:25 -05:00
Matt Corallo
f952cc27d6
Merge pull request #515 from TheBlueMatt/2020-02-further-peer-docs
Further clean up some comments wrt the peer socket handling API
2020-02-24 19:57:42 +00:00
Matt Corallo
a2fce3bbc0 Further clean up some comments wrt the peer socket handling API 2020-02-24 11:54:37 -05:00
Matt Corallo
2be0810e78
Merge pull request #512 from TheBlueMatt/2020-02-peer_handler-docs
Fix incorrect docs/disconnect handling in peer_handler
2020-02-21 19:02:21 +00:00
Matt Corallo
697b47974f
Merge pull request #474 from TheBlueMatt/2020-02-htlc-updated-in-monitors
Move pending-HTLC-updated ChannelMonitor from ManyChannelMonitor
2020-02-21 18:50:45 +00:00
Matt Corallo
faaa4d207d Fix incorrect docs around disconnect in peer_handler + rename fns
The way PeerHandler was written, it was supposed to remove from
self.peers iff the API docs indicate that disconnect_event should
NOT be called (and otherwise rely on disconnect_event to do so).

Sadly, the implementation was way out of whack with reality - in
the implementation, essentially anywhere where PeerHandler
originated the disconnection, the peer was removed and no
disconnect_event was expected. The docs, however, indicated that
disconnect_event should nearly only be called, only not doing so
when the initial handshake message never completed.

We opt to change the docs, mostly, as well as clean up the
ping/pong handling somewhat and rename a few functions to clarify
what they actually do.
2020-02-20 20:48:13 -05:00
Matt Corallo
d296360ba7 Test basic HTLC claim behavior from monitor -> manager on reorg 2020-02-20 20:31:51 -05:00
Matt Corallo
5e43070ef4 Move pending-HTLC-updated ChannelMonitor from ManyChannelMonitor
This is important for a number of reasons:
 * Firstly, I hit this trying to implement rescan in the demo
   bitcoinrpc client - if individual ChannelMonitors are out of
   sync with each other, we cannot add them all into a
   ManyChannelMonitor together and then rescan, but need to rescan
   them individually without having to do a bunch of manual work.
   Of the three return values in ChannelMonitor::block_connected,
   only the HTLCsource stuff that is moved here makes no sense to
   be exposed to the user.
 * Secondly, the logic currently in ManyChannelMonitor cannot be
   reproduced by the user! HTLCSource is deliberately an opaque
   type but we use its data to decide which things to keep when
   inserting into the HashMap. This would prevent a user from
   properly implementing a replacement ManyChannelMonitor, which is
   unacceptable.
 * Finally, by moving the tracking into ChannelMonitor, we can
   serialize them out, which prevents us from forgetting them when
   loading from disk, though there are still other races which need
   to be handled to make this fully safe (see TODOs in
   ChannelManager).

This is safe as no two entries can have the same HTLCSource across
different channels (or, if they did, it would be a rather serious
bug), though note that, IIRC, when this code was added, the
HTLCSource field in the values was not present.

We also take this opportunity to rename the fetch function to match
our other event interfaces, makaing it clear that by calling the
function the set of HTLCUpdates will also be cleared.
2020-02-20 20:31:51 -05:00
Matt Corallo
9666fcc5ce
Merge pull request #514 from TheBlueMatt/2020-02-no-lto-travis-fuzz
Skip lto on travis when building fuzz targets as it takes 30 min
2020-02-21 01:30:17 +00:00
Matt Corallo
1b47ddd226 Skip lto on travis when building fuzz targets as it takes 30 min 2020-02-20 20:02:26 -05:00
Matt Corallo
3122d5c377
Merge pull request #510 from TheBlueMatt/2020-02-fewer-fuzz-rustc-warns
Silence new rustc warnings re: extra ()s, dyn, and unused params
2020-02-20 22:29:10 +00:00
Matt Corallo
76f6822e98
Merge pull request #511 from TheBlueMatt/2020-02-test-pub-in-test-only
Only expose constants exposed for testing in cfg(test)
2020-02-20 21:12:10 +00:00
Matt Corallo
09ba0baf2c Only expose constants exposed for testing in cfg(test) 2020-02-20 15:10:09 -05:00
Matt Corallo
78627de05f Silence new rustc warnings re: extra ()s, dyn, and unused params 2020-02-20 15:08:51 -05:00
Matt Corallo
3e726c4c8e
Merge pull request #506 from arik-so/ping_encryption_fix
Encrypt ping messages before sending them
2020-02-20 19:50:20 +00:00
Arik Sosman
d9e1f98323
Remove unused code in peer handler test utility method. 2020-02-19 17:57:03 -08:00