]> git.bitcoin.ninja Git - rust-lightning/log
rust-lightning
21 months agoAdd test of an initial message other than `Init`
Matt Corallo [Wed, 15 Feb 2023 01:54:21 +0000 (01:54 +0000)]
Add test of an initial message other than `Init`

This test fails without the previous commit.

21 months agoFix (and DRY) the conditionals before calling `peer_disconnected`
Matt Corallo [Wed, 15 Feb 2023 01:13:57 +0000 (01:13 +0000)]
Fix (and DRY) the conditionals before calling `peer_disconnected`

If we have a peer that sends a non-`Init` first message, we'll call
`peer_disconnected` without ever having called `peer_connected`
(which has to wait until we have an `Init` message). This is a
violation of our API guarantees, though should generally not be an
issue.

Because this bug was repeated in a few places, we also take this
opportunity to DRY up the logic which checks the peer state before
calling `peer_disconnected`.

Found by the new `ChannelManager` assertions and the
`full_stack_target` fuzzer.

21 months agoMerge pull request #2020 from valentinewallace/2023-02-test-inflight-scoring
Matt Corallo [Wed, 15 Feb 2023 01:25:09 +0000 (01:25 +0000)]
Merge pull request #2020 from valentinewallace/2023-02-test-inflight-scoring

Fix and test in-flight HTLC scoring in between retries

21 months agoMerge pull request #2029 from wpaulino/update-pgp-key
Matt Corallo [Tue, 14 Feb 2023 22:20:46 +0000 (22:20 +0000)]
Merge pull request #2029 from wpaulino/update-pgp-key

Update Wilmer Paulino's PGP key

21 months agoRemove unnecessary scoring methods from Router trait
Valentine Wallace [Thu, 9 Feb 2023 20:36:35 +0000 (14:36 -0600)]
Remove unnecessary scoring methods from Router trait

21 months agoFix computing in-flight HTLCs in between retries + test
Valentine Wallace [Tue, 7 Feb 2023 19:10:41 +0000 (14:10 -0500)]
Fix computing in-flight HTLCs in between retries + test

21 months agotest_utils: parameterize TestRouter by TestScorer
Valentine Wallace [Tue, 7 Feb 2023 19:04:55 +0000 (14:04 -0500)]
test_utils: parameterize TestRouter by TestScorer

This allows us set scoring expectations and ensure in-flight htlcs are factored
into scoring

21 months agoMerge pull request #1966 from ViktorTigerstrom/2023-01-store-channels-per-peer-followups
Matt Corallo [Tue, 14 Feb 2023 18:44:35 +0000 (18:44 +0000)]
Merge pull request #1966 from ViktorTigerstrom/2023-01-store-channels-per-peer-followups

1507 followups

21 months agoDon't serialize nodes which we have no channels to
Viktor Tigerström [Sat, 4 Feb 2023 18:14:42 +0000 (20:14 +0200)]
Don't serialize nodes which we have no channels to

21 months agoInitialize `list_channels_with_filter` result vec with capacity
Viktor Tigerström [Wed, 18 Jan 2023 01:30:36 +0000 (02:30 +0100)]
Initialize `list_channels_with_filter` result vec with capacity

21 months agoUpdate unknown peer passed to msg and api functions handling
Viktor Tigerström [Wed, 18 Jan 2023 01:20:09 +0000 (02:20 +0100)]
Update unknown peer passed to msg and api functions handling

21 months agoAlways remove disconnected peers with no channels
Viktor Tigerström [Tue, 17 Jan 2023 23:28:00 +0000 (00:28 +0100)]
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.

21 months agoUpdate `ChannelManager` docs
Viktor Tigerström [Sun, 15 Jan 2023 16:01:29 +0000 (17:01 +0100)]
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.

21 months agoCheck `peer_state` existence more idiomatically
Viktor Tigerström [Fri, 13 Jan 2023 20:11:00 +0000 (21:11 +0100)]
Check `peer_state` existence more idiomatically

21 months agoRemove redundant Vec in `get_and_clear_pending_msg_events`
Viktor Tigerström [Thu, 12 Jan 2023 22:25:44 +0000 (23:25 +0100)]
Remove redundant Vec in `get_and_clear_pending_msg_events`

21 months agoDon't clone the Vec in `remove_first_msg_event_to_node`
Viktor Tigerström [Thu, 12 Jan 2023 21:50:43 +0000 (22:50 +0100)]
Don't clone the Vec in `remove_first_msg_event_to_node`

21 months agoRemove redundant hashmap lookups
Viktor Tigerström [Thu, 12 Jan 2023 20:51:18 +0000 (21:51 +0100)]
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.

