Commit graph

4835 commits

Author SHA1 Message Date
Duncan Dean
c56198ade5
Implement interactive tx construction protocol via InteractiveTxConstructor
This implements the interactive construction protocol described at
78e5a6b066/02-peer-protocol.md (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>
2024-03-14 16:10:46 +02:00
Valentine Wallace
664abf20d0
Support receiving keysend payments to blinded paths. 2024-03-13 15:48:04 -04:00
Valentine Wallace
154aa211e6
Parse keysend preimages in blinded onion payloads. 2024-03-13 15:47:58 -04:00
Valentine Wallace
658e2c0a48
Support sending keysend payments to blinded paths. 2024-03-13 15:47:52 -04:00
Matt Corallo
29984a78ac Use structured logging where appropriate in OnionMessenger 2024-03-13 14:18:44 +00:00
Matt Corallo
b29033659f 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.
2024-03-13 14:18:44 +00:00
Matt Corallo
98340dc253 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.
2024-03-13 13:58:47 +00:00
Matt Corallo
aa334d5753
Merge pull request #2917 from jkczyz/2024-02-refund-unsupported-chain
Fail `request_refund_payment` for unsupported chain
2024-03-12 15:18:32 +00:00
Jeffrey Czyz
228e72ca34
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.
2024-03-08 15:57:10 -06:00
Jeffrey Czyz
ad91fcd510
Update pay_for_offer docs about unsupported chains 2024-03-08 15:40:29 -06:00
Jeffrey Czyz
07d766a5e9
Test failing pay_for_offer on an unsupported chain 2024-03-08 15:40:16 -06:00
Matt Corallo
6d5c952556
Merge pull request #2823 from valentinewallace/2024-01-blinded-forwarding-tests
Test blinded forwarding
2024-03-08 21:32:40 +00:00
valentinewallace
670b41ae4e
Merge pull request #2903 from jkczyz/2024-02-bindings-builders
Offers builders for C-bindings
2024-03-08 16:07:10 -05:00
Valentine Wallace
2027bf4e2a
Test that we'll round up blinded intermediate node fees if needed.
See comment in the new test.
2024-03-08 12:03:17 -05:00
Valentine Wallace
7777fc5285
Test utils: support intermediate nodes taking 1msat extra fee.
See docs on the new field.
2024-03-08 12:03:17 -05:00
Valentine Wallace
c30332ac86
Support fee overpayment by 1 msat in expect_payment_forwarded test util.
See ClaimAlongRouteArgs::allow_1_msat_fee_overpay.
2024-03-08 12:03:17 -05:00
Valentine Wallace
0b22ccd477
Functionally test min htlc BlindedPayInfo calculation. 2024-03-08 12:03:17 -05:00
Valentine Wallace
7b85d0145f
Account for prop fee in test util fee calculation. 2024-03-08 12:03:17 -05:00
Valentine Wallace
e8c85bd82b
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.
2024-03-08 12:03:17 -05:00
Valentine Wallace
bde5a652fa
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.
2024-03-08 12:03:17 -05:00
Valentine Wallace
203be7096e
Struct-ify test util pass_along_path args.
Lays groundwork to make pass_along_path easier to adapt without changing a
million callsites.
2024-03-08 12:03:11 -05:00
Valentine Wallace
2c22055589
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.
2024-03-08 11:56:26 -05:00
Jeffrey Czyz
9277166a8b
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.
2024-03-08 10:39:23 -06:00
Jeffrey Czyz
6b7050e8dc
Fix unused import warning 2024-03-08 10:39:23 -06:00
Jeffrey Czyz
407762446c
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.
2024-03-08 10:39:22 -06:00
Jeffrey Czyz
3bd00b943a
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.
2024-03-08 10:39:22 -06:00
Elias Rohrer
47954e95df
Implement Hash for Offer and Refund 2024-03-08 17:35:20 +01:00
Elias Rohrer
3eeb8b82a5
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.
2024-03-08 17:35:20 +01:00
Matt Corallo
aa3dbe8686
Merge pull request #2923 from tnull/2024-03-improve-best-block
Refactor `BestBlock` to expose inner fields
2024-03-07 17:55:59 +00:00
Elias Rohrer
edb22e1ab9
Implement Hash for BestBlock 2024-03-07 17:35:38 +01:00
Elias Rohrer
9bac73b4f3
Merge pull request #2912 from jkczyz/2024-02-prefer-more-connections
Order blinded paths by reliability criteria
2024-03-07 12:06:42 +01:00
Elias Rohrer
007a5dba95
Implement Debug for BestBlock 2024-03-07 11:02:23 +01:00
Elias Rohrer
57911dcd41
Refactor BestBlock to expose inner fields rather than accessors
.. which is more idiomatic Rust, and easier to handle in (downstream)
bindings.
2024-03-07 11:02:23 +01:00
Jeffrey Czyz
07d628e0fa
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.
2024-03-06 09:25:27 -06:00
Jeffrey Czyz
3a92c7b08a
Merge similar InvoiceBuilder impl blocks
This avoids needing to create additional macros when adding c_bindings
support.
2024-03-06 09:25:27 -06:00
Jeffrey Czyz
af318b6efb
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.
2024-03-06 09:25:27 -06:00
Jeffrey Czyz
c7b877efdd
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.
2024-03-06 09:25:26 -06:00
Jeffrey Czyz
702a003270
Merge similar InvoiceRequestBuilder impl blocks
This avoids needing to create additional macros when adding c_bindings
support.
2024-03-06 09:25:26 -06:00
Jeffrey Czyz
b1ad95158e
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.
2024-03-06 09:25:26 -06:00
Jeffrey Czyz
1af5c409fe
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.
2024-03-06 09:25:26 -06:00
Jeffrey Czyz
d9ab2fa581
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.
2024-03-06 09:25:26 -06:00
Elias Rohrer
c8880099ac
Run rustfmt on util/hash_tables.rs
.. to fix the silent rebase conflict.
2024-03-04 16:03:41 +01:00
Elias Rohrer
fe50a507ab
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."
2024-03-01 11:42:54 +01:00
Matt Corallo
bf3bc420c7
Merge pull request #2916 from sr-gi/2024-02-29-payment-preimage-hash
util: Adds Into<PaymentHash> for PaymentPreimage
2024-02-29 21:48:40 +00:00
Sergi Delgado Segura
d2ffcbc233 util: Adds Into<PaymentHash> for PaymentPreimage
This seems like a useful interface to have for downstream users
2024-02-29 15:41:20 -05:00
Elias Rohrer
cfb4391850
Merge pull request #2915 from TheBlueMatt/2024-02-better-rnf-docs
Update docs on `PaymentFailureReason::RouteNotFound` to add context
2024-02-29 15:58:56 +01:00
Matt Corallo
a6478838e8 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.
2024-02-29 14:51:21 +00:00
Arik Sosman
d97e36e3f3
Serialize SocketAddress vectors. 2024-02-28 23:21:53 -08:00
Jeffrey Czyz
e10583365b
Prefer one-hop blinded path to Tor intro nodes
If a node is announced, prefer using a one-hop blinded path with it as
the introduction node to using a two-hop blinded path with a Tor-only
introduction node. The one-hop blinded path is more reliable, thus only
use Tor-only nodes if the recipient is unannounced. And then, prefer
non-Tor-only nodes.
2024-02-28 15:58:14 -06:00
Jeffrey Czyz
5e9a998194
Prefer well-connected nodes for introduction nodes
When forming blinded paths, using a reliable node as the introduction
node is important to ensure onion message reliability. Order blinded
paths by how well-connected the introduction node is as a proxy for
reliability.

For short paths (e.g., when the sender and recipient share an LSP), this
may also result in a scenario where initiating a direct connection isn't
necessary. That is helpful when using RGS since it currently doesn't
include node announcements and thus cannot initiate a direct connection.
2024-02-28 11:23:56 -06:00