Commit graph

599 commits

Author SHA1 Message Date
Matt Corallo
fbc08477e8 Move the final CLTV delta to PaymentParameters from RouteParams
`PaymentParams` is all about the parameters for a payment, i.e. the
parameters which are static across all the paths of a paymet.
`RouteParameters` is about the information specific to a given
`Route` (i.e. a set of paths, among multiple potential sets of
paths for a payment). The CLTV delta thus doesn't belong in
`RouterParameters` but instead in `PaymentParameters`.

Worse, because `RouteParameters` is built from the information in
the last hops of a `Route`, when we deliberately inflate the CLTV
delta in path-finding, retries of the payment will have the final
CLTV delta double-inflated as it inflates starting from the final
CLTV delta used in the last attempt.

By moving the CLTV delta to `PaymentParameters` we avoid this
issue, leaving only the sought amount in the `RouteParameters`.
2023-02-01 17:50:24 +00:00
Matt Corallo
ca5b10884e
Merge pull request #1799 from TheBlueMatt/2022-10-heap-nerdsnipe
Router Optimizations
2023-01-25 23:19:13 +00:00
Matt Corallo
e64b5d9d2e Add a fuzzer to check that IndexedMap is equivalent to BTreeMap 2023-01-25 18:58:51 +00:00
Duncan Dean
5b53670172
Add new payment type and metadata bytes
Adds two new payment `Method`s for identifying payments with custom
`min_final_cltv_expiry_delta` as payments with LDK or user payment
hashes.

The `min_final_cltv_expiry_delta` value is packed into the first 2
bytes of the expiry timestamp in the payment secret metadata.
2023-01-24 21:01:27 +02:00
Wilmer Paulino
acd2ae606d
Remove NodeSigner::get_node_secret
Secrets should not be exposed in-memory at the interface level as it
would be impossible the implement it against a hardware security
module/secure element.
2023-01-18 17:23:25 -08:00
Wilmer Paulino
9133beaf75
Use NodeSigner::ecdh to compute SharedSecrets 2023-01-18 17:23:23 -08:00
Wilmer Paulino
19c4468bfc
Sign gossip messages with NodeSigner 2023-01-18 17:23:22 -08:00
Wilmer Paulino
db0d6ecdbb
Add NodeSigner::sign_gossip_message
Adds signing capability to NodeSigner for all gossip messages that
require a node signature.
2023-01-18 17:23:15 -08:00
Matt Corallo
f3a6ca4adc
Always set _test_utils when building lightning for some tests
This ensures that we hit additional assertions which are intended
to always be run in tests.
2023-01-18 16:57:50 -08:00
Matt Corallo
31b0a13158
Merge pull request #1957 from TheBlueMatt/2022-01-mon-ref-lockorder
Pass MonitorUpdates by ref and tweak manager lockorder
2023-01-17 23:09:05 +00:00
Matt Corallo
437fa4f807
Merge pull request #1959 from danielgranhao/stop-passing-init-features-in-msg-handlers
Stop passing `InitFeatures` in msg handlers
2023-01-17 01:26:31 +00:00
Daniel Granhão
bcf174034a
Stop passing InitFeatures in msg handlers 2023-01-16 21:18:53 +00:00
Matt Corallo
7e23afe1dc Pass monitor updates by reference, not owned
In the next commit(s) we'll start holding `ChannelMonitorUpdate`s
that are being persisted in `Channel`s until they're done
persisting. In order to do that, switch to applying the updates by
reference instead of value.
2023-01-15 23:53:21 +00:00
Matt Corallo
f9bafa6d0e Use ChannelUnavailable for a peer disconnecting not MisuseError
This fixes a crash in the `full_stack_target` fuzz test (found by
Chaincode's generous fuzzing infrastructure!) but ultimately is a
better error code - a peer disconnecting before we can fund a
channel isn't a "misuse error" its an unavailable channel.
2023-01-15 23:38:24 +00:00
Matt Corallo
fb5b427cba Make fuzz assertions explicit in Cargo.toml 2023-01-15 23:32:09 +00:00
Matt Corallo
7bdbbca3b0 Switch to hashbrown in fuzzing
hashbrown by default uses ahash, which may be a bit faster, but
more importantly, if we upgrade to hashbrown 0.13/ahash 0.8 we can
make it use a constant randomization factor, making fuzzers happier.
2023-01-15 23:31:06 +00:00
Matt Corallo
3259996e50 Bump fuzz afl dependency to latest upstream version 2023-01-15 23:31:06 +00:00
Wilmer Paulino
abf4e79dcd
Use UserConfig to determine advertised InitFeatures by ChannelManager
This is purely a refactor that does not change the InitFeatures
advertised by a ChannelManager. This allows users to configure which
features should be advertised based on the values of `UserConfig`. While
there aren't any existing features currently leveraging this behavior,
it will be used by the upcoming anchors_zero_fee_htlc_tx feature.

The UserConfig dependency on provided_init_features caused most
callsites of the main test methods responsible for opening channels to
be updated. This commit foregos that completely by no longer requiring
the InitFeatures of each side to be provided to these methods. The
methods already require a reference to each node's ChannelManager to
open the channel, so we use that same reference to obtain their
InitFeatures. A way to override such features was required for some
tests, so a new `override_init_features` config option now exists on
the test harness.
2023-01-13 23:54:51 -08:00
Arik Sosman
72183bd932
Split up generic parameters that used to comprise KeysInterface. 2023-01-12 16:10:35 -08:00
Arik Sosman
5824e226ca
Remove KeysInterface trait. 2023-01-12 09:18:08 -08:00
Valentine Wallace
3a1982c741
Take in-flight HTLCs by reference in Router::find_route
Useful in upcoming work when for payment retries.
2023-01-05 11:24:56 -05:00
Valentine Wallace
2e06efe2ff
Parameterize ChannelManager by a Router trait
This will be used in upcoming work to fetch routes on-the-fly for payment
retries, which will no longer be the responsibility of InvoicePayer.
2023-01-03 15:34:14 -05:00
Arik Sosman
9d7bb73b59
Split out KeysInterface into EntropySource, NodeSigner, and SignerProvider. 2022-12-20 10:09:11 -08:00
Matt Corallo
5588eeb06b
Merge pull request #1867 from wpaulino/remove-signer-persistence
Re-derive signers instead of persisting them
2022-12-06 18:13:49 +00:00
Wilmer Paulino
b04d1b868f
Split KeysInterface::get_channel_signer into two
`get_channel_signer` previously had two different responsibilites:
generating unique `channel_keys_id` and using said ID to derive channel
keys. We decide to split it into two methods `generate_channel_keys_id`
and `derive_channel_signer`, such that we can use the latter to fulfill
our goal of re-deriving signers instead of persisting them. There's no
point in storing data that can be easily re-derived.
2022-12-05 12:11:23 -08:00
Matt Corallo
de2acc0ee0
Merge pull request #1891 from tnull/2022-12-rename-payment-events
Rename `PaymentReceived` to `PaymentClaimable`
2022-12-04 19:31:52 +00:00
Elias Rohrer
22d74bf28b
Rename PaymentReceived to PaymentClaimable 2022-12-01 09:39:33 +01:00
Valentine Wallace
e0820aee43
Rename APIError::RouteError to ::InvalidRoute
Soon we're going to need to return an error when ChannelManager is unable to
find a route, so we'll need a way to distinguish between that and the user
supplying an invalid route.
2022-12-01 01:08:57 -05:00
Elias Rohrer
b1b36661ee
Expose confirmations via ChannelDetails
We expose the current number of confirmations in `ChannelDetails`.
2022-11-29 18:49:54 +01:00
Devrandom
e6b9694498 Re-add support for non-zero-fee-anchors to chan_utils and InMemorySigner 2022-11-22 12:28:51 +01:00
Matt Corallo
d6aa1bc85a
Merge pull request #1826 from TheBlueMatt/2022-10-idempotency-err
Add a separate PaymentSendFailure for idempotency violation
2022-11-16 17:42:23 +00:00
Matt Corallo
8d8ee55463
Merge pull request #1790 from tnull/2022-10-inbound-user-channel-id-randomization
Randomize `user_channel_id` for inbound channels
2022-11-15 22:35:17 +00:00
Elias Rohrer
dc3ff5489a
Make user_channel_id a u128
We increase the `user_channel_id` type from `u64` to `u128`. In order to
maintain backwards compatibility, we have to de-/serialize it as two
separate `u64`s in `Event` as well as in the `Channel` itself.
2022-11-15 20:41:09 +01:00
Matt Corallo
593d8c4610
Merge pull request #1413 from ViktorTigerstrom/2022-04-default-to-bolt4-tlv-onions
Drop support for creating BOLT 4 Legacy onion format payloads
2022-11-11 00:49:45 +00:00
Viktor Tigerström
f4e6d4a653 Remove OnionHopDataFormat::Legacy 2022-11-10 23:34:25 +01:00
Matt Corallo
fcf73f0f45 Add a separate PaymentSendFailure for idempotency violation
When a user attempts to send a payment but it fails due to
idempotency key violation, they need to know that this was the
reason as they need to handle the error programmatically
differently from other errors.

Here we simply add a new `PaymentSendFailure` enum variant for
`DuplicatePayment` to allow for that.
2022-11-09 18:44:27 +00:00
Matt Corallo
c90aac26ad Rename PaymentSendFailure::AllFailedRetrySafe ...ResendSafe
It was pointed out that its quite confusing that
`AllFailedRetrySafe` does not allow you to call `retry_payment`,
though the documentation on it does specify this. Instead, we
simply rename it to `AllFailedResendSafe` to indicate that the
action that is safe to take is *resending*, not *retrying*.
2022-11-09 18:44:27 +00:00
Matt Corallo
790d26f63f
Merge pull request #1761 from TheBlueMatt/2022-10-user-idempotency-token
Provide `send_payment` idempotency guarantees
2022-11-03 22:38:49 +00:00
Elias Rohrer
f4c2d40700
Add ChannelReady event
This adds a `ChannelReady` event that is emitted as soon as a new
channel becomes usable, i.e., after both sides have sent
`channel_ready`.
2022-11-03 11:45:28 +01:00
Matt Corallo
a10223d1ff Allow users to specify the PaymentId for new outbound payments
In c986e52ce8, an `MppId` was added
to `HTLCSource` objects as a way of correlating HTLCs which belong
to the same payment when the `ChannelManager` sees an HTLC
succeed/fail. This allows it to have awareness of the state of all
HTLCs in a payment when it generates the ultimate user-facing
payment success/failure events. This was used in the same PR to
avoid generating duplicative success/failure events for a single
payment.

Because the field was only used as an internal token to correlate
HTLCs, and retries were not supported, it was generated randomly by
calling the `KeysInterface`'s 32-byte random-fetching function.
This also provided a backwards-compatibility story as the existing
HTLC randomization key was re-used for older clients.

In 28eea12bbe `MppId` was renamed to
the current `PaymentId` which was then used expose the
`retry_payment` interface, allowing users to send new HTLCs which
are considered a part of an existing payment.

At no point has the payment-sending API seriously considered
idempotency, a major drawback which leaves the API unsafe in most
deployments. Luckily, there is a simple solution - because the
`PaymentId` must be unique, and because payment information for a
given payment is held for several blocks after a payment
completes/fails, it represents an obvious idempotency token.

Here we simply require the user provide the `PaymentId` directly in
`send_payment`, allowing them to use whatever token they may
already have for a payment's idempotency token.
2022-11-02 01:09:07 +00:00
Matt Corallo
150c87a089
Give us a self when reading a custom onion message
+ remove MaybeReadableArgs trait as it is now unused
+ remove onion_utils::DecodeInput as it would've now needed to be parameterized
by the CustomOnionMessageHandler trait, and we'd like to avoid either
implementing DecodeInput in messenger or having onion_utils depend on
onion_message::*

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2022-10-27 15:58:33 -04:00
Arik Sosman
22c367b13b
Deparametrize ChannelManager to infer Signer from its KeysInterface. 2022-10-25 10:02:28 -07:00
Wilmer Paulino
f4f1093edc
Bump workspace to rust edition 2018
Mostly motivated by the need of async/await.
2022-10-21 14:47:34 -07:00
Jeffrey Czyz
d6321e6e11
Merge pull request #1748 from valentinewallace/2022-10-custom-oms
Support custom onion messages
2022-10-19 17:15:33 -05:00
Valentine Wallace
7664957bc9
Implement sending and receiving custom onion messages
This uses the work done in the preceding commits to implement encoding a user's
custom TLV in outbound onion messages, and decoding custom TLVs in inbound
onion messages, to be provided to the new CustomOnionMessageHandler.
2022-10-19 16:06:58 -04:00
Valentine Wallace
333be69bb4
Tweak OnionMessenger log on inbound onion message receipt 2022-10-18 13:12:59 -04:00
Valentine Wallace
75fd0f3cbb
Parameterize OnionMessenger by new CustomOnionMessageHandler trait
OnionMessenger::new will now take a custom onion message handler trait
implementation. This handler will be used in upcoming commit(s) to handle
inbound custom onion messages.

The new trait also specifies what custom messages are supported via its
associated type, CustomMessage. This associated type must implement a new
CustomOnionMessagesContents trait, which requires custom messages to support
being written, being read, and supplying their TLV type.
2022-10-18 11:39:39 -04:00
Matt Corallo
f961daef33 Rename APIError::MonitorUpdateFailed to MonitorUpdateInProgress
This much more accurately represents the error, indicating that a
monitor update is in progress asynchronously and may complete at a
later time.
2022-09-29 20:27:53 +00:00
Matt Corallo
12fa0b11a6 Rework chain::Watch return types to make async updates less scary
When a `chain::Watch` `ChannelMonitor` update method is called, the
user has three options:
 (a) persist the monitor update immediately and return success,
 (b) fail to persist the monitor update immediately and return
     failure,
 (c) return a flag indicating the monitor update is in progress and
     will complete in the future.

(c) is rather harmless, and in some deployments should be expected
to be the return value for all monitor update calls, but currently
requires returning `Err(ChannelMonitorUpdateErr::TemporaryFailure)`
which isn't very descriptive and sounds scarier than it is.

Instead, here, we change the return type used to be a single enum
(rather than a Result) and rename `TemporaryFailure`
`UpdateInProgress`.
2022-09-29 20:27:53 +00:00
Matt Corallo
f6fa624da0 Stop relying on *Features::known in fuzzing tests
As we move towards specify supported/required feature bits in the
module(s) where they are supported, the global `known` feature set
constructors no longer make sense.

Here we stop relying on the `known` method in our fuzz tests.
2022-09-14 20:09:36 +00:00