21 months agoUpdate Wilmer Paulino's PGP key
Wilmer Paulino [Sun, 12 Feb 2023 20:11:35 +0000 (12:11 -0800)]
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.

21 months agoMerge pull request #1980 from TheBlueMatt/2023-01-async-utxo-lookups
wpaulino [Sat, 11 Feb 2023 03:57:11 +0000 (19:57 -0800)]
Merge pull request #1980 from TheBlueMatt/2023-01-async-utxo-lookups

21 months agoMerge pull request #2019 from tnull/2023-02-expose-peer-addrs
Matt Corallo [Fri, 10 Feb 2023 21:20:36 +0000 (21:20 +0000)]
Merge pull request #2019 from tnull/2023-02-expose-peer-addrs

Expose peer addresses in `PeerManager`

21 months agoMerge pull request #2027 from danielgranhao/fix-create-inbound-payment-docs
Matt Corallo [Fri, 10 Feb 2023 17:41:18 +0000 (17:41 +0000)]
Merge pull request #2027 from danielgranhao/fix-create-inbound-payment-docs

Fix out-of-date `create_inbound_payment()` docs

21 months agoTest `get_peer_nodeids` returns peer addresses
Elias Rohrer [Fri, 10 Feb 2023 17:31:10 +0000 (11:31 -0600)]
Test `get_peer_nodeids` returns peer addresses

21 months agoExpose peer addresses via `get_peer_node_ids`
Elias Rohrer [Tue, 7 Feb 2023 17:22:12 +0000 (11:22 -0600)]
Expose peer addresses via `get_peer_node_ids`

21 months agoFix out-of-date `create_inbound_payment()` docs
Daniel Granhão [Fri, 10 Feb 2023 16:09:24 +0000 (16:09 +0000)]
Fix out-of-date `create_inbound_payment()` docs

21 months agoMerge pull request #1870 from tnull/2022-11-add-transaction-sync-crate
Matt Corallo [Fri, 10 Feb 2023 00:11:59 +0000 (00:11 +0000)]
Merge pull request #1870 from tnull/2022-11-add-transaction-sync-crate

Add transaction sync crate

21 months agoBuild and test transaction sync crate in CI
Elias Rohrer [Thu, 19 Jan 2023 17:45:46 +0000 (11:45 -0600)]
Build and test transaction sync crate in CI

21 months agoTest syncing against Esplora backend
Elias Rohrer [Fri, 6 Jan 2023 12:17:48 +0000 (13:17 +0100)]
Test syncing against Esplora backend

21 months agoAdd transaction sync crate
Elias Rohrer [Wed, 23 Nov 2022 08:33:37 +0000 (09:33 +0100)]
Add transaction sync crate

This crate provides utilities for syncing LDK via the transaction-based
`Confirm` interface. The initial implementation facilitates
synchronization with an Esplora backend server.

21 months agoMove the channel_announcement process log into `NetworkGraph` 2023-01-async-utxo-lookups
Matt Corallo [Thu, 26 Jan 2023 03:04:14 +0000 (03:04 +0000)]
Move the channel_announcement process log into `NetworkGraph`

This ensures its always written after we update the graph, no
matter how we updated the graph.

21 months agoAdd tests for the new async gossip checking internal APIs
Matt Corallo [Mon, 23 Jan 2023 04:59:13 +0000 (04:59 +0000)]
Add tests for the new async gossip checking internal APIs

21 months agoSupport async results in `TestChainSource`, count `get_utxo` calls
Matt Corallo [Wed, 8 Feb 2023 22:26:56 +0000 (22:26 +0000)]
Support async results in `TestChainSource`, count `get_utxo` calls

21 months agoSuggest a socket read buffer of 4KiB to limit message count
Matt Corallo [Wed, 1 Feb 2023 21:09:46 +0000 (21:09 +0000)]
Suggest a socket read buffer of 4KiB to limit message count

...and switch the same in `lightning-net-tokio`

21 months agoDon't apply gossip backpressure to non-channel-announcing peers
Matt Corallo [Mon, 30 Jan 2023 17:56:46 +0000 (17:56 +0000)]
Don't apply gossip backpressure to non-channel-announcing peers

When we apply the new gossip-async-check backpressure on peer
connections, if a peer has never sent us a `channel_announcement`
at all, we really shouldn't delay reading their messages.

This does so by tracking, on a per-peer basis, whether they've sent
us a channel_announcement, and resetting that state whenever we're
not backlogged.

21 months agoApply backpressure when we have too many gossip checks in-flight
Matt Corallo [Sun, 22 Jan 2023 18:08:33 +0000 (18:08 +0000)]
Apply backpressure when we have too many gossip checks in-flight

Now that the `RoutingMessageHandler` can signal that it needs to
apply message backpressure, we implement it here in the
`PeerManager`. There's not much complicated here, aside from noting
that we need to add the ability to call `send_data` with no data
to indicate that reading should resume (and track when we may need
to make such calls when updating the routing-backpressure state).

21 months agoAllow `RoutingMessageHandler` to signal backpressure
Matt Corallo [Sun, 22 Jan 2023 05:12:45 +0000 (05:12 +0000)]
Allow `RoutingMessageHandler` to signal backpressure

Now that we allow `handle_channel_announcement` to (indirectly)
spawn async tasks which will complete later, we have to ensure it
can apply backpressure all the way up to the TCP socket to ensure
we don't end up with too many buffers allocated for UTXO
validation.

We do this by adding a new method to `RoutingMessageHandler` which
allows it to signal if there are "many" checks pending and
`channel_announcement` messages should be delayed. The actual
`PeerManager` implementation thereof is done in the next commit.

21 months agoForward gossip messages which were verified asynchronously
Matt Corallo [Sun, 22 Jan 2023 04:14:58 +0000 (04:14 +0000)]
Forward gossip messages which were verified asynchronously

Gossip messages which were verified against the chain
asynchronously should still be forwarded to peers, but must now go
out via a new `P2PGossipSync` parameter in the
`AccessResolver::resolve` method, allowing us to wire them up to
the `P2PGossipSync`'s `MessageSendEventsProvider` implementation.

21 months agoAdd the ability to broadcast gossip msgs via the event pipeline
Matt Corallo [Sun, 22 Jan 2023 03:41:28 +0000 (03:41 +0000)]
Add the ability to broadcast gossip msgs via the event pipeline

When we process gossip messages asynchronously we may find that we
want to forward a gossip message to a peer after we've returned
from the existing `handle_*` method. In order to do so, we need to
be able to send arbitrary loose gossip messages back to the
`PeerManager` via `MessageSendEvent`.

This commit modifies `MessageSendEvent` in order to support this.

21 months agoProcess `channel_update`/`node_announcement` async if needed
Matt Corallo [Tue, 7 Feb 2023 20:38:20 +0000 (20:38 +0000)]
Process `channel_update`/`node_announcement` async if needed

If we have a `channel_announcement` which is waiting on a UTXO
lookup before we can process it, and we receive a `channel_update`
or `node_announcement` for the same channel or a node which is a
part of the channel, we have to wait until the lookup completes
until we can decide if we want to accept the new message.

Here, we store the new message in the pending lookup state and
process it asynchronously like the original `channel_announcement`.

21 months agoTrack in-flight `channel_announcement` lookups and avoid duplicates
Matt Corallo [Wed, 8 Feb 2023 22:11:56 +0000 (22:11 +0000)]
Track in-flight `channel_announcement` lookups and avoid duplicates

If we receive two `channel_announcement`s for the same channel at
the same time, we shouldn't spawn a second UTXO lookup for an
identical message. This likely isn't too rare - if we start syncing
the graph from two peers at the same time, it isn't unlikely that
we'll end up with the same messages around the same time.

In order to avoid this we keep a hash map of all the pending
`channel_announcement` messages by SCID and simply ignore duplicate
message lookups.

21 months agoAdd an async resolution option to `ChainAccess::get_utxo`
Matt Corallo [Wed, 8 Feb 2023 22:06:11 +0000 (22:06 +0000)]
Add an async resolution option to `ChainAccess::get_utxo`

For those operating in an async environment, requiring
`ChainAccess::get_utxo` return information about the requested UTXO
synchronously is incredibly painful. Requesting information about a
random UTXO is likely to go over the network, and likely to be a
rather slow request.

Thus, here, we change the return type of `get_utxo` to have both a
synchronous and asynchronous form. The asynchronous form requires
the user construct a `AccessFuture` which they `clone` and pass
back to us. Internally, an `AccessFuture` has an `Arc` to the
`channel_announcement` message which we need to process. When the
user completes their lookup, they call `resolve` on their
`AccessFuture` which we pull the `channel_announcement` from and
then apply to the network graph.

21 months agoClean up `check_channel_announcement` style
Matt Corallo [Sat, 21 Jan 2023 03:51:22 +0000 (03:51 +0000)]
Clean up `check_channel_announcement` style

`check_channel_announcement` had long lines, a (very-)stale TODO
and confusing variable assignment, which is all cleaned up here.

