Check that we refuse to acknowledge bitcoind giving a shorter chain without explicit rescan
(node_factory, bitcoind)
| 1678 | |
| 1679 | |
| 1680 | def 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 |
nothing calls this directly
no test coverage detected