rust-lightning
4 weeks agoAllow `MaybeReadable` to not fully read in `upgradable_option` 2024-03-fix-upgradable-enum
Matt Corallo [Thu, 28 Mar 2024 22:06:36 +0000 (22:06 +0000)]
Allow `MaybeReadable` to not fully read in `upgradable_option`

Whils this is generally not supported, issues in our
`MaybeReadable` implementations may occur, and we should try to be
robust against them.

4 weeks agoEnsure we read the full TLV stream length when maybe-reading `None`
Matt Corallo [Thu, 28 Mar 2024 22:02:09 +0000 (22:02 +0000)]
Ensure we read the full TLV stream length when maybe-reading `None`

If we are reading an object that is `MaybeReadable` in a TLV stream
using `upgradable_required`, it may return early with `Ok(None)`.
In this case, it will not read any further TLVs from the TLV
stream. This is fine, except that we generally expect
`MaybeReadable` always consume the correct number of bytes for the
full object, even if it doesn't understand it.

This could pose a problem, for example, in cases where we're
reading a TLV-stream `MaybeReadable` object inside another
TLV-stream object. In that case, the `MaybeReadable` object may
return `Ok(None)` and not consume all the available bytes, causing
the outer TLV read to fail as the TLV length does not match.

4 weeks agoFix unknown handling in `impl_writeable_tlv_based_enum_upgradable`
Matt Corallo [Tue, 26 Mar 2024 15:08:20 +0000 (15:08 +0000)]
Fix unknown handling in `impl_writeable_tlv_based_enum_upgradable`

`impl_writeable_tlv_based_enum_upgradable` professed to supporting
upgrades by returning `None` from `MaybeReadable` when unknown
variants written by newer versions of LDK were read. However, it
generally didn't support this as it didn't discard bytes for
unknown types, resulting in corrupt reading.

This is fixed here for enum variants written as a TLV stream,
however we don't have a length prefix for tuple enum variants, so
the documentation on the macro is updated to mention that
downgrades are not supported for tuple variants.

5 weeks agoMerge pull request #2963 from jkczyz/2024-03-a-channel-manager
Elias Rohrer [Mon, 25 Mar 2024 13:27:08 +0000 (14:27 +0100)]
Merge pull request #2963 from jkczyz/2024-03-a-channel-manager

Use `AChannelManager` in `BackgroundProcessor`

6 weeks agoUse AChannelManager in BackgroundProcessor
Jeffrey Czyz [Sat, 23 Mar 2024 21:28:54 +0000 (16:28 -0500)]
Use AChannelManager in BackgroundProcessor

Replace instance of ChannelManager in BackgroundProcessor and in
Persister with AChannelManager. This reduces the number of type
parameters need in those types, which would need to be repeated in an
async version of Persister.

6 weeks agoRemove duplicate docs from trait implementations
Jeffrey Czyz [Sat, 23 Mar 2024 21:56:26 +0000 (16:56 -0500)]
Remove duplicate docs from trait implementations

6 weeks agoFix indentation in doc example
Jeffrey Czyz [Sat, 23 Mar 2024 21:18:58 +0000 (16:18 -0500)]
Fix indentation in doc example

6 weeks agoMerge pull request #2756 from arik-so/arik/trampoline/2023-11-outbound
valentinewallace [Fri, 22 Mar 2024 14:41:19 +0000 (10:41 -0400)]
Merge pull request #2756 from arik-so/arik/trampoline/2023-11-outbound

Serialize Trampoline payloads in outbound onions.

6 weeks agoAdd Trampoline variant to OutboundOnionPayload.
Arik Sosman [Tue, 28 Nov 2023 20:17:17 +0000 (12:17 -0800)]
Add Trampoline variant to OutboundOnionPayload.

6 weeks agoIntroduce TrampolineOnionPacket.
Arik Sosman [Fri, 22 Mar 2024 00:44:40 +0000 (17:44 -0700)]
Introduce TrampolineOnionPacket.

6 weeks agoMerge pull request #2946 from tnull/2024-03-txsync-readd-reorged-output-spends
Matt Corallo [Thu, 21 Mar 2024 19:58:11 +0000 (19:58 +0000)]
Merge pull request #2946 from tnull/2024-03-txsync-readd-reorged-output-spends

Tx-Sync: Track spent `WatchedOutput`s and re-add if unconfirmed

6 weeks agoMerge pull request #2953 from dunxen/2024-03-fix2941
Gursharan Singh [Thu, 21 Mar 2024 17:55:19 +0000 (10:55 -0700)]
Merge pull request #2953 from dunxen/2024-03-fix2941

Fix `ChannelManager::accept_inbound_channel` error handling

