Commit Graph

35 Commits

Author SHA1 Message Date
f321x 5a0c052384 onion_message: move round-robin logic in Request method 2026-04-24 14:00:16 +02:00
f321x 3ff3205b19 onion_message: use util.random_shuffled_copy instead rand sort 2026-04-24 14:00:16 +02:00
f321x d31d1cf75e onion_message: simplify send_onion_message_to
Remove the hops data encryption from the blinded path branch of
send_onion_message_to. Our hops data is already encrypted before
and the blinded paths hops data is already encrypted by the recipient,
so this is a no-op.

Also use encrypt_hops_recipient_data in create_route_to_introduction_point,
it does the same as the existing encryption step.
2026-04-24 14:00:16 +02:00
f321x 4254c9a051 onion_message: fix route construction to ip
Don't include first hop of the path,
this is the hop from us to the first node and we don't
need a payload for ourselves.

Also adds unittest checking this.
2026-04-01 09:07:36 +02:00
f321x 4134dc7b25 onion_message: split send_onion_message_to
Factor out code from `send_onion_message_to` into a separate
function `_create_route_to_introduction_point` to make it
easier to reason about it and more testable.
2026-04-01 09:07:36 +02:00
Sander van Grieken 2e0f263269 onion_message: iterate blinded paths for onion message requests 2026-04-01 09:07:36 +02:00
Sander van Grieken 9bcbbdd3eb move blinding_privkey from onion_message to lnonion 2026-04-01 09:07:36 +02:00
Sander van Grieken 3e3bffa4a2 onion_message: let caller specify considered channels for blinded paths.
This allows restricting blinded paths to channels that have sufficient receive
capacity for payment.

NOTE: this might have privacy issues, as this can be used to probe channel capacity.
Maybe randomize leeway?

@f321x: changed to use scid alias in create_blinded_path
2026-04-01 09:07:36 +02:00
Sander van Grieken b7a512845f onion_message: factor out get_blinded_paths_to_me from get_blinded_reply_paths.
the former also calculates payinfo information for payment scenarios.
include payment_relay struct for payment blinded_paths.
2026-04-01 09:07:36 +02:00
SomberNight ea42b02ceb tests: simplify MockLNWallet, add fixme for cyclic inconsistency 2026-01-05 15:55:58 +00:00
SomberNight 1006e8092f lnworker: split LNWallet and LNWorker: LNWallet "has an" LNWorker
- LNWallet no longer "is-an" LNWorker, instead LNWallet "has-an" LNWorker
- the motivation is to make the unit tests nicer, and allow writing unit tests for more things
  - I hope this makes it possible to e.g. test lnsweep in the unit tests
  - some stuff we would previously have to write a regtest for, maybe we can write a unit test for, now
- in unit tests, MockLNWallet now
  - inherits LNWallet
  - the Wallet is no longer being mocked
2026-01-05 15:55:31 +00:00
Sander van Grieken 23b6465780 onion_message: verify ONION_MESSAGE feature on peer before forwarding 2025-12-05 17:53:03 +01:00
Sander van Grieken fb58d210e5 onion_message: fix forwarding, blinding was renamed path_key
followup 130af59760
2025-12-05 17:51:19 +01:00
Sander van Grieken 23d5ed87e7 onion_message: move encrypt_onionmsg_tlv_hops_data() to lnonion as encrypt_hops_recipient_data()
and add support payloads other than onionmsg_tlv
2025-11-25 15:15:12 +01:00
Sander van Grieken d92b0c74a3 onion_message: num_hops in blinded path is byte, not int. 2025-11-21 17:19:02 +01:00
SomberNight 1b600b49e9 lnmsg/lnonion: follow-up prev: "hide" MappingProxyType usage 2025-11-18 14:54:33 +00:00
f321x 936e7fd1c2 lnonion: immutable OnionPacket and OnionHopsDataSingle
Make OnionHopsDataSingle and OnionPacket immutable for safer caching and
handling.

