Commit graph

2295 commits

Author SHA1 Message Date
Matt Corallo
c88b707ac2 Drop ChannelManager::block_disconnected() entirely
It is now entirely redundant with ChannelManager::update_best_block
and is still accessible via `Listen::block_disconnected`.
2021-04-05 17:33:04 -04:00
Matt Corallo
a15c8541dc Make the ChannelManager::block_connected API more electrum-friendly
See the similar commit that operates on `Channel`'s internal API
for more details on the reasoning.
2021-04-05 17:33:04 -04:00
Matt Corallo
d255d91a2a Log the node generating an onion error 2021-04-05 16:23:34 -04:00
Matt Corallo
60b962a18e Move ChannelManager to Channel's new block data API
This also moves the scanning of the block for commitment
transactions into channel, unifying the error path.
2021-04-05 13:03:04 -04: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
de6ddedba8
Merge pull request #864 from valentinewallace/background-process-peer-events
Call peer_manager.process_events() in BackgroundProcessor
2021-04-05 16:51:40 +00:00
Valentine Wallace
0c34529083
Call peer_manager.process_events() in BackgroundProcessor 2021-04-02 18:40:57 -04:00
Matt Corallo
2a432c6fa5 Make Channel's block connection API more electrum-friendly
Electrum clients primarily operate in a world where they query (and
subscribe to notifications for) transactions by script_pubkeys.
They may never learn very much about the actual blockchain and
orient their events around individual transactions, not the
blockchain.

This makes our ChannelManager interface somewhat more amenable to
such a client by splitting `block_connected` into
`transactions_confirmed` and `update_best_block`. The first handles
checking the funding transaction and storing its height/confirmation
block, whereas the second handles funding_locked and reorg logic.

Sadly, this interface is somewhat easy to misuse - notifying the
channel of the funding transaction being reorganized out of the
chain is complicated when the only notification received is that
a new block is connected at a given height. This will be addressed
in a future commit.
2021-04-02 13:32:34 -04:00
Matt Corallo
494d7dd4be Switch to height-based funding-tx tracking from conf-based tracking
Previously, we expected every block to be connected in-order,
allowing us to track confirmations by simply incrementing a counter
for each new block connected. In anticipation of moving to a
update-height model in the next commit, this moves to tracking
confirmations by simply storing the height at which the funding
transaction was confirmed.

This commit also corrects our "funding was reorganized out of the
best chain" heuristic, instead of a flat 6 blocks, it uses half the
confirmation count required as the point at which we force-close.

Even still, for low confirmation counts (eg 1 block), an ill-timed
reorg may still cause spurious force-closes, though that behavior
is not new in this commit.
2021-04-02 13:32:34 -04:00
Matt Corallo
df732f4a6d
Merge pull request #860 from TheBlueMatt/2021-03-bench-sends
Add a simple send-funds benchmark in channelmanager
2021-04-01 21:38:03 +00:00
Matt Corallo
8a9f0b8ced Also benchmark sending funds with a FilesystemPersister 2021-04-01 15:15:36 -04:00
Matt Corallo
7665b14842
Merge pull request #859 from TheBlueMatt/2021-03-fix-warns 2021-04-01 14:37:41 +00:00
Matt Corallo
780625674d Cache our node ID in ChannelManager
While its not necessarily a common operation on a running node,
`get_our_node_id()` is used incredibly heavily in tests, and there
is no reason to not eat the extra ~64 bytes to just cache it.
2021-03-31 19:55:25 -04:00
Matt Corallo
5927920f68 Add a simple send-funds benchmark in channelmanager 2021-03-31 19:55:23 -04:00
Matt Corallo
ccbff84119 Implement Persist for any Signer in TestPersister 2021-03-31 19:53:56 -04:00
Matt Corallo
d015ff250e Fix two new compiler warnings in fuzz
This fixes two trivial compiler warnings in fuzz that point to
broken usage of explicit `panic!()`s.
2021-03-30 23:21:54 -04:00
Matt Corallo
6fcac8bc65
Merge pull request #840 from jkczyz/2021-03-rescan-logic
Rescan dependent transactions in ChainMonitor
2021-03-28 19:47:09 +00:00
Jeffrey Czyz
d8d9eaf398
Test register_output is called on dependent txn
chain::Filter::register_output may return an in-block dependent
transaction that spends the output. Test the scenario where the txdata
given to ChainMonitor::block_connected includes a commitment transaction
whose HTLC output is spent in the same block but not included in txdata.
Instead, it is returned by chain::Filter::register_output when given the
commitment transaction's HTLC output. This is a common scenario for
Electrum clients, which provided filtered txdata.
2021-03-27 18:21:05 -04:00
Jeffrey Czyz
80e81fbea3
Mock-like expectations for TestChainSource
Add a method to TestChainSource to test chain::Filter expectations. This
is limited to register_output, allowing tests to assert that the method
was called with a specific output and dictate what the return value is.

