Commit graph

2394 commits

Author SHA1 Message Date
Antoine Riard
881c0f58e1 Move compute_output_value as part of package member functions 2021-05-25 19:59:40 -04:00
Antoine Riard
bb0e33f383 Move get_height_timer out of OnchainTxHandler 2021-05-25 19:59:40 -04:00
Antoine Riard
4363f965d6 Move onchain* to chain/ 2021-05-25 19:59:40 -04:00
Antoine Riard
5ccb07554b Integrate PackageTemplate
This commit replaces InputMaterial in both ChannelMonitor/
OnchainTxHandler.

This doesn't change behavior.
2021-05-25 19:59:40 -04:00
Antoine Riard
2d451b8622 Duplicate fee computation utilities out of OnchainTxHandler
Duplicated code in onchain.rs is removed in next commits.
2021-05-25 19:54:57 -04:00
Antoine Riard
c9bd7b3f2d Introduce PackageTemplae, a replacement of InputMaterial
PackageTemplate aims to replace InputMaterial, introducing a clean
interface to manipulate a wide range of claim types without
OnchainTxHandler aware of special content of each.

This is used in next commits.
2021-05-25 19:54:57 -04:00
Antoine Riard
0ea7dd8bfc Add package.rs file
Package.rs aims to gather interfaces to communicate between
onchain channel transactions parser (ChannelMonitor) and outputs
claiming logic (OnchainTxHandler). These interfaces are data
structures, generated per-case by ChannelMonitor and consumed
blindly by OnchainTxHandler.
2021-05-25 19:54:57 -04:00
Matt Corallo
499d84c165 Merge pull request #920 from TheBlueMatt/2021-05-tlv-ser
Rebroadcast channel_announcements when we broadcast a node_announce
2021-05-25 20:07:07 +00:00
Matt Corallo
bdb2d220e8 Add note in CONTRIBUTING.md that some structs need prefix/suffixes 2021-05-25 20:06:45 +00:00
Matt Corallo
02c57f5940 Rebroadcast channel_announcements when we broadcast a node_announce 2021-05-25 20:06:45 +00:00
Matt Corallo
a87053a16e Process announcement_signatures messages in Channel and store sigs
Previously we handled most of the logic of announcement_signatures
in ChannelManager, rather than Channel. This is somewhat unique as
far as our message processing goes, but it also avoided having to
pass the node_secret in to the Channel.

Eventually, we'll move the node_secret behind the signer anyway, so
there isn't much reason for this, and storing the
announcement_signatures-provided signatures in the Channel allows
us to recreate the channel_announcement later for rebroadcast,
which may be useful.
2021-05-25 20:06:45 +00:00
Matt Corallo
3d1c72e73f Update net graph copy used in tests and bench for new format 2021-05-25 20:06:45 +00:00
Matt Corallo
5b59178f89 Add version and TLV suffix for more user-facing "major" structs 2021-05-25 20:06:45 +00:00
Matt Corallo
8ee7d841b6 Support serializing TLV fields which may or may not be present 2021-05-25 20:06:45 +00:00
Matt Corallo
a515eb3ba6 Append backwards-compat TLVs to serialization of larger structs
Currently our serialization is very compact, and contains version
numbers to indicate which versions the code can read a given
serialized struct. However, if you want to add a new field without
needlessly breaking the ability of previous versions of the code to
read the struct, there is not a good way to do so.

This adds dummy, currently empty, TLVs to the major structs we
serialize out for users, providing an easy place to put new
optional fields without breaking previous versions.
2021-05-25 20:06:45 +00:00
Matt Corallo
f8450a7c2c
Merge pull request #920 from jkczyz/2021-05-event-processing
Background processing of ChannelManager and ChannelMonitor events
2021-05-25 15:55:50 +00:00
Jeffrey Czyz
a1f95de734
Remove event channel from lightning-net-tokio
It is unnecessary since ChannelManager has a notification interface as
of 12c735ab3a.
2021-05-25 00:28:59 -07:00
Jeffrey Czyz
f63fd83fd6
Process ChainMonitor events in the background 2021-05-25 00:28:59 -07:00
Jeffrey Czyz
501b54300c
Process ChannelManager events in the background 2021-05-25 00:28:58 -07:00
Jeffrey Czyz
86ce44677f
f - Persist when check_free_holding_cells has updates 2021-05-25 00:28:58 -07:00
Jeffrey Czyz
248a107e3d
Guard get_and_clear_pending_msg_events 2021-05-24 14:19:56 -07:00
Jeffrey Czyz
282d092bb1
Remove unnecessary scope from ChannelManager 2021-05-24 14:16:16 -07:00
Jeffrey Czyz
7c465d69dc
Refactor EventsProvider to take an EventHandler 2021-05-24 14:16:16 -07:00
Matt Corallo
3a0356fe30
Merge pull request #851 from TheBlueMatt/2021-03-holding-cell-clear-msg-get
Clean up and more liberally free holding cell HTLCs (without re-entrancy)
2021-05-24 21:02:50 +00:00
Matt Corallo
c7e198e6fc
Merge pull request #926 from GeneFerneau/core
Use core replacements for std members
2021-05-24 17:49:54 +00:00
Gene Ferneau
ec3739b7a2
Use core replacements for std members
In preparation for no_std build support, replace std structs and
functions with core equivalents
2021-05-23 23:48:27 +00:00
Matt Corallo
34fcd99f51 Add trace to ci-fuzz.sh to make debugging CI issues easier 2021-05-21 15:10:45 +00:00
Matt Corallo
96b0faf124 Log info about HTLC failures when we fail them back 2021-05-21 15:10:45 +00:00
Matt Corallo
da54848ba4 Read monitors from our KeysInterface in chanmon_consistency_fuzz
If the fuzz target is failing due to a channel force-close, the
immediately-visible error is that we're signing a stale state. This
is because the ChannelMonitorUpdateStep::ChannelForceClosed event
results in a signature in the test clone which was deserialized
using a OnlyReadsKeysInterface. Instead, we need to deserialize
using the full KeysInterface instance.
2021-05-21 15:10:45 +00:00
Matt Corallo
e19d7ef824 Add a test for HTLC freeing on monitor update restoration 2021-05-21 15:10:45 +00:00
Matt Corallo
b9a1db5ad6 Stop failing back HTLCs on peer disconnection
Previously, if we got disconnected from a peer while there were
HTLCs pending forwarding in the holding cell, we'd clear them and
fail them all backwards. This is largely fine, but since we now
have support for handling such HTLCs on reconnect, we might as
well not, instead relying on our timeout logic to fail them
backwards if it takes too long to forward them.
2021-05-21 15:10:45 +00:00
Matt Corallo
8acdbaf2a4 [fuzz] Handle monitor updates during get_and_clear_pending_msg_events
Because we may now generate a monitor update during
get_and_clear_pending_msg_events calls, we need to ensure we
re-serialize the relevant ChannelManager before attempting to
reload it, if such a monitor update occurred.
2021-05-21 15:10:45 +00:00
Matt Corallo
6815245388 Free holding cell on monitor-updating-restored when there's no upd
If there is no pending channel update messages when monitor updating
is restored (though there may be an RAA to send), and we're
connected to our peer and not awaiting a remote RAA, we need to
free anything in our holding cell.

However, we don't want to immediately free the holding cell during
channel_monitor_updated as it presents a somewhat bug-prone case of
reentrancy:
 a) it would re-enter user code around a monitor update while being
    called from user code notifying us of the same monitor being
    updated, making deadlocs very likely (in fact, our fuzzers
    would have a bug here!),
 b) the re-entrancy only occurs in a very rare case, making it
    likely users will not hit it in testing, only deadlocking in
    production.

Thus, we add a holding-cell-free pass over each channel in
get_and_clear_pending_msg_events. This fits up nicely with the
anticipated bug - users almost certainly need to process new
network messages immediately after monitor updating has been
restored to send messages which were not sent originally when the
monitor updating was paused.

Without this, chanmon_fail_consistency was able to find a stuck
condition where we sit on an HTLC failure in our holding cell and
don't ever handle it (at least until we have other actions to take
which empty the holding cell).
2021-05-21 15:10:45 +00:00
Matt Corallo
75e480eb48 DRY ChannelError conversion macros
Both break_chan_entry and try_chan_entry do almost identical work,
only differing on if they `break` or `return` in response to an
error. Because we will now also need an option to do neither, we
break out the common code into a shared `convert_chan_err` macro.
2021-05-21 15:10:45 +00:00
Matt Corallo
b2cb1fb533 Use new chan_restoration macros in channel_reestablish handling.
This merges the code for restoring channel functionality between
channel monitor updating restored and peer reconnection, reducing
redundant code.
2021-05-21 15:10:45 +00:00
Matt Corallo
1fa2da391c [fuzz] Allow SendAnnouncementSigs events in chanmon_consistency
Because of the merge between peer reconnection and channel monitor
updating channel restoration code, we now sometimes generate
(somewhat spurious) announcement signatures when restoring channel
monitor updating. This should not result in a fuzzing failure.
2021-05-20 21:18:35 +00:00
Matt Corallo
d90aac8d95 [fuzz] Be more strict about msg events in chanmon_consistency
This fails chanmon_consistency on IgnoreError error events and on
messages left over to be sent to a just-disconnected peer, which
should have been drained.

These should never appear, so consider them a fuzzer fail case.
2021-05-20 21:18:35 +00:00
Matt Corallo
e9fd35f494 Clean up channel updating macro somewhat
This mostly swaps some Vecs that can only ever contain one element
for Options.
2021-05-20 21:18:35 +00:00
Matt Corallo
e02accf0b5 Move channel restoration after monitor update to a two-part macro
The channel restoration code in channel monitor updating and peer
reconnection both do incredibly similar things, and there is
little reason to have them be separate. Sadly because they require
holding a lock with a reference to elements in the lock, its not
practical to make them utility functions, so instead we introduce
a two-step macro here which will eventually be used for both.

Because we still support pre-NLL Rust, the macro has to be in two
parts - one which runs with the channel_state lock, and one which
does not.
2021-05-20 21:18:35 +00:00
Matt Corallo
45ccf68857 Drop unused variable and loop in channel_monitor_updated 2021-05-20 21:18:35 +00:00
Matt Corallo
acc9ff6274 [fuzz] Print the output of all failed test cases, not one test.
Our fuzz tests previously only printed the log output of the first
fuzz test case to fail. This commit changes that (with lots of
auto-generated updates) to ensure we print all log outputs.
2021-05-20 21:18:35 +00:00
Matt Corallo
b6de28182f
Merge pull request #918 from TheBlueMatt/2021-05-dup-claims
Make payments not duplicatively fail/succeed on reload/reconnect
2021-05-20 17:10:52 +00:00
Matt Corallo
864375e5f2 [fuzz] Make get_secure_random_bytes in chanmon_consistency unique 2021-05-20 16:38:18 +00:00
Matt Corallo
ef4f4f4160 Test pending payments when resolved duplicatively via reconnect 2021-05-20 16:30:27 +00:00
Matt Corallo
77412dd802 Test pending payments when duplicatively resolved on chain 2021-05-20 16:30:27 +00:00
Matt Corallo
3aa4aa8880 Make payments not duplicatively fail/succeed on reload/reconnect
We currently generate duplicative PaymentFailed/PaymentSent events
in two cases:

a) If we receive a update_fulfill_htlc message, followed by a
   disconnect, then a resend of the same update_fulfill_htlc
   message, we will generate a PaymentSent event for each message.

b) When a Channel is closed, any outbound HTLCs which were relayed
   through it are simply dropped when the Channel is. From there,
   the ChannelManager relies on the ChannelMonitor having a copy of
   the relevant fail-/claim-back data and processes the HTLC
   fail/claim when the ChannelMonitor tells it to.

   If, due to an on-chain event, an HTLC is failed/claimed, and
   then we serialize the ChannelManager, but do not re-serialize
   the relevant ChannelMonitor, we may end up getting a duplicative
   event.

In order to provide the expected consistency, we add explicit
tracking of pending outbound payments using their unique
session_priv field which is generated when the payment is sent.
Then, before generating PaymentFailed/PaymentSent events, we check
that the session_priv for the payment is still pending.

Thix fixes #209.
2021-05-20 16:30:27 +00:00
Matt Corallo
63a245e824
Merge pull request #925 from valentinewallace/ignore-zlib-compressed-msgs
Ignore messages with zlib-compressed fields
2021-05-20 16:26:49 +00:00
Valentine Wallace
9c344b714c
Return new DecodeError::UnsupportedCompression
if we receive a message with zlib-compressed values.
2021-05-20 11:25:43 -04:00
Valentine Wallace
438e70e083
Add new DecodeError for messages that include zlib-compressed values
No need to disconnect peers if this error is encountered. It just means
we can't use some of their gossip messages.
2021-05-20 11:25:39 -04:00
Matt Corallo
5d74cae6c5
Merge pull request #923 from ariard/2021-05-split-sign-justice
Split `sign_justice_transaction` in two halves
2021-05-18 15:24:57 +00:00