Commit graph

54 commits

Author SHA1 Message Date
Matt Corallo
107c6c7939
Merge pull request #1108 from TheBlueMatt/2021-10-persist-mon-blocks
Persist ChannelMonitors after new blocks are connected
2021-10-20 00:53:26 +00:00
Matt Corallo
5c2ff2cb30 Persist ChannelMonitors after new blocks are connected
This resolves several user complaints (and issues in the sample
node) where startup is substantially delayed as we're always
waiting for the chain data to sync.

Further, in an upcoming PR, we'll be reloading pending payments
from ChannelMonitors on restart, at which point we'll need the
change here which avoids handling events until after the user
has confirmed the `ChannelMonitor` has been persisted to disk.
It will avoid a race where we
 * send a payment/HTLC (persisting the monitor to disk with the
   HTLC pending),
 * force-close the channel, removing the channel entry from the
   ChannelManager entirely,
 * persist the ChannelManager,
 * connect a block which contains a fulfill of the HTLC, generating
   a claim event,
 * handle the claim event while the `ChannelMonitor` is being
   persisted,
 * persist the ChannelManager (before the CHannelMonitor is
   persisted fully),
 * restart, reloading the HTLC as a pending payment in the
   ChannelManager, which now has no references to it except from
   the ChannelMonitor which still has the pending HTLC,
 * replay the block connection, generating a duplicate PaymentSent
   event.
2021-10-20 00:06:17 +00:00
Matt Corallo
89ad059548 Use an opaque type to describe monitor updates in Persist
In the next commit, we'll be originating monitor updates both from
the ChainMonitor and from the ChannelManager, making simple
sequential update IDs impossible.

Further, the existing async monitor update API was somewhat hard to
work with - instead of being able to generate monitor_updated
callbacks whenever a persistence process finishes, you had to
ensure you only did so at least once all previous updates had also
been persisted.

Here we eat the complexity for the user by moving to an opaque
type for monitor updates, tracking which updates are in-flight for
the user and only generating monitor-persisted events once all
pending updates have been committed.
2021-10-19 23:49:04 +00:00
Matt Corallo
f2e47e0db2 Bump crate versions to 0.0.102 and lightning-invoice 0.10 2021-10-18 18:32:36 +00:00
Matt Corallo
6a7c48b60d Move ChannelMonitorUpdateErr to chain as it is a chain::Watch val 2021-10-14 00:16:50 +00:00
Matt Corallo
0dfb24e661 Move Persist trait to chainmonitor as that's the only reference 2021-10-14 00:16:50 +00:00
Matt Corallo
43fe3d55f1 Bump Crate versions to 0.0.101 (and invoice to 0.9) 2021-09-23 18:22:59 +00:00
Matt Corallo
a233780c7e Fix windows-only test failure added in #997
This is a trivial bugfix to add a missing test updated required in
PR 997.
2021-09-21 21:16:51 +00:00
Antoine Riard
6ce7f3e1ce Add ChannelClosed generation at cooperative/force-close/error processing
When we detect a channel `is_shutdown()` or call on it
`force_shutdown()`, we notify the user with a Event::ChannelClosed
informing about the id and closure reason.
2021-09-21 15:46:42 -04:00
Matt Corallo
11f78798d3 Update versions to 0.0.100 and lightning-invoice to 0.8 2021-08-17 18:55:07 +00:00
Matt Corallo
84909447e9 Check IO errors in test using raw_os_error() instead of kind()
std::io::ErrorKind is a `#[non_exhaustive]` enum as more specific
error types are to be added in the future. It was unclear in the
docs until very recently, however, that this is to be done by
re-defining `ErrorKind::Other` errors to new enum variants. Thus,
our tests which check explicitly for `ErrorKind::Other` as a
result of trying to access a directory as a file were incorrect.
Sadly, these generated no meaningful feedback from rustc at all,
except that they're suddenly failing in rustc beta!

After some back-and-forth, it seems rustc is moving forward
breaking existing code in future versions, so we move to the
"correct" check here, which is to check the raw IO error.

See rust-lang/rust#86442 and rust-lang/rust#85746 for more info.
2021-08-02 18:50:00 +00:00
Matt Corallo
3f229052ea Bump dependencies to bitcoin 0.27 and bech32 0.8 2021-07-31 18:29:07 +00:00
Matt Corallo
c9a8b26d58 Bump most crate versions to 0.0.99 and lightning-invoice to 0.7.0 2021-07-09 16:34:46 +00:00
Matt Corallo
9c9081dfcb Bump versions to 0.0.98, lightning-invoice to 0.6.0 2021-06-08 21:08:29 +00:00
Matt Corallo
f551d5946b Bump versions to 0.0.14, lightning-invoice 0.5 2021-05-01 00:43:15 +00:00
Valentine Wallace
6f5d81631a
Make _test_utils depend on bitcoinconsensus feature 2021-04-29 18:39:47 -04:00
Matt Corallo
5e968114b6 Drop the amount parameter to claim_funds
Like the payment_secret parameter, this paramter has been the source
of much confusion, so we just drop it.

Users should prefer to do this check when registering the payment
secret instead of at claim-time.
2021-04-28 15:30:25 -04:00
Matt Corallo
3fdf252bd3 Improve + fix indentation and style in lightning-persister 2021-04-12 19:28:17 -04:00
Matt Corallo
6b2e179bc1 Return ChannelMonitors in a Vec, not HashMap when loading from disk
There's little reason for the HashMap - the ChannelMonitors are
already unique (enforced by file names), and the eventual HashMap
that users need when deserializing the `ChannelManager` is a
slightly different form (it requires no BlockHash entry).
2021-04-12 18:35:24 -04:00
Matt Corallo
0a11eb19ab Expand persistence to all ChannelManagers, not just Arc-based ones 2021-04-12 13:49:08 -04:00
Matt Corallo
dba0709b08
Merge pull request #861 from lightning-signer/degenerify
De-generify Sign methods
2021-04-09 23:57:20 +00:00
Matt Corallo
24c1cfe810
Merge pull request #863 from valentinewallace/expose-read-chanmons-from-disk
persister: Expose method to read ChannelMonitors from disk
2021-04-09 16:56:07 +00:00
Valentine Wallace
94aa47b510
persister: Expose method to read ChannelMonitors from disk 2021-04-09 11:19:17 -04:00
Devrandom
db0287137f Separate Clone from Sign
Clone requires Sized, which prevents Sign from being a dyn object.
2021-04-09 11:19:22 +02:00
Matt Corallo
e23c270720
Merge pull request #838 from TheBlueMatt/2021-03-skip-blocks
Make `Channel`'s block connection API more electrum-friendly
2021-04-05 22:12:45 +00:00
Matt Corallo
871f414367 More regularly send an Error message when we force-close a channel
When we force-close a channel, for whatever reason, it is nice to
send an error message to our peer. This allows them to closes the
channel on their end instead of trying to send through it and
failing. Further, it may induce them to broadcast their commitment
transaction, possibly getting that confirmed and saving us on fees.

This commit adds a few more cases where we should have been sending
error messages but weren't. It also includes an almost-global
replace in tests of the second argument in
`check_closed_broadcast!()` from false to true (indicating an error
message is expected). There are only a few exceptions, notably
those where the closure is the result of our counterparty having
sent *us* an error message.
2021-04-05 13:03:04 -04:00
Matt Corallo
8a9f0b8ced Also benchmark sending funds with a FilesystemPersister 2021-04-01 15:15:36 -04:00
Matt Corallo
4fc05af870 Drop height parameter from [dis]connect_block in functional tests 2021-03-19 23:32:38 -04:00
Matt Corallo
e985334fd2 Fix block connection ordering in a number of functional tests
Many functional tests rely on being able to call block_connected
arbitrarily, jumping back in time to confirm a transaction at a
specific height. Instead, this takes us one step towards having a
well-formed blockchain in the functional tests.

