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

Function test_bitcoind_goes_backwards

tests/test_misc.py:1680–1736  ·  view source on GitHub ↗

Check that we refuse to acknowledge bitcoind giving a shorter chain without explicit rescan

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1678
1679
1680def test_bitcoind_goes_backwards(node_factory, bitcoind):
1681 """Check that we refuse to acknowledge bitcoind giving a shorter chain without explicit rescan"""
1682 l1 = node_factory.get_node(may_fail=True)
1683
1684 bitcoind.generate_block(10)
1685 sync_blockheight(bitcoind, [l1])
1686 l1.stop()
1687
1688 # Now shrink chain (invalidateblock leaves 'headers' field until restart)
1689 bitcoind.rpc.invalidateblock(bitcoind.rpc.getblockhash(105))
1690 # Restart without killing proxies
1691 bitcoind.rpc.stop()
1692 TailableProc.stop(bitcoind)
1693 bitcoind.start()
1694
1695 # Will simply refuse to start.
1696 l1.daemon.start(wait_for_initialized=False, stderr_redir=True)
1697 # Will exit with failure code.
1698 assert l1.daemon.wait() == 1
1699 assert l1.daemon.is_in_stderr('bitcoind has gone backwards')
1700
1701 # Nor will it start with if we ask for a reindex of fewer blocks.
1702 l1.daemon.opts['rescan'] = 3
1703
1704 # Will simply refuse to start.
1705 l1.daemon.start(wait_for_initialized=False, stderr_redir=True)
1706 # Will exit with failure code.
1707 assert l1.daemon.wait() == 1
1708 assert l1.daemon.is_in_stderr('bitcoind has gone backwards')
1709
1710 # This will force it, however.
1711 l1.daemon.opts['rescan'] = -100
1712 l1.start()
1713
1714 # Now mess with bitcoind at runtime.
1715 bitcoind.generate_block(6)
1716 sync_blockheight(bitcoind, [l1])
1717
1718 l1.daemon.wait_for_log('Adding block 110')
1719
1720 bitcoind.rpc.invalidateblock(bitcoind.rpc.getblockhash(105))
1721 bitcoind.rpc.stop()
1722 TailableProc.stop(bitcoind)
1723 bitcoind.start()
1724 bitcoind.generate_block(5)
1725
1726 # It will ignore bitcoind and keep asking for block 110.
1727 time.sleep(5)
1728 assert l1.rpc.getinfo()['blockheight'] == 110
1729 assert not l1.daemon.is_in_log('Adding block 109',
1730 start=l1.daemon.logsearch_start)
1731
1732 # Get past that, and it will suddenly read new blocks
1733 bitcoind.generate_block(2)
1734 l1.daemon.wait_for_log('Adding block 109')
1735 l1.daemon.wait_for_log('Adding block 110')
1736 l1.daemon.wait_for_log('Adding block 111')
1737

Callers

nothing calls this directly

Calls 10

sync_blockheightFunction · 0.90
generate_blockMethod · 0.80
is_in_stderrMethod · 0.80
wait_for_logMethod · 0.80
is_in_logMethod · 0.80
get_nodeMethod · 0.45
stopMethod · 0.45
startMethod · 0.45
waitMethod · 0.45
getinfoMethod · 0.45

Tested by

no test coverage detected