58
src/hash.h
58
src/hash.h
@@ -225,6 +225,55 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** An optimized and dangerous writer stream (for serialization) that computes a 256-bit Verus hash without the normal
|
||||||
|
* safety checks. Do not try to write more than 1488 bytes to this hash writer. */
|
||||||
|
class CVerusMiningHashWriter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
union hwBuf {
|
||||||
|
unsigned char charBuf[1488];
|
||||||
|
int32_t i32a[522];
|
||||||
|
hwBuf()
|
||||||
|
{
|
||||||
|
memset(charBuf, 0, sizeof(charBuf));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
hwBuf buf;
|
||||||
|
int nPos;
|
||||||
|
int nType;
|
||||||
|
int nVersion;
|
||||||
|
|
||||||
|
CVerusMiningHashWriter(int nTypeIn, int nVersionIn, int pos = 0) : buf()
|
||||||
|
{
|
||||||
|
nPos = pos;
|
||||||
|
nType = nTypeIn;
|
||||||
|
nVersion = nVersionIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
CVerusMiningHashWriter& write(const char *pch, size_t size) {
|
||||||
|
if ((nPos + size) <= sizeof(buf.charBuf))
|
||||||
|
{
|
||||||
|
memcpy(&(buf.charBuf[nPos]), pch, size);
|
||||||
|
nPos += size;
|
||||||
|
}
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// does not invalidate the object for modification and further hashing
|
||||||
|
uint256 GetHash() {
|
||||||
|
uint256 result;
|
||||||
|
CVerusHash::Hash((unsigned char*)&result, buf.charBuf, nPos);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
CVerusMiningHashWriter& operator<<(const T& obj) {
|
||||||
|
// Serialize to this stream
|
||||||
|
::Serialize(*this, obj, nType, nVersion);
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** Compute the 256-bit hash of an object's serialization. */
|
/** Compute the 256-bit hash of an object's serialization. */
|
||||||
template<typename T>
|
template<typename T>
|
||||||
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
uint256 SerializeHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
||||||
@@ -243,6 +292,15 @@ uint256 SerializeVerusHash(const T& obj, int nType=SER_GETHASH, int nVersion=PRO
|
|||||||
return ss.GetHash();
|
return ss.GetHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Compute the 256-bit Verus hash of an object's serialization. */
|
||||||
|
template<typename T>
|
||||||
|
uint256 SerializeVerusMiningHash(const T& obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
|
||||||
|
{
|
||||||
|
CVerusMiningHashWriter ss = CVerusMiningHashWriter(nType, nVersion);
|
||||||
|
ss << obj;
|
||||||
|
return ss.GetHash();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char>& vDataToHash);
|
unsigned int MurmurHash3(unsigned int nHashSeed, const std::vector<unsigned char>& vDataToHash);
|
||||||
|
|
||||||
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]);
|
void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char header, const unsigned char data[32], unsigned char output[64]);
|
||||||
|
|||||||
@@ -910,7 +910,7 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
|
|||||||
bool ContextualCheckCoinbaseTransaction(const CTransaction& tx, const int nHeight)
|
bool ContextualCheckCoinbaseTransaction(const CTransaction& tx, const int nHeight)
|
||||||
{
|
{
|
||||||
// if time locks are on, ensure that this coin base is time locked exactly as it should be
|
// if time locks are on, ensure that this coin base is time locked exactly as it should be
|
||||||
if ((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE)
|
if (((uint64_t)(tx.GetValueOut()) >= ASSETCHAINS_TIMELOCKGTE) || (nHeight >= 31680) && komodo_ac_block_subsidy(nHeight) >= ASSETCHAINS_TIMELOCKGTE)
|
||||||
{
|
{
|
||||||
CScriptID scriptHash;
|
CScriptID scriptHash;
|
||||||
|
|
||||||
|
|||||||
@@ -1148,17 +1148,20 @@ void static BitcoinMiner_noeq()
|
|||||||
{
|
{
|
||||||
arith_uint256 arNonce = UintToArith256(pblock->nNonce);
|
arith_uint256 arNonce = UintToArith256(pblock->nNonce);
|
||||||
|
|
||||||
|
CVerusMiningHashWriter ss = CVerusMiningHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||||
|
ss << *((CBlockHeader *)pblock);
|
||||||
|
|
||||||
// for speed check 16 mega hash at a time
|
// for speed check 16 mega hash at a time
|
||||||
for (int i = 0; i < 0x1000000; i++)
|
for (int i = 0; i < 0x1000000; i++)
|
||||||
{
|
{
|
||||||
solutionTargetChecks.increment();
|
solutionTargetChecks.increment();
|
||||||
|
|
||||||
// Update nNonce
|
// Update nNonce
|
||||||
*((unsigned char *)&(pblock->nNonce)) = i & 0xff;
|
ss.buf.charBuf[108] = *((unsigned char *)&(pblock->nNonce)) = i & 0xff;
|
||||||
*(((unsigned char *)&(pblock->nNonce))+1) = (i >> 8) & 0xff;
|
ss.buf.charBuf[109] = *(((unsigned char *)&(pblock->nNonce))+1) = (i >> 8) & 0xff;
|
||||||
*(((unsigned char *)&(pblock->nNonce))+2) = (i >> 16) & 0xff;
|
ss.buf.charBuf[110] = *(((unsigned char *)&(pblock->nNonce))+2) = (i >> 16) & 0xff;
|
||||||
|
|
||||||
if ( UintToArith256(pblock->GetHash()) <= hashTarget )
|
if ( UintToArith256(ss.GetHash()) <= hashTarget )
|
||||||
{
|
{
|
||||||
SetThreadPriority(THREAD_PRIORITY_NORMAL);
|
SetThreadPriority(THREAD_PRIORITY_NORMAL);
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ uint256 CBlockHeader::GetVerusHash() const
|
|||||||
return SerializeVerusHash(*this);
|
return SerializeVerusHash(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint256 CBlockHeader::GetVerusMiningHash() const
|
||||||
|
{
|
||||||
|
// no check for genesis block and use the optimized hash
|
||||||
|
return SerializeVerusMiningHash(*this);
|
||||||
|
}
|
||||||
|
|
||||||
void CBlockHeader::SetSHA256DHash()
|
void CBlockHeader::SetSHA256DHash()
|
||||||
{
|
{
|
||||||
CBlockHeader::hashFunction = &CBlockHeader::GetSHA256DHash;
|
CBlockHeader::hashFunction = &CBlockHeader::GetSHA256DHash;
|
||||||
|
|||||||
@@ -84,6 +84,8 @@ public:
|
|||||||
uint256 GetVerusHash() const;
|
uint256 GetVerusHash() const;
|
||||||
static void SetVerusHash();
|
static void SetVerusHash();
|
||||||
|
|
||||||
|
uint256 GetVerusMiningHash() const;
|
||||||
|
|
||||||
int64_t GetBlockTime() const
|
int64_t GetBlockTime() const
|
||||||
{
|
{
|
||||||
return (int64_t)nTime;
|
return (int64_t)nTime;
|
||||||
|
|||||||
@@ -1053,7 +1053,7 @@ int32_t CWallet::VerusStakeTransaction(CMutableTransaction &txNew, uint32_t &bnT
|
|||||||
if (!VerusSelectStakeOutput(hashResult, stakeSource, voutNum, tipindex->nHeight + 1, target) ||
|
if (!VerusSelectStakeOutput(hashResult, stakeSource, voutNum, tipindex->nHeight + 1, target) ||
|
||||||
!Solver(stakeSource.vout[voutNum].scriptPubKey, whichType, vSolutions))
|
!Solver(stakeSource.vout[voutNum].scriptPubKey, whichType, vSolutions))
|
||||||
{
|
{
|
||||||
LogPrintf("No eligible staking transaction found");
|
LogPrintf("No eligible staking transaction found\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user