6 weeks agoDedup `confirmed_txs` `Vec`
Elias Rohrer [Tue, 19 Mar 2024 14:30:16 +0000 (15:30 +0100)]
Dedup `confirmed_txs` `Vec`

Previously, we would just push to the `confirmed_txs` `Vec`, leading to
redundant `Confirm::transactions_confirmed` calls, especially now that
we re-confirm previously disconnected spends.

Here, we ensure that we don't push additional `ConfirmedTx` entries if
already one with matching `Txid` is present. This not only gets rid of
the spurious `transactions_confirmed` calls (which are harmless), but
more importantly saves us from issuing unnecessary network calls, which
improves latency.

6 weeks agoMerge pull request #2934 from TheBlueMatt/2023-03-no-num-traits
valentinewallace [Thu, 21 Mar 2024 14:48:35 +0000 (10:48 -0400)]
Merge pull request #2934 from TheBlueMatt/2023-03-no-num-traits

Replace the generic `parse_int_be` with a macro called twice

6 weeks agoTest ChannelManager::accept_inbound_channel errors
Duncan Dean [Thu, 21 Mar 2024 07:16:23 +0000 (09:16 +0200)]
Test ChannelManager::accept_inbound_channel errors

6 weeks agoFix ChannelManager::accept_inbound_channel error handling
Duncan Dean [Wed, 20 Mar 2024 17:31:39 +0000 (19:31 +0200)]
Fix ChannelManager::accept_inbound_channel error handling

6 weeks agoMerge pull request #2935 from valentinewallace/2024-03-keysend-to-blinded
Matt Corallo [Wed, 20 Mar 2024 19:20:11 +0000 (19:20 +0000)]
Merge pull request #2935 from valentinewallace/2024-03-keysend-to-blinded

Support keysend to blinded paths

6 weeks agoMerge pull request #2419 from jurvis/2023-03-interactivetxs
Matt Corallo [Wed, 20 Mar 2024 19:06:22 +0000 (19:06 +0000)]
Merge pull request #2419 from jurvis/2023-03-interactivetxs

Interactive Transaction Construction

6 weeks agoMerge pull request #2887 from benthecarman/htlc-timeout
Matt Corallo [Wed, 20 Mar 2024 18:13:27 +0000 (18:13 +0000)]
Merge pull request #2887 from benthecarman/htlc-timeout

Add HTLCsTimedOut closing reason

6 weeks agoMerge pull request #2951 from jkczyz/2024-03-fix-sender-is-intro-node
Matt Corallo [Wed, 20 Mar 2024 14:35:35 +0000 (14:35 +0000)]
Merge pull request #2951 from jkczyz/2024-03-fix-sender-is-intro-node

Fix sender is the introduction node onion messages

6 weeks agoMerge pull request #2924 from tnull/2024-03-add-user-channel-id-to-payment-forwarded
valentinewallace [Wed, 20 Mar 2024 14:27:16 +0000 (10:27 -0400)]
Merge pull request #2924 from tnull/2024-03-add-user-channel-id-to-payment-forwarded

Expose `{prev,next}_user_channel_id` fields in `PaymentForwarded`

6 weeks agoMerge pull request #2948 from arik-so/2024-03-public-node-announcement-excess
Matt Corallo [Wed, 20 Mar 2024 00:53:38 +0000 (00:53 +0000)]
Merge pull request #2948 from arik-so/2024-03-public-node-announcement-excess

Publicize all UnsignedNodeAnnouncement fields.

6 weeks agoMerge pull request #2949 from valentinewallace/2024-03-dont-write-empty-features
Matt Corallo [Wed, 20 Mar 2024 00:52:59 +0000 (00:52 +0000)]
Merge pull request #2949 from valentinewallace/2024-03-dont-write-empty-features

Only write `BlindedHopFeatures` if any features are set

6 weeks agoAdd HTLCsTimedOut closing reason
benthecarman [Tue, 20 Feb 2024 18:47:50 +0000 (18:47 +0000)]
Add HTLCsTimedOut closing reason

Before a force closure from timed out HTLCs was treated the same as when
the user manually force closed the channel. This leads to various UX
issues. This adds a new `ClosureReason` called `HTLCsTimedOut` that
signifies that the closure was caused because the HTLCs timed out. To go
along with this, previously we'd always send "Channel force-closed" when
force closing the channel in the error message which was ambigous, now
we send the force closure reason so the peer can know why the channel
was closed.

6 weeks agoUse OnionMessenger::send_onion_message in tests
Jeffrey Czyz [Tue, 19 Mar 2024 22:04:01 +0000 (17:04 -0500)]
Use OnionMessenger::send_onion_message in tests

Use OnionMessenger's public interface in tests whenever possible (i.e.,
when not using any intermediate_nodes in an OnionMessagePath. This
allows us to exercise DefaultMessageRouter, and, in particular that a
path can be found for an unannounced sender when its in the introduction
node.