21 months agoMove logic to check a `ChannelAnnouncement` to `gossip_checking`
Matt Corallo [Sat, 21 Jan 2023 03:48:46 +0000 (03:48 +0000)]
Move logic to check a `ChannelAnnouncement` to `gossip_checking`

This commit is deliberately move-only, though the code being moved
is somewhat crufty.

21 months agoUpdate the `gossip` and `router` module docs which were out of date
Matt Corallo [Tue, 24 Jan 2023 05:04:21 +0000 (05:04 +0000)]
Update the `gossip` and `router` module docs which were out of date

21 months agoMove `chain::Access` to `routing` and rename it `UtxoLookup`
Matt Corallo [Sat, 21 Jan 2023 03:28:35 +0000 (03:28 +0000)]
Move `chain::Access` to `routing` and rename it `UtxoLookup`

The `chain::Access` trait (and the `chain::AccessError` enum) is a
bit strange - it only really makes sense if users import it via the
`chain` module, otherwise they're left with a trait just called
`Access`. Worse, for bindings users its always just called
`Access`, in part because many downstream languages don't have a
mechanism to import a module and then refer to it.

Further, its stuck dangling in the `chain` top-level mod.rs file,
sitting in a module that doesn't use it at all (it's only used in
`routing::gossip`).

Instead, we give it its full name - `UtxoLookup` (and rename the
error enum `UtxoLookupError`) and put it in the a new
`routing::utxo` module, next to `routing::gossip`.

21 months agoMerge pull request #2022 from alecchendev/2023-02-cache-peer-nodeid
Matt Corallo [Wed, 8 Feb 2023 23:50:59 +0000 (23:50 +0000)]
Merge pull request #2022 from alecchendev/2023-02-cache-peer-nodeid

Store a cached `NodeId` for each `Peer`

21 months agoCache `NodeId` by converting `their_node_id` to tuple
Alec Chen [Wed, 8 Feb 2023 17:55:16 +0000 (11:55 -0600)]
Cache `NodeId` by converting `their_node_id` to tuple

This is done to avoid redundantly serializing peer node
ids when forwarding gossip messages in
`PeerManager::forward_broadcast_msg`.

21 months agoMerge pull request #2016 from alecchendev/2023-02-gossip-msg-pubkey-to-nodeid
Matt Corallo [Tue, 7 Feb 2023 20:18:19 +0000 (20:18 +0000)]
Merge pull request #2016 from alecchendev/2023-02-gossip-msg-pubkey-to-nodeid

Swap gossip message `PublicKey` for `NodeId`

21 months agoMerge pull request #2007 from valentinewallace/2023-02-remove-invpayer-add-utils
Matt Corallo [Tue, 7 Feb 2023 17:37:38 +0000 (17:37 +0000)]
Merge pull request #2007 from valentinewallace/2023-02-remove-invpayer-add-utils

21 months agoSwap `PublicKey` for `NodeId` in `UnsignedNodeAnnouncement`
Alec Chen [Mon, 6 Feb 2023 21:33:02 +0000 (15:33 -0600)]
Swap `PublicKey` for `NodeId` in `UnsignedNodeAnnouncement`

Also swaps `PublicKey` for `NodeId` in `get_next_node_announcement`
and `InitSyncTracker` to avoid unnecessary deserialization that came
from changing `UnsignedNodeAnnouncement`.

21 months agoSwap `PublicKey` for `NodeId` in `UnsignedChannelAnnouncement`
Alec Chen [Mon, 6 Feb 2023 20:41:18 +0000 (14:41 -0600)]
Swap `PublicKey` for `NodeId` in `UnsignedChannelAnnouncement`

Adds the macro `get_pubkey_from_node_id`
to parse `PublicKey`s back from `NodeId`s for signature
verification, as well as `make_funding_redeemscript_from_slices`
to avoid parsing back and forth between types.

21 months agoExpand ChannelManager::send_spontaneous_payment_with_retry docs
Valentine Wallace [Mon, 6 Feb 2023 21:30:51 +0000 (16:30 -0500)]
Expand ChannelManager::send_spontaneous_payment_with_retry docs

21 months agoRemove InvoicePayer and replace with util methods
Valentine Wallace [Fri, 3 Feb 2023 01:08:00 +0000 (20:08 -0500)]
Remove InvoicePayer and replace with util methods

21 months agoDon't pass `per_peer_state` to `claim_funds_from_hop`
Viktor Tigerström [Thu, 12 Jan 2023 19:05:35 +0000 (20:05 +0100)]
Don't pass `per_peer_state` to `claim_funds_from_hop`

21 months agoTrack if a peer is connected or not in `ChannelManager`
Matt Corallo [Fri, 27 Jan 2023 04:06:07 +0000 (04:06 +0000)]
Track if a peer is connected or not in `ChannelManager`

