Commit graph

1094 commits

Author SHA1 Message Date
Matt Corallo
f61676ea15 Dont broadcast HTLC-Timeouts when closing a channel until locktime 2021-05-28 23:58:07 +00:00
Matt Corallo
00bbc51cad Skip transactions which are locktime'd when broadcasting in test 2021-05-28 23:58:07 +00:00
Matt Corallo
90e984e797 Track the blocks a node has connected in the TestBroadcaster 2021-05-28 23:56:44 +00:00
Matt Corallo
29a780e9e0 Delay broadcast of PackageTemplate packages until their locktime
This stores transaction templates temporarily until their locktime
is reached, avoiding broadcasting (or RBF bumping) transactions
prior to their locktime. For those broadcasting transactions
(potentially indirectly) via Bitcoin Core RPC, this ensures no
automated rebroadcast of transactions on the client side is
required to get transactions confirmed.
2021-05-28 23:56:44 +00:00
Matt Corallo
79ffc5eac9 Always pass height to OnchainTxHandler::update_claims_view
This simplifies logic somewhat and avoids duplicating the storage
of the current height in OnchainTxHandler.
2021-05-28 23:56:44 +00:00
Matt Corallo
9bd87e9c9d Expose the timelock of transaction packages 2021-05-28 23:56:44 +00:00
Matt Corallo
7d6938a43a Simplify tx checks in functional tests to make later commits simpler
This cleans up some of the transaction format verification and docs
to make it easier when we delay CLTV-locked transactions to update
the tests.
2021-05-28 23:56:44 +00:00
Matt Corallo
56491d91bb Simplify HolderHTLCOutput constructor and track CLTV expiry
This allows us to interrogate a PackageTemplate for the CLTV
timelock of the resulting transaction.
2021-05-28 23:56:44 +00:00
Matt Corallo
f492a192ff Add assertions to ensure we don't use an invalid package_amount
This somewhat cleans up the public API of PackageSolvingData to
make it harder to get an invalid amount and use it, adding further
debug assertion to check it at test-time.
2021-05-28 23:56:44 +00:00
Matt Corallo
df829a8526
Merge pull request #928 from TheBlueMatt/2021-05-really-tlv-ser
Migrate some inner structs to TLVs
2021-05-27 23:05:47 +00:00
Matt Corallo
ad20bc7f5a Update net_graph used for benchmarks to use new ser format. 2021-05-27 21:46:38 +00:00
Matt Corallo
45d86ead64 Migrate packages sub-fields to TLV serialization 2021-05-27 21:41:24 +00:00
Matt Corallo
c8bc1b6d3d Use TLV serialization for Commitment transaction structures 2021-05-27 21:41:24 +00:00
Matt Corallo
a7494228c9 Add TLV suffix to PackageTemplate 2021-05-27 21:41:07 +00:00
Matt Corallo
321b19c4d9 Move NetworkGraph inner structs to TLV storage 2021-05-27 21:41:07 +00:00
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
Gene Ferneau
12461fcba1
Use alloc for no_std builds
Replace std structs with alloc equivalents to support no_std builds

f use prelude::* credit @devrandom
2021-05-27 17:35:20 +00:00
Matt Corallo
c9f6a35756 Fix compile warnings reading type-0 TLVs 2021-05-27 01:05:26 +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
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
Jeffrey Czyz
f63fd83fd6
Process ChainMonitor events in the background 2021-05-25 00:28:59 -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
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
96b0faf124 Log info about HTLC failures when we fail them back 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
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
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