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

Function test_onchain_dust_out

tests/test_closing.py:1886–1956  ·  view source on GitHub ↗

Onchain handling of outgoing dust htlcs (they should fail)

(node_factory, bitcoind, executor)

Source from the content-addressed store, hash-verified

1884
1885
1886def test_onchain_dust_out(node_factory, bitcoind, executor):
1887 """Onchain handling of outgoing dust htlcs (they should fail)"""
1888 # We track channel balances, to verify that accounting is ok.
1889 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1890
1891 # HTLC 1->2, 1 fails after it's irrevocably committed
1892 disconnects = ['-WIRE_REVOKE_AND_ACK', 'permfail']
1893 # Feerates identical so we don't get gratuitous commit to update them
1894 l1, l2 = node_factory.line_graph(2,
1895 opts=[{'disconnect': disconnects,
1896 'feerates': (7500, 7500, 7500, 7500),
1897 'plugin': coin_mvt_plugin},
1898 {'plugin': coin_mvt_plugin}])
1899
1900 channel_id = first_channel_id(l1, l2)
1901
1902 # Must be dust!
1903 inv = l2.rpc.invoice(1, 'onchain_dust_out', 'desc')
1904 rhash = inv['payment_hash']
1905 routestep = {
1906 'amount_msat': 1,
1907 'id': l2.info['id'],
1908 'delay': 5,
1909 'channel': first_scid(l1, l2)
1910 }
1911
1912 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
1913 payfuture = executor.submit(l1.rpc.waitsendpay, rhash)
1914
1915 # l1 will drop to chain.
1916 l1.daemon.wait_for_log('permfail')
1917 l1.wait_for_channel_onchain(l2.info['id'])
1918 l1.bitcoin.generate_block(1)
1919 l1.daemon.wait_for_log(' to ONCHAIN')
1920 l2.daemon.wait_for_log(' to ONCHAIN')
1921
1922 # We use 3 blocks for "reasonable depth"
1923 bitcoind.generate_block(3)
1924
1925 # It should fail.
1926 with pytest.raises(RpcError, match=r'WIRE_PERMANENT_CHANNEL_FAILURE: missing in commitment tx'):
1927 payfuture.result(5)
1928
1929 # Retry payment, this should fail (and, as a side-effect, tickle a
1930 # bug).
1931 with pytest.raises(RpcError, match=r'WIRE_UNKNOWN_NEXT_PEER'):
1932 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
1933
1934 _, txid, blocks = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
1935 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
1936 assert blocks == 4
1937
1938 # 4 later, l1 should collect its to-self payment.
1939 bitcoind.generate_block(4)
1940
1941 # 94 later, l2 is done.
1942 bitcoind.generate_block(94, wait_for_mempool=txid)
1943 l2.daemon.wait_for_log('onchaind complete, forgetting peer')

Callers

nothing calls this directly

Calls 14

first_channel_idFunction · 0.90
first_scidFunction · 0.90
only_oneFunction · 0.90
account_balanceFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
sendpayMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80
wait_for_onchaind_txMethod · 0.80
restartMethod · 0.80

Tested by

no test coverage detected