Skip to content

Commit b3603ed

Browse files
author
barrystyle
committed
Increase internal sha256d miner hashrate by around 33%.
Since the datahash is not likely to change much between blocks (other than work refresh), we can calculate it once and reuse the value. Average hashrate beforehand on 4core vps was 4mh, averages around 5.5-6mh with blocks successfully solved on devnet.
1 parent 2568e61 commit b3603ed

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/miner.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,9 @@ void BitcoinMiner(std::shared_ptr<CReserveScript> coinbaseScript, bool fProofOfS
975975
}
976976
pblock->mixHash = mix_hash;
977977
} else if (pblock->IsSha256D() && pblock->nTime >= Params().PowUpdateTimestamp()) {
978+
uint256 midStateHash = pblock->GetSha256dMidstate();
978979
while (nTries < nInnerLoopCount &&
979-
!CheckProofOfWork(pblock->GetSha256DPoWHash(), pblock->nBits,
980+
!CheckProofOfWork(pblock->GetSha256D(midStateHash), pblock->nBits,
980981
Params().GetConsensus(), CBlockHeader::SHA256D_BLOCK)) {
981982
boost::this_thread::interruption_point();
982983
++nTries;

src/primitives/block.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,23 @@ uint256 CBlockHeader::GetX16RTPoWHash(bool fSetVeilDataHashNull) const
4848
uint256 CBlockHeader::GetSha256DPoWHash() const
4949
{
5050
CSha256dDataInput input(*this);
51-
5251
uint256 dataHash = SerializeHash(input);
53-
5452
CSha256dInput sha256Final(*this, dataHash);
5553
return SerializeHash(sha256Final);
5654
}
5755

56+
uint256 CBlockHeader::GetSha256dMidstate() const
57+
{
58+
CSha256dDataInput input(*this);
59+
return SerializeHash(input);
60+
}
61+
62+
uint256 CBlockHeader::GetSha256D(uint256& midState) const
63+
{
64+
CSha256dInput sha256Final(*this, midState);
65+
return SerializeHash(sha256Final);
66+
}
67+
5868
/**
5969
* @brief This takes a block header, removes the nNonce and the mixHash. Then performs a serialized hash of it SHA256D.
6070
* This will be used as the input to the ProgPow hashing function

src/primitives/block.h

+3
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ class CBlockHeader
198198
uint256 GetX16RTPoWHash(bool fSetVeilDataHashNull = false) const;
199199
uint256 GetSha256DPoWHash() const;
200200

201+
uint256 GetSha256dMidstate() const;
202+
uint256 GetSha256D(uint256& midState) const;
203+
201204
uint256 GetProgPowHeaderHash() const;
202205
uint256 GetRandomXHeaderHash() const;
203206

0 commit comments

Comments
 (0)