Skip to content

Commit

Permalink
pytest: test that we refuse to follow bitcoind backwards.
Browse files Browse the repository at this point in the history
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Nov 20, 2019
1 parent dda792c commit e5a6e67
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/test_misc.py
Expand Up @@ -1145,6 +1145,61 @@ def test_rescan(node_factory, bitcoind):
assert not l1.daemon.is_in_log(r'Adding block 102')


@pytest.mark.xfail(strict=True)
def test_bitcoind_goes_backwards(node_factory, bitcoind):
"""Check that we refuse to acknowledge bitcoind giving a shorter chain without explicit rescan"""
l1 = node_factory.get_node(may_fail=True, allow_broken_log=True)

bitcoind.generate_block(10)
sync_blockheight(bitcoind, [l1])
l1.stop()

# Now shrink chain (invalidateblock leaves 'headers' field until restart)
bitcoind.rpc.invalidateblock(bitcoind.rpc.getblockhash(105))
# Restart without killing proxies
bitcoind.rpc.stop()
TailableProc.stop(bitcoind)
bitcoind.start()

# Will simply refuse to start.
with pytest.raises(ValueError):
l1.start()

# Nor will it start with if we ask for a reindex of fewer blocks.
l1.daemon.opts['rescan'] = 3

with pytest.raises(ValueError):
l1.start()

# This will force it, however.
l1.daemon.opts['rescan'] = -100
l1.start()

# Now mess with bitcoind at runtime.
bitcoind.generate_block(6)
sync_blockheight(bitcoind, [l1])

l1.daemon.wait_for_log('Adding block 110')

bitcoind.rpc.invalidateblock(bitcoind.rpc.getblockhash(105))
bitcoind.rpc.stop()
TailableProc.stop(bitcoind)
bitcoind.start()
bitcoind.generate_block(5)

# It will ignore bitcoind and keep asking for block 110.
time.sleep(5)
assert l1.rpc.getinfo()['blockheight'] == 110
assert not l1.daemon.is_in_log('Adding block 109',
start=l1.daemon.logsearch_start)

# Get past that, and it will suddenly read new blocks
bitcoind.generate_block(2)
l1.daemon.wait_for_log('Adding block 109')
l1.daemon.wait_for_log('Adding block 110')
l1.daemon.wait_for_log('Adding block 111')


@flaky
def test_reserve_enforcement(node_factory, executor):
"""Channeld should disallow you spending into your reserve"""
Expand Down

0 comments on commit e5a6e67

Please sign in to comment.