Skip to content

Commit

Permalink
chore(p2p): Add stop to delayed calls
Browse files Browse the repository at this point in the history
  • Loading branch information
alexruzenhack committed Jun 7, 2023
1 parent 695e0da commit 542225d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hathor/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 5 additions & 0 deletions hathor/p2p/node_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 542225d

Please sign in to comment.