forked from LBRYCommunity/lbry-sdk
exit if zmq misconfigured. tell whats wrong
This commit is contained in:
parent
cb60cd99f4
commit
39a4c4e590
4 changed files with 19 additions and 6 deletions
|
@ -15,7 +15,7 @@ import zmq.asyncio
|
||||||
|
|
||||||
from lbry.conf import Config
|
from lbry.conf import Config
|
||||||
from lbry.event import EventController
|
from lbry.event import EventController
|
||||||
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError
|
from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError, LbrycrdMisconfigurationError
|
||||||
|
|
||||||
from .database import BlockchainDB
|
from .database import BlockchainDB
|
||||||
from .ledger import Ledger, RegTestLedger
|
from .ledger import Ledger, RegTestLedger
|
||||||
|
@ -209,6 +209,8 @@ class Lbrycrd:
|
||||||
|
|
||||||
async def ensure_subscribable(self):
|
async def ensure_subscribable(self):
|
||||||
zmq_notifications = await self.get_zmq_notifications()
|
zmq_notifications = await self.get_zmq_notifications()
|
||||||
|
if not zmq_notifications:
|
||||||
|
raise LbrycrdMisconfigurationError("zmqpubhashblock")
|
||||||
subs = {e['type']: e['address'] for e in zmq_notifications}
|
subs = {e['type']: e['address'] for e in zmq_notifications}
|
||||||
if ZMQ_BLOCK_EVENT not in subs:
|
if ZMQ_BLOCK_EVENT not in subs:
|
||||||
raise LbrycrdEventSubscriptionError(ZMQ_BLOCK_EVENT)
|
raise LbrycrdEventSubscriptionError(ZMQ_BLOCK_EVENT)
|
||||||
|
|
|
@ -12,7 +12,7 @@ from lbry.service.base import Sync, BlockEvent
|
||||||
from lbry.blockchain.lbrycrd import Lbrycrd
|
from lbry.blockchain.lbrycrd import Lbrycrd
|
||||||
|
|
||||||
from . import blocks as block_phase, claims as claim_phase, supports as support_phase
|
from . import blocks as block_phase, claims as claim_phase, supports as support_phase
|
||||||
|
from ...error import LbrycrdMisconfigurationError
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -49,6 +49,9 @@ class BlockchainSync(Sync):
|
||||||
return await self.chain.ensure_subscribable()
|
return await self.chain.ensure_subscribable()
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
raise
|
raise
|
||||||
|
except LbrycrdMisconfigurationError as e:
|
||||||
|
log.warning(str(e))
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning("Blockchain not ready, waiting for it: %s", str(e))
|
log.warning("Blockchain not ready, waiting for it: %s", str(e))
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
|
@ -417,3 +417,10 @@ class LbrycrdEventSubscriptionError(LbrycrdError):
|
||||||
def __init__(self, event):
|
def __init__(self, event):
|
||||||
self.event = event
|
self.event = event
|
||||||
super().__init__(f"Lbrycrd is not publishing '{event}' events.")
|
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")
|
||||||
|
|
|
@ -11,7 +11,7 @@ from lbry import Config, Database, RegTestLedger, Transaction, Output, Input
|
||||||
from lbry.crypto.base58 import Base58
|
from lbry.crypto.base58 import Base58
|
||||||
from lbry.schema.claim import Stream, Channel
|
from lbry.schema.claim import Stream, Channel
|
||||||
from lbry.schema.support import Support
|
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.lbrycrd import Lbrycrd
|
||||||
from lbry.blockchain.sync import BlockchainSync
|
from lbry.blockchain.sync import BlockchainSync
|
||||||
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
|
from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies
|
||||||
|
@ -613,14 +613,15 @@ class TestMultiBlockFileSyncing(BasicBlockchainTestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestGeneralBlockchainSync(SyncingBlockchainTestCase):
|
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.sync.stop()
|
||||||
await self.chain.stop()
|
await self.chain.stop()
|
||||||
sync_start = asyncio.create_task(self.sync.start())
|
sync_start = asyncio.create_task(self.sync.start())
|
||||||
await asyncio.sleep(0)
|
await asyncio.sleep(0)
|
||||||
|
self.chain.ledger.conf.set(lbrycrd_zmq_blocks='')
|
||||||
await self.chain.start()
|
await self.chain.start()
|
||||||
await sync_start
|
with self.assertRaises(LbrycrdMisconfigurationError):
|
||||||
self.assertTrue(sync_start.done()) # test goal is to get here without exceptions
|
await asyncio.wait_for(sync_start, timeout=10)
|
||||||
|
|
||||||
async def test_sync_advances(self):
|
async def test_sync_advances(self):
|
||||||
blocks = []
|
blocks = []
|
||||||
|
|
Loading…
Reference in a new issue