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

Function test_onchain_unwatch

tests/test_closing.py:1771–1828  ·  view source on GitHub ↗

Onchaind should not watch random spends

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1769
1770
1771def test_onchain_unwatch(node_factory, bitcoind, chainparams):
1772 """Onchaind should not watch random spends"""
1773 # We track channel balances, to verify that accounting is ok.
1774 coin_mvt_plugin = os.path.join(os.getcwd(), 'tests/plugins/coin_movements.py')
1775 l1, l2 = node_factory.line_graph(2, opts={'plugin': coin_mvt_plugin})
1776 channel_id = first_channel_id(l1, l2)
1777
1778 l1.pay(l2, 200000000)
1779 # If the HTLC isn't completely removed, we will use an anchor to bump
1780 # the commitment tx. Under valgrind we tend to resolve the HTLC
1781 # before getting to dev_fail. Unify the cases by waiting a bit.
1782 wait_for(lambda: only_one(l1.rpc.listpeerchannels(l2.info['id'])['channels'])['htlcs'] == [])
1783
1784 l1.rpc.dev_fail(l2.info['id'])
1785 l1.daemon.wait_for_log('Failing due to dev-fail command')
1786 l1.wait_for_channel_onchain(l2.info['id'])
1787
1788 l1.bitcoin.generate_block(1, wait_for_mempool=1)
1789 l1.daemon.wait_for_log(' to ONCHAIN')
1790 l2.daemon.wait_for_log(' to ONCHAIN')
1791
1792 _, txid, blocks = l1.wait_for_onchaind_tx('OUR_DELAYED_RETURN_TO_WALLET',
1793 'OUR_UNILATERAL/DELAYED_OUTPUT_TO_US')
1794 assert blocks == 4
1795
1796 # 5 later, l1 should collect its to-self payment.
1797 bitcoind.generate_block(4)
1798
1799 # First time it sees it, onchaind cares.
1800 bitcoind.generate_block(1, wait_for_mempool=txid)
1801 l1.daemon.wait_for_log('Resolved OUR_UNILATERAL/DELAYED_OUTPUT_TO_US by our proposal '
1802 'OUR_DELAYED_RETURN_TO_WALLET')
1803
1804 # Now test unrelated onchain churn.
1805 # Daemon gets told about wallet; says it doesn't care.
1806 l1.rpc.withdraw(l1.rpc.newaddr('bech32')['bech32'], 'all')
1807 bitcoind.generate_block(1)
1808
1809 l1.daemon.wait_for_log("but we don't care")
1810
1811 # And lightningd should respect that!
1812 assert not l1.daemon.is_in_log("Can't unwatch txid")
1813
1814 # So these should not generate further messages
1815 for i in range(5):
1816 l1.rpc.withdraw(l1.rpc.newaddr('bech32')['bech32'], 'all')
1817 bitcoind.generate_block(1)
1818 # Make sure it digests the block
1819 sync_blockheight(bitcoind, [l1])
1820
1821 # We won't see this again.
1822 assert not l1.daemon.is_in_log("but we don't care",
1823 start=l1.daemon.logsearch_start)
1824
1825 assert account_balance(l1, channel_id) == 0
1826 assert account_balance(l2, channel_id) == 0
1827 # Note: for this test we leave onchaind running, so we can detect
1828 # any leaks!

Callers

nothing calls this directly

Calls 15

first_channel_idFunction · 0.90
wait_forFunction · 0.90
only_oneFunction · 0.90
sync_blockheightFunction · 0.90
account_balanceFunction · 0.90
joinMethod · 0.80
line_graphMethod · 0.80
listpeerchannelsMethod · 0.80
dev_failMethod · 0.80
wait_for_logMethod · 0.80
generate_blockMethod · 0.80

Tested by

no test coverage detected