Skip to content

Commit 9444398

Browse files
committed
pytest: two tests for gossip of channels in as-yet-unknown blocks.
Two tests which crash lightningd in different ways. Signed-off-by: Rusty Russell <[email protected]>
1 parent e40f078 commit 9444398

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

tests/test_gossip.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from fixtures import * # noqa: F401,F403
22
from lightning import RpcError
3-
from utils import wait_for, TIMEOUT, only_one
3+
from utils import wait_for, TIMEOUT, only_one, sync_blockheight
44

55
import json
66
import logging
@@ -1317,3 +1317,63 @@ def test_gossip_store_compact_on_load(node_factory, bitcoind):
13171317

13181318
wait_for(lambda: l2.daemon.is_in_log('gossip_store_compact_offline: 9 deleted, 9 copied'))
13191319
wait_for(lambda: l2.daemon.is_in_log(r'gossip_store: Read 1/4/2/0 cannounce/cupdate/nannounce/cdelete from store \(0 deleted\) in 1446 bytes'))
1320+
1321+
1322+
@pytest.mark.xfail(strict=True)
1323+
def test_gossip_announce_invalid_block(node_factory, bitcoind):
1324+
"""bitcoind lags and we might get an announcement for a block we don't have.
1325+
1326+
"""
1327+
# Need to slow down the poll interval so the announcement preceeds the
1328+
# blockchain catchup, otherwise we won't call `getfilteredblock`.
1329+
opts = {}
1330+
if DEVELOPER:
1331+
opts['dev-bitcoind-poll'] = TIMEOUT // 2
1332+
1333+
l1 = node_factory.get_node(options=opts)
1334+
bitcoind.generate_block(1)
1335+
assert bitcoind.rpc.getblockchaininfo()['blocks'] == 102
1336+
1337+
# Test gossip for an unknown block.
1338+
subprocess.run(['devtools/gossipwith',
1339+
'--max-messages=0',
1340+
'{}@localhost:{}'.format(l1.info['id'], l1.port),
1341+
# short_channel_id=103x1x1
1342+
'01008d9f3d16dbdd985c099b74a3c9a74ccefd52a6d2bd597a553ce9a4c7fac3bfaa7f93031932617d38384cc79533730c9ce875b02643893cacaf51f503b5745fc3aef7261784ce6b50bff6fc947466508b7357d20a7c2929cc5ec3ae649994308527b2cbe1da66038e3bfa4825b074237708b455a4137bdb541cf2a7e6395a288aba15c23511baaae722fdb515910e2b42581f9c98a1f840a9f71897b4ad6f9e2d59e1ebeaf334cf29617633d35bcf6e0056ca0be60d7c002337bbb089b1ab52397f734bcdb2e418db43d1f192195b56e60eefbf82acf043d6068a682e064db23848b4badb20d05594726ec5b59267f4397b093747c23059b397b0c5620c4ab37a000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f0000670000010001022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d029053521d6ea7a52cdd55f733d0fb2d077c0373b0053b5b810d927244061b757302d6063d022691b2490ab454dee73a57c6ff5d308352b461ece69f3c284f2c2412'],
1343+
check=True, timeout=TIMEOUT)
1344+
1345+
# Make sure it's OK once it's caught up.
1346+
sync_blockheight(bitcoind, [l1])
1347+
1348+
1349+
@pytest.mark.xfail(strict=True)
1350+
def test_gossip_announce_unknown_block(node_factory, bitcoind):
1351+
"""Don't backfill the future!
1352+
1353+
If we get a channel_announcement that is for a block height that is above
1354+
our sync height we should not store the filteredblock in the blocks table,
1355+
otherwise we end up with a duplicate when we finally catch up with the
1356+
blockchain.
1357+
1358+
"""
1359+
# Need to slow down the poll interval so the announcement preceeds the
1360+
# blockchain catchup, otherwise we won't call `getfilteredblock`.
1361+
opts = {}
1362+
if DEVELOPER:
1363+
opts['dev-bitcoind-poll'] = TIMEOUT // 2
1364+
1365+
l1 = node_factory.get_node(options=opts)
1366+
1367+
bitcoind.generate_block(2)
1368+
assert bitcoind.rpc.getblockchaininfo()['blocks'] == 103
1369+
1370+
# Test gossip for unknown block.
1371+
subprocess.run(['devtools/gossipwith',
1372+
'--max-messages=0',
1373+
'{}@localhost:{}'.format(l1.info['id'], l1.port),
1374+
# short_channel_id=103x1x1
1375+
'01008d9f3d16dbdd985c099b74a3c9a74ccefd52a6d2bd597a553ce9a4c7fac3bfaa7f93031932617d38384cc79533730c9ce875b02643893cacaf51f503b5745fc3aef7261784ce6b50bff6fc947466508b7357d20a7c2929cc5ec3ae649994308527b2cbe1da66038e3bfa4825b074237708b455a4137bdb541cf2a7e6395a288aba15c23511baaae722fdb515910e2b42581f9c98a1f840a9f71897b4ad6f9e2d59e1ebeaf334cf29617633d35bcf6e0056ca0be60d7c002337bbb089b1ab52397f734bcdb2e418db43d1f192195b56e60eefbf82acf043d6068a682e064db23848b4badb20d05594726ec5b59267f4397b093747c23059b397b0c5620c4ab37a000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f0000670000010001022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d029053521d6ea7a52cdd55f733d0fb2d077c0373b0053b5b810d927244061b757302d6063d022691b2490ab454dee73a57c6ff5d308352b461ece69f3c284f2c2412'],
1376+
check=True, timeout=TIMEOUT)
1377+
1378+
# Make sure it's OK once it's caught up.
1379+
sync_blockheight(bitcoind, [l1])

0 commit comments

Comments
 (0)