Commit graph

2580 commits

Author SHA1 Message Date
valentinewallace
e64ebe8608
Merge pull request #1923 from valentinewallace/2022-12-outbound-payment-mod
Abstract `ChannelManager` outbound payment logic
2022-12-20 15:40:48 -05:00
Arik Sosman
9d7bb73b59
Split out KeysInterface into EntropySource, NodeSigner, and SignerProvider. 2022-12-20 10:09:11 -08:00
Valentine Wallace
afdaa64b44
Rename send_payment and retry_payment for retries
Once ChannelManager supports payment retries, it will make more sense for its
current send_payment method to be named send_payment_with_route because
retrying should be the default. Here we get a head start on this by making the
rename in outbound_payment, but not changing the public interface yet.
2022-12-19 21:08:08 -05:00
Valentine Wallace
3e89cc7e08
Reduce visibility of outbound payment methods 2022-12-19 21:08:08 -05:00
Valentine Wallace
ec55730959
Start parameters on a newline if they don't fit
Separating out this commit to keep the main refactor move-only
2022-12-19 21:08:03 -05:00
Valentine Wallace
e69a4c2636
Remove unnecessary mut in finalize_claims 2022-12-19 21:04:58 -05:00
Valentine Wallace
afd31507d9
Swap pending_outbound_payments for OutboundPayments struct
This allows us to move a lot of outbound payment logic out of ChannelManager
and into the new outbound_payment module, and helps avoid growing
ChannelManager when we add retry logic to it in upcoming work.
2022-12-19 21:04:53 -05:00
Valentine Wallace
278ebd208a
Move PaymentSendFailure into outbound_payment module
And re-export it in channelmanager.rs so it can remain public
2022-12-19 14:10:03 -05:00
Valentine Wallace
070832643f
Move PendingOutboundPayment to new outbound_payment module
We want to move all outbound payment-related things to this new module, to help
break up ChannelManager so future payment retries work doesn't increase the
size of ChannelManager.
2022-12-19 14:09:59 -05:00
Matt Corallo
e38ab09c3a
Merge pull request #1922 from wpaulino/avoid-remaining-redundant-commitment-broadcasts
Avoid redundant broadcast of local commitment transaction
2022-12-19 16:31:30 +00:00
Matt Corallo
45eb0f3186
Merge pull request #1908 from jkczyz/2022-11-refund
BOLT 12 refund encoding and building
2022-12-16 21:45:34 +00:00
Wilmer Paulino
ff48f5df4d
Avoid redundant broadcast of local commitment transaction
This change follows the rationale of commit 62236c7 and addresses the
last remaining redundant local commitment broadcast.

There's no need to broadcast our local commitment transaction if we've
already seen a confirmed one as it'll be immediately rejected as a
duplicate/conflict.

