From 3b2b8f814c22acee5c8c08df04e854a441044e0f Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Wed, 29 Jun 2022 12:18:34 -0400 Subject: [PATCH] add wait_until_block testing helper to BlockchainProcessorService --- hub/scribe/service.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hub/scribe/service.py b/hub/scribe/service.py index 468c871..8eadb30 100644 --- a/hub/scribe/service.py +++ b/hub/scribe/service.py @@ -56,6 +56,7 @@ class BlockchainProcessorService(BlockchainService): self.wait_for_blocks_duration = 0.1 self._ready_to_stop = asyncio.Event() self.blocks_event = asyncio.Event() + self.advanced = asyncio.Event() self.prefetcher = Prefetcher(self.daemon, env.coin, self.blocks_event) self._caught_up_event: Optional[asyncio.Event] = None self.height = 0 @@ -226,6 +227,7 @@ class BlockchainProcessorService(BlockchainService): "applying extended claim expiration fork on claims accepted by, %i", self.height ) await self.run_in_thread_with_lock(self.db.apply_expiration_extension_fork) + self.advanced.set() except: self.log.exception("advance blocks failed") raise @@ -271,6 +273,13 @@ class BlockchainProcessorService(BlockchainService): 'resetting the prefetcher') await self.prefetcher.reset_height(self.height) + async def wait_until_block(self, height: int): + while self.height < height: + await self.advanced.wait() + self.advanced.clear() + if self.height >= height: + break + def _add_claim_or_update(self, height: int, txo: 'TxOutput', tx_hash: bytes, tx_num: int, nout: int, spent_claims: typing.Dict[bytes, typing.Tuple[int, int, str]], first_input: 'TxInput'): try: