Wilmer Paulino [Tue, 5 Dec 2023 23:38:47 +0000 (15:38 -0800)]
Rename certain flags to align with dual funding
`FundingCreated` and `FundingSent` were mostly named after the
respective `funding_created` and `funding_sent` wire messages. They
include the signature for the initial commitment transaction when
opening a channel. With dual funding, these messages are no longer used,
and instead we rely on the existing `commitment_signed` to exchange
those signatures.
Matt Corallo [Wed, 29 Nov 2023 23:25:04 +0000 (23:25 +0000)]
Allow users to accept skimmed fees in calling `peel_payment_onion`
LSP users who wish to use `peel_payment_onion` to understand if
they'd accept an HTLC prior to receit should be able to check the
skimmed fees just like they would for full payment receipt. Thus,
we need to expose the fee-skimming acceptance bool to
`peel_payment_onion`, which we do here, in addition to some doc
cleanups.
Matt Corallo [Wed, 29 Nov 2023 23:23:34 +0000 (23:23 +0000)]
Flesh out docs on `PendingHTLCInfo`
Now that `PendingHTLCInfo` is public, its docs should be meaningful
to developers not working directly on LDK, and thus needs
substantially more information than it previously had.
Matt Corallo [Wed, 29 Nov 2023 23:11:02 +0000 (23:11 +0000)]
Flesh out docs on `PendingHTLCRouting`
Now that `PendingHTLCRouting` is public, its docs should be
meaningful to developers not working directly on LDK, and thus
needs substantially more information than it previously had.
Wilmer Paulino [Tue, 24 Oct 2023 23:54:20 +0000 (16:54 -0700)]
Refactor ChannelState to decouple state flags from states
Previously, our `ChannelState` contained bits for both states and flags.
To make matters worse, some of the flags could apply to multiple states.
This led to its API being very cumbersome, having to apply masks in most
scenarios to check for certain states. As LDK grows and more features
are added requiring more states/flags, the need for a simpler API
arises.
This refactor aims to improve this by decoupling the state flags from
the `ChannelState` enum. Each state that requires flags will now have
its own flags type, to ensure flags can only be applied to their
intended state. All of this is done while maintaining backwards and
forwards compatibility.
jbesraa [Sat, 26 Aug 2023 15:06:45 +0000 (18:06 +0300)]
Add `source` and `target` fn's to `CandidateRouteHop`
We add `CandidateRouteHop::source` and
`CandidateRouteHop::source` functions to point
to current and next hops in route respectively.
As we have now `source` and `target`
available in `CandidateRouteHop` we also
remove `CandidateRouteHop::id` inputs
so now they are consumed from `self.target`
and `self.source` functions.
In the `add_entry` macro we also remove `source`
and `target` arguments in favor of `candidate`
of type `CandidateRouteHop` that holds the
needed info.
jbesraa [Tue, 5 Dec 2023 18:56:51 +0000 (20:56 +0200)]
Add `outbound` flag to `DirectedChannelInfo`
If `outband` flag is set to true then `ChannelInfo::node_one`
is forwarding a payment to target `ChannelInfo::node_two`.
If `outband` flag is set to false then `ChannelInfo::node_two`
is forwarding a payment to target `ChannelInfo::node_one`.
Matt Corallo [Tue, 28 Nov 2023 23:19:39 +0000 (23:19 +0000)]
Provide inbound HTLC preimages to the `EcdsaChannelSigner`
The VLS signer has a desire to see preimages for resolved forwarded
HTLCs when they are first claimed by us, even if that claim was for
the inbound edge (where claiming strictly increases our balance).
Luckily, providing that information is rather trivial, which we do
here.
Elias Rohrer [Mon, 4 Dec 2023 14:39:13 +0000 (15:39 +0100)]
Log additional details when ignoring first hops
Users are often confused when we fail to find a route due to some
requirements on the first hop are not being met. While we now take note
and log such candidates, we still previously required users to check
additional details to figure out why exactly the router refused to route
over a particular first hop.
Here, we add additional TRACE logging, in particular for
`ChannelDetails::next_outbound_htlc_limit_msat` and
`ChannelDetails::next_outbound_htlc_minimum_msat` when they are
relevant.
Matt Corallo [Sun, 3 Dec 2023 19:51:24 +0000 (19:51 +0000)]
Remove redundant locking when creating `WithChannelMonitor`
The `WithChannelMonitor` log decorator redundantly locks the
`ChannelMonitor` inner mutex, which we fix here, as well as add a
new constructor which avoids locking at all if an inner mutex lock
is already readily available.
Matt Corallo [Sat, 2 Dec 2023 18:45:03 +0000 (18:45 +0000)]
Drop `log_bytes!()` calls on `Display` types in `ChannelManager`
df3ab2ee2753e7f9ec02ddf1c8a51db77c50e35d was rebased one too many
times and ended up reverting some of the `log_bytes!()` removals
around types which now implement `Display` in `ChannelManager`.
This commit removes those, as well as one additoinal excess macro
which slipped in somewhere else.
Matt Corallo [Sat, 2 Dec 2023 17:54:18 +0000 (17:54 +0000)]
Correct lock drop'ing in `ChainMonitor::update_channel`
e21a500668179c7084e2df5cb75019810eb03cbe cleaned up the error
handling in `ChainMonitor::update_channel` a bit, but accidentally
replaced the deliberate panic with a hang. This commit ensures we
properly drop the monitors read lock before taking a write lock.
Matt Corallo [Sat, 2 Dec 2023 17:54:09 +0000 (17:54 +0000)]
Add some missing `WithContext` wrappers in `peer_handler.rs`
df3ab2ee2753e7f9ec02ddf1c8a51db77c50e35d added `WithContext`
wrappers in most logs in `peer_handler.rs`, but due to long-term
rebasing it missed a few, which we add here.
Matt Corallo [Sat, 2 Dec 2023 04:18:30 +0000 (04:18 +0000)]
Lean on `Logger` wrapping in `ChannelMonitor` rather than in channel
Now that `ChannelMonitor` is careful about wrapping `Logger`s at
the edge, there's no need to use `WithChannelMonitor` in a few
cases in `channel.rs` and one in `channelmanager.rs`.
Matt Corallo [Sun, 3 Dec 2023 20:03:51 +0000 (20:03 +0000)]
Ensure `ChannelMonitor` `Logger`s are always wrapped with metadata
In order to ensure log lines generated by `ChannelMonitor` always
have a counterparty and channel ID entry, this consistently wraps
`Logger`s in a decorator in all `pub(X)` `ChannelMonitor` functions,
removing `pub` markings on `ChannelMonitorImpl` methods that aren't
actually publicly reachable anyway.
This also lets us clean up the `Logger` types in various
`ChannelMonitor` methods.
Matt Corallo [Sun, 3 Dec 2023 19:09:32 +0000 (19:09 +0000)]
Doc that `Record::node_id` may be missing even with `channel_id`
There are various place where we log something related to a channel
but fail to fill in the channel's counterparty information. This is
somewhat surprising, given channel counterparty information is
always known, but simply is sometimes not readily accessible to LDK
when a log is printed.
Matt Corallo [Sat, 2 Dec 2023 19:13:02 +0000 (19:13 +0000)]
Marginally optimize test logging
973636bd2ab2ba35fb8b9703f1d5d0e72f069cdc introduced a new `HashMap`
in the `TestLogger` but then did lookups by iterating the entire
map. This fixes that, and also takes this opportunity to stop
allocating new `String`s for the module to store each log entry in
the `TestLogger`
Jeffrey Czyz [Wed, 29 Nov 2023 16:51:33 +0000 (10:51 -0600)]
Refactor ChainMonitor::update_channel error case
Move the handling of ChannelMonitorUpdateStatus::UnrecoverableError to
the point of error to avoid needing an unwrap later when re-wrapping the
logger.
Jeffrey Czyz [Tue, 21 Nov 2023 16:47:12 +0000 (10:47 -0600)]
Add semantics to logger::Records
Include optional peer and channel ids to logger::Record. This will be
used by wrappers around Logger in order to provide more context (e.g.,
the peer that sent a message, the channel an operation is pertaining to,
etc.). Implementations of Logger can include this as metadata to aid in
searching logs.
Matt Corallo [Thu, 30 Nov 2023 23:35:43 +0000 (23:35 +0000)]
Drop unnecessary SIMD subtraction in ChaCha20 `round`
While its all constant arithmetic to calculate the shift, which
LLVM likely optimizes out for us, there's no reason to do it four
times, which just makes the code harder to read.
Set HTLCPreviousHopData::blinded on intro node forward.
Useful so we know to fail back blinded HTLCs where we are the intro node with
the invalid_onion_blinding error per BOLT 4.
We don't set this field for blinded received HTLCs because we don't support
receiving to multi-hop blinded paths yet, and there's no point in setting it
for HTLCs received to 1-hop blinded paths because per the spec they should fail
back using an unblinded error code.
A blinding point is provided in update_add_htlc messages if we are relaying or
receiving a payment within a blinded path, to decrypt the onion routing packet
and the recipient-provided encrypted payload within. Will be used in upcoming
commits.
A blinding point is provided in update_add_htlc messages if we are relaying or
receiving a payment within a blinded path, to decrypt the onion routing packet
and the recipient-provided encrypted payload within. Will be used in upcoming
commits.
Arik Sosman [Mon, 28 Aug 2023 23:06:41 +0000 (16:06 -0700)]
Move ECDSA-specific signers into ecdsa.rs
To separate out the logic in the `sign` module, which will start to be
convoluted with multiple signer types, we're splitting out each signer
type into its own submodule, following the taproot.rs example from a
previous commit.
Arik Sosman [Mon, 6 Nov 2023 05:51:15 +0000 (21:51 -0800)]
Reparametrize ChannelSignerType by SignerProvider.
ChannelSignerType is an enum that contains variants of all currently
supported signer types. Given that those signer types are enumerated
as associated types in multiple places, it is prudent to denote one
type as the authority on signer types.
SignerProvider seemed like the best option. Thus, instead of
ChannelSignerType declaring the associated types itself, it simply
uses their definitions from SignerProvider.
Arik Sosman [Mon, 6 Nov 2023 05:36:59 +0000 (21:36 -0800)]
Add TaprootSigner variant to SignerProvider.
Previously, SignerProvider was not laid out to support multiple signer
types. However, with the distinction between ECDSA and Taproot signers,
we now need to account for SignerProviders needing to support both.
This approach does mean that if ever we introduced another signer type
in the future, all implementers of SignerProvider would need to add it
as an associated type, and would also need to write a set of dummy
implementations for any Signer trait they do not wish to support.
For the time being, the TaprootSigner associated type is cfg-gated.
Arik Sosman [Sun, 7 May 2023 04:13:53 +0000 (21:13 -0700)]
Introduce TaprootSigner trait.
For Taproot support, we need to define an alternative trait to
EcdsaChannelSigner. This trait will be implemented by all signers
that wish to support Taproot channels.
Matt Corallo [Thu, 9 Nov 2023 04:14:15 +0000 (04:14 +0000)]
Handle missing case in reestablish local commitment number checks
If we're behind exactly one commitment (which we've revoked), we'd
previously force-close the channel, guaranteeing we'll lose funds
as the counterparty has our latest local commitment state's
revocation secret.
While this shouldn't happen because users should never lose data,
sometimes issues happen, and we should ensure we always panic.
Further, `test_data_loss_protect` is updated to test this case.
Matt Corallo [Thu, 9 Nov 2023 03:28:45 +0000 (03:28 +0000)]
Clean up error messages and conditionals in reestablish handling
When we reestablish there are generally always 4 conditions for
both local and remote commitment transactions:
* we're stale and have possibly lost data
* we're ahead and the peer has lost data
* we're caught up
* we're nearly caught up and need to retransmit one update.
In especially the local commitment case we had a mess of different
comparisons, which is improved here. Further, the error messages
are clarified and include more information.
Matt Corallo [Mon, 27 Nov 2023 21:37:42 +0000 (21:37 +0000)]
Add `channel_keys_id` to `SpendableOutputDescriptor::StaticOutput`
In 7f0fd868ad4e8072440f1eb79e78894de1629157, `channel_keys_id` was
added as an argument to `SignerProvider::get_destination_script`,
allowing implementors to generate a new script for each channel.
This is great, however users then have no way to re-derive the
corresponding private key when they ultimately receive a
`SpendableOutputDescriptor::StaticOutput`. Instead, they have to
track all the addresses as they derive them separately. In many
cases this is fine, but we should support both deployments, which
we do here by simply including the missing `channel_keys_id` for
the user.