From 542225d63822b920389d4de3f80b599799fb0fd7 Mon Sep 17 00:00:00 2001 From: Alex Ruzenhack Date: Wed, 7 Jun 2023 18:30:44 +0100 Subject: [PATCH] chore(p2p): Add stop to delayed calls --- hathor/conf/settings.py | 3 +++ hathor/p2p/node_sync.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/hathor/conf/settings.py b/hathor/conf/settings.py index 7aaa14322..1eebd974f 100644 --- a/hathor/conf/settings.py +++ b/hathor/conf/settings.py @@ -392,6 +392,9 @@ def MAXIMUM_NUMBER_OF_HALVINGS(self) -> int: # All settings related to Feature Activation FEATURE_ACTIVATION: FeatureActivationSettings = FeatureActivationSettings() + # Maximum number of GET_TIPS delayed calls while running sync. + MAX_GET_TIPS_DELAYED_CALLS: int = 5 + @classmethod def from_yaml(cls, *, filepath: str) -> 'HathorSettings': """Takes a filepath to a yaml file and returns a validated HathorSettings instance.""" diff --git a/hathor/p2p/node_sync.py b/hathor/p2p/node_sync.py index 7df58b7e2..994ef636f 100644 --- a/hathor/p2p/node_sync.py +++ b/hathor/p2p/node_sync.py @@ -623,6 +623,11 @@ def send_tips(self, timestamp: Optional[int] = None, include_hashes: bool = Fals """Try to send a TIPS message. If rate limit has been reached, it schedules to send it later.""" if not self.global_rate_limiter.add_hit(self.GlobalRateLimiter.SEND_TIPS): self.log.debug('send_tips throttled') + if len(self._send_tips_call_later) > settings.MAX_GET_TIPS_DELAYED_CALLS: + self.protocol.send_error_and_close_connection( + 'Too many GET_TIPS message' + ) + return self._send_tips_call_later.append( self.reactor.callLater( 1, self.send_tips, timestamp, include_hashes, offset