From 544c4cb58b22d25f92f2ea5e77f29fee44845ca6 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Tue, 31 Mar 2015 22:25:39 +0300 Subject: [PATCH] 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 --- src/kernel.cpp | 30 ++++++++++++++++++++++++------ 1 files changed, 24 insertions(+), 6 deletions(-) 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) -- 1.7.1