This will also help prevent dispatching spurious events for bumping
commitment and HTLC transactions through anchor outputs since the
dispatch for said events follows the same flow as our usual commitment
broadcast.
2022-12-16 11:54:26 -08:00
Matt Corallo
08d296ad77
Merge pull request #1903 from TheBlueMatt/2022-12-1867-followups
Clarify docs on `provide_channel_parameters`
2022-12-16 18:29:09 +00:00
Matt Corallo
f96ac1d341 Bump crate versions to 0.0.113/invoice 0.21 2022-12-15 22:15:55 +00:00
Jeffrey Czyz
8e36737dac
Refund parsing tests
Tests for checking refund semantics when parsing invoice_request bytes
as defined by BOLT 12.
2022-12-14 16:22:44 -06:00
Jeffrey Czyz
77c082229b
Refund building tests
Tests for checking invoice_request message semantics when building a
refund as defined by BOLT 12.
2022-12-14 16:22:24 -06:00
Jeffrey Czyz
73e743fb53
Builder for creating refunds
Add a builder for creating refunds given a payer_id and other required
fields. Other settings are optional and duplicative settings will
override previous settings. Building produces a semantically valid
`invoice_request` message representing the refund, which then may be
communicated out of band (e.g., via QR code).
2022-12-14 16:20:53 -06:00
Jeffrey Czyz
d47763af57
Refund parsing from bech32 strings
Implement Bech32Encode for Refund, which supports creating and parsing
QR codes for the merchant-pays-user (i.e., offer for money) flow.
2022-12-14 16:20:53 -06:00
Jeffrey Czyz
92a53dd7aa
Refund encoding and parsing
Define an interface for BOLT 12 refunds (i.e., an `invoice_request`
message without an `offer_node_id`). A refund is more generally an
"offer for money". While it is encoded using the same TLV streams as an
`invoice_request` message, it has different semantics.
2022-12-14 16:20:40 -06:00
Matt Corallo
8dbf6dba7d Update references to "blinded route" to "blinded path"
Finishing the work from the previous two commits.
2022-12-14 21:14:38 +00:00
Matt Corallo
a0d38d7eb9 Rename blinded_route variables and module to blinded_path
Following up on the previous commit, this also renames variables
and the module used to `blinded_path`.
2022-12-14 21:14:38 +00:00
Matt Corallo
9b6de781d8 Unify blinding nomenclature to call them "paths" not "routes".
Currently the `onion_message` module exposes the blinded route
object as *both* `BlindedRoute` and `BlindedPath`. This is somewhat
confusing, and given they are really paths, not routes (at least in
the sense that a route could be multi-path, though for OMs they are
not), here we unify to only call them paths.
2022-12-14 21:07:55 +00:00
Jeffrey Czyz
7e81f8dcb4
Remove Option from OfferContents::signing_pubkey
Refunds (i.e., `invoice_request` without an `offer`) will have its own
contents type, so OfferContents::signing_pubkey can be required.
2022-12-13 16:05:59 -06:00
Matt Corallo
20591900a0 Correct docs on generate_channel_keys
03de0598af appeared to revert updated
docs due to a rebase error. This reverts the docs on
`generate_channel_keys` to the state they were in prior to that
commit, with one additional doc.
2022-12-13 21:41:49 +00:00
Matt Corallo
6ec23aa7db Clarify docs on provide_channel_parameters
Its very confusing to say that LDK will call
`provide_channel_parameters` more than once - its true for a
channel, but not for a given instance. Instead, phrase the docs
with reference to a specific instance, which is much clearer.
2022-12-13 21:31:40 +00:00
Matt Corallo
2d6818376c Drop forwarded HTLCs which were still pending at persist-time
If, after forwarding an intercepted payment to our counterparty, we
restart with a ChannelMonitor update having been persisted, but the
corresponding ChannelManager update not having been persisted,
we'll still have the intercepted HTLC in the
`pending_intercepted_htlcs` map on start (and potentially a pending
`HTLCIntercepted` event). This will cause us to allow the user to
handle the forwarded HTLC twice, potentially double-forwarding it.

This builds on 0bb87ddad7, which
provided a preemptive fix for the general relay case (though it was
not an actual issue at the time). We simply check for the HTLCs
having been forwarded on startup and remove them from the map.

Fixes #1858
2022-12-13 19:33:58 +00:00
Matt Corallo
2cb34678cc
Merge pull request #1900 from tnull/2022-12-improve-confirm-docs
Improve `Confirm` docs
2022-12-12 23:22:52 +00:00
Matt Corallo
0fa67fb96c
Merge pull request #1892 from tnull/2022-12-spendableoutputdescriptor-doccs
Clean up docs in `keysinterface.rs`
2022-12-12 22:45:00 +00:00
Matt Corallo
b291f4ab7a
Merge pull request #1907 from TheBlueMatt/2022-12-abandon-crash-reset
Note that abandon_payment does not persist the state update in docs
2022-12-12 22:16:43 +00:00
Elias Rohrer
9de45ce2d9
Improve Confirm docs 2022-12-12 21:44:19 +01:00
Elias Rohrer
03de0598af
Clean up docs in keysinterface.rs 2022-12-12 21:31:26 +01:00
Matt Corallo
1969b48b7a Note that abandon_payment does not persist the state update in docs
If a user calls `abandon_payment`, then restarts without freshly
persisting the `ChannelManager`, the payment will still be pending
on restart. This was unclear from the docs (and the docs seemed to
imply otherwise). Because this doesn't materially impact the
usability of `abandon_payment` (users shouldn't be called
`retry_payment` on an abandoned one anyway), we simply document it.

