Commit graph

80 commits

Author SHA1 Message Date
Jeffrey Czyz
86e2b0059f
Remove OnionMessageProvider
OnionMessageProvider is a super-trait of OnionMessageHandler, but they
don't need to be used separately. Additionally, the former is misplaced
in the events module. Remove OnionMessageProvider and add it's only
method, next_onion_message_for_peer, into OnionMessageHandler.
2023-10-18 17:00:04 -05:00
Matt Corallo
e0fe325402
Merge pull request #2629 from jkczyz/2023-09-invreqfailed
Config-guard `Event::InvoiceRequestFailed`
2023-09-29 22:42:50 +00:00
Jeffrey Czyz
c7219e4683
Config-guard Event::InvoiceRequestFailed
The event cannot be generated publicly, so remove it for now to avoid
users needing to handle it.
2023-09-29 15:03:13 -07:00
Wilmer Paulino
3299d88595
Fix off-by-one max witness estimate for P2WPKH StaticPaymentDescriptor
We were not accounting for the extra byte denoting the number of items
in the witness stack.
2023-09-29 13:46:59 -07:00
Willem Van Lint
82341991cb Batch funding for v1 channel establishments 2023-09-26 13:37:14 -07:00
Wilmer Paulino
9736c709c0
Sanity check fees on transactions produced by the bump event handler
We add a few debug assertions to ensure we don't overpay fees by 5% more
than expected.
2023-09-19 11:13:44 -07:00
Wilmer Paulino
38f18ceba6
Account for existing input amounts throughout coin selection
We'd previously ignore the existing amount transactions were already
attempting to spend when deciding whether we should add more inputs
throughout coin selection. This would result in us attaching more inputs
than necessary to satisfy our target amount. In the case of HTLC
transactions, we'd burn the HTLC amount completely, since the pre-signed
transaction has zero fee (input amount == output amount).

Along the way, we also fix the slight overpayment in anchor
transactions. We now properly account for the fees the transaction
already paid for, simply by pretending the fees are part of the anchor
input amount.
2023-09-19 11:13:41 -07:00
David Caseria
808a51e701
Make HTLCDescriptor writeable 2023-09-12 16:30:58 -04:00
Jeffrey Czyz
6d0c5f00ba
Add an InvoiceRequestFailed event
When an invoice is requested but either receives an error or never
receives a response, surface an event to indicate to the user that the
corresponding future payment has failed.
2023-09-07 11:08:53 -05:00
optout
8952446684
Fix wrong msg type in SendTxAbort, typo 2023-09-01 00:00:13 +02:00
optout
e99e6ab562
Use new ChannelId type 2023-08-26 01:30:40 +02:00
Matt Corallo
0211daa48b
Merge pull request #2412 from valentinewallace/2023-07-construct-blinded-paths
Add API for constructing blinded payment paths
2023-08-23 17:35:06 +00:00
Matt Corallo
e9be7e272f
Merge pull request #2511 from jbesraa/add-channel-id-to-spendableoutputs-event
Add channel_id to SpendableOutputs event
2023-08-22 20:38:40 +00:00
Valentine Wallace
4a30d9e78a
Rename ser macro
We want a similar macro for reading TLV streams without a length prefix, so
rename this one to disambiguate.
2023-08-22 13:26:12 -04:00
jbesraa
14b761283b Add channel_id to SpendableOutputs event
This will make it possible to
    link between SpendableOuts and ChannelMonitor

    - change channel_id to option so we dont break upgrade
    - remove unused channel_id
    - document channel_id
    - extract channel id dynamically to pass test
    - use contains to check channel_id in test as the events are not ordered
    - update docs framing
    - specify ldk version channel_id will be introduced in

Co-authored-by: Elias Rohrer <dev@tnull.de>

Update lightning/src/events/mod.rs

Co-authored-by: Elias Rohrer <dev@tnull.de>
2023-08-22 17:07:13 +03:00
Elias Rohrer
8f024303e7
Merge pull request #2507 from TheBlueMatt/2023-08-lnd-6039
Work around LND bug 6039
2023-08-22 10:20:02 +02:00
Matt Corallo
b14927968f Send warning messages when repeating shutdown messages at volume 2023-08-21 23:04:47 +00:00
Matt Corallo
4bd4f02fa7
Merge pull request #2478 from waterson/settle-htlcs
Provide the HTLCs that settled a payment.
2023-08-21 22:32:54 +00:00
Chris Waterson
2e562a2ad8 Provide the HTLCs that settled a payment.
Creates a new `events::ClaimedHTLC` struct that contains the relevant
information about a claimed HTLC; e.g., the channel it arrived on, its ID, the
amount of the HTLC, the overall amount of the payment, etc. Adds appropriate
serialization support.