6 weeks agoUse DefaultMessageRouter in functional tests
Jeffrey Czyz [Tue, 19 Mar 2024 21:11:34 +0000 (16:11 -0500)]
Use DefaultMessageRouter in functional tests

This helps test cases in DefaultMessageRouter that may not be exercised
now or in the future.

6 weeks agopub(crate) visibility for routing/test_utils.rs
Jeffrey Czyz [Tue, 19 Mar 2024 21:07:20 +0000 (16:07 -0500)]
pub(crate) visibility for routing/test_utils.rs

Give pub(crate) visibility to some routing test utilities to facilitate
testing DefaultMessageRouter in functional tests.

6 weeks agoFix sender is the introduction node onion messages
Jeffrey Czyz [Tue, 19 Mar 2024 21:04:43 +0000 (16:04 -0500)]
Fix sender is the introduction node onion messages

DefaultMessageRouter will form an OnionMessagePath from a BlindedPath
where the sender is the introduction node but only if the sender is
announced. If the sender is unannounced, then DefaultMessageRouter will
fail. While DefaultMessageRouter will only create a blinded path with an
announced introduction node, it may receive one where the introduction
node is unannounced. Don't return an error in this case, as the
OnionMessenger can advance the blinded path by one hop.

This may occur when two nodes have an unannounced channel and one (the
offer creator) wants to use it for payments without an intermediary node
and without putting its node id in the offer.

6 weeks agoInclude SocketAddress in test node_announcement
Jeffrey Czyz [Tue, 19 Mar 2024 19:20:55 +0000 (14:20 -0500)]
Include SocketAddress in test node_announcement

6 weeks agoRe-order imports
Jeffrey Czyz [Tue, 19 Mar 2024 19:19:59 +0000 (14:19 -0500)]
Re-order imports

6 weeks agoAdd trampoline feature flag.
Arik Sosman [Tue, 28 Nov 2023 21:23:15 +0000 (13:23 -0800)]
Add trampoline feature flag.

6 weeks agoOnly write BlindedHopFeatures if any features are set.
Valentine Wallace [Tue, 19 Mar 2024 18:58:43 +0000 (14:58 -0400)]
Only write BlindedHopFeatures if any features are set.

Minor space-saving optimization.

6 weeks agoPublicize all UnsignedNodeAnnouncement fields.
Arik Sosman [Tue, 19 Mar 2024 15:34:05 +0000 (08:34 -0700)]
Publicize all UnsignedNodeAnnouncement fields.

This is necessary for RGSS tests to create new announcements.

6 weeks agoTrack spent `WatchedOutput`s and re-add if unconfirmed
Elias Rohrer [Tue, 19 Mar 2024 14:07:27 +0000 (15:07 +0100)]
Track spent `WatchedOutput`s and re-add if unconfirmed

Previously, we would track a spending transaction but wouldn't account
for it being reorged out of the chain, in which case we wouldn't monitor
the `WatchedOutput`s until they'd be reloaded on restart.

Here, we keep any `WatchedOutput`s around until their spends are
sufficiently confirmed and only prune them after `ANTI_REORG_DELAY`.

6 weeks agoMerge pull request #2945 from valentinewallace/2024-03-optional-blindedhop-features
Matt Corallo [Tue, 19 Mar 2024 13:41:43 +0000 (13:41 +0000)]
Merge pull request #2945 from valentinewallace/2024-03-optional-blindedhop-features

Make `BlindedHopFeatures` optional per spec

6 weeks agoRemove redundant `claiming_channel_id` variable
Elias Rohrer [Thu, 7 Mar 2024 09:39:37 +0000 (10:39 +0100)]
Remove redundant `claiming_channel_id` variable

.. as it's the same as `prev_channel_id` defined a few lines above.

6 weeks agoExpose `{prev,next}_user_channel_id` fields in `PaymentForwarded`
Elias Rohrer [Thu, 7 Mar 2024 09:37:08 +0000 (10:37 +0100)]
Expose `{prev,next}_user_channel_id` fields in `PaymentForwarded`

This is useful for users that track channels by `user_channel_id`.

For example, in `lightning-liquidity` we currently keep a full
`HashMap<ChanelId, u128>` around *just* to be able to associate
`PaymentForwarded` events with the channels otherwise tracked by
`user_channel_id`.

6 weeks agoMake blinded hop features optional per spec.
Valentine Wallace [Mon, 18 Mar 2024 21:01:07 +0000 (17:01 -0400)]
Make blinded hop features optional per spec.

The spec states that if these features are missing, we MUST process the message
as if it were present and contained an empty array.