21 months agoMerge pull request #1873 from jurvis/jurvis/2022-11-expose-pending-payments
Matt Corallo [Fri, 3 Feb 2023 19:16:02 +0000 (19:16 +0000)]
Merge pull request #1873 from jurvis/jurvis/2022-11-expose-pending-payments

Expose pending payments through `ChannelManager`

21 months agoMerge pull request #2002 from valentinewallace/2023-01-keysend-retries
valentinewallace [Fri, 3 Feb 2023 19:09:00 +0000 (14:09 -0500)]
Merge pull request #2002 from valentinewallace/2023-01-keysend-retries

Support auto-retrying keysend payments in `ChannelManager`

21 months agoMerge pull request #1996 from valentinewallace/2023-01-migrate-payment-scoring
Matt Corallo [Fri, 3 Feb 2023 18:44:13 +0000 (18:44 +0000)]
Merge pull request #1996 from valentinewallace/2023-01-migrate-payment-scoring

Score payment paths from events in `BackgroundProcessor`

21 months agoExpose pending payments through ChannelManager
jurvis [Mon, 5 Dec 2022 01:24:08 +0000 (17:24 -0800)]
Expose pending payments through ChannelManager

Adds a new method, `list_recent_payments ` to `ChannelManager` that
returns an array of `RecentPaymentDetails` containing the payment
status (Fulfilled/Retryable/Abandoned) and its total amount across all
paths.

21 months agoScore payment paths in BackgroundProcessor
Valentine Wallace [Fri, 3 Feb 2023 16:25:20 +0000 (11:25 -0500)]
Score payment paths in BackgroundProcessor

21 months agoUse TestScorer in BackgroundProcessor testing
Valentine Wallace [Fri, 3 Feb 2023 16:14:53 +0000 (11:14 -0500)]
Use TestScorer in BackgroundProcessor testing

21 months agoSpontaneous payments: make preimage construction more concise
Valentine Wallace [Fri, 3 Feb 2023 15:44:31 +0000 (10:44 -0500)]
Spontaneous payments: make preimage construction more concise

21 months agoSupport spontaneous payment retries in ChannelManager
Valentine Wallace [Tue, 24 Jan 2023 17:15:40 +0000 (12:15 -0500)]
Support spontaneous payment retries in ChannelManager

21 months agoStore keysend preimage in outbound payments
Valentine Wallace [Tue, 24 Jan 2023 16:31:50 +0000 (11:31 -0500)]
Store keysend preimage in outbound payments

This sets us up for spontaneous payment retries in ChannelManager.

Currently, retrying spontaneous payments is broken in InvoicePayer because it
does not include the keysend preimage on retry.

21 months agoMerge pull request #1994 from TheBlueMatt/2023-01-1916-followups
Matt Corallo [Thu, 2 Feb 2023 23:05:07 +0000 (23:05 +0000)]
Merge pull request #1994 from TheBlueMatt/2023-01-1916-followups

1916 Followups Part 1

21 months agoReduce the code in the commitment_signed_dance macro 2023-01-1916-followups
Matt Corallo [Sat, 28 Jan 2023 05:25:19 +0000 (05:25 +0000)]
Reduce the code in the commitment_signed_dance macro

This should marginally reduce compile times for the tests by
reducing the total volume of code across the tests in the lightning
crate.

21 months agoUse only the failed amount when retrying payments, not the full amt
Matt Corallo [Sat, 28 Jan 2023 02:14:26 +0000 (02:14 +0000)]
Use only the failed amount when retrying payments, not the full amt

When we landed the initial in-`ChannelManager` payment retries, we
stored the `RouteParameters` in the payment info, and then re-use
it as-is for new payments. `RouteParameters` is intended to store
the information specific to the *route*, `PaymentParameters` exists
to store information specific to a payment.

Worse, because we don't recalculate the amount stored in the
`RouteParameters` before fetching a new route with it, we end up
attempting to retry the full payment amount, rather than only the
failed part.

This issue brought to you by having redundant data in
datastructures, part 5,001.

21 months agoMove retry-limiting to `retry_payment_with_route`
Matt Corallo [Fri, 27 Jan 2023 23:01:39 +0000 (23:01 +0000)]
Move retry-limiting to `retry_payment_with_route`

The documentation for `Retry` is very clear that it counts the
number of failed paths, not discrete retries. When we added
retries internally in `ChannelManager`, we switched to counting
the number if discrete retries, even if multiple paths failed and
were replace with multiple MPP HTLCs.