Adds a `Vec<events::ClaimedHTLC>` to the `ClaimingPayment`
structure. Populates this when creating the struct by converting the
`payment.htlcs` (which are `ClaimingHTLC` structs) into `event::ClaimedHTLC`
structs. This is a straightforward transformation.

Adds a `Vec<events::ClaimedHTLC>` to the `events::Event::PaymentClaimed`
enum. This is populated directly from the `ClaimingPayment`'s `htlcs` vec.

Fixes #2477.
2023-08-21 11:30:12 -04:00
Matt Corallo
31049ed961 Delay RAA-after-next processing until PaymentSent is are handled
In 0ad1f4c943 we fixed a nasty bug
where a failure to persist a `ChannelManager` faster than a
`ChannelMonitor` could result in the loss of a `PaymentSent` event,
eventually resulting in a `PaymentFailed` instead!

As noted in that commit, there's still some risk, though its been
substantially reduced - if we receive an `update_fulfill_htlc`
message for an outbound payment, and persist the initial removal
`ChannelMonitorUpdate`, then respond with our own
`commitment_signed` + `revoke_and_ack`, followed by receiving our
peer's final `revoke_and_ack`, and then persist the
`ChannelMonitorUpdate` generated from that, all prior to completing
a `ChannelManager` persistence, we'll still forget the HTLC and
eventually trigger a `PaymentFailed` rather than the correct
`PaymentSent`.

Here we fully fix the issue by delaying the final
`ChannelMonitorUpdate` persistence until the `PaymentSent` event
has been processed and document the fact that a spurious
`PaymentFailed` event can still be generated for a sent payment.

The original fix in 0ad1f4c943 is
still incredibly useful here, allowing us to avoid blocking the
first `ChannelMonitorUpdate` until the event processing completes,
as this would cause us to add event-processing delay in our general
commitment update latency. Instead, we ultimately race the user
handling the `PaymentSent` event with how long it takes our
`revoke_and_ack` + `commitment_signed` to make it to our
counterparty and receive the response `revoke_and_ack`. This should
give the user plenty of time to handle the event before we need to
make progress.

