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

Function test_onchain_dust_out

tests/test_closing.py:1928–1996  ·  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

1926
1927@pytest.mark.developer("needs DEVELOPER=1")
1928def test_onchain_dust_out(node_factory, bitcoind, executor):
1929 """Onchain handling of outgoing dust htlcs (they should fail)"""
1930 # We track channel balances, to verify that accounting is ok.
1931 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1932
1933 # HTLC 1->2, 1 fails after it's irrevocably committed
1934 disconnects = ['-WIRE_REVOKE_AND_ACK', 'permfail']
1935 # Feerates identical so we don't get gratuitous commit to update them
1936 l1, l2 = node_factory.line_graph(2,
1937 opts=[{'disconnect': disconnects,
1938 'feerates': (7500, 7500, 7500, 7500),
1939 'plugin': coin_mvt_plugin},
1940 {'plugin': coin_mvt_plugin}])
1941
1942 channel_id = first_channel_id(l1, l2)
1943
1944 # Must be dust!
1945 inv = l2.rpc.invoice(1, 'onchain_dust_out', 'desc')
1946 rhash = inv['payment_hash']
1947 routestep = {
1948 'amount_msat': 1,
1949 'id': l2.info['id'],
1950 'delay': 5,
1951 'channel': first_scid(l1, l2)
1952 }
1953
1954 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
1955 payfuture = executor.submit(l1.rpc.waitsendpay, rhash)
1956
1957 # l1 will drop to chain.
1958 l1.daemon.wait_for_log('permfail')
1959 l1.wait_for_channel_onchain(l2.info['id'])
1960 l1.bitcoin.generate_block(1)
1961 l1.daemon.wait_for_log(' to ONCHAIN')
1962 l2.daemon.wait_for_log(' to ONCHAIN')
1963
1964 # We use 3 blocks for "reasonable depth"
1965 bitcoind.generate_block(3)
1966
1967 # It should fail.
1968 with pytest.raises(RpcError, match=r'WIRE_PERMANENT_CHANNEL_FAILURE: missing in commitment tx'):
1969 payfuture.result(5)
1970
1971 # Retry payment, this should fail (and, as a side-effect, tickle a
1972 # bug).
1973 with pytest.raises(RpcError, match=r'WIRE_UNKNOWN_NEXT_PEER'):
1974 l1.rpc.sendpay([routestep], rhash, payment_secret=inv['payment_secret'])
1975
1976 # 6 later, l1 should collect its to-self payment.
1977 bitcoind.generate_block(6)
1978 l1.wait_for_onchaind_broadcast('OUR_DELAYED_RETURN_TO_WALLET',
1979 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
1980
1981 # 94 later, l2 is done.
1982 bitcoind.generate_block(94)
1983 l2.daemon.wait_for_log('onchaind complete, forgetting peer')
1984
1985 # Restart l1, it should not crash!

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
restartMethod · 0.80

Tested by

no test coverage detected