Because we are now rewriting retries, we take this opportunity to
reduce the places where retries are analyzed, specifically a good
chunk of code is removed from `pay_internal`.

Because we now retry multiple failed paths with one single retry,
we keep the new behavior, updating the docs on `Retry` to describe
the new behavior.

21 months agoLog more information when retrying a payment attempt fails
Matt Corallo [Fri, 27 Jan 2023 22:59:28 +0000 (22:59 +0000)]
Log more information when retrying a payment attempt fails

21 months agoTest the `RouteParameters` passed to `TestRouter`
Matt Corallo [Fri, 27 Jan 2023 20:31:10 +0000 (20:31 +0000)]
Test the `RouteParameters` passed to `TestRouter`

`TestRouter` allows us to simply select the `Route` that will be
returned in the next `find_route` call, but it does so without any
checking of what was *requested* for the call. This makes it a
somewhat dubious test utility as it very helpfully ensures we
ignore errors in the routes we're looking for.

Instead, we require users of `TestRouter` pass a `RouteParameters`
to `expect_find_route`, which we compare against the requested
parameters passed to `find_route`.

21 months agoUse the `PaymentParameter` final CLTV delta over `RouteParameters`
Matt Corallo [Fri, 27 Jan 2023 20:28:20 +0000 (20:28 +0000)]
Use the `PaymentParameter` final CLTV delta over `RouteParameters`

`PaymentParams` is all about the parameters for a payment, i.e. the
parameters which are static across all the paths of a paymet.
`RouteParameters` is about the information specific to a given
`Route` (i.e. a set of paths, among multiple potential sets of
paths for a payment). The CLTV delta thus doesn't belong in
`RouterParameters` but instead in `PaymentParameters`.

Worse, because `RouteParameters` is built from the information in
the last hops of a `Route`, when we deliberately inflate the CLTV
delta in path-finding, retries of the payment will have the final
CLTV delta double-inflated as it inflates starting from the final
CLTV delta used in the last attempt.

When we calculate the `final_cltv_expiry_delta` to put in the
`RouteParameters` returned via events after a payment failure, we
should re-use the new one in the `PaymentParameters`, rather than
the one that was in the route itself.

21 months agoMerge pull request #1976 from tnull/2023-01-expose-impl-writeable-msg
Matt Corallo [Wed, 1 Feb 2023 20:24:37 +0000 (20:24 +0000)]
Merge pull request #1976 from tnull/2023-01-expose-impl-writeable-msg

Expose `impl_writeable_msg`

21 months agoMove the final CLTV delta to `PaymentParameters` from `RouteParams`
Matt Corallo [Fri, 27 Jan 2023 19:24:52 +0000 (19:24 +0000)]
Move the final CLTV delta to `PaymentParameters` from `RouteParams`

`PaymentParams` is all about the parameters for a payment, i.e. the
parameters which are static across all the paths of a paymet.
`RouteParameters` is about the information specific to a given
`Route` (i.e. a set of paths, among multiple potential sets of
paths for a payment). The CLTV delta thus doesn't belong in
`RouterParameters` but instead in `PaymentParameters`.

Worse, because `RouteParameters` is built from the information in
the last hops of a `Route`, when we deliberately inflate the CLTV
delta in path-finding, retries of the payment will have the final
CLTV delta double-inflated as it inflates starting from the final
CLTV delta used in the last attempt.

By moving the CLTV delta to `PaymentParameters` we avoid this
issue, leaving only the sought amount in the `RouteParameters`.

21 months agoMerge pull request #1998 from tnull/2023-01-no-none-in-channel-relevant-txids
Matt Corallo [Wed, 1 Feb 2023 17:48:59 +0000 (17:48 +0000)]
Merge pull request #1998 from tnull/2023-01-no-none-in-channel-relevant-txids

Only return previously confirmed Txids from CM's `get_relevant_txids()`

21 months agoAdd version note in `Confirm` docs
Elias Rohrer [Tue, 31 Jan 2023 23:15:46 +0000 (17:15 -0600)]
Add version note in `Confirm` docs

While now `ChannelManager` will only return previously confirmed
transactions, we can't ensure the same for `ChainMonitor`, as we need to
maintain backwards compatibility with version prior to 0.0.113, at which
we started tracking the block hash in `ChannelMonitor`s. We therefore
add a note to the docs stating that users need to track confirmations on
their own for channels created prior to 0.0.113.

21 months agoReturn only `Some(block_hash)` in CM rel. txids
Elias Rohrer [Tue, 31 Jan 2023 23:07:31 +0000 (17:07 -0600)]
Return only `Some(block_hash)` in CM rel. txids

