Commit graph

5248 commits

Author SHA1 Message Date
Matt Corallo
80dd594099 Don't ignore events in test_yield_anchors_events
Our tests should never ignore the events generated as they provide
critical context about what's happening in LDK. Here we fix
`test_yield_anchors_events` to avoid doing so.
2024-08-27 19:57:34 +00:00
Matt Corallo
3f23e3c288 Add a constructor and per-target override to TestFeeEstimator
This will allow us to test `ConfirmationTarget`s used in functional
tests by setting an override on just the target we expect to be
used.
2024-08-27 19:57:34 +00:00
Matt Corallo
1e285cb417 Only generate an Event::DiscardFunding when we need to
5e874c3dc9 changed
`Event::DiscardFunding` to not include a dummy transaction when we
were funded without a full funding tx, but in doing so started
generating `DiscardFunding` events on every channel closure rather
than only when there's actually still a pending funding broadcast.

This restores the previous behavior to only generate the event when
we should actually discard the funding tx.
2024-08-27 19:31:25 +00:00
Matt Corallo
5e62df7f20
Merge pull request #3259 from vincenzopalazzo/macros/dummy-tx
[RFC] event: store the outpoint when is_manual_broadcast
2024-08-27 19:16:57 +00:00
Vincenzo Palazzo
5e874c3dc9
event: store the outpoint when is_manual_broadcast
With [1], it's possible to specify `manual_broadcast` for
the channel funding transaction. When `is_manual_broadcast` is
set to true, the transaction in the `DiscardFunding` event is
replaced with a dummy empty transaction.

This commit checks if `is_manual_broadcast` is true and
stores the funding OutPoint in the DiscardFunding event instead.

[1] https://github.com/lightningdevkit/rust-lightning/pull/3024

Link: https://github.com/lightningdevkit/rust-lightning/issues/3164
Suggested-by: TheBlueMatt
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2024-08-27 19:50:18 +02:00
Matt Corallo
14720190b0 Split ConfirmationTarget::OnChainSweep into urgent and non-urgent
When we force-close a channel, occasionally its due to feerate
disagreements or other non-HTLC-related issues. In those cases,
there's no reason to use a very urgent feerate estimate - we don't
have any timers expiring soon.

Instead, we should give users the information they need to be more
economical on fees in this case, which we do here by splitting
`OnChainSweep` into `UrgentOnChainSweep` and
`NonUrgentOnChainSweep` `ConfirmationTarget`s.
2024-08-27 16:42:03 +00:00
Matt Corallo
f0de37ae1f Add a new ConfirmationTarget::MaximumFeeEstimate
When we broke `ConfirmationTarget` out into task-specific names, we
left `MaxDustHTLCExposure::FeeRateMultiplier` as using the "when we
broadcast feerate" as we were mostly concerned about the dust
thresholds on outbound channels where we pick the fee and drive our
own funds to dust.

In 51bf78d604, that changed to
include transaction fees on both inbound and outbound channels in
our dust exposure amount, but we continued to use
`ConfirmationTarget::OnChainSweep` for the fee estimator threshold.

While the `MaxDustHTLCExposure::FeeRateMultiplier` value is quite
conservative and shouldn't lead to force-closures unless feerate
estimates disagree by something like 500 sat/vB (with only one HTLC
active in a channel), this happened on Aug 22 when feerates spiked
from 4 sat/vB to over 1000 sat/vB in one block.

To avoid simple feerate estimate horizons causing this in the
future, here we add a new
`ConfirmationTarget::MaximumFeeEstimate` which is used for dust
calculations. This allows users to split out the estimates they use
for checking counterparty feerates from the estimates used for
actual broadcasting.
2024-08-27 16:36:54 +00:00
Matt Corallo
fd2f3dc459
Merge pull request #3273 from TheBlueMatt/2024-08-bindings-no-static
Return owned `String`s for onion message message types
2024-08-27 14:14:47 +00:00
dunxen
cf2fa9d60a
Merge pull request #3248 from jkczyz/2024-08-blinded-path-utils-refactor
Refactor `BlindedPath` construction utils
2024-08-27 13:28:43 +02:00
Matt Corallo
feffaf8bbc Return owned Strings for onion message message types
Returning a reference from a trait method is relatively difficult
to map in bindings and is currently handled by storing the object
in the trait instance, returning a reference to the local field.

This is fine when the object we're returning only needs to live as
long as the trait, but when it needs to be `'static` (as is the
case for onion message `msg_type`s), there's not really a good way
to map them at all.

Instead, here, condition on `#[cfg(c_bindings)]` we return a fully
owned `String`. This is obviously relatively less effecient, but
the extra allocation and `memcpy` isn't the end of the world,
especially given it should be released relatively quickly.

Note that this breaks doctests in with `c_bindings`.
2024-08-27 00:05:12 +00:00
Matt Corallo
b6b259c50f Mark io::Cursor as no-export in bindings 2024-08-26 18:32:45 +00:00
Matt Corallo
ff0874adb7
Merge pull request #3153 from alecchendev/2024-07-async-closing-signed
Allow sending closing tx signatures asynchronously
2024-08-26 17:45:05 +00:00
Matt Corallo
688147ae5d
Merge pull request #2992 from G8XSU/monitor-update-seq-doc
Doc Clarity: Handling gaps in persisted ChannelMonitorUpdates.
2024-08-26 14:09:02 +00:00
Alec Chen
6e2071a3d7 Test async sign_closing_transaction 2024-08-23 11:02:05 -07:00
Alec Chen
2fd77d0cf3 Allow sending closing tx signatures asynchronously 2024-08-23 11:02:01 -07:00
Matt Corallo
5359cebe21 Use the actual type, not the associated type, in trait impls
This is equivalent and just easier for the bindings to deal with
(though, really, they should handle it).
2024-08-23 15:33:22 +00:00
Matt Corallo
49dfa5a496
Merge pull request #3263 from TheBlueMatt/2024-08-bindings-om
Remove message type bound on `ResponseInstruction`
2024-08-23 03:04:19 +00:00
Matt Corallo
47b527a656 Add a MessageSendInstructions::ForReply
In order to allow onion message handlers to reply asynchronously
without introducing a circular dependency graph, the message
handlers need to be able to send replies described by
`MessageSendInstructions`. This allows them to send replies via the
normal message queuing (i.e. without making a function call to
`OnionMessenger`).

Here we enable that by adding a `MessageSendInstructions::ForReply`
variant which holds `ReplyInstruction`s.

Fixes #3178
2024-08-22 22:39:46 +00:00
Matt Corallo
131ac4f5a8 Change send_onion_message to take a MessageSendInstructions
This lets callers include a `reply_path` without doing the
path-finding at the callsite, utilizing the built-in path-finding
logic in `OnionMessenger`
2024-08-22 22:30:58 +00:00
Matt Corallo
29990674ea 3/3 Use MessageSendInstructions instead of PendingOnionMessage
Now that the `MessageRouter` can `create_blinded_paths` forcing
callers of the `OnionMessenger` to provide it with a reply path up
front is unnecessary complexity, doubly so in message handlers.

Here we take the next step towards untangling that, moving from
`PendingOnionMessage` to `MessageSendInstructions` for the outbound
message queue in `AsyncPaymentsMessageHandler`. Better, we can also
drop the `c_bindings`-specific message queue variant, unifying the
APIs.

Here we also drop `PendingOnionMessage` entirely.
2024-08-22 22:29:18 +00:00
Matt Corallo
eecaf14879 2/3 Use MessageSendInstructions instead of PendingOnionMessage
Now that the `MessageRouter` can `create_blinded_paths` forcing
callers of the `OnionMessenger` to provide it with a reply path up
front is unnecessary complexity, doubly so in message handlers.

Here we take the next step towards untangling that, moving from
`PendingOnionMessage` to `MessageSendInstructions` for the outbound
message queue in `OffersMessageHandler`. Better, we can also drop
the `c_bindings`-specific message queue variant, unifying the APIs.

Because `ChannelManager` needs to actually control the reply path
set in individual messages, however, we have to halfway this patch,
adding a new `MessageSendInstructions` variant that allows
specifying the `reply_path` explicitly. Still, because other message
handlers are moving this way, its nice to be consistent.
2024-08-22 22:27:47 +00:00
Matt Corallo
90361c18bf 1/3 Use MessageSendInstructions instead of PendingOnionMessage
Now that the `MessageRouter` can `create_blinded_paths` forcing
callers of the `OnionMessenger` to provide it with a reply path up
front is unnecessary complexity, doubly so in message handlers.

Here we take the first step towards untangling that, moving from
`PendingOnionMessage` to `MessageSendInstructions` for the outbound
message queue in `CustomMessageHandler`. Better, we can also drop
the `c_bindings`-specific message queue variant, unifying the APIs.
2024-08-22 22:27:44 +00:00
Matt Corallo
b396f0afd1 Give MessageSendInstructions any Destination, not only Blinded
In the next commit we'll use `MessageSendInstructions` for all
messages, so it needs the ability to take any `Destination`, not
only a `Destination::Blinded`.
2024-08-22 22:20:35 +00:00
Matt Corallo
4784bbf7d9 Make ResponseInstruction Cloneable 2024-08-22 22:20:32 +00:00
Matt Corallo
2695331686 Pull the guts of ResponseInstruction into a new enum
In the coming commits we'll use the `ResponseInstruction` enum's
contents for all messages, allowing message senders to rely on the
in-`OnionMessegner` reply path selection logic.

In order to do so and avoid users confusing the new
`MessageSendInstructions` for `ResponseInstruction`, we leave
`ResponseInstruction` as a now-unconstructible struct which wraps a
`MessageSendInstructions`.
2024-08-22 22:17:56 +00:00
Matt Corallo
cd93a41bd6 Remove message type bound on ResponseInstruction
Our onion message handlers generally have one or more methods which
return a `ResponseInstruction` parameterized with the expected
message type (enum) of the message handler.

Sadly, that restriction is impossible to represent in our bindings -
our bindings concretize all LDK structs, enums, and traits into a
single concrete instance with generics set to our concrete trait
instances (which hold a jump table). This prevents us from having
multiple instances of `ResponseInstruction` structs for different
message types.

Our bindings do, however, support different parameterizations of
standard enums, including `Option`s and tuples.

In order to support bindings for the onion message handlers, we
are thus forced into std types bound by expected message types,
which we do here by making `ResponseInstruction` contain only the
instructions and generally using it as a two-tuple of
`(message, ResponseInstruction)`.
2024-08-22 22:17:54 +00:00
Elias Rohrer
0d7ae8616b
Merge pull request #3193 from tnull/2024-07-2995-followups
#2995 followups
2024-08-22 09:55:17 +02:00
Matt Corallo
dced69d025
Merge pull request #3265 from TheBlueMatt/2024-08-globally-unique-names
Disambiguate blinded path `ForwardNode`s between payment + message
2024-08-21 21:41:28 +00:00
Matt Corallo
311150825e
Merge pull request #3250 from TheBlueMatt/2024-08-feature-cleanup 2024-08-21 20:51:21 +00:00
Elias Rohrer
53a616b46e
Correct ConnectionNeeded docs 2024-08-21 21:57:54 +02:00
Elias Rohrer
a383beda2f
Avoid allocating Vec for a single result 2024-08-21 21:57:54 +02:00
Matt Corallo
7cf4a1995d
Merge pull request #3260 from TheBlueMatt/2024-08-more-deref
Bound `Persister`'s `WriteableScore` by `Deref`
2024-08-21 19:55:44 +00:00
Matt Corallo
2ce2fe9392 Disambiguate blinded path ForwardNodes between payment + message
We currently have two structs with identical names in our public
API - `blinded_path::message::ForwardNode` and
`blinded_path::payment::ForwardNode`. This makes the API somewhat
awkward to use - users have to try (and fail) to import
`ForwardNode` twice only to then have to change their imports.

More importantly, however, this makes the API very hard to use in
some bindings languages where rename-imports or module imports
aren't available.

Thus, here, we rename both to give them context.
2024-08-21 19:48:34 +00:00
Matt Corallo
11ab302087 Remove uneccessary std bounds on many tests
We never actually build with `#![no_std]` in tests as Rust does
not support it. Thus, many tests have spurious `std` feature gates
when they run just fine without them. Here we remove those gates,
though note that tests that depend on behavior elsewhere in the
codebase which is `std`-gated obviously need to retain their
feature gates.
2024-08-21 14:11:01 +00:00
Matt Corallo
5412784893 Reduce feature = std flags in gossip.rs somewhat
Fewer feature flags makes for more readable code, so we opt for
that over very marginally more effecient code here.
2024-08-21 14:11:01 +00:00
Matt Corallo
75a2089c15 Drop std::Error impl for PeerHandleError
Not sure why we ever really had this, no one really ever bounds
anything on `std::Error` and its kinda a dead type, so there's no
need for us to `impl` it for our types.
2024-08-21 14:11:01 +00:00
Matt Corallo
d89a487d5b Simplify Instant mocking in outbound payments
To handle `std` and `no-std` concepts of time in scoring, we'd
originally written a generic `Time` trait which we could use to
fetch the current time, observe real (not wall-clock) elapsed time,
and serialize the time.

Eventually, scoring stopped using this `Time` trait but outbound
payment retry expiry started using it instead to mock time in
tests.

