Commit graph

5509 commits

Author SHA1 Message Date
Matt Corallo
1122e82bf0
Merge pull request #3238 from Mirebella/clippy-checks
Added clippy ignore rules for all errors and warnings
2024-08-29 16:06:40 +00:00
Matt Corallo
bf6a53e0fd
Merge pull request #3275 from TheBlueMatt/2024-08-3259-followups
#3259 followups
2024-08-29 00:54:19 +00:00
Matt Corallo
a97807647a
Merge pull request #3276 from arik-so/arik/2024/08/apply_monitor_updates_on_archive
Process updates before archiving monitors.
2024-08-28 21:53:43 +00:00
Arik Sosman
47c8aa51a6
Process updates before archiving monitors.
Previously, `MonitorUpdatingPersister` was disregarding any unapplied
monitor updates when archiving them. This commit ensures that upon
reading monitors, their corresponding updates are also read and
applied prior to archiving.
2024-08-28 12:19:38 -07:00
Arik Sosman
61197390d6
Store Broadcaster and FeeEstimator on MonitorUpdatingPersister.
`MonitorUpdatingPersister` does not currently correctly archive
monitors because it neglects any unapplied updates. In order to start
applying these updates, the archiving methods will require access to
instances of `BroadcasterInterface` and `FeeEstimator`.

This commit requires that the `MonitorUpdatingPersister` be
instantiated with those instances, obviating the need for passing
them around, and laying the foundation for the following commit.
2024-08-28 12:19:38 -07:00
Matt Corallo
ea646ae888 Test manual funding transaction Event::DiscardFunding generation 2024-08-28 14:50:52 +00:00
Matt Corallo
683aa8350e Correct manual shutdown detection on channel closure
In 5e874c3dc9 we'd intended to not
reveal the dummy funding transaction in `Event::DiscardFunding`.
However, instead of looking at the channel that was just closed,
the logic only looks at any other channels which were funded as a
part of the same batch. Because manually-funded transactions
cannot currently be done for batch funding, this was actually dead
code, preventing the new changes from taking effect.
2024-08-28 14:35:54 +00:00
Matt Corallo
6a81d5d4bb Add additional documentation on Channel::unbroadcasted_funding 2024-08-28 13:50:17 +00:00
Matt Corallo
b7064808ac
Merge pull request #3268 from TheBlueMatt/2024-08-moar-feerate-categories
Split up `ConfirmationTarget` even more
2024-08-28 13:15:13 +00:00
Mirebella
6ff1978eba Add clippy ignore rules for all errors and warnings 2024-08-28 09:47:40 +02:00
Matt Corallo
cf97cefb47 Test new ConfirmationTarget selection based on HTLC set
This updates `test_yield_anchors_events` to test both anchor
channels with and without HTLCs, and relies on overriding only the
singular expected `ConfirmationTarget` used, testing the new
`ConfirmationTarget::UrgentOnChainSweep` use.
2024-08-27 19:57:34 +00:00
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