Sadly, because we change our `ChannelMonitorUpdate` semantics, this
change requires a number of test changes, avoiding checking for a
post-RAA `ChannelMonitorUpdate` until after we process a
`PaymentSent` event. Note that this does not apply to payments we
learned the preimage for on-chain - ensuring `PaymentSent` events
from such resolutions will be addressed in a future PR. Thus, tests
which resolve payments on-chain switch to a direct call to the
`expect_payment_sent` function with the claim-expected flag unset.
2023-08-17 22:19:48 +00: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
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
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
optout
1babca4e2c
Remove an unused use (ChannelSigner) 2023-07-26 21:47:40 +02:00
Matt Corallo
8cffeb6dba Add relevant trait derives for bump_transaction structs
Notably including `Hash`/`Eq`/`Ord` for structs which may be used
in maps.
2023-07-20 21:43:52 +00:00
Matt Corallo
e4c44f3c5b
Merge pull request #2430 from TheBlueMatt/2023-07-116-bindings-part-1
Assorted 0.0.116 Bindings updates
2023-07-20 21:42:44 +00:00
Matt Corallo
0c629ff60a Pass must-spend inputs to users by ownership
We already hold them in a vec, so there's no cost to passing them
by ownership vs making it a slice. Further, this helps bindings as
we can't represent slices to non-pointers in a sensible way.
2023-07-20 19:49:43 +00:00
Matt Corallo
be08b4f6b8 Tweak transaction bumping sign_tx types for bindings
In bindings we can't practically pass a mutable transaction, and
instead need to pass an owned transaction and have the sign method
return a signed copy. We do this here for all build modes as the
API is roughly equivalent also to Rust users.
2023-07-20 19:49:22 +00:00
Duncan Dean
bd297fe39d
Force close pending channels in internal_shutdown 2023-07-19 19:10:30 +02:00
Matt Corallo
1e119a2d6a Tweak generics on derive_channel_signer to be bindings-compatible
The C bindings generation currently has issues looking through a
generic associated type. While this should be fixed in the bindings
generator, its easy to fix here for now and we can revisit it
later.
2023-07-18 20:08:07 +00:00
Wilmer Paulino
964b4939b1
Improve logging in BumpTransactionEventHandler paths 2023-07-14 14:45:19 -07:00
Wilmer Paulino
eac1bc18e3
Add debug assertions for weight estimates of bump transactions
This ensures our estimates are correct by never underestimating and
only allowing overestimations by a margin of 1%.
2023-07-14 14:45:18 -07:00
Wilmer Paulino
9088dae7da
Consider existing commitment transaction feerate when bumping
With anchors, we've yet to change the frequency or aggressiveness of
feerate updates, so it's likely that commitment transactions have a
good enough feerate to confirm on its own. In any case, when producing a
child anchor transaction, we should already take into account the fees
paid by the commitment transaction itself, allowing the user to save
some satoshis. Unfortunately, in its current form, this will still
result in overpaying by a small margin at the expense of making the coin
selection API more complex.
2023-07-14 14:45:18 -07:00
Wilmer Paulino
990c500099
Avoid yielding ChannelClose bump events with sufficient feerate
There's no need to yield such an event when the commitment transaction
already meets the target feerate on its own, so we can simply broadcast
it without an anchor child transaction. This may be a common occurrence
until we are less aggressive about feerate updates.
2023-07-14 14:45:17 -07:00
Wilmer Paulino
19de4353d5
Move feerate helpers to chain module
We plan to use these outside of the `bump_transaction` module in the
next commit, and they really should belong in the same module as
`FeeEstimator`.
2023-07-14 14:45:15 -07:00
Elias Rohrer
07606c1841
Merge pull request #2393 from wpaulino/bump-transaction-event-handler-fixups
Bump transaction event handler fixups
2023-07-12 21:17:56 +02:00
Wilmer Paulino
4c7883c831
Expose previous UTXO for anchor and HTLC inputs
This may be required by some wallets that rely on PSBTs internally to
create/sign transactions.
2023-07-11 16:53:25 -07:00
Wilmer Paulino
0dbfe245a9
Add transaction-related helpers to AnchorDescriptor
This provides a similar interface as `HTLCDescriptor` for users which
choose to implement their own bump transaction event handler.
2023-07-11 16:53:24 -07:00
Wilmer Paulino
690ad18b22
Provide missing post-derivation signer parameters
Users may expect these to be provided manually after derivation in the
event they need to perform any enforcement prior to signing.
2023-07-11 16:53:24 -07:00
Wilmer Paulino
72c42ee786
Cache HTLC per_commitment_point in descriptor
This allows us to obtain the HTLC input and output from its descriptor
without needing to derive the `per_commitment_point` through the signer.
2023-07-11 16:53:22 -07:00
Wilmer Paulino
ae701a0d20
Expose CoinSelection struct members
These are meant to be provided by the user, so they need to be exposed
in the API.
2023-07-11 13:34:42 -07:00
Wilmer Paulino
a100ed0098
Accept BumpTransactionEvent in handle_event
There's no reason to accept the general `Event` enum.
2023-07-11 13:34:35 -07:00
Matt Corallo
884160c5c1 Convert Event vec storage away from vec_type
* `PaymentPathFailed::path` was added without an optional compat
   wrapper in e5310dd5f0.
 * `PaymentPathSuccessful::path` has always been written since the
   event was added in 2c4f16d5e3.
 * `Probe{Failed,Successful}::path` have always been written since
   the events were added in eb8bce0d16.
2023-07-07 21:07:06 +00:00
Tony Giorgio
5cc625e8f7
Clarify event doc specifying anchor support 2023-06-29 22:10:02 -05:00
Wilmer Paulino
82b646c548
Remove anchors config flag
Now that all of the core functionality for anchor outputs has landed,
we're ready to remove the config flag that was temporarily hiding it
from our API.
2023-06-23 13:32:08 -07:00
Matt Corallo
397386539d
Merge pull request #2361 from arik-so/2023-06-anchor-channel-type-features
Replace `opt_anchors` with `ChannelTypeFeatures`
2023-06-23 19:12:15 +00:00
Arik Sosman
1d9a709529
Replace opt_anchors with ChannelTypeFeatures
This change modifies six structs that were keeping
track of anchors features with an `opt_anchors` field,
as well as another field keeping track of nonzero-fee-
anchor-support.
2023-06-23 10:37:14 -07:00
Elias Rohrer
15b1c9b837
Merge pull request #2319 from valentinewallace/2023-05-forward-less-than-onion
Allow forwarding less than the amount in the onion
2023-06-21 09:25:07 +02:00
Valentine Wallace
2127eb8a19
Document on claim events that amount_msat may be > invoice amount 2023-06-20 17:57:38 -04:00