Commit graph

743 commits

Author SHA1 Message Date
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
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
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
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
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
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
18a0967758 Enforce doc link correctness during cargo doc runs and in CI 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
Valentine Wallace
5b28744755
Add CounterpartyForwardingInfo field to channel.
This will be filled in in upcoming commits, then exposed in ChannelDetails
to allow constructing route hints for invoices.

Also update the cltv_expiry_deta comment in msgs::ChannelUpdate

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Antoine Riard <ariard@student.42.fr>
2021-03-17 17:36:21 -04:00
Matt Corallo
8799a2a044
Merge pull request #828 from bmancini55/reply_channel_range
Handle query_channel_range gossip queries
2021-03-17 20:35:03 +00:00
bmancini55
7b842b61f8 Simplify sequencing of handle_query_channel_range
Modify NetGraphMsgHandler::handle_query_channel_range to always use
first_blocknum=0 in replies. This is spec compliant after changes to
make sequence completion explicity using sync_complete.
2021-03-16 19:36:38 -04:00
bmancini55
7815965bf7 Comment cleanup for handling query_channel_range
Cleans up NetGraphMsgHandler::handle_query_channel_range
2021-03-16 19:36:30 -04:00
bmancini55
f4adb9f013 Use constant MAX_REPLY_SCID
Modifies NetGraphMsgHandler::handle_query_channel_range to use a constant
max value in replies. Modifies tests to generate 8000 channels instead
of making this value configurable.
2021-03-13 14:51:36 -05:00
Valentine Wallace
e0c8ec56dc
Add methods to set features in Features objects. 2021-03-12 12:57:55 -05:00
Matt Corallo
52edab7055
Merge pull request #837 from TheBlueMatt/2021-03-0.0.13 2021-03-10 23:26:50 +00:00
bmancini55
1809ef199e Use constant in QueryChannelRange::end_blocknum
Clarifies u32 max value used as the default.
2021-03-10 06:46:44 -05:00
Matt Corallo
c9321c5ec0
Merge pull request #834 from TheBlueMatt/2021-03-no-pub-internals
Make `util::logger::macro_logger` pub(crate) not pub.
2021-03-10 01:54:55 +00:00
Matt Corallo
eeec6fac5c Update licenses and add missing fields in Cargo.toml files 2021-03-09 16:53:03 -05:00
bmancini55
deffb4a3d8 Clean up iteration in handle_query_channel_range
Refactor to use an enumerator in NetGraphMsgHandler::handle_query_channel_range
2021-03-09 16:30:52 -05:00
bmancini55
dd0bb25694 Use scid_from_parts in Channel::block_connected
Refactors validation and short_channel_id construction to use
the new scid_from_parts function.
2021-03-09 15:42:45 -05:00
bmancini55
d5fd8d96e1 Improve short_channel_id utils
Modifies scid_from_parts to use u64 inputs allowing untruncated
validation. Adds public constants for limits.
2021-03-09 15:34:52 -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
Matt Corallo
c896461319
Merge pull request #827 from TheBlueMatt/2021-03-invoice-features
Disable MPP routing when the payee does not support it
2021-03-09 17:16:50 +00:00
Matt Corallo
2cb655b3b1
Merge pull request #826 from valentinewallace/raise-max-to-self-delay
Raise max to_self_delay.
2021-03-08 15:44:18 -08:00
Valentine Wallace
b75437dcb1
Raise max to_self_delay.
lnd requires this to_self_delay for the max channel size
(excluding wumbo).
2021-03-08 17:30:02 -05:00
Matt Corallo
b9fef85aa3 Split router benchmark into an MPP and a non-MPP route benchmark 2021-03-08 17:19:23 -05:00
Matt Corallo
ef0f249294 Disable MPP routing when the payee does not support it 2021-03-08 17:19:23 -05:00
Matt Corallo
9e57364a89 Add an Option<>al InvoiceFeatures object for the payee in get_route
We currently only use it to override the graph-specific features
returned in the route, though we should also use it to enable or
disable MPP.

Note that tests which relied on MPP behavior have had all of their
get_route calls upgraded to provide the MPP flag.
2021-03-08 17:19:23 -05:00
Matt Corallo
05ac59c42f
Merge pull request #830 from TheBlueMatt/2021-03-chanmon-deser-utils
Make chain::Filter slightly easier with some ChannelMonitor utilities.
2021-03-08 13:25:56 -08:00
Matt Corallo
9b55c0349a Make util::logger::macro_logger pub(crate) not pub.
There is no reason for it to be pub, its a largely-internal
implementation detail of how we format our own objects for logging.
2021-03-08 16:23:01 -05:00
Matt Corallo
5b230d9137 Create new InvoiceFeatures object for Invoice-specific features
In the past we skipped doing this since invoice parsing occurs in a
different crate. However, we need to accept InvoiceFeatures in routing
now that we support MPP route collection, to detect if we can select
multiple paths or not. Further, we should probably take
rust-lightning-invoice as either a module or a subcrate in this repo.
2021-03-08 13:28:54 -05:00
Matt Corallo
f52f777c97 Use the new load_outputs_to_watch util in ChainMonitor
This is slightly more effecient as it avoids a clone, but its also
nice to use our own code more.
2021-03-08 11:45:32 -05:00
Matt Corallo
154dfe5755 Make get_outputs_to_watch return a Vec instead of a HashMap
`get_outputs_to_watch` returned a reference to an existing
`HashMap` avoiding extra clones, but there isn't a huge reason to
do so now that we have to clone to copy it out of the
`ChannelMonitor` mutex. Instead, return a `Vec` since it may be
less memory and it allows us to have a bindings C mapping for the
function.

Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
Co-authored-by: Matt Corallo <git@bluematt.me>
2021-03-08 11:45:32 -05:00
Jeffrey Czyz
7a0acf951d
Fix misspelling of 'occurred' in public interface 2021-03-08 00:09:58 -08:00