Commit graph

3392 commits

Author SHA1 Message Date
Jeffrey Czyz
a799fc9b30
Onion message payload for BOLT 12 Offers
BOLT 12 Offers makes use of onion messages to request and respond with
invoices. Add these types and an error type to OnionMessageContents
along with the necessary parsing and encoding.
2023-06-13 13:07:47 -05:00
Jeffrey Czyz
7533a3c42f
Pass logger to onion payload decoder
In an upcoming commit, messages for BOLT 12 offers are read from the
onion payload. Passing a logger allows for logging semantic errors when
parsing the messages.
2023-06-13 13:07:46 -05:00
Jeffrey Czyz
9b3a35a133
Add InvoiceError message
If an InvoiceRequest or an Invoice delivered via an onion message cannot
be handled, the recipient should reply with an InvoiceError if a reply
path was given. Define the message and conversion from SemanticError.
2023-06-13 13:07:46 -05:00
Jeffrey Czyz
1feddaeafd
Support WithoutLength for UntrustedString 2023-06-13 13:07:41 -05:00
Valentine Wallace
6b6d549854
Fix oops'd docs on PaymentParameters::with_max_channel_saturation 2023-06-12 17:27:03 -04:00
Valentine Wallace
d017657bcd
Fix panic on pathfinding to blinded recipient
The previous dummy payee id was an invalid pubkey
2023-06-12 17:27:03 -04:00
Matt Corallo
942d77699b Stop writing old user_payment_id field not read since 0.0.103
Since we're breaking downgrade compatibility to LDK version 0.0.103
and before, we might as well go ahead and remove other code we have
for compatibility.
2023-06-12 18:46:41 +00:00
Matt Corallo
6535627a3e Drop create_inbound_payment*_legacy breaking downgrade to 0.0.103
0.0.103 is now downright ancient, and certainly shouldn't exist in
production anywhere today. Thus, it seems fine to remove the
ability to create legacy stateful inbound payment entries.

Users downgrading to 0.0.103 will thus not be able to claim any
payments created on modern LDK, though we still retain the ability
to claim such payments at least for one more release.
2023-06-12 16:43:01 +00:00
Matt Corallo
42e2f1d1a6
Merge pull request #2156 from alecchendev/2023-04-mpp-keysend
Support MPP Keysend
2023-06-10 19:48:54 +00:00
Alec Chen
9db962c719
Add test for duplicate keysend payment
The logic has been changed around duplicate keysend payments such that
it's no longer explicitly clear that we reject duplicate keysend
payments now that we handle receiving multi-part keysends. This test
catches that. Note that this also tests that we reject MPP keysends when
our config states we should, and that we reject MPP keysends without
payemnt secrets when our config states we support MPP keysends.
2023-06-09 11:27:09 -05:00
Alec Chen
8dde17773a
Support receiving MPP keysend
This commit refactors a significant portion of the receive validation in
`ChannelManager::process_pending_htlc_forwards` now that we repurpose
previous MPP validation logic to accomodate keysends. This also removes
a previous restriction on claiming, as well as tests sending and
receiving MPP keysends.
2023-06-09 11:27:07 -05:00
Alec Chen
4be3adb51f
Track MPP data while receiving keysends
This commit adds the field `payment_data: FinalOnionHopData` to
`ReceiveKeysend` which will allow us to check for payment secrets and
total amounts which is needed to support receiving MPP keysends. This
field is non-backwards compatible since we wouldn't be able to handle
an MPP keysend properly if we were to downgrade to a prior version.

We also no longer reject keysends with payment secrets if we support MPP
keysend.
2023-06-09 11:27:06 -05:00
Alec Chen
07def9292a
Help users support sending MPP keysend
When routing a keysend payment, the user may want to signal to the
router whether to find multi-path routes in the
`PaymentParameters::for_keysend` helper, without going through manual
construction. Since some implementations do not support MPP keysend, we
have the user make the choice here rather than making it the default.

