diff --git a/hathor/p2p/sync_v1/agent.py b/hathor/p2p/sync_v1/agent.py index 110514a83..a1a03a27b 100644 --- a/hathor/p2p/sync_v1/agent.py +++ b/hathor/p2p/sync_v1/agent.py @@ -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 @@ -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.""" diff --git a/hathor/p2p/sync_v1/downloader.py b/hathor/p2p/sync_v1/downloader.py index 670b1133a..2b3b786bc 100644 --- a/hathor/p2p/sync_v1/downloader.py +++ b/hathor/p2p/sync_v1/downloader.py @@ -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 @@ -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.