Since scoring no longer uses the full features which required the
`Time` trait, we can substantially simplify by just having the
mocking option.
2024-08-21 14:11:01 +00:00
Matt Corallo
1c83e612ad Remove note about std/no-std scorer serialization compat
In 81389dee30 we removed a note about
mixing the `std` and `no-std` feature when de/serializing
`ProbabilisticScorer`s but forgot to note that there was a second
copy of that note in the module documentation.

This removes that note.
2024-08-21 14:11:01 +00:00
Matt Corallo
636125e089 Bound Persister's WriteableScore by Deref
This makes the trait marginally more flexible, but more importantly
matches our normal structure which makes the bindings generator a
bit happier.
2024-08-21 13:48:19 +00:00
Elias Rohrer
b3abb192cc
Rename ChannelDetails::is_public to is_announced
Referring to announced/unannounced channels as 'public'/'private'
regularly leads to confusion on what they are and when which should be
used. To avoid perpetuating this confusion, we should avoid referring to
announced channels as 'public' in our API.

Here we rename `ChannelDetails::is_public` (which breaks
previously-released API) to align it with the changes in
`OpenChannelRequest`.
2024-08-21 12:40:21 +02:00
Elias Rohrer
b9c73b1767
Rename OpenChannelRequest::is_public to is_announced
Referring to announced/unannounced channels as 'public'/'private'
regularly leads to confusion on what they are and when which should be
used. To avoid perpetuating this confusion, we should avoid referring to
announced channels as 'public' in our API.

Here we rename the recently introduced field in `OpenChannelRequest`
(which doesn't break released API), and will align the pre-existing
instances of `is_public` in the following commit (which will break API).
2024-08-21 12:38:27 +02:00
Jeffrey Czyz
76c9fdad58
Rename construct_keys_callback functions 2024-08-20 16:54:10 -05:00
Jeffrey Czyz
b4073b0a7f
Require Destination in construct_keys_callback 2024-08-20 16:54:09 -05:00
Jeffrey Czyz
2787ffef1e
Use a single iterator to construct a BlindedPath
Instead of using separate iterators for pubkeys and TLVs, use an
iterator that yields a tuple of them. This allows for holding a mutable
reference to the TLVs such that they can be padded. With two iterators,
the pubkey iterator would have a reference to the ForwardNode slice when
constructing a payment path. However, this would prevent holding mutable
references in the TLVs iterator.
2024-08-20 16:47:33 -05:00
Jeffrey Czyz
b28fc40260
Generalize build_keys_helper
When constructing a blinded path, two iterators are used: one for the
pubkeys and another for Writeable TLVs. The first iterator is used in
the build_keys_helper utility function while the second is used inside
of a callback. Update this utility to work on any type that can be
borrowed as a PublicKey. This allows for using a single iterator of
tuples, which is necessary for padding the hops without additional
allocations and clones.
2024-08-20 16:35:43 -05:00
Jeffrey Czyz
51d9218f67
Add a construct_keys_callback for blinded paths
When constructing a BlindedPath, an Option<Destination> parameter to
construct_keys_callback is never passed. Make a separate utility
function that doesn't take this parameter. This allows for using the
build_keys_helper macro with a Iterator yielding items other than
PublicKey.
2024-08-20 16:35:43 -05:00
Jeffrey Czyz
4922548bf2
Use PublicKey values in construct_keys_callback
Instead of accepting iterators yielding PublicKey by reference in
utils::construct_keys_callback, take iterators yielding values since
these implement Copy and need to be copied anyway. This will help avoid
a situation when padding where both a reference and mutable reference
are needed.
2024-08-20 16:35:40 -05:00
Jeffrey Czyz
8d22f99740
Refactor helper macro from construct_keys_callback
When constructing a BlindedPath, utils::construct_blinded_hops uses two
iterators. However, this makes it difficult to pad blinded hops to equal
sizes without allocating a vector or cloning data. Refactor the
construct_keys_callback utility function so that is can be used with an
Iterator with different Item types. This allows using a single Iterator
of tuples while still supporting its use only with pubkeys.
2024-08-20 16:00:19 -05:00
Matt Corallo
bbfa15eb18
Merge pull request #3247 from dunxen/2024-08-deprecate-balancemsat
Deprecate AvailableBalances::balance_msat
2024-08-20 20:52:10 +00:00
Matt Corallo
3605777c01
Merge pull request #3258 from TheBlueMatt/2024-08-default-for-bindings
Consistently pass `DefaultRouter::new` `Default` scoring parameters
2024-08-20 20:46:27 +00:00