As of now the `Confirm::get_relevant_txids()` docs state that it won't
return any transactions for which we hadn't previously seen a
confirmation. To align its functionality a bit more with the docs, at
least for `ChannelManager`, we only return values for which we had
registered a confirmation block hash before.

21 months agoExpose Retry enum from channelmanager module
Valentine Wallace [Tue, 31 Jan 2023 20:28:49 +0000 (15:28 -0500)]
Expose Retry enum from channelmanager module

21 months agoMerge pull request #1997 from Kurtsley/fix-clean-up-documentation
Matt Corallo [Tue, 31 Jan 2023 18:06:55 +0000 (18:06 +0000)]
Merge pull request #1997 from Kurtsley/fix-clean-up-documentation

Clean up documentation in the create_phantom_invoice functions

21 months agoClean up documentation in the create_phantom_invoice functions
Kurtsley [Tue, 31 Jan 2023 03:09:17 +0000 (21:09 -0600)]
Clean up documentation in the create_phantom_invoice functions

21 months agoMerge pull request #1961 from TheBlueMatt/2023-01-expose-hist-buckets
Matt Corallo [Tue, 31 Jan 2023 00:38:14 +0000 (00:38 +0000)]
Merge pull request #1961 from TheBlueMatt/2023-01-expose-hist-buckets

Expose historical bucket data via new accessors

21 months agoMerge pull request #1972 from jkczyz/2023-01-bolt12-spec-updates
Matt Corallo [Mon, 30 Jan 2023 23:36:20 +0000 (23:36 +0000)]
Merge pull request #1972 from jkczyz/2023-01-bolt12-spec-updates

BOLT 12 spec updates

21 months agoExpose historical bucket data via new accessors 2023-01-expose-hist-buckets
Matt Corallo [Mon, 16 Jan 2023 23:23:13 +0000 (23:23 +0000)]
Expose historical bucket data via new accessors

Users should be able to view the data we use to score channels, so
this exposes that data in new accessors.

Fixes #1854.

21 months agoCalc decayed buckets to decide if we have valid historical points
Matt Corallo [Mon, 16 Jan 2023 23:18:39 +0000 (23:18 +0000)]
Calc decayed buckets to decide if we have valid historical points

When we're calculating if, once we apply the unupdated decays, the
historical data tracker has enough data to assign a score, we
previously calculated the decayed points while walking the buckets
as we don't use the decayed buckets anyway (to avoid losing
precision). That is fine, except that as written it decayed
individual buckets additional times.

Instead, here we actually calculate the full set of decayed buckets
and use those to decide if we have valid points. This adds some
additional stack space and may in fact be slower, but will be
useful in the next commit and shouldn't be a huge change.

21 months agoUpdate docs regarding payment path privacy
Jeffrey Czyz [Wed, 25 Jan 2023 05:43:14 +0000 (23:43 -0600)]
Update docs regarding payment path privacy

21 months agoDisallow offer_metadata in Refund
Jeffrey Czyz [Thu, 19 Jan 2023 00:58:20 +0000 (18:58 -0600)]
Disallow offer_metadata in Refund

The offer_metadata was optional but is redundant with invreq_metadata
(i.e., payer_metadata) for refunds. It is now disallowed in the spec and
was already unsupported by RefundBuilder.

21 months agoAllow quantity in Refund
Jeffrey Czyz [Wed, 18 Jan 2023 23:29:31 +0000 (17:29 -0600)]
Allow quantity in Refund

The spec always allowed this but the reason was unclear. It's useful if
the refund is for an invoice paid for offer where a quantity was given
in the request. The description in the refund would be from the offer,
which may have given a unit for each item. So allowing a quantity makes
it clear how many items the refund is for.

21 months agoSupport explicit quantity_max = 1 in Offer
Jeffrey Czyz [Wed, 18 Jan 2023 22:44:16 +0000 (16:44 -0600)]
Support explicit quantity_max = 1 in Offer

The spec was modified to allow setting offer_quantity_max explicitly to
one. This is to support a use case where more than one item is supported
but only one item is left in the inventory. Introduce a Quantity::One
variant to replace Quantity::Bounded(1) so the later can be used for the
explicit setting.

21 months agoMerge pull request #1985 from Kurtsley/chore-no-std-phantom-invoice
Matt Corallo [Mon, 30 Jan 2023 21:01:51 +0000 (21:01 +0000)]
Merge pull request #1985 from Kurtsley/chore-no-std-phantom-invoice

Remove std::SystemTime from create_phantom_invoice, ref #1978

