Commit graph

4956 commits

Author SHA1 Message Date
Matt Corallo
07d991c82f
Merge pull request #2966 from G8XSU/2647-distribute
Optimize ChannelMonitor persistence on block connections.
2024-06-20 09:51:54 -07:00
optout
80eb5cee10
Interactive TX negotiation tracks shared outputs 2024-06-20 17:28:56 +02:00
Matt Corallo
38285167b1
Merge pull request #3127 from wvanlint/non_strict_forwarding
Implement non-strict forwarding
2024-06-20 07:26:43 -07:00
Valentine Wallace
445ec8d508
Onion message payload for async payments
Async payments uses onion messages to indicate when HTLCs are held and
released. Add these types along with the necessary parsing and encoding.
2024-06-20 10:09:03 -04:00
Willem Van Lint
05e6252b20 Implement non-strict forwarding
This change implements non-strict forwarding, allowing the node to
forward an HTLC along a channel other than the one specified
by short_channel_id in the onion message, so long as the receiver has
the same node public key intended by short_channel_id
([BOLT](57ce4b1e05/04-onion-routing.md (non-strict-forwarding))).
This can improve payment reliability when there are multiple channels
with the same peer e.g. when outbound liquidity is replenished by
opening a new channel.

The implemented forwarding strategy now chooses the channel with the
lowest outbound liquidity that can forward an HTLC to maximize the
probability of being able to successfully forward a subsequent HTLC.

