Browse Source

lnpeer: disable msg processing rate-limiting in tests

patch-4
SomberNight 3 years ago
parent
commit
12f3525df0
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 7
      electrum/lnpeer.py
  2. 24
      electrum/tests/test_lnpeer.py

7
electrum/lnpeer.py

@ -69,6 +69,8 @@ class Peer(Logger):
SPAMMY_MESSAGES = (
'ping', 'pong', 'channel_announcement', 'node_announcement', 'channel_update',)
DELAY_INC_MSG_PROCESSING_SLEEP = 0.01
def __init__(
self,
lnworker: Union['LNGossip', 'LNWallet'],
@ -479,7 +481,10 @@ class Peer(Logger):
raise GracefulDisconnect(f'initialize failed: {repr(e)}') from e
async for msg in self.transport.read_messages():
self.process_message(msg)
await asyncio.sleep(.01)
if self.DELAY_INC_MSG_PROCESSING_SLEEP:
# rate-limit message-processing a bit, to make it harder
# for a single peer to bog down the event loop / cpu:
await asyncio.sleep(self.DELAY_INC_MSG_PROCESSING_SLEEP)
def on_reply_short_channel_ids_end(self, payload):
self.querying.set()

24
electrum/tests/test_lnpeer.py

@ -283,6 +283,10 @@ def transport_pair(k1, k2, name1, name2):
return t1, t2
class PeerInTests(Peer):
DELAY_INC_MSG_PROCESSING_SLEEP = 0 # disable rate-limiting
class SquareGraph(NamedTuple):
# A
# high fee / \ low fee
@ -354,8 +358,8 @@ class TestPeer(TestCaseForTestnet):
w1 = MockLNWallet(local_keypair=k1, chans=[alice_channel], tx_queue=q1, name=bob_channel.name)
w2 = MockLNWallet(local_keypair=k2, chans=[bob_channel], tx_queue=q2, name=alice_channel.name)
self._lnworkers_created.extend([w1, w2])
p1 = Peer(w1, k2.pubkey, t1)
p2 = Peer(w2, k1.pubkey, t2)
p1 = PeerInTests(w1, k2.pubkey, t1)
p2 = PeerInTests(w2, k1.pubkey, t2)
w1._peers[p1.pubkey] = p1
w2._peers[p2.pubkey] = p2
# mark_open won't work if state is already OPEN.
@ -409,14 +413,14 @@ class TestPeer(TestCaseForTestnet):
w_c = MockLNWallet(local_keypair=key_c, chans=[chan_ca, chan_cd], tx_queue=txq_c, name="carol")
w_d = MockLNWallet(local_keypair=key_d, chans=[chan_db, chan_dc], tx_queue=txq_d, name="dave")
self._lnworkers_created.extend([w_a, w_b, w_c, w_d])
peer_ab = Peer(w_a, key_b.pubkey, trans_ab)
peer_ac = Peer(w_a, key_c.pubkey, trans_ac)
peer_ba = Peer(w_b, key_a.pubkey, trans_ba)
peer_bd = Peer(w_b, key_d.pubkey, trans_bd)
peer_ca = Peer(w_c, key_a.pubkey, trans_ca)
peer_cd = Peer(w_c, key_d.pubkey, trans_cd)
peer_db = Peer(w_d, key_b.pubkey, trans_db)
peer_dc = Peer(w_d, key_c.pubkey, trans_dc)
peer_ab = PeerInTests(w_a, key_b.pubkey, trans_ab)
peer_ac = PeerInTests(w_a, key_c.pubkey, trans_ac)
peer_ba = PeerInTests(w_b, key_a.pubkey, trans_ba)
peer_bd = PeerInTests(w_b, key_d.pubkey, trans_bd)
peer_ca = PeerInTests(w_c, key_a.pubkey, trans_ca)
peer_cd = PeerInTests(w_c, key_d.pubkey, trans_cd)
peer_db = PeerInTests(w_d, key_b.pubkey, trans_db)
peer_dc = PeerInTests(w_d, key_c.pubkey, trans_dc)
w_a._peers[peer_ab.pubkey] = peer_ab
w_a._peers[peer_ac.pubkey] = peer_ac
w_b._peers[peer_ba.pubkey] = peer_ba

Loading…
Cancel
Save