Commit graph

2372 commits

Author SHA1 Message Date
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
Antoine Riard
6319690891 keysinterface: replace Result match with map_err 2021-05-17 22:32:02 -04:00
Antoine Riard
55eccfa7b3 Split sign_justice_transaction in two halves
To avoid caller data struct storing HTLC-related information when
a revokeable output is claimed on top of a commitment/second-stage
HTLC transactions, we split `keysinterface::sign_justice_transaction`
in two new halves `keysinterfaces::sign_justice_revoked_output` and
`keysinterfaces::sign_justice_revoked_htlc`.

Further, this split offers more flexibility to signer policy as a
commitment revokeable output might be of a value far more significant
than HTLC ones.
2021-05-17 22:31:28 -04:00
Matt Corallo
e0986de477
Merge pull request #916 from TheBlueMatt/2021-05-fix-disabled-announcements
Avoid persisting a ChannelManager after each timer tick and send update_channel re-enable messages
2021-05-15 00:44:40 +00:00
Matt Corallo
ee36d647c7 Simplify+expand per-channel check in test_announce_disable_channels 2021-05-14 23:20:27 +00:00
Matt Corallo
33c06c078b Rename Channel::UpdateStatus to be more descriptive and update docs 2021-05-14 23:20:27 +00:00
Matt Corallo
fdc11f2c76 Do not wait in PersistenceNotifier when the persist flag is set
When we had a event which caused us to set the persist flag in a
PersistenceNotifier in between wait calls, we will still wait,
potentially not persisting a ChannelManager when we should.

Worse, for wait_timeout, this caused us to always wait up to the
timeout, but then always return true that a persistence is needed.

Instead, we simply check the persist flag before waiting, returning
immediately if it is set.
2021-05-14 23:20:27 +00:00
Matt Corallo
316f01a42f Avoid persisting a ChannelManager update after each timer tick
Currently, when a user calls `ChannelManager::timer_tick_occurred`
we always set the persister's update flag to true. This results in
a ChannelManager persistence after each timer tick, even when
nothing happened.

Instead, we add a new flag to `PersistenceNotifierGuard` to
indicate if we should skip setting the update flag.
2021-05-14 23:20:27 +00:00
Matt Corallo
1dd9a4df88 Test new channel_update re-enabled announcements 2021-05-14 22:36:28 +00:00
Matt Corallo
eeabac8ccb
Merge pull request #922 from valentinewallace/update-default-expiry
Correct default invoice expiry
2021-05-14 22:31:34 +00:00
Valentine Wallace
4503ef3523
Correct default expiry.
We previously stated in the codebase that the default invoice expiry
stated in the spec is 2 hours. It's actually 1 hour.
2021-05-14 16:51:46 -04:00
Matt Corallo
0b1f0a7edc
Merge pull request #921 from TheBlueMatt/2021-05-no-control-chars
Don't return ASCII control characters in HTTP error messages
2021-05-14 01:44:07 +00:00
Matt Corallo
f0084e12e2 Don't return ASCII control characters in HTTP error messages 2021-05-13 21:58:01 +00:00
Matt Corallo
ac3380e470 Send update_channel messages to re-enable a disabled channel
Currently, we only send an update_channel message after
disconnecting a peer and waiting some time. We do not send a
followup when the peer has been reconnected for some time.

This changes that behavior to make the disconnect and reconnect
channel updates symmetric, and also simplifies the state machine
somewhat to make it more clear.

Finally, it serializes the current announcement state so that we
usually know when we need to send a new update_channel.
2021-05-13 20:53:53 +00:00
Matt Corallo
0ac3b444be
Merge pull request #919 from valentinewallace/http-error-msgs
Return more error details on http's read_response
2021-05-13 19:25:47 +00:00
Valentine Wallace
4f880c6b75
Return more error details on http's read_response
Otherwise helpful error information gets swallowed
2021-05-13 13:18:26 -04:00
Matt Corallo
fcc0723528
Merge pull request #915 from TheBlueMatt/2021-05-bump-rpc-timeout
Increase the timeout for RPC responses from Bitcoin Core
2021-05-10 18:04:28 +00:00
Matt Corallo
4ade6bcb69 Increase the timeout for RPC responses from Bitcoin Core
Early sample testing showed multiple users hitting
EWOULDBLOCK/EAGAIN waiting for an initial response from Bitcoin
Core while it was doing some long operation (eg UTXO cache
flushing). Instead of only waiting 5 seconds for each attempt, we
now wait a full two minutes, but only for the first header
response, not each byte.
2021-05-10 16:55:09 +00:00
Matt Corallo
b465318e12 Allow retrying HTTP requests if we hit a socket timeout 2021-05-10 16:55:09 +00:00
Matt Corallo
7297e13871
Merge pull request #912 from TheBlueMatt/2021-05-more-chan-info
Add flags for if a channel is pub and funding txo in ChannelDetails
2021-05-07 15:19:44 +00:00
Matt Corallo
d2955be5cf
Merge pull request #911 from TheBlueMatt/2021-05-fix-cltv-diff 2021-05-06 21:49:24 +00:00
Matt Corallo
85f1a91de0
Merge pull request #914 from TheBlueMatt/2021-05-log-txids
Always log_info when we broadcast a transaction, including the txid
2021-05-06 21:08:08 +00:00
Matt Corallo
62f466a0a2 Rename ChannelDetails::is_live to is_usable
This matches is_usable_channels and slightly better captures the
meaning.
2021-05-06 20:49:20 +00:00