Skip to content

Commit bd1f8db

Browse files
pytest: test gossip_store loading of spam node announcement before channel update
1 parent 846cec4 commit bd1f8db

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tests/test_gossip.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,3 +2383,85 @@ def test_dump_own_gossip(node_factory):
23832383

23842384
# We should get exactly what we expected.
23852385
assert expect == []
2386+
2387+
2388+
@pytest.mark.xfail
2389+
@pytest.mark.developer("needs --dev-gossip-time")
2390+
def test_read_spam_nannounce(node_factory, bitcoind):
2391+
"""issue #6531 lead to a node announcement not being deleted from
2392+
the gossip_store."""
2393+
"""broadcastable and spam node announcements should be loaded properly when
2394+
reading the gossip_store - even when they are both pending a channel
2395+
update."""
2396+
opts = {'dev-gossip-time': 1691773540}
2397+
l1 = node_factory.get_node(start=False, opts=opts)
2398+
canned_store = (
2399+
"0c" # Gossip store version byte
2400+
"0000" # length flags
2401+
"01b0" # length
2402+
"d163af25" # checksum
2403+
"64d66a3a" # timestamp
2404+
# Channel announcement
2405+
"010000335733f5942df5d950eb8766dee3a9d6626922844ed6ae7a110dd7e7edc32e3f6f3d9ac5cdea23ce25bb8dbf761fd3d5fc56c05b6856316d12e9d32ca0f08c69ca0306fe716e7b5151317d6440b7373d9fbc646ead48f2163f2b6d511afe6a79c75551c2620fc80974f2f864329d9778a08cdfbc9f2c9c1344c432702c66807cfb4db69b80fae8c33c70143d948b36614d620891bee2df99c86bc62207c17e3b9186214c0ccff2ded5598accc90eb1d5b2f7a83cd7f68d712ea047d8019f343063b0a236356a387146f58fa832ddc13c4714522cbb503f5f3ca8fcec6602be2438ad3f98fa0ceed58fe3a066d385fcacd98c704b2a8e98a3e20bf76b35b736000006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f0000670000010000022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d029053521d6ea7a52cdd55f733d0fb2d077c0373b0053b5b810d927244061b757302d6063d022691b2490ab454dee73a57c6ff5d308352b461ece69f3c284f2c2412"
2406+
# Channel Amount
2407+
"0000000a911183f600000000"
2408+
"100500000000000f4240"
2409+
# broadcastable node announcement (rgb=000006)
2410+
"0000009558061a6c64d66a5d"
2411+
"0101181c00878e7232991d7f80f5cdb904aa3a35d3751317df5ae3e4649ffd1340f5765bafee78e0597450de542f65a5a561137e1e5f238e2fe319777a0eae22fa85000788a0000a0269a264d66a5d022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d5900000653494c454e544152544953542d3536392d67303030643963302d6d6f646465640000"
2412+
# Rate-limited node announcment (rgb=000007)
2413+
"20000095734d7eec64d66a62"
2414+
"010118ca1b68e4b496b1a499821ceda8f839ea4aac8629cb5faa61b11dd0e647b64f68e6cce18fe1a71594b68253eb47c6d5a09f175fcd1d9fb7de53c25c367aa028000788a0000a0269a264d66a62022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d5900000753494c454e544152544953542d3536392d67303030643963302d6d6f646465640000"
2415+
# Channel Update
2416+
"0000008a0234021c64d66a61"
2417+
"010242ce9d9e79f939399ea1291c04fffcafdfa911246464a4b48c16b7b816dd57b4168562a6c519eb31c37718b68bdfc6345d7c2db663b8b04a3558ce7736c5b61706226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000067000001000064d66a6101000006000000000000000000000015000003e8000000003b023380"
2418+
# Channel Update
2419+
"0000008acd55fcb264d66a61"
2420+
"01023f5dd1f69f675a71d2a7a34956b26f12c4fe9ee287a8449a3eb7b756c583e3bb1334a8eb7c3e148d0f43e08b95c50017ba62da9a7843fe4850a3cb3c74dc5e2c06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000067000001000064d66a6101010006000000000000000000000015000003e8000000003b023380"
2421+
)
2422+
with open(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, 'gossip_store'), 'wb') as f:
2423+
f.write(bytearray.fromhex(canned_store))
2424+
2425+
# initial_funding_tx = '02000000000101b92be26cfc25043affb7778693cca3595e1e1692132c7df2663722ae16fdb33b0000000000fdffffff02b32ad829010000001600148b9062396f94f32ffa5829345d2377d74ffea04bc0c62d000000000016001427213e2217b4f56bd19b6c8393dc9f61be691233024730440220515ffaa8a7a086cd266a0e7fb623632e658749afa9f7a4de551008350722b60802206f253f6aaf61033c751cc77a9686d6d4c54e1bf19e12e73273d8fc81d345950d012102bf081980b5be8074162ba66d0528da1d153c619c084b51b6869c68327cb1c84965000000'
2426+
# bitcoind.rpc.sendrawtransaction(initial_funding_tx)
2427+
bitcoind.generate_block(1)
2428+
tx = bitcoind.rpc.createrawtransaction(
2429+
[],
2430+
[
2431+
# Fundrawtransaction will fill in the first output with the change
2432+
{"bcrt1qpd7nwe3jrt07st89uy82nn2xrmqtxyzqpty5ygt6w546lf6n0wcskswjvh": 0.01000000}
2433+
]
2434+
)
2435+
tx = bitcoind.rpc.fundrawtransaction(tx, {'changePosition': 0})['hex']
2436+
tx = bitcoind.rpc.signrawtransactionwithwallet(tx)['hex']
2437+
txid = bitcoind.rpc.sendrawtransaction(tx)
2438+
wait_for(lambda: txid in bitcoind.rpc.getrawmempool())
2439+
bitcoind.generate_block(6)
2440+
l1.start()
2441+
# retrieves node info originating from the spam announcement
2442+
node_info = l1.rpc.listnodes('022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59')
2443+
assert only_one(node_info['nodes'])['color'] == '000007'
2444+
2445+
out = subprocess.run(['devtools/gossipwith',
2446+
'--initial-sync',
2447+
'--timeout-after={}'.format(int(math.sqrt(TIMEOUT) + 1)),
2448+
'--hex',
2449+
'{}@localhost:{}'.format(l1.info['id'], l1.port)],
2450+
check=True,
2451+
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.decode()
2452+
2453+
received_broadcastable = False
2454+
received_spam = False
2455+
for message in out.splitlines():
2456+
gos = subprocess.run(['devtools/decodemsg', message], check=True,
2457+
timeout=TIMEOUT,
2458+
stdout=subprocess.PIPE).stdout.decode()
2459+
2460+
for line in gos.splitlines():
2461+
if 'rgb_color=[000006]' in line:
2462+
received_broadcastable = True
2463+
if 'rgb_color=[000007]' in line:
2464+
received_spam = True
2465+
2466+
assert received_broadcastable
2467+
assert not received_spam

0 commit comments

Comments
 (0)