Commit graph

353 commits

Author SHA1 Message Date
Matt Corallo
03b5da10b7 Broadcast final local txn via ChannelMonitorUpdate 2020-03-19 19:21:36 -04:00
Matt Corallo
8a03830d43 Don't return a feerate of 0 in full_stack_target fuzz on EOF
This triggered a (legitimate) panic in OnChainTxHandler that the
feerate in use was non-0, which is required by the feerate API.
2020-03-16 22:09:08 -04:00
Matt Corallo
6f06858304 Swap read_event read type for a slice isntead of a Vec
It looks like we don't currently use the Vec as a Vec, and can
happily take a slice, which makes things easier on the calling
side.
2020-03-10 11:52:12 -04:00
Matt Corallo
107da97cd0 Allow more than one address per type in node_announcement messages
lnd has been blatantly ignoring this line in the spec forever, so
its somewhat of a lost cause trying to enforce it.
2020-03-05 18:42:49 -05:00
Matt Corallo
32ca8ec13e Make Readable::read a templated on the stream, not Readable itself
This makes Readable symmetric with Writeable and makes sense -
something which is Readable should be Readable for any stream which
implements std::io::Read, not only for a stream type it decides on.

This solves some lifetime-compatibility issues in trying to read()
from a LengthLimitingReader in arbitrary Readable impls.
2020-03-04 14:29:06 -05:00
Christopher Coverdale
53c894bcaa Add an override optional UserConfig per new outbound channel 2020-02-28 22:58:26 +00:00
Valentine Wallace
f5b5bf2acb
Update ChannelManager's FeeEstimator from Arc to Deref. 2020-02-27 15:27:58 -05:00
Valentine Wallace
bff9982299
multi: update ChannelManager's keys manager from Arc to Deref 2020-02-27 11:55:18 -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
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
Valentine Wallace
d768cc234e
multi: update ChannelManager tx broadcaster from Arc to Deref 2020-02-25 20:12:25 -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
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
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
1b47ddd226 Skip lto on travis when building fuzz targets as it takes 30 min 2020-02-20 20:02:26 -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
c94e53d9dd Add support for variable-length onion payload reads using TLV 2020-02-11 16:27:38 -05:00
Matt Corallo
87a0018e3e Better document msg fuzz target behavior and be slightly more strict 2020-02-11 13:48:56 -05:00
Matt Corallo
425e4adbf2
Merge pull request #454 from TheBlueMatt/2020-01-fuzz-mega-value
Panic on txn with value > 21mill in ChannelMonitor::block_connected, Clean up fuzz targets a bit
2020-02-05 01:23:44 +00:00
Devrandom
c20e930b31 Add ChannelKeys to ChannelMonitor 2020-02-04 16:24:11 -08:00
Matt Corallo
af4738b778
Merge pull request #460 from lightning-signer/channel-value
Channel value to ChannelKeys constructor
2020-01-25 21:17:12 +00:00
Valentine Wallace
4833d1acf9 Update ChannelManager's ChannelMonitor Arc to be a Deref
Additional changes:
* Update fuzz crate to match ChannelManager's new API
* Update lightning-net-tokio library to match ChannelManager's new ChannelMonitor Deref API
* Update tests to match ChannelManager's new ChannelMonitor Deref API
2020-01-25 14:39:52 -05:00
Devrandom
d14ece4ac0 channel value to ChannelKeys constructor 2020-01-23 19:06:57 -08:00
Matt Corallo
912f877482 Pass node features through to RouteHops
This exposes the latest Init-context features in the ChannelDetails
passed to the Router during route calculation, which combines those
with the Node-context features tracked from node_announcements to
provide the latest Node-context features in RouteHop structs.

Fields are also added for Channel-context features, though those are
only partially used since no such features are defined today anyway.

