Commit graph

4870 commits

Author SHA1 Message Date
Matt Corallo
56f979be3e Track actions to execute after a ChannelMonitor is updated
When a `ChannelMonitor` update completes, we may need to take some
further action, such as exposing an `Event` to the user initiating
another `ChannelMonitor` update, etc. This commit adds the basic
structure to track such actions and serialize them as required.

Note that while this does introduce a new map which is written as
an even value which users cannot opt out of, the map is only filled
in when users use the asynchronous `ChannelMonitor` updates. As
these are still considered beta, breaking downgrades for such users
is considered acceptable here.
2023-02-17 19:09:28 +00:00
Matt Corallo
8aa518f23d Add an infallible no-sign version of send_commitment_no_status_check
In the coming commits we'll move to async `ChannelMonitorUpdate`
application, which means we'll want to generate a
`ChannelMonitorUpdate` (including a new counterparty commitment
transaction) before we actually send it to our counterparty. To do
that today we'd have to actually sign the commitment transaction
by calling the signer, then drop it, apply the
`ChannelMonitorUpdate`, then re-sign the commitment transaction to
send it to our peer.

In this commit we instead split `send_commitment_no_status_check`
and `send_commitment_no_state_update` into `build_` and `send_`
variants, allowing us to generate new counterparty commitment
transactions without actually signing, then build them for sending,
with signatures, later.
2023-02-17 19:09:28 +00:00
Matt Corallo
5be29c6add Fix the err msg provided when a send fails due to peer disconnected
We haven't had a `MonitorUpdateInProgress` check in
`Channel::is_live` for some time.
2023-02-17 19:09:28 +00:00
Matt Corallo
d0b8f455fe
Merge pull request #2009 from TheBlueMatt/2023-02-no-racey-retries
Fix (and test) threaded payment retries
2023-02-16 23:41:09 +00:00
Matt Corallo
d986329734 Fix (and test) threaded payment retries
The new in-`ChannelManager` retries logic does retries as two
separate steps, under two separate locks - first it calculates
the amount that needs to be retried, then it actually sends it.
Because the first step doesn't udpate the amount, a second thread
may come along and calculate the same amount and end up retrying
duplicatively.

Because we generally shouldn't ever be processing retries at the
same time, the fix is trivial - simply take a lock at the top of
the retry loop and hold it until we're done.
2023-02-16 21:35:25 +00:00
Matt Corallo
1dc96cbde2 Always check next_route in TestRouter is fully consumed
...rather than only in std.
2023-02-16 21:35:25 +00:00
Matt Corallo
6090d9e6a8 Test if a given mutex is locked by the current thread in tests
In anticipation of the next commit(s) adding threaded tests, we
need to ensure our lockorder checks work fine with multiple
threads. Sadly, currently we have tests in the form
`assert!(mutex.try_lock().is_ok())` to assert that a given mutex is
not locked by the caller to a function.

The fix is rather simple given we already track mutexes locked by a
thread in our `debug_sync` logic - simply replace the check with a
new extension trait which (for test builds) checks the locked state
by only looking at what was locked by the current thread.
2023-02-16 21:35:23 +00:00
Matt Corallo
a1704787b6
Merge pull request #2037 from valentinewallace/2023-02-fix-probe-leak
Fix outbound payments probe leak
2023-02-16 21:29:26 +00:00
Matt Corallo
4b043c97bc
Merge pull request #1921 from arik-so/2022-12-prohibit-old-rgs-updates
Throw error for RGS data that's more than two weeks old
2023-02-16 21:20:28 +00:00
Arik Sosman
2f36c921b6
Throw error for RGS data that's more than two weeks old, fixing #1785 2023-02-16 12:17:42 -08:00
Valentine Wallace
a2b956d46e
Remove pending probes on update_fail
Previously we had a memory leak where probes would not be removed from
outbound_payments on htlc fail
2023-02-15 23:30:46 -05:00
Matt Corallo
30b9d9fbea
Merge pull request #2008 from valentinewallace/2023-02-remove-manual-retries
Abandon payments on behalf of the user and remove manual retries
2023-02-16 00:49:04 +00:00
Valentine Wallace
da34ada8d4
Reword and fix grammar in PartialFailure docs 2023-02-15 17:59:44 -05:00
Valentine Wallace
5c6d8a7cb8
Remove retry_payments method
We're no longer supporting manual retries since
ChannelManager::send_payment_with_retry can be parameterized by a retry
strategy

This commit also updates all docs related to retry_payment and abandon_payment.
Since these docs frequently overlap with changes in preceding commits where we
start abandoning payments on behalf of the user, all the docs are updated in
one go.
2023-02-15 17:59:39 -05:00
Valentine Wallace
13e60da7fa
When processing pending htlcs, abandon outbounds that are not retryable 2023-02-15 17:57:13 -05:00
Valentine Wallace
82e0880442
Abandon payment on behalf of the user on payment path failure
Removed retry_single_path_payment, it's replaced by automatic_retries with
AutoRetry::Success
2023-02-15 17:46:30 -05:00
Valentine Wallace
07dd8b2794
Abandon payment if retry fails in process_pending_htlcs 2023-02-15 15:55:00 -05:00
Matt Corallo
5e9e68ad68
Merge pull request #1832 from jkczyz/2022-11-composite-handler
Macro for composing custom message handlers
2023-02-15 17:45:39 +00:00
Valentine Wallace
f8712106d2
Pass pending events to outbound_payments::abandon_payment
This makes it uniform with the outbound payment methods that generate events
and set us up for abandoning payments on behalf of the user.
2023-02-14 22:51:28 -05:00
Valentine Wallace
8d0c08c155
Fix indentation in outbound payment mark_abandoned 2023-02-14 21:29:34 -05:00
Matt Corallo
2edb3f1983
Merge pull request #2020 from valentinewallace/2023-02-test-inflight-scoring
Fix and test in-flight HTLC scoring in between retries
2023-02-15 01:25:09 +00:00
Jeffrey Czyz
9876a08aab
Add CI testing for lightning-custom-message crate 2023-02-14 18:20:56 -06:00
Jeffrey Czyz
c31fe8ce67
Re-write CustomMessageHandler documentation
Documentation for CustomMessageHandler wasn't clear how it is related to
PeerManager and contained some grammatical and factual errors. Re-write
the docs and link to the lightning_custom_message crate.
2023-02-14 18:20:56 -06:00
Jeffrey Czyz
d956634eec
Fix compilation errors in some doc tests
These are seen in newer versions of rustc.
2023-02-14 18:20:56 -06:00
Jeffrey Czyz
6e0384e39c
Macro for composing custom message handlers
BOLT 1 specifies a custom message type range for use with experimental
or application-specific messages. While a `CustomMessageHandler` can be
defined to support more than one message type, defining such a handler
requires a significant amount of boilerplate and can be error prone.

Add a crate exporting a `composite_custom_message_handler` macro for
easily composing pre-defined custom message handlers. The resulting
handler can be further composed with other custom message handlers using
the same macro.

This requires a separate crate since the macro needs to support "or"
patterns in macro_rules, which is only available in edition 2021.

https://doc.rust-lang.org/edition-guide/rust-2021/or-patterns-macro-rules.html

