Skip to content

Commit

Permalink
fix: improve unnecessary alerts (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco authored Mar 22, 2024
1 parent ded7fef commit 08590e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 4 additions & 3 deletions hathor/p2p/sync_v1/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from weakref import WeakSet

from structlog import get_logger
from twisted.internet.defer import Deferred, inlineCallbacks
from twisted.internet.defer import CancelledError, Deferred, inlineCallbacks
from twisted.internet.interfaces import IDelayedCall

from hathor.conf.get_settings import get_global_settings
Expand Down Expand Up @@ -685,12 +685,13 @@ def on_tx_success(self, tx: 'BaseTransaction') -> 'BaseTransaction':
self.update_received_stats(tx, success)
return tx

def on_get_data_failed(self, reason: 'Failure', hash_bytes: bytes) -> None:
def on_get_data_failed(self, failure: 'Failure', hash_bytes: bytes) -> None:
""" Method called when get_data deferred fails.
We need this errback because otherwise the sync crashes when the deferred is canceled.
We should just log a warning because it will continue the sync and will try to get this tx again.
"""
self.log.warn('failed to download tx', tx=hash_bytes.hex(), reason=reason)
log_func = self.log.debug if isinstance(failure.value, CancelledError) else self.log.warn
log_func('failed to download tx', tx=hash_bytes.hex(), reason=failure)

def is_sync_enabled(self) -> bool:
"""Return True if sync is enabled for this connection."""
Expand Down
5 changes: 3 additions & 2 deletions hathor/p2p/sync_v1/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from structlog import get_logger
from twisted.internet import defer
from twisted.internet.defer import Deferred
from twisted.python.failure import Failure

from hathor.conf.get_settings import get_global_settings
from hathor.transaction.storage.exceptions import TransactionDoesNotExist
Expand Down Expand Up @@ -238,10 +239,10 @@ def on_deferred_timeout(self, result: Any, timeout: int, *, tx_id: bytes) -> Non
"""
self.retry(tx_id)

def on_error(self, result: Any) -> None:
def on_error(self, failure: Failure) -> None:
""" Errback for downloading deferred.
"""
self.log.error('failed to download tx', err=result)
self.log.error('failed to download tx', err=failure, traceback=failure.getTraceback())

def on_new_tx(self, tx: 'BaseTransaction') -> None:
""" This is called when a new transaction arrives.
Expand Down

0 comments on commit 08590e3

Please sign in to comment.