1
0

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
This commit is contained in:
Sander van Grieken
2025-02-13 14:09:37 +01:00
parent 560b244b4d
commit 0b86e39121
2 changed files with 13 additions and 1 deletions

View File

@@ -206,6 +206,12 @@ def send_onion_message_to(
raise
introduction_point = blinded_path['first_node_id']
if len(introduction_point) != 33:
raise Exception('first_node_id not a nodeid but a sciddir, which is not supported')
# Note: blinded_path specifies type sciddir_or_nodeid for first_node_id
# but only nodeid is supported in onion_message context;
# https://github.com/lightning/bolts/blob/master/04-onion-routing.md
# "MUST set first_node_id to N0"
hops_data = []
blinded_node_ids = []
@@ -609,7 +615,9 @@ class OnionMessageManager(Logger):
# - `encrypted_data_tlv.allowed_features.features` contains an unknown feature bit (even if it is odd).
# - the message uses a feature not included in `encrypted_data_tlv.allowed_features.features`.
if 'allowed_features' in recipient_data:
pass # TODO
# Note: These checks will be usecase specific (e.g. BOLT12) and probably should be checked
# by consumers of the message.
self.logger.debug(f'allowed_features={recipient_data["allowed_features"].get("features", b"").hex()}')
# - if `path_id` is set and corresponds to a path the reader has previously published in a `reply_path`:
# - if the onion message is not a reply to that previous onion:

View File

@@ -104,6 +104,10 @@ class TestOnionMessage(ElectrumTestCase):
self.assertEqual(packet.to_bytes(), ONION_MESSAGE_PACKET)
def test_onion_message_payload_size(self):
# Note: payload size is not _strictly_ limited to (1300+66, 32768+66), but Electrum only generates these sizes
# However, the spec allows for other payload sizes.
# https://github.com/lightning/bolts/blob/master/04-onion-routing.md
# "SHOULD set onion_message_packet len to 1366 or 32834."
hop_shared_secrets, blinded_node_ids = get_shared_secrets_along_route([DAVE_PUBKEY], SESSION_KEY)
def hops_data_for_message(message):