def _stratum_deferred_resolve(self, tx: Transaction, request: Request) -> None: """ Method called after stratum resolves tx proof of work We remove the mining data of this tx on stratum and start a new thread to verify the tx """ funds_hash = tx.get_funds_hash() tx = self.manager.stratum_factory.mined_txs[funds_hash] # Delete it to avoid memory leak del(self.manager.stratum_factory.mined_txs[funds_hash]) deferred = threads.deferToThreadPool(reactor, self.manager.pow_thread_pool, self._stratum_thread_verify, tx) deferred.addCallback(self._cb_tx_resolve, request) deferred.addErrback(self._err_tx_resolve, request)
def mine_transaction(self, tx: Transaction, deferred: Deferred) -> None: """ Puts the transaction in a queue of transactions to be mined via Stratum protocol. """ self.log.info('mine transaction', tx=tx) tx_hash = tx.get_funds_hash() if tx_hash in self.mining_tx_pool: self.log.warn('tried to mine a transaction twice or a twin') return self.mining_tx_pool[tx_hash] = tx self.tx_queue.append(tx_hash) self.deferreds_tx[tx_hash] = deferred