6 weeks agoMerge pull request #2936 from valentinewallace/2024-03-pay-relay-constraints-ser
Matt Corallo [Mon, 18 Mar 2024 13:37:23 +0000 (13:37 +0000)]
Merge pull request #2936 from valentinewallace/2024-03-pay-relay-constraints-ser

Fix ser for `PaymentRelay` and `PaymentConstraints`

6 weeks agoMerge pull request #2942 from benthecarman/node-id-slice
Elias Rohrer [Mon, 18 Mar 2024 09:13:00 +0000 (09:13 +0000)]
Merge pull request #2942 from benthecarman/node-id-slice

Add NodeId::from_slice

7 weeks agoAdd NodeId::from_slice
benthecarman [Sun, 17 Mar 2024 15:26:27 +0000 (15:26 +0000)]
Add NodeId::from_slice

7 weeks agoMerge pull request #2937 from TheBlueMatt/2024-03-no-wake-on-shutdown
Matt Corallo [Thu, 14 Mar 2024 20:32:27 +0000 (20:32 +0000)]
Merge pull request #2937 from TheBlueMatt/2024-03-no-wake-on-shutdown

Avoid writing `ChannelManager` when hitting lnd bug 6039

7 weeks agoAvoid writing `ChannelManager` when hitting lnd bug 6039 2024-03-no-wake-on-shutdown
Matt Corallo [Thu, 14 Mar 2024 19:47:07 +0000 (19:47 +0000)]
Avoid writing `ChannelManager` when hitting lnd bug 6039

When we hit lnd bug 6039, we end up sending error messages to peers
in a loop. This should be fine, but because we used the generic
`PersistenceNotifierGuard::notify_on_drop` lock above the specific
handling, we end up writing `ChannelManager` every time we manage a
round-trip to our peer.

This can add up quite quickly, and isn't actually changing, so we
really need to avoid writing the `ChannelManager` in this case.

7 weeks agoFix ser for PaymentRelay and PaymentConstraints.
Valentine Wallace [Thu, 14 Mar 2024 19:19:10 +0000 (15:19 -0400)]
Fix ser for PaymentRelay and PaymentConstraints.

Two fields were serialized as u32/u64 when the spec said *tu32/tu64*.
/facepalm.

7 weeks agoImplement interactive tx construction protocol via `InteractiveTxConstructor`
Duncan Dean [Tue, 21 Mar 2023 19:12:53 +0000 (21:12 +0200)]
Implement interactive tx construction protocol via `InteractiveTxConstructor`

This implements the interactive construction protocol described at
https://github.com/lightning/bolts/blob/78e5a6b066d3a8e235931dfc06aa325337874749/02-peer-protocol.md?plain=1#L92.

Our implementation includes a state machine with typed states and transitions
to ensure consumers have compile-time assurances that the protocol is upheld.

States are tracked as in the `StateMachine` enum and can take on all
possible states during the negotiation.

The states are further divided into two categories, namely by the two traits
they implement, either `ReceivedMsgState` or `SentMsgState`.

The defined `StateTransitions` enforce the transitions that `ReceivedMsgState`,
`SentMsgState`, and the `_TxComplete`s can go through.

Co-authored-by: Wilmer Paulino <9447167+wpaulino@users.noreply.github.com>
Co-authored-by: Duncan Dean <git@dunxen.dev>
Co-authored-by: Jurvis Tan <5944973+jurvis@users.noreply.github.com>
7 weeks agoMerge pull request #2932 from TheBlueMatt/2023-04-ci-fix
Elias Rohrer [Thu, 14 Mar 2024 09:57:23 +0000 (09:57 +0000)]
Merge pull request #2932 from TheBlueMatt/2023-04-ci-fix

Avoid new "out of disk space" issues in CI

7 weeks agoSupport receiving keysend payments to blinded paths.
Valentine Wallace [Wed, 13 Mar 2024 19:46:30 +0000 (15:46 -0400)]
Support receiving keysend payments to blinded paths.

7 weeks agoParse keysend preimages in blinded onion payloads.
Valentine Wallace [Wed, 13 Mar 2024 19:46:12 +0000 (15:46 -0400)]
Parse keysend preimages in blinded onion payloads.

7 weeks agoSupport sending keysend payments to blinded paths.
Valentine Wallace [Wed, 13 Mar 2024 19:43:23 +0000 (15:43 -0400)]
Support sending keysend payments to blinded paths.

7 weeks agoReplace the generic `parse_int_be` with a macro called twice 2023-03-no-num-traits
Matt Corallo [Wed, 13 Mar 2024 19:18:20 +0000 (19:18 +0000)]
Replace the generic `parse_int_be` with a macro called twice

`parse_int_be` is generic across integer types and also input
types, but to do so it relies on the `num-traits` crate. There's
not a lot of reason for this now that std has `from_be_bytes`, so
we drop the generic now and replace it with a macro which is called
twice to create two functions, both only supporting conversion from
`u5` arrays.

7 weeks agoUse std's `from_be_bytes` rather than our `to_int_be` for int conv
Matt Corallo [Wed, 13 Mar 2024 19:16:20 +0000 (19:16 +0000)]
Use std's `from_be_bytes` rather than our `to_int_be` for int conv

`lightning-invoice` was mostly written before std's `from_be_bytes`
was stabilized, so used its own `to_int_be` utility to do int
conversions from `u8` arrays. Now that the std option has been
stable for quite some time, we should juse use it instead.

7 weeks agoMerge pull request #2881 from TheBlueMatt/2024-02-offers-tweak
Matt Corallo [Wed, 13 Mar 2024 16:34:40 +0000 (16:34 +0000)]
Merge pull request #2881 from TheBlueMatt/2024-02-offers-tweak

Small Offers Fixes

7 weeks agoUse structured logging where appropriate in `OnionMessenger` 2024-02-offers-tweak
Matt Corallo [Wed, 7 Feb 2024 01:19:09 +0000 (01:19 +0000)]
Use structured logging where appropriate in `OnionMessenger`

7 weeks agoAdd `PersistenceNotifierGuard` take to offer/refund payments
Matt Corallo [Tue, 6 Feb 2024 23:17:50 +0000 (23:17 +0000)]
Add `PersistenceNotifierGuard` take to offer/refund payments

This resolves an issue where offer and refund payments get delayed
while we wait for the `invoice_request`/`invoice` onion messages to
get sent. It further ensures we're likely to have the
`ChannelManager` persisted with the new payment info after
initiating the send/receive.

7 weeks agoUse `{}`, not `{:?}` for `PublicKey` logging
Matt Corallo [Tue, 6 Feb 2024 23:13:08 +0000 (23:13 +0000)]
Use `{}`, not `{:?}` for `PublicKey` logging

The `Debug` serialization of `PublicKey`s includes both the X and Y
coordinate, which isn't something most of our users deal with.
Instead, logging using `Display` gives users the keys they're used
to.

7 weeks agoAvoid new "out of disk space" issues in CI 2023-04-ci-fix
Matt Corallo [Tue, 12 Mar 2024 15:19:51 +0000 (15:19 +0000)]
Avoid new "out of disk space" issues in CI

Our 1.63 build on Ubuntu has been failing for quite some time
because it runs out of disk space trying to build tests in the last
cfg-flag steps. Thus, we add a few new `cargo clean`s here to fix
it.

7 weeks agoMerge pull request #2917 from jkczyz/2024-02-refund-unsupported-chain
Matt Corallo [Tue, 12 Mar 2024 15:18:32 +0000 (15:18 +0000)]
Merge pull request #2917 from jkczyz/2024-02-refund-unsupported-chain

Fail `request_refund_payment` for unsupported chain

8 weeks agoFail request_refund_payment for unsupported chain
Jeffrey Czyz [Thu, 29 Feb 2024 21:21:03 +0000 (15:21 -0600)]
Fail request_refund_payment for unsupported chain

If a Refund has an unsupported chain, ChannelManager should not send an
invoice as it can't be paid on that chain. Instead, return an error when
calling ChannelManager::request_refund_payment for such refunds.

8 weeks agoUpdate pay_for_offer docs about unsupported chains
Jeffrey Czyz [Thu, 29 Feb 2024 21:44:57 +0000 (15:44 -0600)]
Update pay_for_offer docs about unsupported chains

8 weeks agoTest failing pay_for_offer on an unsupported chain
Jeffrey Czyz [Thu, 29 Feb 2024 21:03:31 +0000 (15:03 -0600)]
Test failing pay_for_offer on an unsupported chain

8 weeks agoMerge pull request #2823 from valentinewallace/2024-01-blinded-forwarding-tests
Matt Corallo [Fri, 8 Mar 2024 21:32:40 +0000 (21:32 +0000)]
Merge pull request #2823 from valentinewallace/2024-01-blinded-forwarding-tests

Test blinded forwarding

8 weeks agoMerge pull request #2903 from jkczyz/2024-02-bindings-builders
valentinewallace [Fri, 8 Mar 2024 21:07:10 +0000 (16:07 -0500)]
Merge pull request #2903 from jkczyz/2024-02-bindings-builders

Offers builders for C-bindings

8 weeks agoMerge pull request #2926 from tnull/2024-03-derive-eq-for-offer-refund
Matt Corallo [Fri, 8 Mar 2024 17:34:37 +0000 (17:34 +0000)]
Merge pull request #2926 from tnull/2024-03-derive-eq-for-offer-refund

Impl `PartialEq`/`Eq` for `Offer`/`Refund`

