From: CryptoManiac Date: Tue, 31 Mar 2015 19:25:39 +0000 (+0300) Subject: Another kernel scanning optimization X-Git-Tag: nvc-v0.5.3~52^2~2 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=544c4cb58b22d25f92f2ea5e77f29fee44845ca6 Another kernel scanning optimization There is no sense of continuous hashing of full 28 bytes sequence because first 24 bytes of kernel are static. Pre-calculate midstate from first 24 bytes instead to avoid unnecessary operations. ~33% performance boost --- diff --git a/src/kernel.cpp b/src/kernel.cpp index 30816d9..14fa4d2 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -545,19 +545,37 @@ bool ScanInputForStakeKernelHash(CTransaction &tx, uint32_t nOut, uint32_t nBits CBigNum bnMaxTargetPerCoinDay = bnTargetPerCoinDay * CBigNum(nValueIn) * nStakeMaxAge / COIN / (24 * 60 * 60); uint256 maxTarget = bnMaxTargetPerCoinDay.getuint256(); + + // Build static part of kernel + CDataStream ssKernel(SER_GETHASH, 0); + ssKernel << nStakeModifier; + ssKernel << block.nTime << nTxOffset << tx.nTime << nOut; + CDataStream::const_iterator it = ssKernel.begin(); + + // Init sha256 context and update it + // with first 16 bytes of kernel + SHA256_CTX ctxCurrent; + SHA256_Init(&ctxCurrent); + SHA256_Update(&ctxCurrent, (unsigned char*)&it[0], 8 + 16); + SHA256_CTX ctxCopy = ctxCurrent; + // Search forward in time from the given timestamp // Stopping search in case of shutting down for (unsigned int n=0; n maxTarget)