Commit graph

527 commits

Author SHA1 Message Date
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
Matt Corallo
f1d70be864 Fix warnings in fuzz which should have been fixed in f725c5a90a 2022-09-14 00:50:29 +00:00
Matt Corallo
45ec1db2e0 Encrypt+MAC most P2P messages in-place
For non-gossip-broadcast messages, our current flow is to first
serialize the message into a `Vec`, and then allocate a new `Vec`
into which we write the encrypted+MAC'd message and header.

This is somewhat wasteful, and its rather simple to instead
allocate only one buffer and encrypt the message in-place.
2022-09-12 18:06:52 +00:00
Matt Corallo
989cb064b5 Move broadcast_node_announcement to PeerManager
Some `NodeFeatures` will, in the future, represent features which
are not enabled by the `ChannelManager`, but by other message
handlers handlers. Thus, it doesn't make sense to determine the
node feature bits in the `ChannelManager`.

The simplest fix for this is to change to generating the
node_announcement in `PeerManager`, asking all the connected
handlers which feature bits they support and simply OR'ing them
together. While this may not be sufficient in the future as it
doesn't consider feature bit dependencies, support for those could
be handled at the feature level in the future.

This commit moves the `broadcast_node_announcement` function to
`PeerHandler` but does not yet implement feature OR'ing.
2022-09-08 19:50:36 +00:00
Matt Corallo
7223f70616 Drop honggfuzz arbitrary dependency to meet MSRV 2022-08-30 15:15:00 +00:00
Valentine Wallace
4adff1039f
Add boilerplate for sending and receiving onion messages in PeerManager
Adds the boilerplate needed for PeerManager and OnionMessenger to work
together, with some corresponding docs and misc updates mostly due to the
PeerManager public API changing.
2022-08-26 19:02:59 -04:00
Valentine Wallace
950b7d777a
Support sending and receiving reply paths 2022-08-23 20:37:26 -04:00
Valentine Wallace
8424f3f054
Fuzz test onion messages
Also update the fuzz ChaCha20Poly1305 to not mark as finished after a single
encrypt_in_place.  This is because more bytes may still need to be encrypted,
causing us to panic at the assertion that finished == false when we go to
encrypt more.

Also fix unused_mut warning in messenger + add log on OM forward for testing
2022-08-16 12:12:10 -04:00
Devrandom
11166aa836 Modify ecdh to take Scalar 2022-08-11 00:21:26 +02:00
Devrandom
7e05623bef Update bitcoin crate to 0.29.0 2022-08-11 00:21:26 +02:00
Matt Corallo
353b1e7e46 Update libfuzzer-sys to new upstream inclusion method
Dunno why they changed it, but the old "depend directly on git"
thing that cargo-fuzz used forever is now deprecated that that
repo is archived, they've now moved to another repo and publish
properly on crates.io.
2022-08-07 19:02:33 +00:00
Matt Corallo
28c9b56113
Merge pull request #1503 from valentinewallace/2022-05-onion-msgs
Onion messages v1
2022-08-03 04:39:56 +00:00
Valentine Wallace
6017379b8e
KeysInterface: add new ecdh method
This method will help us avoid retrieving our node secret, something we want to
get rid of entirely.  It will be used in upcoming commits when decoding the
onion message packet, and in future PRs to help us get rid of
KeysInterface::get_node_secret usages across the codebase
2022-08-02 19:17:23 -04:00
Jeffrey Czyz
f0b818952b
Merge pull request #1403 from jurvis/jurvis/add-paymentforwardingfailed-event
Add HTLCHandlingFailed event
2022-07-25 19:23:53 -05:00
Matt Corallo
a491200f96 Avoid blanket implementing FeeEstimator for Deref<FeeEstimator>
This simplifies things for bindings (and, to some extent,
downstream users) by exploiting the fact that we can always "clone"
a reference to a struct by dereferencing and then creating a new
reference.
2022-07-25 18:33:10 +00:00
jurvis
ac842ed9dd
Send failure event if we fail to handle a HTLC
In `ChannelManager::fail_htlc_backwards_internal`, we push a `HTLCHandlingFailed`
containing some information about the HTLC
2022-07-25 11:28:51 -07:00
jurvis
17e6c374c5
Add HTLCHandlingFailed event
Adds a HTLCHandlingFailed that expresses failure by our node to process
a specific HTLC. A HTLCDestination enum is defined to express the
possible cases that causes the handling to fail.
2022-07-25 10:22:43 -07:00
Jeffrey Czyz
4e5f74a6f3
Merge pull request #1567 from tnull/2022-06-send-probe
Add simple probing API
2022-07-07 09:27:14 -05:00
Elias Rohrer
eb8bce0d16 Add send_probe and introduce probing cookies
When we send payment probes, we generate the [`PaymentHash`] based on a
probing cookie secret and a random [`PaymentId`]. This allows us to
discern probes from real payments, without keeping additional state.
2022-07-07 09:02:29 +02:00
Matt Corallo
f58f2eb0fa Drop unused imports in fuzzing test cases 2022-07-06 16:18:30 +00:00
Matt Corallo
d246e61379 [fuzz] Update auto-generated target list 2022-07-01 20:55:26 +00:00
Matt Corallo
c9a52d6ecf [fuzz] Add a ChannelDetails msg target 2022-07-01 20:55:26 +00:00
Matt Corallo
cee1feb165 [fuzz] Take a full struct path in msg gen_target.sh 2022-07-01 20:55:26 +00:00