Fixes #1278.
2024-06-19 21:24:21 -07:00
Matt Corallo
a17a159c93 Store the source and destination node_counters in ChannelInfo
In the next commit, we'll use the new `node_counter`s to remove a
`HashMap` from the router, using a `Vec` to store all our per-node
information. In order to make finding entries in that `Vec` cheap,
here we store the source and destintaion `node_counter`s in
`ChannelInfo`, givind us the counters for both ends of a channel
without doing a second `HashMap` lookup.
2024-06-19 13:57:41 +00:00
Matt Corallo
6d714b8cbd Track a counter for each node in our network graph
These counters are simply a unique number describing each node.
They have no specific meaning, but start at 0 and count up, with
counters being reused after a node has been deleted.
2024-06-19 13:57:41 +00:00
Elias Rohrer
f45a840c47
Merge pull request #3132 from jkczyz/2024-06-bolt12-unannounced
Blinded paths with unannounced introduction nodes
2024-06-19 14:42:08 +02:00
G8XSU
bf28957f6d
Optimize ChannelMonitor persistence on block connections.
Currently, every block connection triggers the persistence of all
ChannelMonitors with an updated best_block. This approach poses
challenges for large node operators managing thousands of channels.
Furthermore, it leads to a thundering herd problem
(https://en.wikipedia.org/wiki/Thundering_herd_problem), overwhelming
the storage with simultaneous requests.

To address this issue, we now persist ChannelMonitors at a
regular cadence, spreading their persistence across blocks to
mitigate spikes in write operations.

Outcome: After doing this, Ldk's IO footprint should be reduced
by ~50 times. The processing time required to sync each block
will be significantly reduced, particularly for nodes with 1000s
of channels, as write latency plays a significant role in this process.
As a result, the Node/ChainMonitor will be blocked for a shorter
duration, leading to further efficiency gains.
2024-06-19 00:04:23 -07:00
Gursharan Singh
87fc324c71
Merge pull request #3126 from TheBlueMatt/2024-06-preimage-removal-blocked-by-claim-event
(Very) marginally expand `test_monitor_update_fail_claim`
2024-06-18 13:31:38 -07:00
Matt Corallo
68af6d0809 (Very) marginally expand test_monitor_update_fail_claim
For some reason I wasn't sure this happened yet, so making the
test for no-`PaymentClaimed`-event-before-preimage-on-disk explicit
is nice.
2024-06-18 17:59:12 +00:00
Matt Corallo
c39ff87f44
Merge pull request #3115 from alecchendev/2024-06-specific-async-sign
Refactor async signing test utils to toggle specific method availability
2024-06-18 08:33:43 -07:00
Jeffrey Czyz
c1eda4ba3d
Relax channel count check for unannounced nodes
When creating blinded paths, introduction nodes are limited to peers
with at least three channels to prevent easily guessing the recipient.
Relax this check when the recipient is unannounced since they won't be
in the NetworkGraph.
2024-06-18 09:26:29 -05:00
Jeffrey Czyz
642913c586
Advance self blinded payment paths
DefaultRouter will ignore blinded paths where the sender is the
introduction node. Similar to message paths, advance such paths by one
so that payments may be sent to them.
2024-06-18 09:26:29 -05:00
Jeffrey Czyz
55ba2aab41
Re-order imports 2024-06-18 09:26:29 -05:00
Jeffrey Czyz
79122d69d4
Rename variable 2024-06-18 09:26:29 -05:00
Jeffrey Czyz
b6fcd84a13
Add advance_path_by_one for blinded payment paths
Similar to blinded paths for onion messages, if given a blinded payment
path where we are the introduction node, the path must be advanced by
one in order to use it.
2024-06-18 09:26:28 -05:00
Jeffrey Czyz
efc4647c65
Don't modify path when advance_path_by_one errors
When using advance_path_by_one when we are the introduction node, any
error will result having the first hop of the input blinded path
removed. Instead, only remove the first hop on success. Otherwise, the
path will be invalid.
2024-06-18 09:26:28 -05:00
Jeffrey Czyz
3bf84204e3
Blinded payments to unannounced introduction node
When creating blinded paths for receiving onion payments, allow using
the recipient's only peer as the introduction node when the recipient is
unannounced. This allows for sending payments without going through an
intermediary, which is useful for testing or when only connected to an
LSP with an empty NetworkGraph.
2024-06-18 09:26:28 -05:00
Jeffrey Czyz
7d1745e721
BlindedPath with unannounced introduction node
When creating blinded paths for receiving onion messages, allow using
the recipient's only peer as the introduction node when the recipient is
unannounced. This allows for sending messages without going through an
intermediary, which is useful for testing or when only connected to an
LSP with an empty NetworkGraph.
2024-06-18 09:26:26 -05:00
Elias Rohrer
249886497e
Merge pull request #3130 from TheBlueMatt/2024-06-doc-fee-present
Document when `Events::PaymentSent::pending_fee_msat` is `Some`
2024-06-18 14:49:38 +02:00
Alec Chen
21eeca4add Remove global availability logic for testing async signing 2024-06-17 16:34:56 -07:00
Alec Chen
1fb2b8e0ff Refactor tests to use specific async signing ops 2024-06-17 16:32:07 -07:00
Alec Chen
e8939e26bc Allow toggling specific signing methods in test channel signer 2024-06-17 16:32:06 -07:00
G8XSU
1912d8df01
Start tracking chain_sync_monitor_persistences in TestPersister
It is helpful to assert that chain-sync did trigger a monitor
persist.
2024-06-17 12:50:04 -07:00
valentinewallace
737df0f46f
Merge pull request #3128 from TheBlueMatt/2024-06-no-claim-ret
Drop unused return value from `claim_funds_from_hop`
2024-06-17 10:13:04 -04:00
Matt Corallo
f2005ba79d Document when Events::PaymentSent::pending_fee_msat is Some 2024-06-17 13:54:20 +00:00
Matt Corallo
fea6393083 Drop unused return value from claim_funds_from_hop 2024-06-16 14:15:07 +00:00
Duncan Dean
0881b24895
Move accept_channel checks into ChannelContext::do_accept_channel_checks
This is done ahead of getting the dual-funding implementation to reduce
refactoring noise there.
2024-06-14 10:52:32 +02:00
Valentine Wallace
66df329236
ser_macros: support messages with no fields 2024-06-13 12:20:43 -04:00
Elias Rohrer
3ec0dcdac1
Merge pull request #3078 from jkczyz/2024-05-invoice-event
Asynchronous `Bolt12Invoice` payment
2024-06-13 08:25:59 +02:00
Jeffrey Czyz
97c1d656ee
Add pays_bolt12_invoice_asynchronously test 2024-06-12 19:39:49 -05:00
Jeffrey Czyz
65efd92c4a
Expose send_payment_for_bolt12_invoice
UserConfig::manually_handle_bolt12_invoices allows deferring payment of
BOLT12 invoices by generating Event::InvoiceReceived. Expose
ChannelManager::send_payment_for_bolt12_invoice to allow users to pay
the Bolt12Invoice included in the event. While the event contains the
PaymentId for reference, that parameter is now removed from the method
in favor of extracting the PaymentId from the invoice's payer_metadata.
2024-06-12 19:38:22 -05:00
Jeffrey Czyz
232959cd27
Reformat and tick config docs 2024-06-12 19:38:21 -05:00
Jeffrey Czyz
a9dcfaf952
Add UserConfig::manually_handle_bolt12_invoices
BOLT12 invoices are automatically paid once they have been verified.
Users may want to manually pay them by first performing additional
checks. Add a manually_handle_bolt12_invoices configuration option that
when set generates an Event::InvoiceReceived instead of paying the
invoice.
2024-06-12 19:38:16 -05:00
Matt Corallo
f267ffe2fc
Merge pull request #3082 from valentinewallace/2024-04-bolt12-keysend-invoice
BOLT 12 static invoice encoding and building
2024-06-12 15:17:48 -07:00
Matt Corallo
08c566ccfb
Merge pull request #3103 from TheBlueMatt/2024-06-real-bench
Use a real (probing-generated) scorer in benchmarks
2024-06-12 15:17:25 -07:00
Valentine Wallace
bafe4ed218
Static invoice parsing tests 2024-06-12 16:42:29 -04:00
Valentine Wallace
7970de47a6
Static invoice building tests 2024-06-12 16:42:29 -04:00
Valentine Wallace
1e58066868
Builder for creating static invoices from offers
Add a builder for creating static invoices for an offer. Building produces a
semantically valid static invoice for the offer, which can then be signed with
the key associated with the offer's signing pubkey.
2024-06-12 16:42:27 -04:00
Jeffrey Czyz
4666c33c0f
Add an InvoiceReceived event
Some users may want to handle a Bolt12Invoice asynchronously, either in
a different process or by first performing additional verification
before paying the invoice. Add an InvoiceReceived event to facilitate
this.
2024-06-12 15:24:08 -05:00
Matt Corallo
7ae311d64c Drop unnecessary key derivation in route tests
In our route tests we need some "random" bytes for the router to
randomize amounts using. We generate this by building an actual
`KeysManager` and then deriving some random bytes using the
`EntropySource` trait. However, `get_route` (what we're normally
testing) doesn't actually use the random bytes, and even if it did,
using a `KeysManager` is just a fancy way of creating a constant,
so there's really no reason to do all the fancy crypto.

Instead, here, we change our routing tests and benchmarks to simply
use `[42; 32]` as the "random" bytes.
2024-06-12 19:35:06 +00:00
Matt Corallo
d74c143afe Push the route benchmark results into a separate uninlined function
This ensures the route benchmarks themselves will appear with a
distinct callgraph, making router profiling somewhat easier.
2024-06-12 19:35:06 +00:00
Matt Corallo
050e7ebaa3 Use a real (probing-generated) scorer in benchmarks
Until now, our routing benchmarks used a synthetic scorer,
generated by scoring random paths to build up some history. This is
pretty far removed from real-world routing conditions, as
alternative paths generally have no scoring information and even
the paths we do take have only one or two past scoring results.

Instead, we fetch a static serialized scorer, generated using
minutely probes. This means future changes to the scorer's data may
be harder to benchmark, but makes for substantially more realistic
benchmarks for changes which don't impact the serialized state.
2024-06-12 19:35:06 +00:00
Valentine Wallace
e3dea2c3c7
Static invoice encoding and parsing
Define an interface for BOLT 12 static invoice messages. The underlying
format consists of the original bytes and the parsed contents.

The bytes are later needed for serialization. This is because it must
mirror all the offer TLV records, including unknown ones, which aren't
represented in the contents.

Invoices may be created from an offer.
2024-06-12 15:07:48 -04:00
Elias Rohrer
67732665c7
Merge pull request #3116 from TheBlueMatt/2024-06-3107-nit
Clarify `Display` text for `ClosureReason::HolderForceClosed` some
2024-06-12 19:58:06 +02:00
Elias Rohrer
5e3056e988
Merge pull request #3113 from TheBlueMatt/2024-04-async-monitor-fuzz
Fuzz reloading with a stale monitor in chanmon_consistency
2024-06-12 19:20:28 +02:00
Matt Corallo
920d96edb6 Unblock channels awaiting monitor update based on ChanMan queue
When we have `ChannelMonitorUpdate`s which are completing both
synchronously and asynchronously, we need to consider a channel as
unblocked based on the `ChannelManager` monitor update queue,
rather than by checking the `update_id`s.

Consider the case where a channel is updated, leading to a
`ChannelMonitorUpdate` which completes asynchronously. The update
completes, but prior to the `ChannelManager` receiving the
`MonitorEvent::Completed` it generates a further
`ChannelMonitorUpdate`. This second update completes synchronously.
As a result, when the `MonitorEvent` is processed, the event's
`monitor_update_id` is the first update, but there are no updates
queued and the channel should be free to return to be unblocked.

Here we fix this by looking only at the `ChannelManager` update
queue, rather than the update_id of the `MonitorEvent`.

While we don't anticipate many users having both synchronous and
asynchronous persists in the same application, there isn't much
cost to supporting it, which we do here.

Found by the chanmon_consistency target.
2024-06-12 15:32:33 +00:00
Valentine Wallace
3cfb24d265
InvoiceTlvStream{Ref}: add message_paths field
Will be used in static invoices. Also test that we'll fail to decode if these
paths are included in single-use BOLT 12 invoices.
2024-06-12 11:27:08 -04:00
Matt Corallo
64336faa75 Clarify Display text for ClosureReason::HolderForceClosed some
... to make it clear that we elected not to broadcast, rather than
failed to broadcast.
2024-06-11 19:01:13 +00:00