Ejemplo n.º 1
0
        private void runWorkers(BlockMiningParameters blockMiningParameters, uint threadCount)
        {
            Debug.Assert(threadCount > 0);

            m_logger.functorMethod(Logging.Level.INFO) << "Starting mining for difficulty " << blockMiningParameters.difficulty;

            try
            {
                blockMiningParameters.blockTemplate.nonce = Crypto.GlobalMembers.rand <uint>();

                for (uint i = 0; i < threadCount; ++i)
                {
                    m_workers.emplace_back(std::unique_ptr <System.RemoteContext> (new System.RemoteContext(m_dispatcher, std::bind(this.workerFunc, this, blockMiningParameters.blockTemplate, blockMiningParameters.difficulty, (uint)threadCount))));
                    m_logger.functorMethod(Logging.Level.INFO) << "Thread " << i << " started at nonce: " << blockMiningParameters.blockTemplate.nonce;

                    blockMiningParameters.blockTemplate.nonce++;
                }

                m_workers.Clear();
            }
            catch (System.Exception e)
            {
                m_logger.functorMethod(Logging.Level.ERROR) << "Error occurred during mining: " << e.Message;
                m_state = MiningState.MINING_STOPPED;
            }

            m_miningStopped.set();
        }