MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_hook_crash

Function test_hook_crash

tests/test_plugin.py:2346–2409  ·  view source on GitHub ↗

Verify that we fail over if a plugin crashes while handling a hook. We create a star topology, with l1 opening channels to the other nodes, and then triggering the plugins on those nodes in order to exercise the hook chain. p0 is the interesting plugin because as soon as it get called

(node_factory, executor, bitcoind)

Source from the content-addressed store, hash-verified

2344
2345@unittest.skipIf(TEST_NETWORK != 'regtest', 'p2tr addresses not supported by elementsd')
2346def test_hook_crash(node_factory, executor, bitcoind):
2347 """Verify that we fail over if a plugin crashes while handling a hook.
2348
2349 We create a star topology, with l1 opening channels to the other nodes,
2350 and then triggering the plugins on those nodes in order to exercise the
2351 hook chain. p0 is the interesting plugin because as soon as it get called
2352 for the htlc_accepted hook it'll crash on purpose. We should still make it
2353 through the chain, the plugins should all be called and the payment should
2354 still go through.
2355
2356 """
2357 p0 = os.path.join(os.path.dirname(__file__), "plugins/hook-crash.py")
2358 p1 = os.path.join(os.path.dirname(__file__), "plugins/hook-chain-odd.py")
2359 p2 = os.path.join(os.path.dirname(__file__), "plugins/hook-chain-even.py")
2360 perm = [
2361 (p0, p1, p2), # Crashing plugin is first in chain
2362 (p1, p0, p2), # Crashing plugin is in the middle of the chain
2363 (p1, p2, p0), # Crashing plugin is last in chain
2364 ]
2365
2366 l1 = node_factory.get_node()
2367 nodes = [node_factory.get_node() for _ in perm]
2368
2369 # For simplicity, give us N UTXOs to spend.
2370 addr = l1.rpc.newaddr('p2tr')['p2tr']
2371 for n in nodes:
2372 bitcoind.rpc.sendtoaddress(addr, (FUNDAMOUNT + 30000) / 10**8)
2373 bitcoind.generate_block(1, wait_for_mempool=len(nodes))
2374 sync_blockheight(bitcoind, [l1])
2375
2376 # Start them in any order and we should still always end up with each
2377 # plugin being called and ultimately the `pay` call should succeed:
2378 for plugins, n in zip(perm, nodes):
2379 for p in plugins:
2380 n.rpc.plugin_start(p)
2381 l1.connect(n)
2382 l1.rpc.fundchannel(n.info['id'], FUNDAMOUNT)
2383
2384 # Mine txs first.
2385 mine_funding_to_announce(bitcoind, [l1] + nodes, num_blocks=6, wait_for_mempool=len(nodes))
2386
2387 wait_for(lambda: len(l1.rpc.listchannels()['channels']) == 2 * len(nodes))
2388
2389 # Start an RPC call that should error once the plugin crashes.
2390 f1 = executor.submit(nodes[0].rpc.hold_rpc_call)
2391
2392 futures = []
2393 for n in nodes:
2394 inv = n.rpc.invoice(123, "lbl", "desc")['bolt11']
2395 futures.append(executor.submit(l1.rpc.xpay, inv))
2396
2397 for n in nodes:
2398 n.daemon.wait_for_logs([
2399 r'Plugin is about to crash.',
2400 r'plugin-hook-chain-odd.py: htlc_accepted called for payment_hash',
2401 r'plugin-hook-chain-even.py: htlc_accepted called for payment_hash',
2402 ])
2403

Callers

nothing calls this directly

Calls 13

sync_blockheightFunction · 0.90
mine_funding_to_announceFunction · 0.90
wait_forFunction · 0.90
joinMethod · 0.80
generate_blockMethod · 0.80
plugin_startMethod · 0.80
wait_for_logsMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
connectMethod · 0.45
fundchannelMethod · 0.45
listchannelsMethod · 0.45

Tested by

no test coverage detected