These will be useful when determining whether to use new
TLV-formatted onion hop datas when generating onions for peers.
2020-01-21 15:09:12 -05:00
Matt Corallo
d2ba7caf47 Pass peer's Init message through to ChannelManager 2020-01-19 22:47:08 -05:00
Matt Corallo
f263b3793f
Merge pull request #451 from lightning-signer/txkeys
Provide remote channel public keys to signer
2020-01-20 03:46:00 +00:00
Devrandom
42d7738234 Provide remote channel public keys to signer 2020-01-19 20:40:49 -05:00
Matt Corallo
04215c4658 Panic on txn with value > 21mill in ChannelMonitor::block_connected
full_stack_target found a crash where we may overflow ruring fee
calculation if a transaction appears on-chain with massive value
available for us to claim. Since these transactions are clearly
bogus, we shouldn't allow full_stack_target to connect them, but
we also improve the error generated by explicitly panicing on them.
2020-01-19 16:13:47 -05:00
Matt Corallo
a343cf9436 Drop individual fuzz target duplicate_crash tests for file reader
Previously, in each of our fuzz tests we had a dummy test which
had a hard-coded hex string which it passed into the fuzz target
so that when a failing test case was found, its hex could be
copied into the test and you could run cargo test to analyze the
failure. However, this was somewhat unwieldy as converting large
tests back and forth between hex and raw files is quite annoying.

Instead, we replace each of those tests with a test in each target
that looks for files in fuzz/test_cases and runs each file it finds.

Since we're editing every bin target anyway, we also automate adding
no_main to libfuzzer builds with #![cfg_attr].
2020-01-19 16:13:47 -05:00
Antoine Riard
865267ac68 Fix full_stack_target mishandling of block disconnection 2020-01-17 14:21:02 -05:00
Devrandom
6200302dc7 construct funding redeem script in signer 2020-01-16 13:18:23 -08:00
Matt Corallo
cd5a11fe0d Move features into a separate module out of msgs. 2020-01-13 13:53:20 -05:00
Matt Corallo
7ec52c6ecb Refactor features a bit more to describe what the constructors do
The Features::new() method is nonsense and doesn't describe what
features were being set - we introduce an empty() and supported()
constructors instead.
2020-01-13 13:52:23 -05:00
Matt Corallo
31cc243e6f Implement Flat Features
This merges local and global features into one struct, which is
parameterized by where it appers. The parameterization restricts
which queries can be made and which features can be set, in line
with the latest BOLT 9.

Closes #427.
2020-01-12 18:15:25 -05:00
Antoine Riard
933ae34703 Drop Result for ChannelMessageHandler methods
Simplify interfaces between ChannelMessageHandler and PeerManager,
by switching all ChannelMessageHandler errors to HandleError sent
internally instead of being return. With further refactors in Router
and PeerChannelEncryptor, errors management on the PeerManager-side
won't be splitted between try_potential_handleerror and HandleError
processing.

Inside ChannelManager, we now log MsgHandleErrInternal and send
ErrorAction to PeerManager.

On a high-level, it should allow client using API to be more flexible
by polling events instead of waiting function call returns.

We also update handle_error macro to take channel_state_lock from
caller which should avoid some deadlock potential for some edges
cases.

Filter out IgnoreError in handle_error macro, update test in
consequence.
2020-01-05 20:50:07 -05:00
Matt Corallo
eb97a7534d Make ChannelMonitor sign local transactions (at broadcast time) 2019-12-24 12:14:20 -05:00
Matt Corallo
d6382f5ed4 Remove unused lifetimes.
f71518365f added a series of lifetimes
which were required for an earlier version of the patch but not the
final version. They can be freely removed.
2019-12-20 14:54:23 -05:00
Matt Corallo
ae16c5ca34 Use EnforcingChannelKeys in fuzz targets to get more coverage 2019-12-12 13:37:07 -05:00
Matt Corallo
edab29e8d8
Merge pull request #404 from TheBlueMatt/2019-11-signer-api
Replace keys API with Signer API to support hardware wallets eventually
2019-12-12 18:01:46 +00:00
Matt Corallo
6fc775da45 Bump bitcoin dep to 0.21 2019-12-11 18:17:54 -05:00
Matt Corallo
ccd4f12078 Pre-build fuzz targets at once in travis instead of as we need them 2019-12-11 18:17:54 -05:00
Matt Corallo
f2a2fd0d48 Make ChannelKeys an API and template Channel with it.
Instead of having in-memory access to the list of private keys
associated with a channel, we should have a generic API which
allows us to request signing, allowing the user to store private
keys any way they like.

The first step is the (rather mechanical) process of templating
the entire tree of ChannelManager -> Channel impls by the
key-providing type. In a later commit we should expose only public
keys where possible.
2019-12-11 17:29:42 -05:00
Matt Corallo
580a4234fd Bump bitcoin dep to 0.21 2019-12-11 17:29:42 -05:00
Matt Corallo
e28fd78e67 Refactor fuzzing to be a C-callable library plus rust binaries
This should help us avoid rust's at-load syscalls by calling the
tests from a C program.
2019-12-11 15:13:14 -05:00
Matt Corallo
2c8bc3c64e Correct input comparison for input-subset RBF bump creation
This resolves a regression introduced in "Implement bumping engine in
ChannelMonitor::block_connected" in which not all inputs are checked.
Several opportunities to clarify and clean up comments are also taken.

Fix test_bump_penalty_txn_on_revoked_htlcs as now remote claim txn
build the same way than us are going to be register as cleaning
pending_claim_request after ANTI_REORG_DELAY. It means during this
delay we are going to generate invalid bumped claiming txn on
already claimed outpoints. Previously these txn weren't issued
because all their outpoints would have been removed.

Fix full_stack_target by adding more input for FuzzEstimator
2019-12-10 17:42:40 -05:00
Antoine Riard
feb472dc9e Track and react to remote partial-claiming of pending claim request
A pending claim request may contain a set of multiple outpoints.
If one or multiple of them get claimed by remote party, our in-flight
claiming transactions aren't valid anymore so we need to react
quickly and regenerate claiming transaction with accurate set.

However, a claimed outpoint may be disconnected and we need to resurrect
back outpoint among set of orignal pending claim request.

To guarantee consistency of contentious claimed outpoint we cache it
as OnchainEvent::ContentionsOutpoint and only delete it after
ANTI_REORG_DELAY.

Fix test broken by change, partial claiming on revoked txn
force us to regenerate txn
2019-12-10 15:50:56 -05:00
Antoine Riard
6eb290d780 Add RBF-bumping of preimage/timeout txn on remote HTLC outputs
Given they are only signed by us we can RBF at wish

Fix tests broken by introduction of more txn broadcast
(channel_monitor_network_test)

Add locktime in RemoteHTLC as it's needed to generate
timeout txn.
2019-12-10 15:50:51 -05:00
Antoine Riard
116b1eb028 Implement bumping engine in ChannelMonitor::block_connected
Add RBF-bumping of justice txn, given they are only signed by us we
can RBF at wish.

Aggregation of bump-candidates and more aggresive bumping heuristics
are left open

Fix tests broken by introduction of more txn broadcast.
Some tests may have a relaxed check (claim_htlc_ouputs_single_tx)
as broadcast bumped txn are now interwining in previous broadcast ones
and breaking simple expectations

Use bumping engine to rebuild claiming transaction in case of partial-
claim of its outpoints set.
2019-12-09 22:22:54 -05:00
Steven Roose
3f3dc6c067 Change the new() functions for config to Default::default() 2019-12-09 15:56:51 -05:00
Matt Corallo
fd1d5fd62c Randomize initial onion packet data.
This avoids at least the trivial hop count discovery attack, though
other obvious ones remain and are slightly harder to avoid.

See https://github.com/lightningnetwork/lightning-rfc/pull/697
2019-12-01 19:22:44 -05:00