21 months agoRemove std::SystemTime from create_phantom_invoice, ref #1978
Kurtsley [Wed, 25 Jan 2023 06:40:56 +0000 (00:40 -0600)]
Remove std::SystemTime from create_phantom_invoice, ref #1978

Replace current_timestamp call with no-std duration_from_epoch

21 months agoMerge pull request #1974 from danielgranhao/speed-up-secure-random-byte-gen
Matt Corallo [Thu, 26 Jan 2023 23:13:06 +0000 (23:13 +0000)]
Merge pull request #1974 from danielgranhao/speed-up-secure-random-byte-gen

21 months agoUse `Chacha20` in `get_secure_random_bytes()`
Daniel Granhão [Thu, 26 Jan 2023 10:32:14 +0000 (10:32 +0000)]
Use `Chacha20` in `get_secure_random_bytes()`

21 months agoMerge pull request #1991 from TheBlueMatt/2023-01-fix-comment
Matt Corallo [Thu, 26 Jan 2023 19:51:32 +0000 (19:51 +0000)]
Merge pull request #1991 from TheBlueMatt/2023-01-fix-comment

Remove stale comment in test

21 months agoMerge pull request #1986 from TheBlueMatt/2023-01-monitor-eq
Matt Corallo [Thu, 26 Jan 2023 19:11:49 +0000 (19:11 +0000)]
Merge pull request #1986 from TheBlueMatt/2023-01-monitor-eq

Implement PartialEq for ChannelMonitor

22 months agoRemove stale comment in test 2023-01-fix-comment
Matt Corallo [Thu, 26 Jan 2023 17:39:55 +0000 (17:39 +0000)]
Remove stale comment in test

This should have been done in 7dcbf2cd1c4de29b7c32165ca3d6ac3c47f1
but was not.

22 months agoAdd `get_secure_random_bytes()` benchmark
Daniel Granhão [Wed, 25 Jan 2023 20:55:09 +0000 (20:55 +0000)]
Add `get_secure_random_bytes()` benchmark

22 months agoMerge pull request #1984 from TheBlueMatt/2023-01-test-robust
Matt Corallo [Thu, 26 Jan 2023 04:02:31 +0000 (04:02 +0000)]
Merge pull request #1984 from TheBlueMatt/2023-01-test-robust

Make `test_duplicate_payment_hash_one_failure_one_success` robust

22 months agoRemove the `ChannelMonitor` secp context 2023-01-monitor-eq
Matt Corallo [Thu, 26 Jan 2023 02:21:31 +0000 (02:21 +0000)]
Remove the `ChannelMonitor` secp context

`ChannelMonitor` indirectly already has a context - the
`OnchainTxHandler` has one. This makes it trivial to remove the
existing one, so we do so for a free memory usage reduction.

22 months agoImplement `PartialEq` for `ChannelMonitor`
Matt Corallo [Thu, 26 Jan 2023 02:23:08 +0000 (02:23 +0000)]
Implement `PartialEq` for `ChannelMonitor`

It turns out `#[derive(PartialEq)]` will automatically bound the
`PartialEq` implementation by any bounds on the struct also being
`PartialEq`. This means to use an auto-derived `ChannelMonitor`
`PartialEq` the `EcdsaSigner` used must also be `PartialEq`, but
for the use-cases we have today for a `ChannelMonitor` `PartialEq`
it doesn't really matter - we use it internally in tests and
downstream users wanted similar test-only usage.

Fixes #1912.

22 months agoMerge pull request #1916 from valentinewallace/2022-11-chanman-payment-retries
valentinewallace [Thu, 26 Jan 2023 02:09:13 +0000 (21:09 -0500)]
Merge pull request #1916 from valentinewallace/2022-11-chanman-payment-retries

`ChannelManager` Payment Retries

22 months agoMake `test_duplicate_payment_hash_one_failure_one_success` robust 2023-01-test-robust
Matt Corallo [Wed, 25 Jan 2023 02:56:13 +0000 (02:56 +0000)]
Make `test_duplicate_payment_hash_one_failure_one_success` robust

`test_duplicate_payment_hash_one_failure_one_success` currently
fails if the "wrong" HTLC is picked to be claimed. Given the HTLCs
are identical, there's no way to figure out which we should claim.
The test instead relies on a magic value - the first one is the
right one....unless we change our CSPRNG implementation. When we
try to do so, the test randomly fails.

Here we change one HTLC to a lower amount so we can figure out
which transaction to broadcast to make the test robust against
CSPRNG changes.

22 months agoImplement `PartialEq`/`Eq` for `Event`s
Matt Corallo [Thu, 26 Jan 2023 01:51:43 +0000 (01:51 +0000)]
Implement `PartialEq`/`Eq` for `Event`s