Commit graph

39 commits

Author SHA1 Message Date
henghonglee
ff5e5221d2 logging every sent and receive onion message
Logs every sent + receive for P2P messages
solves #2346
2023-12-03 00:24:14 +05:30
Matt Corallo
26c00ad751 derive(Hash) for P2P messages
In other languages (Java and C#, notably), overriding `Eq` without
overriding `Hash` can lead to surprising or broken behavior. Even
in Rust, its usually the case that you actually want both. Here we
add missing `Hash` derivations for P2P messages, to at least
address the first pile of warnings the C# compiler dumps.
2023-11-14 00:40:30 +00:00
Matt Corallo
4918c415af Drop an unnecessary no-export on ParsedOnionMessageContents 2023-10-23 16:50:35 +00:00
Jeffrey Czyz
840efd5334
Generalize CustomOnionMessageContents trait
Rename CustomOnionMessageContents to OnionMessageContents and use it as
a trait bound on messages passed to OnionMessenger methods. This allows
using the trait in an upcoming commit as a bound on the contents of
PendingOnionMessage.

Also, make ParsedOnionMessageContent implement OnionMessageContents so
that Payload can be bounded by OnionMessageContents directly, but used
when either reading a ParsedOnionMessageContent or writing a specific
type of OnionMessageContents (e.g., OffersMessage).
2023-10-18 18:15:05 -05:00
Jeffrey Czyz
94573dda33
Rename OnionMessageContents
In preparation for needing the name OnionMessageContents for a trait to
bound methods, rename it to ParsedOnionMessageContents. In the next
commit, it's use will be limited to reading only, and the new trait will
be a bound on method parameters instead.
2023-10-18 17:18:03 -05:00
Evan Feenstra
30b74a6bcf public make_onion_message static method on OnionMessenger 2023-09-20 13:42:35 -07:00
Valentine Wallace
ebb0676e85
Fix documentation on onion message packet ControlTlvs 2023-08-23 11:28:42 -04:00
Valentine Wallace
d224f980ed
Simplify onion message blinded hop construction
Also adds a util for general blinded hop creation to be reused for blinded
payment paths.
2023-08-23 11:26:45 -04:00
Valentine Wallace
cf64e3fba5
Add new _init_and_read_tlv_stream ser macro
Useful for when you want to use _init_and_read_len_prefixed_tlv_fields but there is no
length byte at the start of the TLV stream.
2023-08-23 11:24:54 -04:00
Valentine Wallace
1b356619b3
Move Padding into blinded_path module for use in blinded payments 2023-08-22 13:26:12 -04:00
Valentine Wallace
381cc646c6
Move some blinded path message code into message submodule.
We'll similarly separate blinded path payments code into its own module.
2023-08-22 13:18:42 -04:00
Matt Corallo
a04bf844d4 Convert some vec_type TLVs to required_vec
This converts some required TLVs to `required_vec` which are, in
fact, required (and have been written forever).

* `HTLCFailReason` hasn't changed since many structs were converted
  to TLVs in 66784e32fe.
* `NodeInfo::channels` has been written since `NetworkGraph`
  structs were converted to TLVs in 321b19c4d9.
* Several test-only TLV writes were converted.
2023-07-07 21:07:06 +00:00
Jeffrey Czyz
c83d5bf162
Remove unnecessary Sized bound 2023-06-13 13:07:48 -05:00
Jeffrey Czyz
f521e4cceb
OffersMessageHandler trait for OnionMessenger
Add a trait for handling BOLT 12 Offers messages to OnionMessenger and a
skeleton implementation of it for ChannelManager. This allows users to
either provide their own custom handling Offers messages or rely on a
version provided by LDK using stateless verification.
2023-06-13 13:07:47 -05:00
Jeffrey Czyz
cff88aa509
Avoid an unnecessary unwrap 2023-06-13 13:07:47 -05:00
Jeffrey Czyz
a799fc9b30
Onion message payload for BOLT 12 Offers
BOLT 12 Offers makes use of onion messages to request and respond with
invoices. Add these types and an error type to OnionMessageContents
along with the necessary parsing and encoding.
2023-06-13 13:07:47 -05:00
Jeffrey Czyz
7533a3c42f
Pass logger to onion payload decoder
In an upcoming commit, messages for BOLT 12 offers are read from the
onion payload. Passing a logger allows for logging semantic errors when
parsing the messages.
2023-06-13 13:07:46 -05:00
Valentine Wallace
efed905a4f
Move blinded_path and its utils into a new module 2023-04-20 10:14:15 -04:00
munjesi
b0bf50fa24 Replacing (C-not exported) in the docs 2023-03-22 14:30:36 +03:00
Omer Yacine
3a33693b1e
Expose impl_writeable_tlv_based macro
Every exported macro needed to have all the macros used inside it:
1- to be exported as well.
2- be called from the `$crate` namespace so it works in other crates.

Some structs in `lightning::util::ser` needed to be made public as they were used inside the exported macros.

Use the macros like this:
```Rust
lightning::impl_writeable_tlv_based!(...)
```
2023-01-09 21:16:30 +02:00
Matt Corallo
f00bc4d713 No-export &self methods on non-cloneable enum(s)
Specifically, `OnionMessageContents` is a non-cloneable enum, which
isn't stored opaque so we cannot call `&self` methods on it.
Because its methods aren't critical to the API for now, we simply
no-export them rather than trying to work out an alternative
approach.
2022-12-25 00:58:19 +00:00
Matt Corallo
8dbf6dba7d Update references to "blinded route" to "blinded path"
Finishing the work from the previous two commits.
2022-12-14 21:14:38 +00:00
Matt Corallo
a0d38d7eb9 Rename blinded_route variables and module to blinded_path
Following up on the previous commit, this also renames variables
and the module used to `blinded_path`.
2022-12-14 21:14:38 +00:00
Matt Corallo
9b6de781d8 Unify blinding nomenclature to call them "paths" not "routes".
Currently the `onion_message` module exposes the blinded route
object as *both* `BlindedRoute` and `BlindedPath`. This is somewhat
confusing, and given they are really paths, not routes (at least in
the sense that a route could be multi-path, though for OMs they are
not), here we unify to only call them paths.
2022-12-14 21:07:55 +00:00
Jeffrey Czyz
227fd51cb4
Add WithoutLength wrapper
When serializing variable-length types as part of a TLV stream, the
length does not need to be serialized as it is already encoded in TLV
records. Add a WithoutLength wrapper for this encoding. Replace
VecReadWrapper and VecWriteWrapper with this single type to avoid
redundant encoders.
2022-11-04 15:09:14 -05: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
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
ec538d1816
Update send_onion_message API to take new OnionMessageContents enum
OnionMessageContents specifies the data TLV that the sender wants in the onion
message. This enum only has one variant for now, Custom. When offers are added,
additional variants for invoice, invoice_request, and invoice_error will be
added.

This commit does not actually implement sending the custom OM contents, just
the API change.
2022-10-18 13:28:29 -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
Gabriel Comte
aa916bb594
Derive Eq for all structs that derive PartialEq 2022-10-14 13:24:02 +02:00
Valentine Wallace
0b1f476b83
Expose onion message module as public
And fix warnings
2022-09-02 16:25:32 -04:00
Valentine Wallace
950b7d777a
Support sending and receiving reply paths 2022-08-23 20:37:26 -04:00
Valentine Wallace
351349c845
Fix bug in onion message payload decode
Previously, we were decoding payload lengths as a VarInt. Per the spec, this is
wrong -- it should be decoded as a BigSize.  This bug also exists in our
payment payload decoding, to be fixed separately.

Upcoming reply path tests caught this bug because we hadn't encoded a payload
greater than 253 before, so we hadn't hit the problem that VarInts are encoded
as little-endian whereas BigSizes are encoded as big-endian.
2022-08-23 20:33:58 -04:00
Valentine Wallace
81b7b03d4f
Fix fuzzer-found underflow 2022-08-15 12:46:39 -04:00
Valentine Wallace
bf007ea763
Implement receiving and forwarding onion messages
This required adapting `onion_utils::decode_next_hop` to work for both payments
and onion messages.

Currently we just print out the path_id of any onion messages we receive. In
the future, these received onion messages will be redirected to their
respective handlers: i.e. an invoice_request will go to an InvoiceHandler,
custom onion messages will go to a custom handler, etc.
2022-08-02 19:19:37 -04:00
Valentine Wallace
9051c38ebe
Support sending onion messages
This adds several utilities in service of then adding
OnionMessenger::send_onion_message, which can send to either an unblinded
pubkey or a blinded route. Sending custom TLVs and sending an onion message
containing a reply path are not yet supported.

We also need to split the construct_keys_callback macro into two macros to
avoid an unused assignment warning.
2022-08-02 19:17:27 -04:00
Valentine Wallace
33ff2746ef
Add onion_message::Packet and adapt construct_onion_packet_with_init_noise for it
We need to add a new Packet struct because onion message packet hop_data fields
can be of variable length, whereas regular payment packets are always 1366
bytes.

Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2022-08-02 19:17:19 -04:00