8 weeks agoTest that we'll round up blinded intermediate node fees if needed.
Valentine Wallace [Mon, 25 Dec 2023 01:19:47 +0000 (20:19 -0500)]
Test that we'll round up blinded intermediate node fees if needed.

See comment in the new test.

8 weeks agoTest utils: support intermediate nodes taking 1msat extra fee.
Valentine Wallace [Wed, 20 Dec 2023 22:37:03 +0000 (17:37 -0500)]
Test utils: support intermediate nodes taking 1msat extra fee.

See docs on the new field.

8 weeks agoSupport fee overpayment by 1 msat in expect_payment_forwarded test util.
Valentine Wallace [Mon, 25 Dec 2023 01:13:28 +0000 (20:13 -0500)]
Support fee overpayment by 1 msat in expect_payment_forwarded test util.

See ClaimAlongRouteArgs::allow_1_msat_fee_overpay.

8 weeks agoFunctionally test min htlc BlindedPayInfo calculation.
Valentine Wallace [Sun, 24 Dec 2023 21:50:42 +0000 (16:50 -0500)]
Functionally test min htlc BlindedPayInfo calculation.

8 weeks agoAccount for prop fee in test util fee calculation.
Valentine Wallace [Sun, 24 Dec 2023 21:49:58 +0000 (16:49 -0500)]
Account for prop fee in test util fee calculation.

8 weeks agoUse correct min/max htlc in test util for constructing blinded pay params.
Valentine Wallace [Sun, 24 Dec 2023 21:47:49 +0000 (16:47 -0500)]
Use correct min/max htlc in test util for constructing blinded pay params.

In testing, we use channel updates to construct blinded paths and the
{Forward,Receive}Tlvs encoded within. Given a blinded path from node A > B > C,
we currently use channel_update_A->B to construct the payment constraints for
A’s blinded payload.

This is incorrect for setting A's PaymentConstraints::htlc_minimum_msat,
because channel_update_A->B contains the minimum value that *B* will accept,
and we want the constraints to contain the min value that *A* will accept.

This never caused test failures before because min/max htlc values were always
identical in both channel directions.

Therefore, set A’s htlc min/max values to the min/max that A will accept.

8 weeks agoParameterize blinded test util with intro node min/max htlc.
Valentine Wallace [Sun, 24 Dec 2023 21:44:33 +0000 (16:44 -0500)]
Parameterize blinded test util with intro node min/max htlc.

We're currently not setting each node's min/max htlc correctly, see next
commit.

8 weeks agoStruct-ify test util pass_along_path args.
Valentine Wallace [Wed, 20 Dec 2023 20:01:42 +0000 (15:01 -0500)]
Struct-ify test util pass_along_path args.

Lays groundwork to make pass_along_path easier to adapt without changing a
million callsites.

8 weeks agoTest 3-hop blinded path recipient failure.
Valentine Wallace [Mon, 18 Dec 2023 20:07:45 +0000 (15:07 -0500)]
Test 3-hop blinded path recipient failure.

This tests an intermediate forwarding node being failed back to with malformed
and then failing back themselves with malformed.

8 weeks agoDrop error type parameter from SignError
Jeffrey Czyz [Thu, 7 Mar 2024 22:59:09 +0000 (16:59 -0600)]
Drop error type parameter from SignError

SignError allows implementors of SignFunction to return a custom error
type. Drop this as an unconstrained type causes problems with bindings
and isn't useful unless the caller can take some sort of action based on
different errors.

8 weeks agoFix unused import warning
Jeffrey Czyz [Fri, 1 Mar 2024 16:27:54 +0000 (10:27 -0600)]
Fix unused import warning

8 weeks agoSupport BOLT 12 signing in c_bindings
Jeffrey Czyz [Fri, 1 Mar 2024 16:17:08 +0000 (10:17 -0600)]
Support BOLT 12 signing in c_bindings

Replace the Fn trait bound on signing methods with a dedicated trait
since Fn is not supported in bindings. Implement the trait for Fn so
that closures can still be used in Rust.

8 weeks agoAdd c_bindings version of InvoiceBuilder
Jeffrey Czyz [Mon, 26 Feb 2024 02:42:57 +0000 (20:42 -0600)]
Add c_bindings version of InvoiceBuilder

Use the macros introduced in the previous commit to define two builders
for each type parameterization of InvoiceBuilder
- InvoiceWithExplicitSigningPubkeyBuilder
- InvoiceWithDerivedSigningPubkeyBuilder

The difference between these and InvoiceBuilder is that these have
methods that take `self` by mutable reference instead of by value and
don't return anything instead returning the modified builder. This is
required because bindings don't support move semantics nor impl blocks
specific to a certain type parameterization. Because of this, the
builder's contents must be cloned when building a Bolt12Invoice.

