MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_gossip_throttle

Function test_gossip_throttle

tests/test_gossip.py:2166–2256  ·  view source on GitHub ↗

Make some gossip, test it gets throttled

(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

2164
2165
2166def test_gossip_throttle(node_factory, bitcoind, chainparams):
2167 """Make some gossip, test it gets throttled"""
2168 l1, l2, l3, l4 = node_factory.line_graph(4, wait_for_announce=True,
2169 opts=[{}, {}, {},
2170 {'broken_log': 'Throttling incoming peer',
2171 'dev-throttle-gossip': None}])
2172
2173 # We expect: self-advertizement (3 messages for l1 and l4) plus
2174 # 4 node announcements, 3 channel announcements and 6 channel updates.
2175 expected = 4 + 4 + 3 + 6
2176
2177 # l1 is unlimited
2178 start_fast = time.time()
2179 out1 = subprocess.run(['devtools/gossipwith',
2180 '--all-gossip',
2181 '--hex',
2182 '--network={}'.format(TEST_NETWORK),
2183 '--filter=256,257,258',
2184 '--max-messages={}'.format(expected),
2185 '{}@localhost:{}'.format(l1.info['id'], l1.port)],
2186 check=True,
2187 timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
2188 time_fast = time.time() - start_fast
2189 assert time_fast < 2
2190
2191 # l4 is throttled
2192 start_slow = time.time()
2193 out2 = subprocess.run(['devtools/gossipwith',
2194 '--all-gossip',
2195 '--hex',
2196 '--network={}'.format(TEST_NETWORK),
2197 '--filter=256,257,258',
2198 '--max-messages={}'.format(expected),
2199 '{}@localhost:{}'.format(l4.info['id'], l4.port)],
2200 check=True,
2201 timeout=TIMEOUT, stdout=subprocess.PIPE).stdout.split()
2202 time_slow = time.time() - start_slow
2203 assert time_slow > 3
2204
2205 # Contents should be identical (once uniquified, since each
2206 # doubles-up on its own gossip)
2207 assert set(out1) == set(out2)
2208
2209 encoded = subprocess.run(['devtools/mkencoded', '--scids', '00',
2210 first_scid(l1, l2),
2211 first_scid(l2, l3),
2212 first_scid(l3, l4)],
2213 check=True,
2214 timeout=TIMEOUT,
2215 stdout=subprocess.PIPE).stdout.strip().decode()
2216
2217 query = subprocess.run(['devtools/mkquery',
2218 'query_short_channel_ids',
2219 chainparams['chain_hash'],
2220 encoded,
2221 # We want channel announce, updates and node ann.
2222 '00', '1F1F1F'],
2223 check=True,

Callers

nothing calls this directly

Calls 4

first_scidFunction · 0.90
line_graphMethod · 0.80
runMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected