Portable VerusHash and CPU check

This commit is contained in:
Michael Toutonghi
2018-06-16 14:51:13 -07:00
parent 2c05c25598
commit 5296a85018
10 changed files with 537 additions and 5 deletions

View File

@@ -27,6 +27,15 @@ uint256 CBlockHeader::GetVerusHash() const
return SerializeVerusHash(*this);
}
uint256 CBlockHeader::GetVerusHashPortable() const
{
if (hashPrevBlock.IsNull())
// always use SHA256D for genesis block
return SerializeHash(*this);
else
return SerializeVerusHashPortable(*this);
}
uint256 CBlockHeader::GetVerusMiningHash() const
{
// no check for genesis block and use the optimized hash
@@ -43,6 +52,11 @@ void CBlockHeader::SetVerusHash()
CBlockHeader::hashFunction = &CBlockHeader::GetVerusHash;
}
void CBlockHeader::SetVerusHashPortable()
{
CBlockHeader::hashFunction = &CBlockHeader::GetVerusHashPortable;
}
uint256 CBlock::BuildMerkleTree(bool* fMutated) const
{
/* WARNING! If you're reading this because you're learning about crypto

View File

@@ -84,6 +84,9 @@ public:
uint256 GetVerusHash() const;
static void SetVerusHash();
uint256 GetVerusHashPortable() const;
static void SetVerusHashPortable();
uint256 GetVerusMiningHash() const;
int64_t GetBlockTime() const
@@ -107,14 +110,14 @@ public:
{
arith_uint256 arNonce = UintToArith256(nNonce);
arith_uint256 tmpNonce = ((arNonce << 128) >> 128);
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
CVerusHashPortableWriter hashWriter = CVerusHashPortableWriter(SER_GETHASH, PROTOCOL_VERSION);
hashWriter << ArithToUint256(tmpNonce);
return (nNonce == ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce));
}
void SetVerusPOSTarget(int32_t nBits)
{
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
CVerusHashPortableWriter hashWriter = CVerusHashPortableWriter(SER_GETHASH, PROTOCOL_VERSION);
uint256 hash;
arith_uint256 tmpNonce;