Beispiel #1
0
        public BlockTemplate mine(BlockMiningParameters blockMiningParameters, uint threadCount)
        {
            if (threadCount == 0)
            {
                throw new System.Exception("Miner requires at least one thread");
            }

            if (m_state == MiningState.MINING_IN_PROGRESS)
            {
                throw new System.Exception("Mining is already in progress");
            }

            m_state = MiningState.MINING_IN_PROGRESS;
            m_miningStopped.clear();

//C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
//ORIGINAL LINE: runWorkers(blockMiningParameters, threadCount);
            runWorkers(new CryptoNote.BlockMiningParameters(blockMiningParameters), new uint(threadCount));

            Debug.Assert(m_state != MiningState.MINING_IN_PROGRESS);
            if (m_state == MiningState.MINING_STOPPED)
            {
                m_logger.functorMethod(Logging.Level.DEBUGGING) << "Mining has been stopped";
                throw System.InterruptedException();
            }

            Debug.Assert(m_state == MiningState.BLOCK_FOUND);
            return(m_block);
        }
Beispiel #2
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();
        }