class LightPeerChainBridgePlugin(BaseAsyncStopPlugin): """ The ``LightPeerChainBridgePlugin`` runs in the ``networking`` process and acts as a bridge between other processes and the ``LightPeerChain``. It runs only in ``light`` mode. Other plugins can instantiate the ``EventBusLightPeerChain`` from separate processes to interact with the ``LightPeerChain`` indirectly. """ chain: BaseChain = None handler: LightPeerChainEventBusHandler = None @property def name(self) -> str: return "LightPeerChain Bridge" def ready(self) -> None: if self.context.trinity_config.sync_mode != SYNC_LIGHT: return self.event_bus.subscribe( ResourceAvailableEvent, self.handle_event ) def should_start(self) -> bool: return self.chain is not None and self.context.trinity_config.sync_mode == SYNC_LIGHT def handle_event(self, event: ResourceAvailableEvent) -> None: if event.resource_type is BaseChain: self.chain = event.resource self.start() def _start(self) -> None: chain = cast(LightDispatchChain, self.chain) self.handler = LightPeerChainEventBusHandler(chain._peer_chain, self.context.event_bus) asyncio.ensure_future(self.handler.run()) async def _stop(self) -> None: # This isn't really needed for the standard shutdown case as the LightPeerChain will # automatically shutdown whenever the `CancelToken` it was chained with is triggered. # It may still be useful to stop the LightPeerChain Bridge plugin individually though. if self.handler.is_operational: await self.handler.cancel() self.logger.info("Successfully stopped LightPeerChain Bridge")
def _start(self) -> None: chain = cast(LightDispatchChain, self.chain) self.handler = LightPeerChainEventBusHandler(chain._peer_chain, self.context.event_bus) asyncio.ensure_future(self.handler.run())
def start(self) -> None: self.logger.info('LightPeerChain Bridge started') chain = cast(LightDispatchChain, self.chain) handler = LightPeerChainEventBusHandler(chain._peer_chain, self.context.event_bus) asyncio.ensure_future(handler.run())