async def _mixing_initiate_loop(self): # Task 4. Initiate mixing epochs contract_concise = ConciseContract(self.contract) K = contract_concise.K() # noqa: N806 while True: # Step 4.a. Wait until there are k values then call initiate_mix while True: inputs_ready = contract_concise.inputs_ready() mixes_avail = contract_concise.mixes_available() if inputs_ready >= K and mixes_avail >= 1: break await asyncio.sleep(5) # Step 4.b. Call initiate mix tx_hash = self.contract.functions.initiate_mix().transact( {"from": self.w3.eth.accounts[0]} ) tx_receipt = await wait_for_receipt(self.w3, tx_hash) rich_logs = self.contract.events.MixingEpochInitiated().processReceipt( tx_receipt ) if rich_logs: epoch = rich_logs[0]["args"]["epoch"] logging.info(f"[{self.myid}] Mixing epoch initiated: {epoch}") else: logging.info(f"[{self.myid}] initiate_mix failed (redundant?)") await asyncio.sleep(10)
async def _offline_mixes_loop(self): contract_concise = ConciseContract(self.contract) n = contract_concise.n() t = contract_concise.t() preproc_round = 0 PER_MIX_TRIPLES = contract_concise.PER_MIX_TRIPLES() # noqa: N806 PER_MIX_BITS = contract_concise.PER_MIX_BITS() # noqa: N806 # Start up: await self._preprocess_report() while True: # Step 1a. I) Wait for more triples/bits to be needed while True: mixes_available = contract_concise.mixes_available() # Policy: try to maintain a buffer of mixes target = 10 if mixes_available < target: break # already have enough triples/bits, sleep await asyncio.sleep(5) # Step 1a. II) Run generate triples and generate_bits logging.info(f"[{self.myid}] mixes available: {mixes_available} \ target: {target}") logging.info(f"[{self.myid}] Initiating Triples {PER_MIX_TRIPLES}") send, recv = self.get_send_recv( f"preproc:mixes:triples:{preproc_round}") start_time = time.time() triples = await generate_triples(n, t, PER_MIX_TRIPLES, self.myid, send, recv, field) end_time = time.time() logging.info( f"[{self.myid}] Triples finished in {end_time-start_time}") # Bits logging.info(f"[{self.myid}] Initiating Bits {PER_MIX_BITS}") send, recv = self.get_send_recv( f"preproc:mixes:bits:{preproc_round}") start_time = time.time() bits = await generate_bits(n, t, PER_MIX_BITS, self.myid, send, recv, field) end_time = time.time() logging.info( f"[{self.myid}] Bits finished in {end_time-start_time}") # Append each triple self._triples += triples self._bits += bits # Step 1a. III) Submit an updated report await self._preprocess_report() # Increment the preprocessing round and continue preproc_round += 1