Commit graph

4056 commits

Author SHA1 Message Date
benthecarman
dd15ab0394
More flexible fee rate estimates 2023-10-20 11:53:52 -05:00
Matt Corallo
10b8f4c44e
Merge pull request #2039 from jkczyz/2023-02-offer-flow
BOLT 12 Offers message flow
2023-10-20 16:40:17 +00:00
Matt Corallo
323366cfd3 Update docs on MonitorEvent::HolderForceClosed
In a96e2fe144 we renamed
`MonitorEvent::CommitmentTxConfirmed` to `HolderForceClosed` to
better document what actually happened. However, we failed to
update the documentation on the type, which we do here.

Pointed out by @yellowred.
2023-10-20 16:00:49 +00:00
Jeffrey Czyz
fe9044831e
Fix PaymentConstraints::max_cltv_expiry docs 2023-10-20 09:51:31 -05:00
Jeffrey Czyz
6a97f648d3
Fix build warnings 2023-10-20 09:51:29 -05:00
Jeffrey Czyz
6d2ffdd8bd
Expand request_refund_payment docs for limitations 2023-10-20 09:49:58 -05:00
Jeffrey Czyz
a841e6b9e1
Onion message routing to immediate peers.
DefaultMessageRouter always fails. Update it so that it can route to a
directly connected peer. This is needed for an Offers minimum viable
product.
2023-10-20 09:49:58 -05:00
Jeffrey Czyz
681f89881e
Add privacy section to pay_for_offer docs 2023-10-20 09:49:57 -05:00
Jeffrey Czyz
3fd9fc6fc0
Organize create_refund and pay_for_offer docs 2023-10-20 09:49:57 -05:00
Jeffrey Czyz
5a0b111668
Document InvoiceRequestFailed in ChannelManager 2023-10-20 09:49:57 -05:00
Jeffrey Czyz
2840252cbc
Revert "Config-guard Event::InvoiceRequestFailed"
This reverts commit c7219e4683.
2023-10-20 09:49:57 -05:00
Jeffrey Czyz
0e41d8085a
Use ChannelManager as OffersMessageHandler 2023-10-20 09:49:57 -05:00
Jeffrey Czyz
debc20cc3e
OffersMessageHandler impl for ChannelManager
Define the BOLT 12 message flow in ChannelManager's
OffersMessageHandler implementation.
- An invoice_request message results in responding with an invoice
  message if it can be verified that the request is for a valid offer.
- An invoice is paid if it can be verified to have originated from a
  sent invoice_request or a refund.
- An invoice_error is sent in some failure cases.
- Initial messages enqueued for sending are released to OnionMessenger
2023-10-20 09:49:57 -05:00
Jeffrey Czyz
b191fd48d5
Check offer expiry when building invoice in no-std
Building an invoice will fail if the underlying offer or refund has
already expired. The check was skipped in no-std since there is no
system clock. However, the invoice creation time can be used instead.
This prevents responding to an invoice request if the offer has already
expired.
2023-10-20 09:49:57 -05:00
Jeffrey Czyz
89542807bd
Grammar fix in docs 2023-10-20 09:49:56 -05:00
Jeffrey Czyz
6f6e086196
BOLT12 invoice_feature methods for ChannelManager 2023-10-20 09:49:56 -05:00
Jeffrey Czyz
1d85efed78
Qualify BOLT11 ChannelManager invoice_features 2023-10-20 09:49:56 -05:00
Jeffrey Czyz
46b794e9a2
Utility for creating and sending Bolt12Invoices
Add a utility to ChannelManager for creating a Bolt12Invoice for a
Refund such that the ChannelManager can recognize the PaymentHash and
reconstruct the PaymentPreimage from the PaymentSecret, the latter of
which is contained in a BlindedPath within the invoice.
2023-10-20 09:49:56 -05:00
Jeffrey Czyz
ffe9ae285d
Utility for paying for an Offer
Add a utility to ChannelManager for sending an InvoiceRequest for an
Offer such that derived keys are used for the payer id. This allows for
stateless verification of any Invoice messages before it is paid.

Also tracks future payments using the given PaymentId such that the
corresponding Invoice is paid only once.
2023-10-20 09:49:56 -05:00
Jeffrey Czyz
34bdf22489
Absolute expiry or timer tick payment expiration
Pending outbound payments use an absolute expiry to determine when they
are considered stale and should be fail. In `no-std`, this may result in
long timeouts as the highest seen block time is used. Instead, allow for
expiration based on timer ticks. This will be use in an upcoming commit
for invoice request expiration.
2023-10-20 09:49:56 -05:00
Jeffrey Czyz
ddfeb3f642
Store OffersMessages for later sending
Upcoming commits will add utilities for sending an InvoiceRequest for an
Offer and an Invoice for a Refund. These messages need to be enqueued so
that they can be released in ChannelManager's implementation of
OffersMessageHandler to OnionMessenger for sending.

