Test bwatch handles reorg that happened while node was down
(node_factory, bitcoind)
| 5640 | |
| 5641 | @pytest.mark.slow_test |
| 5642 | def test_bwatch_reorg_at_startup(node_factory, bitcoind): |
| 5643 | """Test bwatch handles reorg that happened while node was down""" |
| 5644 | l1 = node_factory.get_node(options=BWATCH_OPTS) |
| 5645 | |
| 5646 | # Wait for bwatch to initialize and fully sync |
| 5647 | wait_bwatch_caught_up(l1) |
| 5648 | |
| 5649 | bitcoind.generate_block(5) |
| 5650 | expected_height = bitcoind.rpc.getblockcount() |
| 5651 | # Wait for bwatch to catch up to these new blocks |
| 5652 | l1.daemon.wait_for_log(rf'Added block {expected_height} to history', timeout=60) |
| 5653 | |
| 5654 | # Get block hash before stopping |
| 5655 | height = bitcoind.rpc.getblockcount() |
| 5656 | reorg_from_hash = bitcoind.rpc.getblockhash(height - 2) |
| 5657 | |
| 5658 | # Stop the node |
| 5659 | l1.stop() |
| 5660 | |
| 5661 | # Cause a reorg while node is down |
| 5662 | bitcoind.rpc.invalidateblock(reorg_from_hash) |
| 5663 | bitcoind.generate_block(5) |
| 5664 | |
| 5665 | # Restart the node |
| 5666 | l1.start() |
| 5667 | |
| 5668 | # bwatch should detect the chain changed and handle reorg during catch-up |
| 5669 | # (reorg detection happens during catch-up, before "initialized" message) |
| 5670 | l1.daemon.wait_for_log(r'Reorg detected', timeout=60) |
| 5671 | |
| 5672 | # Wait for it to finish syncing |
| 5673 | l1.daemon.wait_for_log(r'No block change') |
| 5674 | |
| 5675 | # Verify the node is tracking the correct chain |
| 5676 | info = l1.rpc.getinfo() |
| 5677 | assert info['blockheight'] == bitcoind.rpc.getblockcount() |
| 5678 | |
| 5679 | |
| 5680 | @pytest.mark.slow_test |
nothing calls this directly
no test coverage detected