Commit graph

333 commits

Author SHA1 Message Date
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
Matt Corallo
c1349e82cd Add dyn tags in fuzz_targets
We only support newish rust in fuzz_targets, so this is fine.
2019-11-28 01:21:41 -05:00
Matt Corallo
9501ecce49 Move fuzz to top level. 2019-11-25 15:42:07 -05:00
RJ Rybarczyk
88fef649b1 Use workspaces to separate crates 2019-11-15 02:44:30 +00:00
Elichai Turkel
20302064a8
Update the fuzz and net-tokio crates 2019-08-24 11:05:38 -04:00
RJ Rybarczyk
d32015377e Make SocketDescriptor::send_data take slice instead of vec and offset 2019-07-31 11:22:59 -04:00
Matt Corallo
e5c8f05891 Make temporary channel ids unique in full_stack_target
This avoids a crash where a channel with a duplicate id is created
immediately after another is closed, where the other still has a
pending funding generation event. Resulting in funding generation
being passed to the wrong channel (which isn't in an appropriate
state).
2019-07-29 12:51:33 -04:00
Matt Corallo
a9aa3c37fe Make chanmon_fail_consistency slightly less aggressive
This resolves some crashes that both afl and honggfuzz found.
2019-07-25 11:30:53 -04:00
Matt Corallo
20efabdaa6 Add deserialize+load steps to chanmon_fail_consistency (fixes #327) 2019-07-24 15:31:29 -04:00
Matt Corallo
c2f72b9de3 Drop msgs bound for a disconnecting peer at disconnect time
This simplifies chanmon_fail_consistency greatly and makes it a
tiny bit more realistic. It also sets us up for more
disconnect-relatex events without the complexity blowing up.
2019-07-23 15:53:47 -04:00
Matt Corallo
bf7eeb1ec7 Make rand a dev-dep by having the user randomize HTLC forward delay
This removes the last calls to rand outside of test and moves the
dep to a dev-dependency, dropping our fuzz rng wrapper in the
process.
2019-07-23 14:29:56 -04:00
Matt Corallo
084ef28708 Stop using rng in peer_channel_encryptor to generate ephemeral keys
This removes the bulk of our reliance on the rand crate in non-test
envs, paving a way towards a syscall-less rust-lightning and WASM.
Since this is a breaking change for full_stack_target (and several
fuzz targets), go ahead and make other changes to make things more
distinct.
2019-07-23 14:29:56 -04:00
Matt Corallo
1650992ec2 Update commitment tx to match actual tx (dunno when it broke) 2019-07-23 14:29:56 -04:00
Matt Corallo
d9043b51bb Remove dangling link in fuzz/ 2019-07-23 14:29:56 -04:00
Antoine Riard
0052b2c5c3 Provide peer local_features to handle_open_channel/accept_channel
Peer may send us a shutdown_scriptpubkey in open_channel or
accept_channel messages. Before to enforce this policy on channel
closing, we want to be sure that our peer has opt-in to it.

Extend LocalFeatures new method visibilty from crate to public
for fuzz tests
2019-07-22 13:13:01 -04:00
Matt Corallo
8470e60415
Merge pull request #336 from ariard/2019-04-in-flight-txn-tracking-clean
2019 04 in flight txn tracking clean
2019-07-19 18:02:25 -04:00
Matt Corallo
3d55d71fda Add balance and is_live fields to ChannelDetails 2019-07-18 18:02:31 -04:00
Antoine Riard
a2b6a76e59 Delay failure of non-dust HTLC-outputs until solving timeout tx matures
Fix tests broken by introduced change
2019-07-17 15:26:33 -04:00
Antoine Riard
587af43eca Implement block_disconnect for pruning of waiting-conf HTLC updates
Modify ChainListener API by adding height field to block_disconnect
2019-07-17 15:26:33 -04:00
Matt Corallo
882f7307c8 Bump rust-bitcoin dep to 0.18 2019-06-01 07:40:21 -04:00
Matt Corallo
06eddc3465
Merge pull request #320 from TheBlueMatt/2019-03-chan-send-rewrite
Rewrite Channel resend tracking to make it much more reliable
2019-04-22 17:32:24 -04:00