exit if zmq misconfigured. tell whats wrong

This commit is contained in:
Victor Shyba 2020-09-11 14:03:58 -03:00
parent cb60cd99f4
commit 39a4c4e590
4 changed files with 19 additions and 6 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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")

View file

@ -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 = []