These messages do not need to be serialized as they must be resent upon
restart.
2023-10-20 09:49:55 -05:00
Jeffrey Czyz
bc0203d69b
Expand docs on failing expired outbound payments 2023-10-20 09:49:55 -05:00
Antonio Yang
31aa48304d impl Display for SocketAddress 2023-10-20 16:15:35 +08:00
Elias Rohrer
62fd36d795
Merge pull request #2636 from slanesuke/impl-ToSocketAddrs-for-Hostname
Impl ToSocketAddrs for SocketAddress
2023-10-20 09:52:29 +02:00
Matt Corallo
6fff3e58b0
Merge pull request #2666 from tnull/2023-10-observable-update 2023-10-19 21:49:02 +00:00
Matt Corallo
d7a6d0d10d
Merge pull request #2661 from TheBlueMatt/2023-10-dup-claim-chan-hang
Immediately unblock channels on duplicate claims
2023-10-19 17:53:46 +00:00
Matt Corallo
f47270e760 Immediately unblock channels on duplicate claims
When `MonitorUpdateCompletionAction`s were added, we didn't
consider the case of a duplicate claim during normal HTLC
processing (as the handling only had an `if let` rather than a
`match`, which made the branch easy to miss). This can lead to a
channel freezing indefinitely if an HTLC is claimed (without a
`commitment_signed`), the peer disconnects, and then the HTLC is
claimed again, leading to a never-completing
`MonitorUpdateCompletionAction`.

The fix is simple - if we get back an
`UpdateFulfillCommitFetch::DuplicateClaim` when claiming from the
inbound edge, immediately unlock the outbound edge channel with a
new `MonitorUpdateCompletionAction::FreeOtherChannelImmediately`.

Here we implement this fix by actually generating the new variant
when a claim is duplicative.
2023-10-19 15:27:57 +00:00
Matt Corallo
9ea90a4a44 Add an immediately-freeing MonitorUpdateCompletionAction.
When `MonitorUpdateCompletionAction`s were added, we didn't
consider the case of a duplicate claim during normal HTLC
processing (as the handling only had an `if let` rather than a
`match`, which made the branch easy to miss). This can lead to a
channel freezing indefinitely if an HTLC is claimed (without a
`commitment_signed`), the peer disconnects, and then the HTLC is
claimed again, leading to a never-completing
`MonitorUpdateCompletionAction`.

The fix is simple - if we get back an
`UpdateFulfillCommitFetch::DuplicateClaim` when claiming from the
inbound edge, immediately unlock the outbound edge channel with a
new `MonitorUpdateCompletionAction::FreeOtherChannelImmediately`.

Here we add the new variant, which we start generating in the next
commit.
2023-10-19 15:27:57 +00:00
Matt Corallo
6d85be27d4 Indicate to claim_funds_internal that we're replaying on startup
While we'd previously avoided this, this is sadly now required in
the next commit.
2023-10-19 15:27:57 +00:00
Matt Corallo
82b532c54d Log when we prepare to block a channel's next revoke_and_ack
This may help in debugging blocking actions in the future.
2023-10-19 15:27:57 +00:00
Elias Rohrer
1c352555b6
Don't apply PathFailure::ChannelUpdateMessage
If we receive a channel update from an intermediary via a failure onion
we shouldn't apply them in a persisted and network-observable way to our
network graph, as this might introduce a privacy leak. Here, we
therefore avoid applying such updates to our network graph.
2023-10-19 17:03:15 +02:00
Elias Rohrer
1dffb20199
Allow to verify channel updates without applying them
We introduce a new `NetworkGraph::verify_channel_update` method that
allows to check whether an update would be applied by `update_channel`.
2023-10-19 14:45:33 +02:00
Willem Van Lint
316a7941da Construct ShutdownResult as a struct in Channel
This refactors ShutdownResult as follows:
- Makes ShutdownResult a struct instead of a tuple to represent
  individual results that need to be handled. This recently also
  includes funding batch closure propagations.
- Makes Channel solely responsible for constructing ShutdownResult as
  it should own all channel-specific logic.
2023-10-18 20:52:17 -07:00
Willem Van Lint
a2b46b54da Refactor check_closed_event for multiple events
The check_closed_event function verified closure events against multiple
counterparty nodes, but only a single closure reason and channel
capacity. This commit introduces a check_closed_events function to
verify events against descriptions of each expected event, and refactors
check_closed_event in function of check_closed_events.
2023-10-18 20:46:02 -07:00
Willem Van Lint
46dab8f5ef Clean up typos and unused variables/imports 2023-10-18 20:46:02 -07:00
slanesuke
e9ff38fbb2 Impl ToSocketAddrs for SocketAddress 2023-10-18 17:52:31 -06:00
Jeffrey Czyz
905028b615
Clean up peel_onion name, parameters, and docs
For consistency with other functions and doc cleanliness.
2023-10-18 18:33:14 -05:00
Jeffrey Czyz
80ae66ac17
Include a one-hop blinded path in Offer and Refund
While this doesn't add much privacy over not including any blinded
paths, it allows us to exercise code for receiving on blinded paths.
2023-10-18 18:33:14 -05:00
Jeffrey Czyz
7c6e62f423
Stateless offer and refund builder utilities
Add utility functions to ChannelManager for creating OfferBuilder,
and RefundBuilder such that derived keys are used for the signing
pubkey and payer id, respectively. This allows for stateless
verification of any InvoiceRequest and Invoice messages.

Later, blinded paths can be included in the returned builders.

Also tracks future payments using the given PaymentId such that the
corresponding Invoice is paid only once.
2023-10-18 18:33:14 -05:00
Jeffrey Czyz
11fb9c486b
Await for invoices using an absolute expiry
PendingOutboundPayment::AwaitingInvoice counts the number of timer ticks
that have passed awaiting a Bolt12Invoice for an InvoiceRequest. When a
constant INVOICE_REQUEST_TIMEOUT_TICKS has passed, the payment is
forgotten. However, this mechanism is insufficient for the Refund
scenario, where the Refund's expiration should be used instead.

Change AwaitingInvoice to store an absolute expiry instead. When
removing stale payments, pass the `SystemTime` in `std` and the highest
block time minus two hours in `no-std`.
2023-10-18 18:32:46 -05:00
Jeffrey Czyz
622f7f2f79
Remove outdated docs 2023-10-18 18:31:27 -05:00
Jeffrey Czyz
6dc42235ba
Allow sending onion messages to 1-hop blinded path
This allows for specifying the introduction node as the message
recipient.
2023-10-18 18:31:27 -05:00
Jeffrey Czyz
8b442fe4eb
Enqueue onion messages in handlers
When constructing onion messages to send initially (opposed to replying
to one from a handler), the user must construct an OnionMessagePath first
before calling OnionMessener::send_onion_message. Additionally, having a
reference to OnionMessener isn't always desirable. For instance, in an
upcoming commit, ChannelManager will implement OffersMessageHandler,
which OnionMessenger needs a reference to. If ChannelManager had a
reference to OnionMessenger, too, there would be a dependency cycle.

Instead, modify OffersMessageHandler and CustomOnionMessageHandler's
interfaces to include a method for releasing pending onion messages.
That way, ChannelManager may, for instance, construct and enqueue an
InvoiceRequest for sending without needing a reference to
OnionMessenger.

Additionally, OnionMessenger has responsibility for path finding just as
it does when replying to messages from a handler. It performs this when
extracting messages from the handlers before returning the next message
to send to a peer.
2023-10-18 18:31:16 -05:00
Jeffrey Czyz
840efd5334
Generalize CustomOnionMessageContents trait
Rename CustomOnionMessageContents to OnionMessageContents and use it as
a trait bound on messages passed to OnionMessenger methods. This allows
using the trait in an upcoming commit as a bound on the contents of
PendingOnionMessage.

Also, make ParsedOnionMessageContent implement OnionMessageContents so
that Payload can be bounded by OnionMessageContents directly, but used
when either reading a ParsedOnionMessageContent or writing a specific
type of OnionMessageContents (e.g., OffersMessage).
2023-10-18 18:15:05 -05:00
benthecarman
439f916f52
Remove channel monitor sync in progress log
This log is super spammy for us and isn't very useful.
2023-10-18 17:53:27 -05:00
Jeffrey Czyz
94573dda33
Rename OnionMessageContents
In preparation for needing the name OnionMessageContents for a trait to
bound methods, rename it to ParsedOnionMessageContents. In the next
commit, it's use will be limited to reading only, and the new trait will
be a bound on method parameters instead.
2023-10-18 17:18:03 -05:00
Jeffrey Czyz
81c6147a9e
Generalize respond_with_onion_message
OnionMessenger can send onion message responses from its handlers using
respond_with_onion_message, which finds a path to the destination and
enqueues the response for sending. Generalize this as it can be used not
only for responses but for initial sends as well.
2023-10-18 17:09:27 -05:00
Jeffrey Czyz
cfe6b952a8
Import msgs::OnionMessage 2023-10-18 17:09:24 -05:00
Jeffrey Czyz
a4894bd3ca
Clean up onion messenger parameters and docs 2023-10-18 17:00:04 -05:00
Jeffrey Czyz
b78cb69de3
Avoid overloading introduction_node_id 2023-10-18 17:00:04 -05:00