Otherwise, a crate defining a handler for a set of custom messages could
not easily be reused with another custom message handler. Doing so would
require explicitly duplicating the reused handlers type ids, but those
may change when the crate is updated.
2023-02-14 18:20:40 -06:00
Matt Corallo
9422370dd2 Move fairrwlock to the sync module 2023-02-14 23:33:02 +00:00
Matt Corallo
9f102037a9
Merge pull request #2029 from wpaulino/update-pgp-key
Update Wilmer Paulino's PGP key
2023-02-14 22:20:46 +00:00
Valentine Wallace
2b2965f1fe
Remove unnecessary scoring methods from Router trait 2023-02-14 14:20:49 -05:00
Valentine Wallace
825ea9d062
Fix computing in-flight HTLCs in between retries + test 2023-02-14 14:20:49 -05:00
Valentine Wallace
aa4b429eb2
test_utils: parameterize TestRouter by TestScorer
This allows us set scoring expectations and ensure in-flight htlcs are factored
into scoring
2023-02-14 14:20:48 -05:00
Matt Corallo
33720b07a0
Merge pull request #1966 from ViktorTigerstrom/2023-01-store-channels-per-peer-followups
1507 followups
2023-02-14 18:44:35 +00:00
Viktor Tigerström
7f6f90dc78 Don't serialize nodes which we have no channels to 2023-02-14 15:04:30 +01:00
Viktor Tigerström
9ae2810c31 Initialize list_channels_with_filter result vec with capacity 2023-02-14 15:04:30 +01:00
Viktor Tigerström
4fc15f0e12 Update unknown peer passed to msg and api functions handling 2023-02-14 15:04:30 +01:00
Viktor Tigerström
6ffd02237f Always remove disconnected peers with no channels
When a peer disconnects but still has channels, the peer's `peer_state`
entry in the `per_peer_state` is not removed by the `peer_disconnected`
function. If the channels with that peer is later closed while still
being disconnected (i.e. force closed), we therefore need to remove the
peer from `peer_state` separately.

To remove the peers separately, we push such peers to a separate HashSet
that holds peers awaiting removal, and remove the peers on a timer to
limit the negative effects on parallelism as much as possible.
2023-02-14 15:04:30 +01:00
Viktor Tigerström
3d38364173 Update ChannelManager docs
Updates multiple instances of the `ChannelManager` docs related to the
previous change that moved the storage of the channels to the
`per_peer_state`. This docs update corrects some grammar errors and
incorrect information, as well as clarifies documentation that was
confusing.
2023-02-14 15:04:30 +01:00
Viktor Tigerström
b45d69ea7c Check peer_state existence more idiomatically 2023-02-14 15:04:16 +01:00
Viktor Tigerström
29ed2864f3 Remove redundant Vec in get_and_clear_pending_msg_events 2023-02-14 15:03:32 +01:00
Viktor Tigerström
a0adc51da1 Don't clone the Vec in remove_first_msg_event_to_node 2023-02-14 15:03:32 +01:00
Viktor Tigerström
b852df5276 Remove redundant hashmap lookups
Avoid doing the same hashmap lookups twice in a row, when it's not
needed. Refactor `claim_funds_from_hop` in order to enable this change.
2023-02-14 15:03:26 +01:00
Wilmer Paulino
403db28636
Update Wilmer Paulino's PGP key
The old key (729E9D9D92C75A5FBFEEE057B5DD717BEF7CA5B1) has been revoked
as of 2023-02-11.

All commits going forward will be signed with the new key.
2023-02-12 12:11:35 -08:00
wpaulino
be4bb58573
Merge pull request #1980 from TheBlueMatt/2023-01-async-utxo-lookups 2023-02-10 19:57:11 -08:00
Matt Corallo
90bb3f9075
Merge pull request #2019 from tnull/2023-02-expose-peer-addrs
Expose peer addresses in `PeerManager`
2023-02-10 21:20:36 +00:00
Matt Corallo
50a39b9647
Merge pull request #2027 from danielgranhao/fix-create-inbound-payment-docs
Fix out-of-date `create_inbound_payment()` docs
2023-02-10 17:41:18 +00:00
Elias Rohrer
36e0cffc8b
Test get_peer_nodeids returns peer addresses 2023-02-10 11:31:10 -06:00
Elias Rohrer
2e8f73e52d
Expose peer addresses via get_peer_node_ids 2023-02-10 11:01:55 -06:00
Daniel Granhão
dab08c1135
Fix out-of-date create_inbound_payment() docs 2023-02-10 16:09:24 +00:00
Matt Corallo
41a6c674f9
Merge pull request #1870 from tnull/2022-11-add-transaction-sync-crate
Add transaction sync crate
2023-02-10 00:11:59 +00:00
Elias Rohrer
ce8b5ba0f7
Build and test transaction sync crate in CI 2023-02-09 15:28:46 -06:00
Elias Rohrer
c032d3cb52
Test syncing against Esplora backend 2023-02-09 15:28:46 -06:00