Keeps InvoiceBuilder defined so that it can be used internally in
ChannelManager's OffersMessageHandler even when compiled for c_bindings.

8 weeks agoImplement `Hash` for `Offer` and `Refund`
Elias Rohrer [Fri, 8 Mar 2024 15:43:45 +0000 (16:43 +0100)]
Implement `Hash` for `Offer` and `Refund`

8 weeks agoImpl `PartialEq`/`Eq` for `Offer`/`Refund`
Elias Rohrer [Fri, 8 Mar 2024 09:24:50 +0000 (10:24 +0100)]
Impl `PartialEq`/`Eq` for `Offer`/`Refund`

We add custom implementations based on comparing the `bytes` for
`Offer`/`Refund` themselves as this is sufficient and should be faster
than comapring all fields in the worst case.

8 weeks agoMerge pull request #2923 from tnull/2024-03-improve-best-block
Matt Corallo [Thu, 7 Mar 2024 17:55:59 +0000 (17:55 +0000)]
Merge pull request #2923 from tnull/2024-03-improve-best-block

Refactor `BestBlock` to expose inner fields

8 weeks agoImplement `Hash` for `BestBlock`
Elias Rohrer [Thu, 7 Mar 2024 16:35:38 +0000 (17:35 +0100)]
Implement `Hash` for `BestBlock`

8 weeks agoMerge pull request #2912 from jkczyz/2024-02-prefer-more-connections
Elias Rohrer [Thu, 7 Mar 2024 11:06:42 +0000 (12:06 +0100)]
Merge pull request #2912 from jkczyz/2024-02-prefer-more-connections

Order blinded paths by reliability criteria

8 weeks agoImplement `Debug` for `BestBlock`
Elias Rohrer [Thu, 7 Mar 2024 08:45:45 +0000 (09:45 +0100)]
Implement `Debug` for `BestBlock`

8 weeks agoRefactor `BestBlock` to expose inner fields rather than accessors
Elias Rohrer [Thu, 7 Mar 2024 08:44:45 +0000 (09:44 +0100)]
Refactor `BestBlock` to expose inner fields rather than accessors

.. which is more idiomatic Rust, and easier to handle in (downstream)
bindings.

8 weeks agoMacro-ize InvoiceBuilder
Jeffrey Czyz [Sun, 25 Feb 2024 20:58:07 +0000 (14:58 -0600)]
Macro-ize InvoiceBuilder

InvoiceBuilder is not exported to bindings because it has methods that
take `self` by value and are only implemented for certain type
parameterizations. Define these methods using macros such that different
builders and related methods can be defined for c_bindings.

8 weeks agoMerge similar InvoiceBuilder impl blocks
Jeffrey Czyz [Sun, 25 Feb 2024 17:32:02 +0000 (11:32 -0600)]
Merge similar InvoiceBuilder impl blocks

This avoids needing to create additional macros when adding c_bindings
support.

8 weeks agoAdd c_bindings version of InvoiceRequestBuilder
Jeffrey Czyz [Fri, 23 Feb 2024 19:34:24 +0000 (13:34 -0600)]
Add c_bindings version of InvoiceRequestBuilder

Use the macros introduced in the previous commit to define two builders
for each type parameterization of InvoiceRequestBuilder
- InvoiceRequestWithExplicitPayerIdBuilder
- InvoiceRequestWithDerivedPayerIdBuilder

The difference between these and InvoiceRequestBuilder is that these
have methods that take `self` by mutable reference instead of by value
and don't return anything instead returning the modified builder. This
is required because bindings don't support move semantics nor impl
blocks specific to a certain type parameterization. Because of this, the
builder's contents must be cloned when building an InvoiceRequest.

Keeps InvoiceRequestBuilder defined so that it can be used internally in
ChannelManager::pay_for_offer even when compiled for c_bindings.

8 weeks agoMacro-ize InvoiceRequestBuilder
Jeffrey Czyz [Thu, 22 Feb 2024 22:47:38 +0000 (16:47 -0600)]
Macro-ize InvoiceRequestBuilder

InvoiceRequestBuilder is not exported to bindings because it has methods
that take `self` by value and are only implemented for certain type
parameterizations. Define these methods using macros such that different
builders and related methods can be defined for c_bindings.

8 weeks agoMerge similar InvoiceRequestBuilder impl blocks
Jeffrey Czyz [Thu, 22 Feb 2024 21:13:32 +0000 (15:13 -0600)]
Merge similar InvoiceRequestBuilder impl blocks

This avoids needing to create additional macros when adding c_bindings
support.

8 weeks agoAdd c_bindings version of RefundBuilder
Jeffrey Czyz [Sat, 24 Feb 2024 02:30:50 +0000 (20:30 -0600)]
Add c_bindings version of RefundBuilder