Some implementations will reject keysend payments with payment secrets,
so this commit also adds docs to `RecipientOnionFields` to communicate
this to the user.
2023-06-09 11:26:58 -05:00
Matt Corallo
b6787a4f36
Merge pull request #2334 from jkczyz/2023-06-bolt12-test-vectors
Update BOLT 12 test vectors
2023-06-08 18:51:05 +00:00
Wilmer Paulino
99985c6209
Merge pull request #2333 from benthecarman/chan-mon-bal-helper
Add helper for getting claimable balance
2023-06-07 18:06:01 -07:00
Matt Corallo
f09c37082c
Merge pull request #2342 from vladimirfomene/2023-06-use-untrustedstring-in-error-logs
Use PrintableString for displaying errors in PeerManager
2023-06-07 23:06:15 +00:00
Jeffrey Czyz
ecd283ea23
Include signature check in BOLT 12 signature test
The BOLT 12 test vectors had inadvertently left out a signature, but it
has since been added. Include a signature check in the corresponding
test for completeness.
2023-06-07 16:57:24 -05:00
Jeffrey Czyz
8540985351
Update BOLT 12 test vectors
The previous test vectors contained recurrences and older TLV types, and
therefore couldn't be parsed. Update the tests with the latest test
vectors from the spec and stop ignoring the tests.
2023-06-07 16:56:56 -05:00
Jeffrey Czyz
0970f3f63f
Remove custom blinded path test vector
These were added to help debug an encoding issue. However, the encoding
code was moved to the blinded_path module. Additionally, the test vector
used an old TLV encoding.
2023-06-07 16:55:09 -05:00
benthecarman
06c6750b54
Add helper for getting claimable balance
It is annoying to have to match across all the enums of `Balance` to
just pull out the `claimable_amount_satoshis` value. This helper makes
it easier if you just want to amount.
2023-06-07 13:39:50 -05:00
Vladimir Fomene
b5c89cc977
Use PrintableString for displaying errors in PeerManager
We currently just print "with non-ASCII error message"
to log when we see non-ASCII chars, but should instead
use our fancy PrintableString type to display the
untrusted string and ignore control chars.
2023-06-07 21:38:23 +03:00
Matt Corallo
f068df03c5
Merge pull request #2312 from TheBlueMatt/2023-05-next-htlc-min-max
Avoid generating unpayable routes due to balance restrictions
2023-06-07 17:03:01 +00:00
valentinewallace
7a78998552
Merge pull request #2305 from valentinewallace/2023-05-respect-hint-maxhtlc
Respect route hint `max_htlc` in pathfinding
2023-06-07 15:02:26 +02:00
Matt Corallo
583a5b2748
Merge pull request #2330 from wvanlint/partial_config_updates
Support atomic partial updates to ChannelConfig
2023-06-07 01:02:48 +00:00
Matt Corallo
4bc3a79365 Slightly improve docs on next_*_commit_tx_fee_msat 2023-06-06 23:57:56 +00:00
Matt Corallo
10e213cf40 Replace send_htlc amount checking with available balances
Now that the `get_available_balances` min/max bounds are exact, we
can stop doing all the explicit checks in `send_htlc` entirely,
instead comparing against the `get_available_balances` bounds and
failing if the amount is out of those bounds.

This breaks support for sending amounts below the dust limit if
there is some amount of dust exposure remaining before we hit our
cap, however we will no longer generate such routes anyway.
2023-06-06 23:57:56 +00:00
Matt Corallo
66c4f454f0 Ensure a 1:1 mapping of value sendable to send success in fuzzing
Now that the value available to send is expected to match the
success or failure of sending exactly, we should assert this in the
`chanmon_consistency` fuzzer.

In the next commit we'll actually rip the checks out of `send_htlc`
which will make this a somewhat less useful test, however fuzzing
on this specific commit can help to reveal bugs.
2023-06-06 23:57:56 +00:00
Matt Corallo
7edbf547fb Consider dust exposure when assembling a route
When calculating the amount available to send for the next HTLC, if
we over-count we may create routes which are not actually usable.

Historically this has been an issue, which we resolve over a few
commits.

Here we consider how much adding one additional (dust) HTLC would
impact our total dust exposure, setting the new next-HTLC-minimum
field to require HTLCs be non-dust if required or set our next-HTLC
maximum if we cannot send a dust HTLC but do have some additional
exposure remaining.

We also add some testing when sending to ensure that send failures
are accounted for in our balance calculations.

Fixes #2252.
2023-06-06 23:57:56 +00:00
Matt Corallo
3aa8a1721c Add a next-outbound-HTLC minimum field to chan details and use it
In the coming commits, in order to ensure all routes we generate
are usable, we'll start calculating the next-HTLC minimum for our
channels and using it in the router. Here we set this up by adding
an always-0 field for it in `ChannelDetails` and use it when
routing.
2023-06-06 23:57:55 +00:00
Matt Corallo
52a90577f2 Consider counterparty commitment tx fees when assembling a route
When calculating the amount available to send for the next HTLC, if
we over-count we may create routes which are not actually usable.

Historically this has been an issue, which we resolve over a few
commits.

Here we consider whether one additional HTLC's commitment tx fees
would result in the counterparty's commitment tx fees being greater
than the reserve we've picked for them and, if so, limit our next
HTLC value to only include dust HTLCs.

We also add some testing when sending to ensure that send failures
are accounted for in our balance calculations.

This, and the previous few commits, fixes #1126.
2023-06-06 23:57:55 +00:00
Willem Van Lint
8fd8966b9a Support atomic partial updates to ChannelConfig 2023-06-06 16:17:47 -07:00
Valentine Wallace
f130f95018
Account for used liquidity in first hops when processing route hints
.. in get_route.
2023-06-06 15:15:30 +02:00
Valentine Wallace
14cd18b5e6
Abide by route hint max_htlc in pathfinding 2023-06-06 15:12:18 +02:00
Matt Corallo
166f32621d
Merge pull request #2329 from dunxen/2023-05-initgenesischeck
Add support for `networks` field in `Init` message
2023-06-05 18:14:17 +00:00
Duncan Dean
b52b936bdd
Send and handle networks field in Init messages
If the `networks` field is present in a received `Init` message, then
we need to make sure our genesis chain hash matches one of those, otherwise
we should disconnect the peer.

We now also always send our genesis chain hash in `Init` messages to
our peers.
2023-06-05 09:45:48 +02:00
Duncan Dean
e23102f565
Add networks TLV to Init's TLV stream
This was a fairly old introduction to the spec to allow nodes to indicate
to their peers what chains they are interested in (i.e. will open channels
and gossip for).

We don't do any of the handling of this message in this commit and leave
that to the very next commit, so the behaviour is effectively the same
(ignore networks preference).
2023-06-05 09:45:41 +02:00
Jeffrey Czyz
b6bb32ce14
Remove duplicate BOLT 12 test vector 2023-06-02 14:20:30 -05:00
Daniel Granhão
490ab6e453
Fix wrong link in ChannelManager::send_payment() docs 2023-06-02 17:29:52 +01:00
Matt Corallo
fb140b55c7
Merge pull request #2328 from benthecarman/partial-eq-in-mem-signer
Impl PartialEq and Debug for InMemorySigner
2023-06-01 19:51:24 +00:00
benthecarman
a8a7fc1092
Impl PartialEq and Debug for InMemorySigner
These are needed for being able to compare a
ChannelMonitor<InMemorySigner> and are just nice to haves for
developers.
2023-05-31 18:19:31 -05:00
Matt Corallo
32eb89474c
Merge pull request #2167 from TheBlueMatt/2023-04-monitor-e-monitor-prep
Add infra to block ChannelMonitorUpdates on forwarded claims
2023-05-31 22:48:34 +00:00
Matt Corallo
91536edb0d
Merge pull request #2324 from dunxen/2023-05-rgscheckgenesishash
Fail RGS data processing early if there is a chain hash mismatch
2023-05-31 19:21:10 +00:00
Matt Corallo
394f54da31 Add infra to block ChannelMonitorUpdates on forwarded claims
When we forward a payment and receive an `update_fulfill_htlc`
message from the downstream channel, we immediately claim the HTLC
on the upstream channel, before even doing a `commitment_signed`
dance on the downstream channel. This implies that our
`ChannelMonitorUpdate`s "go out" in the right order - first we
ensure we'll get our money by writing the preimage down, then we
write the update that resolves giving money on the downstream node.

