Commit graph

5630 commits

Author SHA1 Message Date
Alec Chen
83f0dbc002 Address custom HTLC TLV fixups
Don't collect iterators to compare, minorly simplify encoding the
keysend TLV, combine the _encode_tlv_stream variants to check that the
ordering of TLVs is correct including custom TLVs.
2023-08-16 19:06:19 -05:00
Alec Chen
bd90bd2055
Simplify custom HTLC TLV tests
Remove print statement, remove some unnecessary checks copied over from
test utils, make minor simplifications, wrap especially long lines.
2023-08-16 13:06:39 -05:00
Matt Corallo
9b13862506
Merge pull request #2500 from TheBlueMatt/2023-08-fix-test-lifetimes 2023-08-16 05:39:50 +00:00
Matt Corallo
8e92223a44 Use more human-readable lifetime names in test structs 2023-08-15 23:19:03 +00:00
Matt Corallo
e1bfea3029 Correct test struct initialization ordering
When reloading a node in the test framework, we end up with a new
`ChannelManager` that has references to various test util structs.
In order for the tests to compile reliably in the face of unrelated
changes, those test structs need to always be initialized before
both the new but also the original `ChannelManager`.

Here we make that change.
2023-08-15 23:19:03 +00:00
Matt Corallo
fe0f845582
Merge pull request #2428 from waterson/create-channel-after-accept
Wait to create a channel until after accepting.
2023-08-15 22:15:09 +00:00
Matt Corallo
645e056a07
Merge pull request #2476 from wvanlint/remove_balance_msat
Remove AvailableBalances::balance_msat
2023-08-15 20:59:45 +00:00
Matt Corallo
417e866792 Correct lifetimes on _reload_node
For some reason an unrelated PR caused all our tests with
`reload_node` calls to fail to compile. This is due, in part, to
the lifetimes on `reload_node` implying that the new and original
`ChannelManager` (or some of the structs they reference) must live
for the same lifetime.

This fixes that issue by correcting the lifetimes to be consistent
across `Node` and `_reload_node`.
2023-08-15 19:17:31 +00:00
Willem Van Lint
ef5be580f5 Remove AvailableBalances::balance_msat
The ChannelMonitor::get_claimable_balances method provides a more
straightforward approach to the balance of a channel, which satisfies
most use cases. The computation of AvailableBalances::balance_msat is
complex and originally had a different purpose that is not applicable
anymore.
2023-08-15 11:42:00 -07:00
Matt Corallo
a24626b919
Merge pull request #2496 from dunxen/2023-08-fix2488
Send error message to peer if we drop an unfunded channel on timeout
2023-08-14 19:39:23 +00:00
valentinewallace
4a4163fcf4
Merge pull request #2458 from valentinewallace/2023-07-om-test-vectors
Onion message test vectors
2023-08-14 11:44:24 -04:00
Duncan Dean
eda6e9d0ec
Send error message to peer if we drop an unfunded channel on timeout 2023-08-14 16:22:33 +02:00
Chris Waterson
01847277b9 Wait to create a channel until after accepting.
Create a new table in 'peer_state' to maintain unaccepted inbound
channels; i.e., a channel for which we've received an 'open_channel'
message but that user code has not yet confirmed for acceptance. When
user code accepts the channel (e.g. via 'accept_inbound_channel'),
create the channel object and as before.

Currently, the 'open_channel' message eagerly creates an
InboundV1Channel object before determining if the channel should be
accepted. Because this happens /before/ the channel has been assigned
a user identity (which happens in the handler for OpenChannelRequest),
the channel is assigned a random user identity. As part of the
creation process, the channel's cryptographic material is initialized,
which then uses this randomly generated value for the user's channel
identity e.g. in SignerProvider::generate_channel_keys_id.

By delaying the creation of the InboundV1Channel until /after/ the
channel has been accepted, we ensure that we defer cryptographic
initialization until we have given the user the opportunity to assign
an identity to the channel.
2023-08-13 19:40:17 -07:00
Matt Corallo
131560e08f
Merge pull request #2387 from vladimirfomene/add_extra_fields_to_ChannelClosed_event
Add counterparty_node_id & channel_capacity to ChannelClosed event
2023-08-10 22:43:21 +00:00
Matt Corallo
9e4a35a60d
Merge pull request #2308 from alecchendev/2023-05-custom-htlc-tlvs
Add support for custom HTLC TLVs
2023-08-10 17:26:30 +00:00
Matt Corallo
7a63ab77da
Merge pull request #1789 from jkczyz/2022-10-scorer-decay
Smooth out channel liquidity bounds decay
2023-08-09 16:34:33 +00:00
Matt Corallo
7e3de70448
Merge pull request #2481 from TheBlueMatt/2023-08-keysend-robust-test
Scope payment preimage in do_test_keysend_payments
2023-08-09 00:40:53 +00:00
Alec Chen
dec3fb316a
Enforce explicit claims on payments with even custom TLVs
Because we don't know which custom TLV type numbers the user is
expecting (and it would be cumbersome for them to tell us), instead of
failing unknown even custom TLVs on deserialization, we accept all
custom TLVs, and pass them to the user to check whether they recognize
them and choose to fail back if they don't. However, a user may not
check for custom TLVs, in which case we should reject any even custom
TLVs as unknown.

This commit makes sure a user must explicitly accept a payment with
even custom TLVs, by (1) making the default
`ChannelManager::claim_funds` fail if the payment had even custom TLVs
and (2) adding a new function
`ChannelManager::claim_funds_with_known_custom_tlvs` that accepts them.

This commit also refactors our custom TLVs test and updates various
documentation to account for this.
2023-08-08 16:16:45 -05:00
Alec Chen
8ff1604647
Add FailureCode::InvalidOnionPayload variant
When a user decodes custom TLVs, if they fail to recognize even type
numbers they should fail back with the correct failure code and fail
data. This new variant adds the proper failure variant for the user to
pass into `ChannelManager::fail_htlc_backwards_with_reason`.

Note that the enum discriminants were removed because when adding a
struct variant we can no longer make use of the discriminant through
casting like we previously did, and instead have to manually define the
associated failure code anyway.
2023-08-08 16:16:44 -05:00
Alec Chen
e84fb067aa
Drop non-matching custom TLVs when receiving MPP
Upon receiving multiple payment parts with custom TLVs, we fail payments
if they have any non-matching or missing even TLVs, and otherwise just
drop non-matching TLVs if they're odd.
2023-08-08 16:16:43 -05:00
Alec Chen
0a2dbdf247
Handle receiving custom HTLC TLVs
This completes basic receiver-side support for custom TLVs and adds
functional testing for sending and receiving.
2023-08-08 16:16:38 -05:00
Alec Chen
f560320b5f
De/serialize custom TLVs on {Inbound,Outbound}OnionPayload
When serialized, the TLVs in `OutboundOnionPayload`, unlike a normal
TLV stream, are prefixed with the length of the stream. To allow a user
to add arbitrary custom TLVs, we aren't able to communicate to our
serialization macros exactly which fields to expect, so this commit
adds new macro variants to allow appending an extra set of bytes (and
modifying the prefixed length accordingly).

Because the keysend preimage TLV has a type number in the custom type
range, and a user's TLVs may have type numbers above and/or below
keysend's type number, and because TLV streams must be serialized in
increasing order by type number, this commit also ensures the keysend
TLV is properly sorted/serialized amongst the custom TLVs.
2023-08-08 16:13:19 -05:00
Alec Chen
d2e9cb4bcd
Add custom tlvs to PendingOutboundPayment::Retryable 2023-08-08 15:55:06 -05:00
Alec Chen
039b1c8d10
Allow users to provide custom TLVs through RecipientOnionFields
Custom TLVs allow users to send extra application-specific data with
a payment. These have the additional flexibility compared to
`payment_metadata` that they don't have to reflect recipient generated
data provided in an invoice, in which `payment_metadata` could be
reused.

