From ad6eb73dd310d47dcf2f8a953484679680da3b81 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 19 Feb 2025 18:06:04 +0100 Subject: [PATCH] onion_messages: guard onion message forwarding behind config option EXPERIMENTAL_LN_FORWARD_PAYMENTS (default False) --- electrum/onion_message.py | 4 +++- tests/test_onion_message.py | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/electrum/onion_message.py b/electrum/onion_message.py index ed83e5b92..d57ccbb87 100644 --- a/electrum/onion_message.py +++ b/electrum/onion_message.py @@ -758,5 +758,7 @@ class OnionMessageManager(Logger): if processed_onion_packet.are_we_final: self.on_onion_message_received(recipient_data, payload) - else: + elif self.network.config.EXPERIMENTAL_LN_FORWARD_PAYMENTS: self.on_onion_message_forward(recipient_data, processed_onion_packet.next_packet, blinding, shared_secret) + else: + self.logger.info('onion_message dropped') diff --git a/tests/test_onion_message.py b/tests/test_onion_message.py index a65a90be8..2ad9b1de7 100644 --- a/tests/test_onion_message.py +++ b/tests/test_onion_message.py @@ -8,6 +8,7 @@ import logging import electrum_ecc as ecc from electrum_ecc import ECPrivkey +from electrum import SimpleConfig from electrum.lnmsg import decode_msg, OnionWireSerializer from electrum.lnonion import ( OnionHopsDataSingle, OnionPacket, @@ -16,15 +17,17 @@ from electrum.lnonion import ( HOPS_DATA_SIZE, InvalidPayloadSize) from electrum.crypto import get_ecdh, privkey_to_pubkey from electrum.lnutil import LnFeatures, Keypair -from electrum.onion_message import blinding_privkey, create_blinded_path, encrypt_onionmsg_tlv_hops_data, \ +from electrum.onion_message import ( + blinding_privkey, create_blinded_path, encrypt_onionmsg_tlv_hops_data, OnionMessageManager, NoRouteFound, Timeout +) from electrum.util import bfh, read_json_file, OldTaskGroup, get_asyncio_loop from electrum.logging import console_stderr_handler from . import ElectrumTestCase, test_lnpeer from .test_lnpeer import PutIntoOthersQueueTransport, PeerInTests, keypair -TIME_STEP = 0.01 # run tests 100 x faster +TIME_STEP = 0.01 # run tests 100 x faster OnionMessageManager.SLEEP_DELAY *= TIME_STEP OnionMessageManager.REQUEST_REPLY_TIMEOUT *= TIME_STEP OnionMessageManager.REQUEST_REPLY_RETRY_DELAY *= TIME_STEP @@ -263,6 +266,8 @@ class MockNetwork: def __init__(self): self.asyncio_loop = get_asyncio_loop() self.taskgroup = OldTaskGroup() + self.config = SimpleConfig() + self.config.EXPERIMENTAL_LN_FORWARD_PAYMENTS = True class MockWallet: