onion_message: dev options to ignore obsolete/modern onions.

This lets us test that both work, as expected.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-10-01 06:49:37 +09:30 committed by Christian Decker
parent 368fc07d05
commit 09c2fef4a4
5 changed files with 61 additions and 3 deletions

View file

@ -127,6 +127,8 @@ static struct lightningd *new_lightningd(const tal_t *ctx)
ld->dev_no_htlc_timeout = false;
ld->dev_no_version_checks = false;
ld->dev_max_funding_unconfirmed = 2016;
ld->dev_ignore_modern_onion = false;
ld->dev_ignore_obsolete_onion = false;
#endif
/*~ These are CCAN lists: an embedded double-linked list. It's not

View file

@ -242,6 +242,9 @@ struct lightningd {
/* Number of blocks we wait for a channel to get funded
* if we are the fundee. */
u32 dev_max_funding_unconfirmed;
/* Special switches to test onion compatibility */
bool dev_ignore_modern_onion, dev_ignore_obsolete_onion;
#endif /* DEVELOPER */
/* tor support */

View file

@ -142,6 +142,11 @@ void handle_obs_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
size_t submsglen;
const u8 *subptr;
#if DEVELOPER
if (ld->dev_ignore_obsolete_onion)
return;
#endif
payload = tal(ld, struct onion_message_hook_payload);
payload->obsolete = true;
payload->reply_first_node = NULL;
@ -228,6 +233,11 @@ void handle_onionmsg_to_us(struct lightningd *ld, const u8 *msg)
size_t submsglen;
const u8 *subptr;
#if DEVELOPER
if (ld->dev_ignore_modern_onion)
return;
#endif
payload = tal(ld, struct onion_message_hook_payload);
payload->obsolete = false;
payload->om = tlv_onionmsg_payload_new(payload);

View file

@ -648,6 +648,12 @@ static void dev_register_opts(struct lightningd *ld)
opt_register_arg("--dev-timeout-secs", opt_set_u32, opt_show_u32,
&ld->config.connection_timeout_secs,
"Seconds to timeout if we don't receive INIT from peer");
opt_register_noarg("--dev-no-modern-onion", opt_set_bool,
&ld->dev_ignore_modern_onion,
"Ignore modern onion messages");
opt_register_noarg("--dev-no-obsolete-onion", opt_set_bool,
&ld->dev_ignore_obsolete_onion,
"Ignore obsolete onion messages");
}
#endif /* DEVELOPER */

View file

@ -4117,15 +4117,34 @@ def test_offer(node_factory, bitcoind):
assert 'recurrence: every 600 seconds paywindow -10 to +600 (pay proportional)\n' in output
@pytest.mark.developer("dev-no-modern-onion is DEVELOPER-only")
def test_fetchinvoice_3hop(node_factory, bitcoind):
l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True,
opts={'experimental-offers': None})
opts={'experimental-offers': None,
'may_reconnect': True})
offer1 = l4.rpc.call('offer', {'amount': '2msat',
'description': 'simple test'})
assert offer1['created'] is True
l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']})
# Test with obsolete onion.
l4.stop()
l4.daemon.opts['dev-no-modern-onion'] = None
l4.start()
l4.rpc.connect(l3.info['id'], 'localhost', l3.port)
l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']})
# Test with modern onion.
l4.stop()
del l4.daemon.opts['dev-no-modern-onion']
l4.daemon.opts['dev-no-obsolete-onion'] = None
l4.start()
l4.rpc.connect(l3.info['id'], 'localhost', l3.port)
l1.rpc.call('fetchinvoice', {'offer': offer1['bolt12']})
def test_fetchinvoice(node_factory, bitcoind):
# We remove the conversion plugin on l3, causing it to get upset.
@ -4426,9 +4445,13 @@ def test_dev_rawrequest(node_factory):
assert 'invoice' in ret
def test_sendinvoice(node_factory, bitcoind):
def do_test_sendinvoice(node_factory, bitcoind, disable):
l2opts = {'experimental-offers': None}
if disable:
l2opts[disable] = None
l1, l2 = node_factory.line_graph(2, wait_for_announce=True,
opts={'experimental-offers': None})
opts=[{'experimental-offers': None},
l2opts])
# Simple offer to send money (balances channel a little)
offer = l1.rpc.call('offerout', {'amount': '100000sat',
@ -4507,6 +4530,20 @@ def test_sendinvoice(node_factory, bitcoind):
assert out['amount_received_msat'] == Millisatoshi(10000000)
def test_sendinvoice(node_factory, bitcoind):
do_test_sendinvoice(node_factory, bitcoind, None)
@pytest.mark.developer("needs to --dev-no-obsolete-onion")
def test_sendinvoice_modern(node_factory, bitcoind):
do_test_sendinvoice(node_factory, bitcoind, 'dev-no-obsolete-onion')
@pytest.mark.developer("needs to --dev-no-modern-onion")
def test_sendinvoice_obsolete(node_factory, bitcoind):
do_test_sendinvoice(node_factory, bitcoind, 'dev-no-modern-onion')
def test_self_pay(node_factory):
"""Repro test for issue 4345: pay ourselves via the pay plugin.