We also take this opportunity to reduce the number of blocks
connected during tests, requiring a number of constant tweaks in
various functional tests.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Matt Corallo <git@bluematt.me>
2021-03-19 23:32:38 -04:00
Matt Corallo
b2c5e3aedb Add assertions for in-order block [dis]connection in ChannelManager
Sadly the connected-in-order tests have to be skipped in our normal
test suite as many tests violate it. Luckily we can still enforce
it in the tests which run in other crates.

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2021-03-19 23:32:38 -04:00
Matt Corallo
2c7c1a6a7a Enforce no missing docs in all crates (+ add docs that were missing) 2021-03-18 11:28:23 -04:00
Matt Corallo
18a0967758 Enforce doc link correctness during cargo doc runs and in CI 2021-03-18 11:28:23 -04:00
Matt Corallo
eeec6fac5c Update licenses and add missing fields in Cargo.toml files 2021-03-09 16:53:03 -05:00
Matt Corallo
d65d7e7257 Bump versions to 0.0.13 across the board
We also skip having different versions for different subcrates,
since that is confusing.
2021-03-09 14:11:11 -05:00
Jeffrey Czyz
4cd2e4e94b
Revert "Merge pull request #819 from TheBlueMatt/2021-03-810-rebased"
This reverts commit 793de5fe69, reversing
changes made to 03a5189651.
2021-03-05 13:35:07 -08:00
Valentine Wallace
7c8e740b6e Change ChannelMonitor deserialization to return an optional blockhash.
See previous commit msg for details.
2021-03-02 14:30:56 -05:00
Matt Corallo
9fba7c92ad
Merge pull request #802 from TheBlueMatt/2021-01-update-rust-bitcoin
Update rust-bitcoin and add secp256k1 context randomization
2021-02-28 16:43:08 -08:00
Matt Corallo
a51d5cef58 Update rust-bitcoin 2021-02-26 15:15:18 -05:00
Valentine Wallace
bfaec717ae
persist: Persist ChannelMonitors in their own directory. 2021-02-26 12:38:47 -05:00
Matt Corallo
aa127f55ed Use ChannelSigner instead of ChanSigner for type parameters 2021-02-19 16:04:19 -05:00
Matt Corallo
523fcb6f3f Change Persist's Sign from an associated type to a generic param 2021-02-19 16:04:19 -05:00
Matt Corallo
ff00f6f886 Rename ChannelKeys -> Sign and generic it consistently
The `ChannelKeys` object really isn't about keys at all anymore,
its all about signing. At the same time, we rename the type aliases
used in traits from both `ChanKeySigner` and `Keys` to just
`Signer` (or, in contexts where Channel isnt clear, `ChanSigner`).
2021-02-19 15:54:41 -05:00
Valentine Wallace
a368093803
Add BackgroundProcessor for ChannelManager persistence and other
Other includes calling timer_chan_freshness_every_minute() and in the
future, possibly persisting channel graph data.

This struct is suitable for things that need to happen periodically and
can happen in the background.
2021-02-19 15:00:43 -05:00
Valentine Wallace
a88dfbfcca
Fix Windows persistence
Windows started giving 'Access is denied' errors after
a few rounds of persistence. This seems to fix it.
2021-02-19 15:00:43 -05:00
Valentine Wallace
36eaccc607
Abstract out disk-writing utilities from FilesystemPersister 2021-02-19 15:00:43 -05:00
Matt Corallo
f151c02975
Merge pull request #764 from lightning-signer/revoke-enforcement
Revocation enforcement
2021-01-25 09:06:43 -08:00
Sergi Delgado Segura
821f6cdd1e
Makes ChannelManager::force_close_channel fail for unknown chan_ids
ChannelManager::force_close_channel does not fail if a non-existing channel id is being passed, making it hard to catch from an API point of view.

Makes force_close_channel return in the same way close_channel does so the user calling the method with an unknown id can be warned.
2021-01-21 16:12:57 +01:00
Devrandom
2cbb8358f1 Use TestKeysInterface in functional tests
This allows stateful validation in EnforcingChannelKeys
2021-01-18 11:59:39 -08:00
Matt Corallo
990d1de99a Use KeysInterface::read_chan_signer for all channel keys deser
This drops any direct calls to a generic `ChannelKeys::read()` and
replaces it with the new `KeysInterface::read_chan_signer()`. Still,
under the hood all of our own `KeysInterface::read_chan_signer()`
implementations simply call out to a `Readable::read()` implemention.
2021-01-04 12:40:40 -05:00
Matt Corallo
0f5580afd4 Use Writeable for ChannelMonitor instead of a specific function.
There's no reason to have ChannelMonitor::write_for_disk instead of
just using the Writeable trait anymore. Previously, it was used to
differentiate with `write_for_watchtower`, but support for
watchtower-mode ChannelMonitors was never completed and the partial
bits were removed long ago.

This has the nice benefit of hitting the custom Writeable codepaths
in C bindings instead of trying to hit trait-generics paths.
2021-01-04 12:40:40 -05:00