Use the macros introduced in the previous commit to define a builder
called RefundMaybeWithDerivedMetadataBuilder.

The difference between this and RefundBuilder is that this has methods
that take `self` by mutable reference instead of by value and don't
return anything instead returning the modified builder. This is required
because bindings don't support move semantics. Because of this, the
builder's contents must be cloned when building a Refund.

Keeps RefundBuilder defined so that it can be used internally in
ChannelManager::create_refund_builder even when compiled for c_bindings.

8 weeks agoMacro-ize RefundBuilder
Jeffrey Czyz [Fri, 23 Feb 2024 22:52:49 +0000 (16:52 -0600)]
Macro-ize RefundBuilder

RefundBuilder is not exported to bindings because it has methods that
take `self` by value. Define these methods using macros such that
different builders and related methods can be defined for c_bindings.

8 weeks agoAdd c_bindings version of OfferBuilder
Jeffrey Czyz [Fri, 23 Feb 2024 22:33:23 +0000 (16:33 -0600)]
Add c_bindings version of OfferBuilder

Use the macros introduced in the previous commit to define two builders
for each type parameterization of OfferBuilder
- OfferWithExplicitMetadataBuilder
- OfferWithDerivedMetadataBuilder

The difference between these and OfferBuilder is that these have methods
that take `self` by mutable reference instead of by value and don't
return anything instead returning the modified builder. This is required
because bindings don't support move semantics nor impl blocks specific
to a certain type parameterization. Because of this, the builder's
contents must be cloned when building an Offer.

Keeps OfferBuilder defined so that it can be used internally in
ChannelManager::create_offer_builder even when compiled for c_bindings.

2 months agoMerge pull request #2919 from tnull/2024-03-fix-hashtables-rustfmt
Matt Corallo [Mon, 4 Mar 2024 16:30:29 +0000 (16:30 +0000)]
Merge pull request #2919 from tnull/2024-03-fix-hashtables-rustfmt

`rustfmt`: Fix CI by running `rustfmt` on `util/hash_tables.rs`

2 months agoRun `rustfmt` on `util/hash_tables.rs`
Elias Rohrer [Fri, 23 Feb 2024 10:51:50 +0000 (11:51 +0100)]
Run `rustfmt` on `util/hash_tables.rs`

.. to fix the silent rebase conflict.

2 months agoMerge pull request #2918 from tnull/2024-03-prefer-from-over-into
Matt Corallo [Fri, 1 Mar 2024 21:01:32 +0000 (21:01 +0000)]
Merge pull request #2918 from tnull/2024-03-prefer-from-over-into

2 months agoPrefer implementing `From` over `Into`
Elias Rohrer [Fri, 1 Mar 2024 10:42:54 +0000 (11:42 +0100)]
Prefer implementing `From` over `Into`

.. as the std library docs state that implementing Into should be avoided:
"One should avoid implementing Into and implement From instead.
Implementing From automatically provides one with an implementation of
Into thanks to the blanket implementation in the standard library."

2 months agoMerge pull request #2916 from sr-gi/2024-02-29-payment-preimage-hash
Matt Corallo [Thu, 29 Feb 2024 21:48:40 +0000 (21:48 +0000)]
Merge pull request #2916 from sr-gi/2024-02-29-payment-preimage-hash

util: Adds Into<PaymentHash> for PaymentPreimage

2 months agoutil: Adds Into<PaymentHash> for PaymentPreimage
Sergi Delgado Segura [Thu, 29 Feb 2024 19:51:38 +0000 (14:51 -0500)]
util: Adds Into<PaymentHash> for PaymentPreimage

This seems like a useful interface to have for downstream users

2 months agoMerge pull request #2915 from TheBlueMatt/2024-02-better-rnf-docs
Elias Rohrer [Thu, 29 Feb 2024 14:58:56 +0000 (15:58 +0100)]
Merge pull request #2915 from TheBlueMatt/2024-02-better-rnf-docs

Update docs on `PaymentFailureReason::RouteNotFound` to add context

2 months agoUpdate docs on `PaymentFailureReason::RouteNotFound` to add context 2024-02-better-rnf-docs
Matt Corallo [Thu, 29 Feb 2024 14:50:26 +0000 (14:50 +0000)]
Update docs on `PaymentFailureReason::RouteNotFound` to add context

tnull noted on discord that its somewhat unclear to users what
`RouteNotFound` actually means - that we ran out of routes, rather
than could not find a route at all - so the docs are updated here.

2 months agoMerge pull request #2913 from arik-so/2024/02/serialize-socket-address-vectors
Elias Rohrer [Thu, 29 Feb 2024 08:29:40 +0000 (09:29 +0100)]
Merge pull request #2913 from arik-so/2024/02/serialize-socket-address-vectors

Serialize SocketAddress vectors