Skip to content

Commit

Permalink
Miner starting nonce randomization
Browse files Browse the repository at this point in the history
  • Loading branch information
mike31 committed Dec 10, 2017
1 parent 41cbef3 commit 42d6ea4
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/miner/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class TxPriorityCompare
}
};

uint32_t RandomStartNonce()
{
return mc_RandomInRange(0,0x4fffffff);
}

bool UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
{
/* MCHN START */
Expand Down Expand Up @@ -693,7 +698,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int&
static uint256 hashPrevBlock;
if (hashPrevBlock != pblock->hashPrevBlock)
{
nExtraNonce = 0;
nExtraNonce = RandomStartNonce();
hashPrevBlock = pblock->hashPrevBlock;
}
++nExtraNonce;
Expand Down Expand Up @@ -1201,7 +1206,7 @@ void static BitcoinMiner(CWallet *pwallet)

// Each thread has its own key and counter
CReserveKey reservekey(pwallet);
unsigned int nExtraNonce = 0;
unsigned int nExtraNonce = RandomStartNonce();//0;

/* MCHN START */
int canMine;
Expand Down Expand Up @@ -1437,18 +1442,18 @@ void static BitcoinMiner(CWallet *pwallet)
CBlock *pblock = &pblocktemplate->block;
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce,pwallet);

LogPrint("mcminer","mchn-miner: Running MultiChainMiner with %u transactions in block (%u bytes)\n", pblock->vtx.size(),
::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION));

//
// Search
//
int64_t nStart = GetTime();
uint256 hashTarget = uint256().SetCompact(pblock->nBits);
uint256 hash;
uint32_t nNonce = 0;
uint32_t nNonce = RandomStartNonce();
uint32_t nStartNonce=nNonce;
uint32_t nOldNonce = 0;

LogPrint("mcminer","mchn-miner: Running MultiChainMiner with %u transactions in block (%u bytes). Starting nonce: %08x/%08x\n", pblock->vtx.size(),
::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION),nNonce,nExtraNonce);
double wStartTime=mc_TimeNowAsDouble();
uint64_t wThisCount=0;
while (true) {
Expand Down Expand Up @@ -1554,8 +1559,12 @@ void static BitcoinMiner(CWallet *pwallet)
// if (vNodes.empty() && Params().MiningRequiresPeers() && not_setup_period)
break;
}
if (nNonce >= 0xffff0000)
// if (nNonce >= 0xffff0000)
if ( (nNonce-nStartNonce) >= 0x8fffffff/GetArg("-genproclimit", 1))
{
LogPrint("mcminer","Too many nonces tried for %08x, switching timestamp\n",nStartNonce);
break;
}
if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60)
break;
if (pindexPrev != chainActive.Tip())
Expand Down

0 comments on commit 42d6ea4

Please sign in to comment.