diff --git a/lbry/blockchain/lbrycrd.py b/lbry/blockchain/lbrycrd.py index a43d5f600..31fc85e14 100644 --- a/lbry/blockchain/lbrycrd.py +++ b/lbry/blockchain/lbrycrd.py @@ -15,7 +15,7 @@ import zmq.asyncio from lbry.conf import Config from lbry.event import EventController -from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError +from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError, LbrycrdMisconfigurationError from .database import BlockchainDB from .ledger import Ledger, RegTestLedger @@ -209,6 +209,8 @@ class Lbrycrd: async def ensure_subscribable(self): zmq_notifications = await self.get_zmq_notifications() + if not zmq_notifications: + raise LbrycrdMisconfigurationError("zmqpubhashblock") subs = {e['type']: e['address'] for e in zmq_notifications} if ZMQ_BLOCK_EVENT not in subs: raise LbrycrdEventSubscriptionError(ZMQ_BLOCK_EVENT) diff --git a/lbry/blockchain/sync/synchronizer.py b/lbry/blockchain/sync/synchronizer.py index 95a68aea2..5bdf3931e 100644 --- a/lbry/blockchain/sync/synchronizer.py +++ b/lbry/blockchain/sync/synchronizer.py @@ -12,7 +12,7 @@ from lbry.service.base import Sync, BlockEvent from lbry.blockchain.lbrycrd import Lbrycrd from . import blocks as block_phase, claims as claim_phase, supports as support_phase - +from ...error import LbrycrdMisconfigurationError log = logging.getLogger(__name__) @@ -49,6 +49,9 @@ class BlockchainSync(Sync): return await self.chain.ensure_subscribable() except asyncio.CancelledError: raise + except LbrycrdMisconfigurationError as e: + log.warning(str(e)) + raise except Exception as e: log.warning("Blockchain not ready, waiting for it: %s", str(e)) await asyncio.sleep(1) diff --git a/lbry/error/__init__.py b/lbry/error/__init__.py index 57086d852..cf0cee4c5 100644 --- a/lbry/error/__init__.py +++ b/lbry/error/__init__.py @@ -417,3 +417,10 @@ class LbrycrdEventSubscriptionError(LbrycrdError): def __init__(self, event): self.event = event super().__init__(f"Lbrycrd is not publishing '{event}' events.") + + +class LbrycrdMisconfigurationError(LbrycrdError): + def __init__(self, config_key): + self.config_key = config_key + super().__init__(f"Lbrycrd is misconfigured. Please double check if" + f" {config_key} is properly set on lbrycrd.conf") diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index 2e94a0990..9e9acfdc9 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -11,7 +11,7 @@ from lbry import Config, Database, RegTestLedger, Transaction, Output, Input from lbry.crypto.base58 import Base58 from lbry.schema.claim import Stream, Channel from lbry.schema.support import Support -from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError +from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError, LbrycrdMisconfigurationError from lbry.blockchain.lbrycrd import Lbrycrd from lbry.blockchain.sync import BlockchainSync from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies @@ -613,14 +613,15 @@ class TestMultiBlockFileSyncing(BasicBlockchainTestCase): class TestGeneralBlockchainSync(SyncingBlockchainTestCase): - async def test_sync_waits_for_lbrycrd_to_start(self): + async def test_sync_exits_if_zmq_is_misconfigured(self): await self.sync.stop() await self.chain.stop() sync_start = asyncio.create_task(self.sync.start()) await asyncio.sleep(0) + self.chain.ledger.conf.set(lbrycrd_zmq_blocks='') await self.chain.start() - await sync_start - self.assertTrue(sync_start.done()) # test goal is to get here without exceptions + with self.assertRaises(LbrycrdMisconfigurationError): + await asyncio.wait_for(sync_start, timeout=10) async def test_sync_advances(self): blocks = []