Fixes #1804.
2022-12-12 19:59:19 +00:00
Matt Corallo
a4df59b377
Merge pull request #1904 from TheBlueMatt/2022-12-1825-followups
Trivial Followups to #1825
2022-12-12 17:58:21 +00:00
valentinewallace
4a0010d739
Merge pull request #1738 from jkczyz/2022-09-invoice-request
BOLT 12 `invoice_request` encoding and building
2022-12-12 11:25:07 -05:00
Matt Corallo
3d2c8f5937
Merge pull request #1906 from wpaulino/prevent-downgrade-from-anchors
Use even types for opt_anchors
2022-12-12 03:11:30 +00:00
Matt Corallo
626c60600e
Merge pull request #1886 from TheBlueMatt/2022-11-claim-relock
Relock `channel_state` in for each HTLC in `claim_funds` and lay the groundwork for async event generation
2022-12-12 03:10:38 +00:00
Jeffrey Czyz
04d64f0808
Check entire TLV stream instead of by field
This causes a compilation error if a new field is added but missed in
the tests.
2022-12-09 14:45:56 -06:00
Jeffrey Czyz
b25c8df648
Add BOLT 12 merkle root test for invoice_request
A BOLT 12 test vector uses an `invoice_request` message that has a
currency, which aren't supported, so using OfferBuilder::build_unchecked
is required to avoid a panic.
2022-12-09 13:28:53 -06:00
Jeffrey Czyz
984c906406
Invoice request parsing tests
Tests for checking invoice_request message semantics when parsing bytes
as defined by BOLT 12.
2022-12-09 13:28:52 -06:00
Jeffrey Czyz
d666eb6700
Invoice request building tests
Tests for checking invoice_request message semantics when building as
defined by BOLT 12.
2022-12-09 13:28:26 -06:00
Jeffrey Czyz
13ba7cc523
Builder for creating invoice requests
Add a builder for creating invoice requests for an offer given a
payer_id. Other settings may be optional depending on the offer and
duplicative settings will override previous settings. Building produces
a semantically valid `invoice_request` message for the offer, which then
can be signed for the payer_id.
2022-12-09 08:53:46 -06:00
Jeffrey Czyz
59a7bd29fe
Invoice request raw byte encoding and decoding
When reading an offer, an `invoice_request` message is sent over the
wire. Implement Writeable for encoding the message and TryFrom for
decoding it by defining in terms of TLV streams. These streams represent
content for the payer metadata (0), reflected `offer` (1-79),
`invoice_request` (80-159), and signature (240).
2022-12-09 08:53:46 -06:00
Jeffrey Czyz
a7adc7602a
Merkle root hash computation
Offers uses a merkle root hash construction for signature calculation
and verification. Add a submodule implementing this so that it can be
used when parsing and signing invoice_request and invoice messages.
2022-12-09 08:53:45 -06:00
Jeffrey Czyz
05bf27f745
Schnorr Signature serialization
BOLT 12 uses Schnorr signatures for signing offers messages, which need
to be serialized.
2022-12-09 08:53:45 -06:00
Jeffrey Czyz
0c621646a6
Invoice request message interface and data format
Define an interface for BOLT 12 `invoice_request` messages. The
underlying format consists of the original bytes and the parsed
contents.

The bytes are later needed when constructing an `invoice` message. This
is because it must mirror all the `offer` and `invoice_request` TLV
records, including unknown ones, which aren't represented in the
contents.

The contents will be used in `invoice` messages to avoid duplication.
Some fields while required in a typical user-pays-merchant flow may not
be necessary in the merchant-pays-user flow (e.g., refund, ATM).
2022-12-09 08:53:33 -06:00
Matt Corallo
616d3ac784 Add second TODO when claiming to mirror the existing TODO on claim fail 2022-12-08 21:24:26 +00:00
Matt Corallo
7c48151c22 Drop unused link in claim_funds 2022-12-08 21:24:26 +00:00
Matt Corallo
b331778e34 Drop now-unused ClaimFundsFromHop enum and replace with an Err 2022-12-08 21:24:26 +00:00
Matt Corallo
1feb459811 Handle claim result event generation in claim_funds_from_hop
Currently `claim_funds` and `claim_funds_internal` call
`claim_funds_from_hop` and then surface and `Event` to the user
informing them of the forwarded/claimed payment based on it's
result. In both places we assume that a claim "completed" even if
a monitor update is being done async.

Instead, here we push that event generation through a
`MonitorUpdateCompletionAction` and a call to
`handle_monitor_update_completion_action`. This will allow us to
hold the event(s) until async monitor updates complete in the
future.
2022-12-08 21:24:26 +00:00
Matt Corallo
def193d6bd Don't hold channel_state lock for entire duration of claim_funds
When `claim_funds` has to claim multiple HTLCs as a part of a
single MPP payment, it currently does so holding the
`channel_state` lock for the entire duration of the claim loop.
Here we swap that for taking the lock once for each HTLC. This
allows us to be more flexible with locks going forward, and
ultimately isn't a huge change - if our counterparty intends to
force-close a channel, us choosing to ignore it by holding the
`channel_state` lock for the duration of the claim isn't going to
result in a commitment update, it will just result in the preimage
already being in the `ChannelMonitor`.
2022-12-08 21:24:26 +00:00