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

Function test_onchain_timeout

tests/test_closing.py:1960–2083  ·  view source on GitHub ↗

Onchain handling of outgoing failed htlcs

(node_factory, bitcoind, executor, chainparams, anchors)

Source from the content-addressed store, hash-verified

1958
1959@pytest.mark.parametrize("anchors", [False, True])
1960def test_onchain_timeout(node_factory, bitcoind, executor, chainparams, anchors):
1961 """Onchain handling of outgoing failed htlcs"""
1962
1963 if chainparams['elements'] and anchors:
1964 pytest.skip('elementsd anchors unsupported')
1965
1966 # We track channel balances, to verify that accounting is ok.
1967 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1968
1969 opts = {'plugin': coin_mvt_plugin}
1970 if anchors is False:
1971 opts['dev-force-features'] = "-23"
1972
1973 # HTLC 1->2, 1 fails just after it's irrevocably committed
1974 disconnects = ['+WIRE_REVOKE_AND_ACK*3', 'permfail']
1975 # Feerates identical so we don't get gratuitous commit to update them
1976 l1, l2 = node_factory.line_graph(2,
1977 opts=[{**opts, **{'disconnect': disconnects,
1978 'feerates': (7500, 7500, 7500, 7500)}},
1979 opts])
1980
1981 channel_id = first_channel_id(l1, l2)
1982
1983 inv = l2.rpc.invoice(10**8, 'onchain_timeout', 'desc')
1984 rhash = inv['payment_hash']
1985 # We underpay, so it fails.
1986 routestep = {
1987 'amount_msat': 10**8 - 1,
1988 'id': l2.info['id'],
1989 'delay': 5,
1990 'channel': first_scid(l1, l2)
1991 }
1992
1993 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=1)
1994 with pytest.raises(RpcError):
1995 l1.rpc.waitsendpay(rhash)
1996
1997 # Make sure CLTVs are different, in case it confuses onchaind.
1998 bitcoind.generate_block(1)
1999 sync_blockheight(bitcoind, [l1])
2000
2001 # Second one will cause drop to chain.
2002 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=2)
2003 payfuture = executor.submit(l1.rpc.waitsendpay, rhash)
2004
2005 # l1 will drop to chain.
2006 l1.daemon.wait_for_log('permfail')
2007 l1.wait_for_channel_onchain(l2.info['id'])
2008 l1.bitcoin.generate_block(1)
2009 l1.daemon.wait_for_log(' to ONCHAIN')
2010 l2.daemon.wait_for_log(' to ONCHAIN')
2011
2012 # Could happen any order.
2013 ((_, txid1, blocks1), (_, txid2, blocks2)) = \
2014 l1.wait_for_onchaind_txs(('OUR_DELAYED_RETURN_TO_WALLET',
2015 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US'),
2016 ('OUR_HTLC_TIMEOUT_TX',
2017 'OUR_UNILATERAL/OUR_HTLC'))

Callers

nothing calls this directly

Calls 15

first_channel_idFunction · 0.90
first_scidFunction · 0.90
sync_blockheightFunction · 0.90
only_oneFunction · 0.90
account_balanceFunction · 0.90
check_utxos_channelFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
generate_blockMethod · 0.80
wait_for_logMethod · 0.80

Tested by

no test coverage detected