We ensure provided type numbers are unique, increasing, and within the
experimental range with the `RecipientOnionFields::with_custom_tlvs`
method.

This begins sender-side support for custom TLVs.
2023-08-08 15:55:00 -05:00
Matt Corallo
4b24135738
Merge pull request #2128 from valentinewallace/2023-03-route-blinding-groundwork
Route blinding groundwork
2023-08-08 19:59:05 +00:00
Jeffrey Czyz
bdbe9c8925
Smooth out channel liquidity bounds decay
Decaying the channel liquidity bounds by a half life can result in a
large decrease, which may have an oscillating affect on whether a
channel is retried. Approximate an additional three-quarter life when
half of the next half life has passed to help smooth out the decay.
2023-08-08 12:58:25 -05:00
Vladimir Fomene
7cfafc98ba
Add test coverage ChannelClosed event fields 2023-08-08 14:07:16 +03:00
Vladimir Fomene
bd6323e94b
Add counterparty_node_id & channel_capacity to ChannelClosed
The current ChannelClosed event does not let
you know the counterparty during a channel close
event. This change adds the counterparty_node_id
and the channel_capacity to the ChannelClosed event.
This helps users to have more context during a
channel close event. Solves #2343
2023-08-08 13:58:40 +03:00
Matt Corallo
67e5399eff Make CI build -> test flows test -> build.
Doing `cargo test` causes us to build both the crate(s) themselves
and the test binaries, which depend on the main builds. However, it
can start building the test code while the actual program code for
the main crate(s) themselves are being built, making a
build -> test flow slightly slower than test -> build.

Its not really a huge deal, but I'm using `ci/ci-tests.sh` more
locally and it meaningfully changes the time-to-test-run.
2023-08-08 04:19:51 +00:00
Matt Corallo
fe6366895a Scope payment preimage in do_test_keysend_payments
b0d4ab8cf8 fixed a nasty bug where
we'd failed to include the payment preimage in keysend onions at
all. Ultimately, this was a test failure - the existing test suite
should which did keysend payments were not structured in a way that
would fail in this case, instead using the same preimage variable
both for sending and receiving.

Here we improve the main keysend test tweaked by b0d4ab8cf8
to make absolutely sure it cannot work if the preimage doesn't come
from the onion. We make the payment preimage on the sending side a
variable inside a scope which only exists for the send call. Once
that scope completes the payment preimage only exists in the
sending `ChannelManager`, which must have put it in the onion in
order for the receiving node to have it.
2023-08-08 04:15:20 +00:00
valentinewallace
100fdbb7e8
Merge pull request #2475 from alecchendev/2023-08-actually-fix-keysend
Fix keysend not being sent in `OutboundPayment::send_payment_internal`
2023-08-07 15:56:09 -07:00
Alec Chen
b0d4ab8cf8
Send keysend preimage through OutboundPayment::send_payment_internal
Fixes a bug where we wouldn't use the provided keysend preimage when
piping through OutboundPayment::pay_route_internal.

Also simplifies and refactors existing keysend tests to make sure this
gets hit.
2023-08-04 22:05:13 -05:00
Alec Chen
b7d0357a8a
Move keysend tests to payment_tests.rs 2023-08-04 19:17:29 -05:00
Valentine Wallace
c9d3544314
Remove unnecessary vecs in channel.rs 2023-08-02 12:54:44 -07:00
Valentine Wallace
67868aec72
Replace OnionHopData with OutboundPayload for outbound onions
Follows on from the previous commit, see its message
2023-08-02 12:54:41 -07:00
Valentine Wallace
02a6d895a5
Receive payment onions as new InboundPayload instead of OnionHopData
To support route blinding, we want to split OnionHopData into two separate
structs, one for inbound onions and one for outbound onions. This is because
blinded payloads change the fields present in the onion hop data struct based
on whether we're sending vs receiving (outbound onions include encrypted blobs,
inbound onions can decrypt those blobs and contain the decrypted fields
themselves).

