Commit graph

736 commits

Author SHA1 Message Date
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
Matt Corallo
d039fc5cd1 Make IgnoringMessageHandler and ErroringMessageHandler pub
This is largely useful for bindings, and the off-github discussion
around #814 concluded these should be pub, but the PR was not
updated to capture this. Now that the bindings support generation
for the structs, expose them.
2021-03-07 13:06:07 -05:00
Matt Corallo
578f8b72e2 Change ChannelManager::wait to be more descriptive
`wait` doesn't capture enough of what's going on, but also Java
Java doesn't accpet methods just called `wait`, as it conflicts
with existing sync primitives on all Objects.
2021-03-07 13:06:07 -05:00
Matt Corallo
135cff1c95 Add utility in ChannelMonitor to reload chain::Filter data
The deserialization process for `ChannelManager`/`ChannelMonitor`
data includes reloading any relevant `chain::Filter` with data
provided from the `ChannelMonitor`, but its nice if we adapt the
data to `chain::Filter` calls for users.
2021-03-07 13:05:04 -05:00
Jeffrey Czyz
873014875c
Correctly update the last block hash on disconnect
When a block is disconnected, the hash of the disconnected block was
used to update the last connected block. However, this amounts to a
no-op because these hashes should be equal. Successive disconnections
would update the hash but leave it one block off.

Normally, this not a problem because the last block_disconnected should
be followed by block_connected since the former is triggered by a chain
re-org. However, this assumes the user calls the API correctly and that
no failure occurs that would prevent block_connected from being called
(e.g., if fetching the connected block fails).

Instead, update the last block hash with the disconnected block's
previous block hash.
2021-03-05 15:45:13 -08:00
Jeffrey Czyz
035dda6708
Hold ChannelManager locks independently
ChannelManager reads channel_state and last_block_hash while processing
funding_created and funding_signed messages. It writes these while
processing block_connected and block_disconnected events. To avoid any
potential deadlocks, have each site hold these locks independent of one
another and in a consistent order.

Additionally, use a RwLock instead of Mutex for last_block_hash since
exclusive access is not needed in funding_created / funding_signed and
cannot be guaranteed in block_connected / block_disconnected because of
the reads in the former.
2021-03-05 15:45:13 -08:00
Jeffrey Czyz
d21d8b3463
Rename header_hash to block_hash 2021-03-05 15:45:12 -08:00
Jeffrey Czyz
31093adef8
Pass along ChannelManager's last_block_hash
ChannelMonitor keeps track of the last block connected. However, it is
initialized with the default block hash, which is a problem if the
ChannelMonitor is serialized before a block is connected. Instead, pass
ChannelManager's last_block_hash, which is initialized with a "birthday"
hash, when creating a new ChannelMonitor.
2021-03-05 15:45:12 -08:00