This is safe as long as `ChannelMonitorUpdate`s complete in the
order in which they are generated, but of course looking forward we
want to support asynchronous updates, which may complete in any
order.

Here we add infrastructure to handle downstream
`ChannelMonitorUpdate`s which are blocked on an upstream
preimage-containing one. We don't yet actually do the blocking which
will come in a future commit.
2023-05-30 23:05:03 +00:00
Matt Corallo
785bdb84cb Reapply pending ChannelMonitorUpdates on startup
If a `ChannelMonitorUpdate` was created and given to the user but
left uncompleted when the `ChannelManager` is persisted prior to a
restart, the user likely lost the `ChannelMonitorUpdate`(s). Thus,
we need to replay them for the user, which we do here using the
new `BackgroundEvent::MonitorUpdateRegeneratedOnStartup` variant.
2023-05-30 23:05:03 +00:00
Matt Corallo
e5070c4880 Process background events when taking the total_consistency_lock
When we generated a `ChannelMonitorUpdate` during `ChannelManager`
deserialization, we must ensure that it gets processed before any
other `ChannelMonitorUpdate`s. The obvious hook for this is when
taking the `total_consistency_lock`, which makes it unlikely we'll
regress by forgetting this.

Here we add that call in the `PersistenceNotifierGuard`, with a
test-only atomic bool to test that this criteria is met.
2023-05-30 23:05:02 +00:00
Matt Corallo
acbe41abe2 Handle BackgroundEvents replaying non-closing monitor updates
`BackgroundEvent` was used to store `ChannelMonitorUpdate`s which
result in a channel force-close, avoiding relying on
`ChannelMonitor`s having been loaded while `ChannelManager`
block-connection methods are called during startup.

In the coming commit(s) we'll also generate non-channel-closing
`ChannelMonitorUpdate`s during startup, which will need to be
replayed prior to any other `ChannelMonitorUpdate`s generated from
normal operation.

In the next commit we'll handle that by handling `BackgroundEvent`s
immediately after locking the `total_consistency_lock`.
2023-05-30 23:00:59 +00:00
Matt Corallo
a2989129a7 Make AChannelManager trait slightly more generic and always on
Rather than letting `AChannelManager` be bounded by all traits
being `Sized` we make them explicitly `?Sized`. We also make the
trait no longer test-only as it will be used in a coming commit.
2023-05-30 18:15:32 +00:00
Matt Corallo
34d5f2afc4 Return the counterparty node_id as a part of a force-shutdown res
In the coming commits we'll need the counterparty node_id when
handling a background monitor update as we may need to resume
normal channel operation as a result. Thus, we go ahead and pipe it
through from the shutdown end, as it makes the codepaths
consistent.

Sadly, the monitor-originated shutdown case doesn't allow for a
required counterparty node_id as some versions of LDK didn't have
it present in the ChannelMonitor.
2023-05-30 18:15:32 +00:00
Matt Corallo
3ce1a5e087 Move the ShutdownResult type alias to channel.rs
This allows us to make the `force_shutdown` definition less verbose
2023-05-30 18:15:32 +00:00
Matt Corallo
660daaacdf Fix held_by_thread in no-std to return instead of panicing
Our `no-std` locks simply panic if a lock cannot be taken as there
should be no lock contention in a single-threaded environment.
However, the `held_by_thread` debug methods were delegating to the
lock methods which resulted in a panic when asserting that a lock
*is* held by the current thread.

Instead, they are updated here to call the relevant `RefCell`
testing methods.
2023-05-30 18:15:32 +00:00