In upcoming commits, we'll add variants for blinded payloads to the new
InboundPayload enum.
2023-08-02 12:54:34 -07:00
Valentine Wallace
0c37488ff4
Remove outdated documentation of a panic 2023-08-02 12:54:34 -07:00
Valentine Wallace
9473f1cb5f
Remove indentation in payment receive util
This also set us up for supporting receiving blinded onion payloads.
2023-08-02 12:54:31 -07:00
valentinewallace
6f58072585
Merge pull request #2366 from valentinewallace/2023-05-blinded-pathfinding-fuzz
Blinded pathfinding fuzzing
2023-07-31 15:27:47 -07:00
Matt Corallo
0607ed766a
Merge pull request #2460 from TheBlueMatt/2023-07-claimable-clarify
Rename `Balance::claimable_amount_satoshis` to have a unique name
2023-07-31 17:47:33 +00:00
Matt Corallo
3c525ef694
Merge pull request #2463 from TheBlueMatt/2023-07-no-rustdoc-unicode
Drop unicode in documentation
2023-07-31 17:47:19 +00:00
Matt Corallo
56fba35422
Merge pull request #2465 from alecchendev/2023-07-flip-keysend-feature-bit
Flip keysend feature bit on
2023-07-31 17:46:57 +00:00
valentinewallace
390d49c596
Merge pull request #2454 from optout21/unused-use
(Minor) Remove an unused import (ChannelSigner)
2023-07-31 10:35:15 -07:00
Elias Rohrer
7768b73251
Merge pull request #2459 from valentinewallace/2023-07-reconnect-peers-test-util
Struct-ify `reconnect_nodes` test util args
2023-07-31 15:25:05 +02:00
Alec Chen
7ee90a5dc6 Flip keysend feature bit in node features 2023-07-30 21:18:43 -05:00
Matt Corallo
28f303c193 Drop unicode in documentation
Javadocs refuse unicode and as our rustdocs get copied over to Java
bindings (and thus get run through javadocs) we can't have unicode
in our rustdocs.
2023-07-30 17:12:08 +00:00
Matt Corallo
830220393f Drop claimable from Balance::claimable_amount_satoshis fields
In Java/TypeScript, we map enums as a base class and each variant
as a class which extends the base. In Java/TypeScript, functions
and fields share the same namespace, which means we cannot have
functions on an enum which have the same name as any fields in any
enum variants.

`Balance`'s `claimable_amount_satoshis` method aliases with fields
in each variant, and thus ultimately doesn't compile in TypeScript.

Because `Balance::claimable_amount_satoshis` has the same name as
the fields, it's also a bit confusing, as it doesn't return the
field for each variant, but sometimes returns zero if we're not
sure we can claim the balance.

Instead, we rename the fields in each enum variant to simply
`amount_satoshis`, to avoid implying that we can definitely claim
the balance.
2023-07-30 02:24:16 +00:00
Valentine Wallace
ece4db67fe
Struct-ify reconnect_nodes test util args
Makes it easier to add new arguments without a ton of resulting test changes.
Useful for route blinding testing because we need to check for malformed HTLCs,
which is not currently supported by reconnect_nodes. It also makes it easier to
tell what is being checked in relevant tests.
2023-07-27 16:00:28 -07:00
Valentine Wallace
49f4d5f8f4
Add onion message test vectors
Also re-alphabetize the imports in the onion message functional tests.

Co-authored-by: Carla Kirk-Cohen <kirkcohenc@gmail.com>
2023-07-27 11:55:47 -07:00
valentinewallace
5cddf5e06a
Merge pull request #2104 from douglaz/docs_fixes_channel
Docs improvements for channel
2023-07-26 14:52:15 -07:00