Skip to content

Commit 9b07d64

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 9b07d64

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
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 localDataHash = pblock->GetDataHash();
978979
while (nTries < nInnerLoopCount &&
979-
!CheckProofOfWork(pblock->GetSha256DPoWHash(), pblock->nBits,
980+
!CheckProofOfWork(pblock->GetSha256D(localDataHash), pblock->nBits,
980981
Params().GetConsensus(), CBlockHeader::SHA256D_BLOCK)) {
981982
boost::this_thread::interruption_point();
982983
++nTries;

src/primitives/block.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,19 @@ uint256 CBlockHeader::GetX16RTPoWHash(bool fSetVeilDataHashNull) const
4848
uint256 CBlockHeader::GetSha256DPoWHash() const
4949
{
5050
CSha256dDataInput input(*this);
51-
5251
uint256 dataHash = SerializeHash(input);
52+
CSha256dInput sha256Final(*this, dataHash);
53+
return SerializeHash(sha256Final);
54+
}
55+
56+
uint256 CBlockHeader::GetDataHash() const
57+
{
58+
CSha256dDataInput input(*this);
59+
return SerializeHash(input);
60+
}
5361

62+
uint256 CBlockHeader::GetSha256D(uint256& dataHash) const
63+
{
5464
CSha256dInput sha256Final(*this, dataHash);
5565
return SerializeHash(sha256Final);
5666
}

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 GetDataHash() const;
202+
uint256 GetSha256D(uint256& dataHash) const;
203+
201204
uint256 GetProgPowHeaderHash() const;
202205
uint256 GetRandomXHeaderHash() const;
203206

0 commit comments

Comments
 (0)