# Conflicts:
#	electrum/onion_message.py
2025-11-11 14:37:37 +01:00
Sander van Grieken 1ad6607405 onion_message: fix handling of ONION_MESSAGE_LARGE_SIZE payload sizes for onion messages,
process dummy hops regardless of EXPERIMENTAL_LN_FORWARD_PAYMENTS config option.
2025-11-10 16:20:15 +01:00
Sander van Grieken 3cb639f9b4 onion_message: ensure blinded path is list 2025-11-10 15:02:37 +01:00
Sander van Grieken 130af59760 update field naming for BOLT04 structures
see also: https://github.com/lightning/bolts/commit/3fffab3b889c9a6818130b56fb6dcfdf6906f90e
2025-11-10 13:47:20 +01:00
accumulator 6996574c8e Update electrum/onion_message.py _get_request_for_path_id return type
Co-authored-by: ghost43 <somber.night@protonmail.com>
2025-02-20 17:17:14 +01:00
Sander van Grieken ad6eb73dd3 onion_messages: guard onion message forwarding behind config option
EXPERIMENTAL_LN_FORWARD_PAYMENTS (default False)
2025-02-20 00:31:36 +01:00
Sander van Grieken c3c5aaab3d onion_messages: add tests for forwards, receive unsolicited. 2025-02-19 17:43:36 +01:00
Sander van Grieken 0b86e39121 onion_messages: additional checks and comments;
- check on initial_node_id as the type can in theory contain a sciddir.
- log allowed_features if present in recipient_data, with an additional comment describing
the handling of allowed_features in the future.
- document the SHOULD constraint on onion_message payload size
2025-02-19 14:29:50 +01:00
Sander van Grieken f9a374729e onion_messages: generalize List parameter typing to more abstract Sequence 2025-02-19 14:29:50 +01:00
Sander van Grieken 6e35ffe4b5 lnmsg: support both primitive and complex types (subtypes) in LNSerializer.
This renames lnmsg._{read,write}_field to lnmsg._{read,write}_primitive_field, renames
LNSerializer._{read,write}_complex_type to LNSerializer.{read,write}_field and allows
LNSerializer.{read,write}_field to handle both primitive and complex types.

Also makes these funcs public, as these encodings are used outside of lnmsg as well
(e.g. encoding blinded paths in BOLT12 invoice_request)
2025-02-19 14:29:50 +01:00
Sander van Grieken e216f1b324 onion_messages: add parameter typing and comments 2025-02-19 14:29:50 +01:00
ThomasV 71b9761981 onion_messages_manager:
- use namedtuple instead of dict for pending messages
 - use asyncio.Future instead of event and result
2025-02-19 14:29:50 +01:00
ThomasV d814796484 Deobfuscate names
The name 'requestreply' do not mean anything. If something can either
be a request or a reply, perhaps we can call it 'message', instead of
introducing a new name?

In general, coming up with new names comes at a cost, because you
are forcing other developers to learn and use your terminology.
Please minimize that.
2025-02-19 14:29:50 +01:00
ThomasV aeaec452a0 Remove unnecessary events
We do not need asyncio Events in order to signal that a queue is
empty. Instead, we should use asyncio queues.
2025-02-19 14:29:34 +01:00
ThomasV 86432f55ee Remove redundant code: this line is duplicated 2 lines below 2025-02-19 14:29:34 +01:00
ThomasV 3314ee1de1 test_onion_messages: cleanup time constants, make speedup homogeneous.
1. Do not pass request_reply_timeout and request_reply_retry_delay
to OnionMessageManager.

Arguments passed to a function are useful only if their value might
change during the execution of a program. If that is not the case,
it is preferable to define them as constants. That makes the code
easier to read, because the reader can focus on arguments that are
actually relevant.

2 . Multiply all time constants by the same factor, instead
of doing so incompletely and on a per parameter basis. (note
that before this commit, the speedup factor was not consistent)

3. Do not use util.now(), because it is rounded as integer.

With these changes, the tests can effectively run with a 100x speedup
2025-02-19 14:29:34 +01:00
ThomasV a157108e75 onion_messages: fix code indentation 2025-02-19 14:29:34 +01:00
Sander van Grieken 7109c22317 unasync, no add_peer in create_onion_message_route_to, add manager tests 2025-02-19 14:29:34 +01:00
Sander van Grieken 7b4180202a add onion message support 2025-02-19 14:29:02 +01:00