Skip to content

Commit

Permalink
onion_message: dev options to ignore obsolete/modern onions.
Browse files Browse the repository at this point in the history
This lets us test that both work, as expected.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and cdecker committed Oct 4, 2021
1 parent 368fc07 commit 09c2fef
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
10 changes: 10 additions & 0 deletions lightningd/onion_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
43 changes: 40 additions & 3 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 09c2fef

Please sign in to comment.