Commit graph

2403 commits

Author SHA1 Message Date
Matt Corallo
9ec0f04b74 Move ChannelManager-inner structs to TLV storage
Note that enums are left alone as we can use the type byte already
present for future compatibility.
2021-05-27 21:41:07 +00:00
Matt Corallo
557aa81619 Add dummy OutPoint constructor to be used when reading it in a TLV 2021-05-27 21:41:07 +00:00
Matt Corallo
cf430029c4 Add a macro which implements Readable/Writeable using TLVs only
This also includes a `VecWriteWrapper` and `VecReadWrapper` which
implements serialization for any `Readable`/`Writeable` type that is
in a Vec. We do this instead of implementing `Readable`/`Writeable`
directly as there isn't always a univerally-defined way to serialize
a Vec and this makes things more explicit.

Finally, this tweaks existing macros (and in the new macros) to
support a trailing `,` after a list, eg
`write_tlv_fields!(stream, {(0, a),}, {});` whereas previously the
trailing `,` after the `(0, a)` would be a compile-error.
2021-05-27 21:41:07 +00:00
Matt Corallo
c9f6a35756 Fix compile warnings reading type-0 TLVs 2021-05-27 01:05:26 +00:00
Matt Corallo
8e7b5905fd
Merge pull request #929 from jkczyz/2021-05-json-rpc-error
Parse RPC errors as JSON content
2021-05-27 00:20:08 +00:00
Jeffrey Czyz
b2f16ad821
Parse RPC errors as JSON content
Bitcoin Core's JSON RPC server returns errors as HTTP error responses
with JSON content in the body. Parse this content as JSON to give a more
meaningful error. Otherwise, "binary" is given because the content
contains ASCII control characters.
2021-05-26 10:57:39 -07:00
Jeffrey Czyz
61648fc804
Define an HttpError for returning error contents
Return an HTTP error response as a status code and contents. This allows
clients to interpret the response as desired (e.g., the contents as a
JSON-formatted error).
2021-05-26 10:51:16 -07:00
Matt Corallo
f0743433e7
Merge pull request #642 from ariard/2020-06-anchor-backend-refacto
Anchor-outputs (1/3): Refactoring chain backend to extract PackageTemplate
2021-05-26 15:50:25 +00:00
Antoine Riard
c40ebf18e5 Add package template unit tests 2021-05-25 23:18:56 -04:00
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