Multiple expectations are checked in the order in which they were added.
Failure occurs if a call doesn't match the next expectation or if there
are unsatisfied expectations. If not expectations are added, then no
calls are checked.
2021-03-27 18:21:05 -04:00
Jeffrey Czyz
6b14adebdb
Add rescan logic to ChainMonitor::block_connected
Electrum clients will only provide transaction data for outputs that
have been explicitly registered. Hence, upon registering new outputs,
recursively register any outputs to watch contained within dependent
transactions from the same block.
2021-03-27 18:20:55 -04:00
Jeffrey Czyz
02b85fabcd
Include block hash for watched transaction output
When registering a watched transaction output, any in-block descendant
transactions spending the output must be supplied. Give the block hash
when registering such outputs such that this is possible. Otherwise,
spends from other blocks may be returned inadvertently.
2021-03-27 18:20:13 -04:00
Matt Corallo
fe8569638c
Merge pull request #855 from valentinewallace/expose-asyncblocksourceresult
Expose AsyncBlockSourceResult as pub
2021-03-26 19:41:55 +00:00
Valentine Wallace
85106c9768
Expose AsyncBlockSourceResult and BlockSourceResult as pub
Useful for writing objects that implement BlockSource trait.
2021-03-26 14:54:19 -04:00
Sergi Delgado Segura
c7f405edf5
Adds zbase32 encoding 2021-03-22 11:27:18 +01:00
Jeffrey Czyz
d70fdd3a5c
Return optional Transaction from register_output
Electrum clients primarily operate by subscribing to notifications of
transactions by script pubkeys. Therefore, they will send filtered
transaction data without including dependent transactions. Outputs for
such transactions must be explicitly registered with these clients.

Therefore, upon block_connected, provide a mechanism for an Electrum-
backed chain::Filter to return new transaction data to scan.
2021-03-21 00:54:36 -04:00
Matt Corallo
8a8c75a8fc
Merge pull request #846 from TheBlueMatt/2021-03-test-chains
Require syntactically-valid blockchains in functional and unit tests
2021-03-20 04:03:27 +00:00
Matt Corallo
4ebfa1d7ac [functional tests] Drop unused disconnect_block utility
This also reduces some needless clones and indirections.
2021-03-19 23:32:38 -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
580190f78a [tests] Demonstrate that the commit is trivially safe
See comment in the code, This commit exists only to aid reviewers.
2021-03-19 23:32:38 -04:00
Matt Corallo
f25a46cf42 [tests] Drop redundant parameters from connect_blocks 2021-03-19 23:32:38 -04:00
Matt Corallo
4266518d8d [test] Demonstrate that the next commit is trivially safe
See comment in the code. This commit exists only to aid reviewers.
2021-03-19 23:32:38 -04:00
Matt Corallo
561f0e22ac Enforce block connection ordering in unit and functional tests
This expands the assertions on block ordering to apply to
`#[cfg(test)]` builds in addition to normal builds, requiring that
unit and functional tests have syntactically-valid (ie the previous
block hash pointer and the heights match the blocks) blockchains.

This requires a reasonably nontrivial diff in the functional tests
however it is mostly straightforward changes.
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
0ac839d8cd Add Debug to derive list in MessageSendEvent
It can be quite useful in debugging, and potentially also so for
users.
2021-03-19 22:57:31 -04:00
Matt Corallo
d7402b7360 Clean up log warning in the event ChannelMonitor force-closed 2021-03-19 22:57:31 -04:00
Matt Corallo
80ee1daf3e
Merge pull request #849 from TheBlueMatt/2021-03-config-cltv-delta
Make cltv_expiry_delta configurable and reduce the min/default some
2021-03-20 02:52:51 +00:00
Matt Corallo
e640b935f5 Ignore patch codecov as long as total coverage is within 1% of base
In some PRs, codecov gets mad that the coverage of the patch itself
is lower than the base. In most cases, we largely don't want a Big
Red X, at least as long as the total coverage has not gone down
substantially.
2021-03-19 20:49:14 -04:00
Matt Corallo
7503e2a43b Tweak our_to_self_delay documentation wording to make it flow better 2021-03-19 20:49:14 -04:00
Matt Corallo
c8d4536b3e Make cltv_expiry_delta configurable and reduce the min/default some
We allow users to configure the to_self_delay, which is analogous to
the cltv_expiry_delta in terms of its security context, so we should
allow users to specify both.

We similarly bound it on the lower end, but reduce that bound
somewhat now that it is configurable.
2021-03-19 20:49:14 -04:00
Matt Corallo
fba204b02e
Merge pull request #848 from TheBlueMatt/2021-03-doc-cleanups
Clean up doc links and enforce them in CI
2021-03-18 15:59:44 +00:00
Matt Corallo
e44713190a Also correct/check links in private item documentation 2021-03-18 11:28:23 -04:00
Matt Corallo
836985a5e5 Drop all HTML-relative links since rustdoc now supports resolution 2021-03-18 11:28:23 -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
98c6566b01 Clean up some doc links in lightning_block_sync.
Relative HTML doc paths in doc links works locally, but breaks on
crates.io. Luckily, we can now use explicit full paths and rustdoc
will resolve them for us.
2021-03-18 11:28:23 -04:00
Matt Corallo
c88e3eb452 Expose the constants mentioned in docs, and use doc links 2021-03-18 11:28:23 -04:00
Matt Corallo
32f6205848
Merge pull request #841 from valentinewallace/207-replacement
Expose counterparty forwarding info in ChannelDetails
2021-03-17 22:41:30 +00:00
Valentine Wallace
c318ad87e0
Expose counterparty forwarding info in ChannelDetails.
Useful for constructing route hints for private channels in invoices.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Antoine Riard <ariard@student.42.fr>
2021-03-17 17:36:26 -04:00
Valentine Wallace
e8a0824dd4
Pass channel updates to ChannelManager and Channel.
This will be used to expose forwarding info for route hints in the next commit.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Antoine Riard <ariard@student.42.fr>
2021-03-17 17:36:26 -04:00