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

Function test_onchain_timeout

tests/test_closing.py:2000–2111  ·  view source on GitHub ↗

Onchain handling of outgoing failed htlcs

(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

1998
1999@pytest.mark.developer("needs DEVELOPER=1")
2000def test_onchain_timeout(node_factory, bitcoind, executor):
2001 """Onchain handling of outgoing failed htlcs"""
2002 # We track channel balances, to verify that accounting is ok.
2003 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
2004
2005 # HTLC 1->2, 1 fails just after it's irrevocably committed
2006 disconnects = ['+WIRE_REVOKE_AND_ACK*3', 'permfail']
2007 # Feerates identical so we don't get gratuitous commit to update them
2008 l1, l2 = node_factory.line_graph(2,
2009 opts=[{'disconnect': disconnects,
2010 'feerates': (7500, 7500, 7500, 7500),
2011 'plugin': coin_mvt_plugin},
2012 {'plugin': coin_mvt_plugin}])
2013
2014 channel_id = first_channel_id(l1, l2)
2015
2016 inv = l2.rpc.invoice(10**8, 'onchain_timeout', 'desc')
2017 rhash = inv['payment_hash']
2018 # We underpay, so it fails.
2019 routestep = {
2020 'amount_msat': 10**8 - 1,
2021 'id': l2.info['id'],
2022 'delay': 5,
2023 'channel': first_scid(l1, l2)
2024 }
2025
2026 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=1)
2027 with pytest.raises(RpcError):
2028 l1.rpc.waitsendpay(rhash)
2029
2030 # Make sure CLTVs are different, in case it confuses onchaind.
2031 bitcoind.generate_block(1)
2032 sync_blockheight(bitcoind, [l1])
2033
2034 # Second one will cause drop to chain.
2035 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'], groupid=2)
2036 payfuture = executor.submit(l1.rpc.waitsendpay, rhash)
2037
2038 # l1 will drop to chain.
2039 l1.daemon.wait_for_log('permfail')
2040 l1.wait_for_channel_onchain(l2.info['id'])
2041 l1.bitcoin.generate_block(1)
2042 l1.daemon.wait_for_log(' to ONCHAIN')
2043 l2.daemon.wait_for_log(' to ONCHAIN')
2044
2045 # Wait for timeout.
2046 l1.daemon.wait_for_logs(['Propose handling OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by OUR_DELAYED_RETURN_TO_WALLET .* after 5 blocks',
2047 'Propose handling OUR_UNILATERAL/OUR_HTLC by OUR_HTLC_TIMEOUT_TX .* after 6 blocks'])
2048 bitcoind.generate_block(4)
2049
2050 l1.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
2051 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
2052
2053 bitcoind.generate_block(1)
2054 l1.wait_for_onchaind_broadcast('OUR_HTLC_TIMEOUT_TX',
2055 'OUR_UNILATERAL/OUR_HTLC')
2056
2057 # We use 3 blocks for "reasonable depth"

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
anchor_expectedFunction · 0.90
check_utxos_channelFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
sendpayMethod · 0.80
waitsendpayMethod · 0.80
generate_blockMethod · 0.80

Tested by

no test coverage detected