Skip to content

Commit

Permalink
pytest: test_gossip_ratelimit checks routing graph and squelch
Browse files Browse the repository at this point in the history
  • Loading branch information
endothermicdev authored and rustyrussell committed Jul 6, 2022
1 parent 9dc794d commit 08a2b3b
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions tests/test_gossip.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ def test_gossip_ratelimit(node_factory, bitcoind):
"""Check that we ratelimit incoming gossip.
We create a partitioned network, in which the first partition consisting
of l1 and l2 is used to create an on-chain footprint and twe then feed
of l1 and l2 is used to create an on-chain footprint and we then feed
canned gossip to the other partition consisting of l3. l3 should ratelimit
the incoming gossip.
Expand Down Expand Up @@ -1863,13 +1863,32 @@ def channel_fees(node):
'0102c479b7684b9db496b844f6925f4ffd8a27c5840a020d1b537623c1545dcd8e195776381bbf51213e541a853a4a49a0faf84316e7ccca5e7074901a96bbabe04e06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00006700000100015d77400201010006000000000000000000000014000003eb000000003b023380',
# timestamp=1568096259, fee_proportional_millionths=1004
'01024b866012d995d3d7aec7b7218a283de2d03492dbfa21e71dd546ec2e36c3d4200453420aa02f476f99c73fe1e223ea192f5fa544b70a8319f2a216f1513d503d06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00006700000100015d77400301010006000000000000000000000014000003ec000000003b023380',
# update 5 marks you as a nasty spammer!
# update 5 marks you as a nasty spammer, but we listen to you anyway now! fee_proportional_millionths=1005
'01025b5b5a0daed874ab02bd3356d38190ff46bbaf5f10db5067da70f3ca203480ca78059e6621c6143f3da4e454d0adda6d01a9980ed48e71ccd0c613af73570a7106226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00006700000100015d77400401010006000000000000000000000014000003ed000000003b023380'
],
timeout=TIMEOUT
)
# Rate limited channel_update okay to use in routing graph.
wait_for(lambda: channel_fees(l3) == [1005])
# but should be flagged so we don't propagate to the network.
assert(l3.daemon.is_in_log("Spammy update for 103x1x1/1 flagged"))

wait_for(lambda: channel_fees(l3) == [1004])
# ask for a gossip sync
raw = subprocess.run(['devtools/gossipwith',
'--initial-sync',
'--timeout-after={}'.format(1),
'--hex',
'{}@localhost:{}'.format(l3.info['id'], l3.port)],
check=True,
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout
# The last message is the most recent channel update.
message = raw.decode('utf-8').split()[-1]
decoded = subprocess.run(['devtools/decodemsg', message],
check=True,
timeout=TIMEOUT,
stdout=subprocess.PIPE).stdout.decode('utf8')
# Used in routing graph, but not passed to gossip peers.
assert("fee_proportional_millionths=1005" not in decoded)

# 24 seconds later, it will accept another.
l3.rpc.call('dev-gossip-set-time', [1568096251 + 24])
Expand All @@ -1882,6 +1901,20 @@ def channel_fees(node):
check=True, timeout=TIMEOUT)

wait_for(lambda: channel_fees(l3) == [1006])
raw = subprocess.run(['devtools/gossipwith',
'--initial-sync',
'--timeout-after={}'.format(1),
'--hex',
'{}@localhost:{}'.format(l3.info['id'], l3.port)],
check=True,
timeout=TIMEOUT, stdout=subprocess.PIPE).stdout
message = raw.decode('utf-8').split()[-1]
decoded = subprocess.run(['devtools/decodemsg', message],
check=True,
timeout=TIMEOUT,
stdout=subprocess.PIPE).stdout.decode('utf8')

assert("fee_proportional_millionths=1006" in decoded)


def check_socket(ip_addr, port):
Expand Down

0 comments on commit 08a2b3b

Please sign in to comment.