Browse Source

miner: indentation fixes, remove for (;;)

- change a for (;;) into while (true), as we nowhere else use the first
- init nNonceFound to 0
- fix indentation in BitcoinMiner try/catch block
0.10
Philip Kaufmann 11 years ago
parent
commit
0655fac0b1
  1. 21
      src/miner.cpp

21
src/miner.cpp

@ -49,7 +49,6 @@ public: @@ -49,7 +49,6 @@ public:
}
};
uint64_t nLastBlockTx = 0;
uint64_t nLastBlockSize = 0;
@ -58,8 +57,10 @@ typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority; @@ -58,8 +57,10 @@ typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority;
class TxPriorityCompare
{
bool byFee;
public:
TxPriorityCompare(bool _byFee) : byFee(_byFee) { }
bool operator()(const TxPriority& a, const TxPriority& b)
{
if (byFee)
@ -114,6 +115,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) @@ -114,6 +115,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
// Collect memory pool transactions into the block
int64_t nFees = 0;
{
LOCK2(cs_main, mempool.cs);
CBlockIndex* pindexPrev = chainActive.Tip();
@ -334,7 +336,6 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& @@ -334,7 +336,6 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
pblock->hashMerkleRoot = pblock->BuildMerkleTree();
}
#ifdef ENABLE_WALLET
//////////////////////////////////////////////////////////////////////////////
//
@ -349,7 +350,8 @@ int64_t nHPSTimerStart = 0; @@ -349,7 +350,8 @@ int64_t nHPSTimerStart = 0;
// nonce is 0xffff0000 or above, the block is rebuilt and nNonce starts over at
// zero.
//
bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phash) {
bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phash)
{
// Write the first 76 bytes of the block header to a double-SHA256 state.
CHash256 hasher;
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
@ -357,7 +359,7 @@ bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phas @@ -357,7 +359,7 @@ bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phas
assert(ss.size() == 80);
hasher.Write((unsigned char*)&ss[0], 76);
for (;;) {
while (true) {
nNonce++;
// Write the last 4 bytes of the block header (the nonce) to a copy of
@ -435,7 +437,8 @@ void static BitcoinMiner(CWallet *pwallet) @@ -435,7 +437,8 @@ void static BitcoinMiner(CWallet *pwallet)
CReserveKey reservekey(pwallet);
unsigned int nExtraNonce = 0;
try { while (true) {
try {
while (true) {
if (Params().MiningRequiresPeers()) {
// Busy-wait for the network to come online so we don't waste time mining
// on an obsolete chain. In regtest mode we expect to fly solo.
@ -466,8 +469,7 @@ void static BitcoinMiner(CWallet *pwallet) @@ -466,8 +469,7 @@ void static BitcoinMiner(CWallet *pwallet)
uint256 hash;
uint32_t nNonce = 0;
uint32_t nOldNonce = 0;
while (true)
{
while (true) {
bool fFound = ScanHash(pblock, nNonce, &hash);
uint32_t nHashesDone = nNonce - nOldNonce;
nOldNonce = nNonce;
@ -542,7 +544,8 @@ void static BitcoinMiner(CWallet *pwallet) @@ -542,7 +544,8 @@ void static BitcoinMiner(CWallet *pwallet)
hashTarget.SetCompact(pblock->nBits);
}
}
} }
}
}
catch (boost::thread_interrupted)
{
LogPrintf("BitcoinMiner terminated\n");
@ -577,4 +580,4 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) @@ -577,4 +580,4 @@ void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
}
#endif
#endif // ENABLE_WALLET

Loading…
Cancel
Save