pytest: protect against bad gossip messages from mining confirms too fast.

If we fund a channel between two nodes, then mine all the blocks to
announce it, any other nodes may see the announcement before the
blocks, causing CI to complain about "bad gossip":

```
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Ignoring future channel_announcment for 113x1x1 (current block 112)
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Bad gossip order: WIRE_CHANNEL_UPDATE before announcement 113x1x1/0
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Bad gossip order: WIRE_CHANNEL_UPDATE before announcement 113x1x1/1
lightningd-4: 2022-01-25T22:33:25.468Z DEBUG   032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e-gossipd: Bad gossip order: WIRE_NODE_ANNOUNCEMENT before announcement 032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e
```

Add a new helper for this case, and use it where there are more than 2 nodes.

Cleans up test_routing_gossip and a few other places which did this manually.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-01-30 14:07:23 +10:30
parent 6d9f6ffd67
commit e8d2176e6b
9 changed files with 77 additions and 82 deletions

View File

@@ -11,7 +11,7 @@ from utils import (
expected_channel_features,
check_coin_moves, first_channel_id, account_balance, basic_fee,
scriptpubkey_addr,
EXPERIMENTAL_FEATURES
EXPERIMENTAL_FEATURES, mine_funding_to_announce
)
from pyln.testing.utils import SLOW_MACHINE, VALGRIND, EXPERIMENTAL_DUAL_FUND, FUNDAMOUNT
@@ -2556,7 +2556,7 @@ def test_disconnectpeer(node_factory, bitcoind):
# Fund channel l1 -> l3
l1.fundchannel(l3, 10**6)
bitcoind.generate_block(5)
mine_funding_to_announce(bitcoind, [l1, l2, l3])
# disconnecting a non gossiping peer results in error
with pytest.raises(RpcError, match=r'Peer is in state CHANNELD_NORMAL'):
@@ -2945,11 +2945,9 @@ def test_restart_many_payments(node_factory, bitcoind):
# OK to use change from previous fundings
l1.rpc.fundchannel(n.info['id'], 10**6, minconf=0)
# Now mine them, get scids; make sure they all see the first block
# otherwise they may complain about channel_announcement from the future.
bitcoind.generate_block(1, wait_for_mempool=num * 2)
sync_blockheight(bitcoind, [l1] + nodes)
bitcoind.generate_block(5)
# Now mine them, get scids
mine_funding_to_announce(bitcoind, [l1] + nodes,
num_blocks=6, wait_for_mempool=num * 2)
wait_for(lambda: [only_one(n.rpc.listpeers()['peers'])['channels'][0]['state'] for n in nodes] == ['CHANNELD_NORMAL'] * len(nodes))