Delete Verus junk, which breaks ARMv8/aarch64 builds
This commit is contained in:
@@ -35,96 +35,12 @@ uint256 CBlockHeader::GetSHA256DHash() const
|
||||
return SerializeHash(*this);
|
||||
}
|
||||
|
||||
uint256 CBlockHeader::GetVerusHash() const
|
||||
{
|
||||
if (hashPrevBlock.IsNull())
|
||||
// always use SHA256D for genesis block
|
||||
return SerializeHash(*this);
|
||||
else
|
||||
return SerializeVerusHash(*this);
|
||||
}
|
||||
|
||||
uint256 CBlockHeader::GetVerusV2Hash() const
|
||||
{
|
||||
if (hashPrevBlock.IsNull())
|
||||
// always use SHA256D for genesis block
|
||||
return SerializeHash(*this);
|
||||
else
|
||||
return SerializeVerusHashV2(*this);
|
||||
}
|
||||
|
||||
void CBlockHeader::SetSHA256DHash()
|
||||
{
|
||||
CBlockHeader::hashFunction = &CBlockHeader::GetSHA256DHash;
|
||||
}
|
||||
|
||||
void CBlockHeader::SetVerusHash()
|
||||
{
|
||||
CBlockHeader::hashFunction = &CBlockHeader::GetVerusHash;
|
||||
}
|
||||
|
||||
void CBlockHeader::SetVerusHashV2()
|
||||
{
|
||||
CBlockHeader::hashFunction = &CBlockHeader::GetVerusV2Hash;
|
||||
}
|
||||
|
||||
// returns false if unable to fast calculate the VerusPOSHash from the header.
|
||||
// if it returns false, value is set to 0, but it can still be calculated from the full block
|
||||
// in that case. the only difference between this and the POS hash for the contest is that it is not divided by the value out
|
||||
// this is used as a source of entropy
|
||||
bool CBlockHeader::GetRawVerusPOSHash(uint256 &ret, int32_t nHeight) const
|
||||
{
|
||||
// if below the required height or no storage space in the solution, we can't get
|
||||
// a cached txid value to calculate the POSHash from the header
|
||||
if (!(CPOSNonce::NewNonceActive(nHeight) && IsVerusPOSBlock()))
|
||||
{
|
||||
ret = uint256();
|
||||
return false;
|
||||
}
|
||||
|
||||
// if we can calculate, this assumes the protocol that the POSHash calculation is:
|
||||
// hashWriter << ASSETCHAINS_MAGIC;
|
||||
// hashWriter << nNonce; (nNonce is:
|
||||
// (high 128 bits == low 128 bits of verus hash of low 128 bits of nonce)
|
||||
// (low 32 bits == compact PoS difficult)
|
||||
// (mid 96 bits == low 96 bits of HASH(pastHash, txid, voutnum)
|
||||
// pastHash is hash of height - 100, either PoW hash of block or PoS hash, if new PoS
|
||||
// )
|
||||
// hashWriter << height;
|
||||
// return hashWriter.GetHash();
|
||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
|
||||
hashWriter << ASSETCHAINS_MAGIC;
|
||||
hashWriter << nNonce;
|
||||
hashWriter << nHeight;
|
||||
ret = hashWriter.GetHash();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlockHeader::GetVerusPOSHash(arith_uint256 &ret, int32_t nHeight, CAmount value) const
|
||||
{
|
||||
uint256 raw;
|
||||
if (GetRawVerusPOSHash(raw, nHeight))
|
||||
{
|
||||
ret = UintToArith256(raw) / value;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// depending on the height of the block and its type, this returns the POS hash or the POW hash
|
||||
uint256 CBlockHeader::GetVerusEntropyHash(int32_t height) const
|
||||
{
|
||||
uint256 retVal;
|
||||
// if we qualify as PoW, use PoW hash, regardless of PoS state
|
||||
if (GetRawVerusPOSHash(retVal, height))
|
||||
{
|
||||
// POS hash
|
||||
return retVal;
|
||||
}
|
||||
return GetHash();
|
||||
}
|
||||
|
||||
uint256 BuildMerkleTree(bool* fMutated, const std::vector<uint256> leaves,
|
||||
std::vector<uint256> &vMerkleTree)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||
// Copyright (c) 2009-2013 The Bitcoin Core developers
|
||||
// Copyright (c) 2019 The Hush developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
@@ -51,7 +52,9 @@ public:
|
||||
uint256 hashFinalSaplingRoot;
|
||||
uint32_t nTime;
|
||||
uint32_t nBits;
|
||||
CPOSNonce nNonce;
|
||||
//CPOSNonce nNonce;
|
||||
uint256 nNonce;
|
||||
|
||||
std::vector<unsigned char> nSolution;
|
||||
|
||||
CBlockHeader()
|
||||
@@ -98,57 +101,14 @@ public:
|
||||
uint256 GetSHA256DHash() const;
|
||||
static void SetSHA256DHash();
|
||||
|
||||
uint256 GetVerusHash() const;
|
||||
static void SetVerusHash();
|
||||
|
||||
bool GetRawVerusPOSHash(uint256 &ret, int32_t nHeight) const;
|
||||
bool GetVerusPOSHash(arith_uint256 &ret, int32_t nHeight, CAmount value) const; // value is amount of stake tx
|
||||
uint256 GetVerusEntropyHash(int32_t nHeight) const;
|
||||
|
||||
uint256 GetVerusV2Hash() const;
|
||||
static void SetVerusHashV2();
|
||||
|
||||
int64_t GetBlockTime() const
|
||||
{
|
||||
return (int64_t)nTime;
|
||||
}
|
||||
|
||||
uint32_t GetVerusPOSTarget() const
|
||||
{
|
||||
uint32_t nBits = 0;
|
||||
|
||||
for (const unsigned char *p = nNonce.begin() + 3; p >= nNonce.begin(); p--)
|
||||
{
|
||||
nBits <<= 8;
|
||||
nBits += *p;
|
||||
}
|
||||
return nBits;
|
||||
}
|
||||
|
||||
bool IsVerusPOSBlock() const
|
||||
{
|
||||
if ( ASSETCHAINS_LWMAPOS != 0 )
|
||||
return nNonce.IsPOSNonce();
|
||||
else return(0);
|
||||
}
|
||||
|
||||
void SetVerusPOSTarget(uint32_t nBits)
|
||||
{
|
||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
|
||||
arith_uint256 arNonce = UintToArith256(nNonce);
|
||||
|
||||
// printf("before svpt: %s\n", ArithToUint256(arNonce).GetHex().c_str());
|
||||
|
||||
arNonce = (arNonce & CPOSNonce::entropyMask) | nBits;
|
||||
|
||||
// printf("after clear: %s\n", ArithToUint256(arNonce).GetHex().c_str());
|
||||
|
||||
hashWriter << ArithToUint256(arNonce);
|
||||
nNonce = CPOSNonce(ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | arNonce));
|
||||
|
||||
// printf(" after svpt: %s\n", nNonce.GetHex().c_str());
|
||||
}
|
||||
};
|
||||
|
||||
// this class is used to address the type mismatch that existed between nodes, where block headers
|
||||
|
||||
@@ -21,66 +21,3 @@
|
||||
#include "nonce.h"
|
||||
#include <cstring>
|
||||
|
||||
extern char ASSETCHAINS_SYMBOL[65];
|
||||
|
||||
arith_uint256 CPOSNonce::entropyMask = UintToArith256(uint256S("00000000000000000000000000000000ffffffffffffffffffffffff00000000"));
|
||||
arith_uint256 CPOSNonce::posDiffMask = UintToArith256(uint256S("00000000000000000000000000000000000000000000000000000000ffffffff"));
|
||||
|
||||
bool CPOSNonce::NewPOSActive(int32_t height)
|
||||
{
|
||||
if ((strcmp(ASSETCHAINS_SYMBOL, "VRSC") == 0) && (height < (96480 + 100)))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CPOSNonce::NewNonceActive(int32_t height)
|
||||
{
|
||||
if ((strcmp(ASSETCHAINS_SYMBOL, "VRSC") == 0) && (height < 96480))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPOSNonce::SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum)
|
||||
{
|
||||
// get low 96 bits of past hash and put it in top 96 bits of low 128 bits of nonce
|
||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
|
||||
// first hash the pastHash, txid, and voutNum, to create a combined 96 bits, which will be used in the nonce
|
||||
hashWriter << pastHash;
|
||||
hashWriter << txid;
|
||||
hashWriter << voutNum;
|
||||
|
||||
arith_uint256 arNonce = (UintToArith256(*this) & posDiffMask) |
|
||||
(UintToArith256(hashWriter.GetHash()) & entropyMask);
|
||||
|
||||
// printf("before %s\n", ArithToUint256(arNonce).GetHex().c_str());
|
||||
|
||||
hashWriter.Reset();
|
||||
hashWriter << ArithToUint256(arNonce);
|
||||
|
||||
*this = CPOSNonce(ArithToUint256((UintToArith256(hashWriter.GetHash()) << 128) | arNonce));
|
||||
|
||||
// printf("after %s\n", this->GetHex().c_str());
|
||||
}
|
||||
|
||||
bool CPOSNonce::CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum)
|
||||
{
|
||||
// get low 96 bits of past hash and put it in top 96 bits of low 128 bits of nonce
|
||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
|
||||
// first hash the pastHash, txid, and voutNum, to create a combined 96 bits, which will be used in the nonce
|
||||
hashWriter << pastHash;
|
||||
hashWriter << txid;
|
||||
hashWriter << voutNum;
|
||||
|
||||
arith_uint256 arNonce = (UintToArith256(*this) & posDiffMask) |
|
||||
(UintToArith256(hashWriter.GetHash()) & entropyMask);
|
||||
|
||||
hashWriter.Reset();
|
||||
hashWriter << ArithToUint256(arNonce);
|
||||
|
||||
return UintToArith256(*this) == (UintToArith256(hashWriter.GetHash()) << 128 | arNonce);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Copyright (c) 2019 Hush Developers
|
||||
// Copyright (c) 2018 Michael Toutonghi
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
@@ -25,55 +26,4 @@
|
||||
#include "arith_uint256.h"
|
||||
|
||||
|
||||
/** For POS blocks, the nNonce of a block header holds the entropy source for the POS contest
|
||||
* in the latest VerusHash protocol
|
||||
* */
|
||||
class CPOSNonce : public uint256
|
||||
{
|
||||
public:
|
||||
static bool NewPOSActive(int32_t height);
|
||||
static bool NewNonceActive(int32_t height);
|
||||
|
||||
static arith_uint256 entropyMask;
|
||||
static arith_uint256 posDiffMask;
|
||||
|
||||
CPOSNonce() : uint256() { }
|
||||
CPOSNonce(const base_blob<256> &b) : uint256(b) { }
|
||||
CPOSNonce(const std::vector<unsigned char> &vch) : uint256(vch) { }
|
||||
|
||||
int32_t GetPOSTarget() const
|
||||
{
|
||||
uint32_t nBits = 0;
|
||||
|
||||
for (const unsigned char *p = begin() + 3; p >= begin(); p--)
|
||||
{
|
||||
nBits <<= 8;
|
||||
nBits += *p;
|
||||
}
|
||||
return nBits;
|
||||
}
|
||||
|
||||
bool IsPOSNonce() const
|
||||
{
|
||||
arith_uint256 arNonce = UintToArith256(*this);
|
||||
arith_uint256 tmpNonce = ((arNonce << 128) >> 128);
|
||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
hashWriter << ArithToUint256(tmpNonce);
|
||||
return (*this == ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | tmpNonce));
|
||||
}
|
||||
|
||||
void SetPOSTarget(uint32_t nBits)
|
||||
{
|
||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
|
||||
arith_uint256 arNonce = (UintToArith256(*this) & entropyMask) | nBits;
|
||||
hashWriter << ArithToUint256(arNonce);
|
||||
|
||||
(uint256 &)(*this) = ArithToUint256(UintToArith256(hashWriter.GetHash()) << 128 | arNonce);
|
||||
}
|
||||
|
||||
void SetPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum);
|
||||
bool CheckPOSEntropy(const uint256 &pastHash, uint256 txid, int32_t voutNum);
|
||||
};
|
||||
|
||||
#endif // BITCOIN_PRIMITIVES_NONCE_H
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "arith_uint256.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "hash.h"
|
||||
#include "nonce.h"
|
||||
|
||||
#ifndef __APPLE__
|
||||
#include <stdint.h>
|
||||
@@ -727,41 +726,6 @@ public:
|
||||
return a.hash != b.hash;
|
||||
}
|
||||
|
||||
// verus hash will be the same for a given txid, output number, block height, and blockhash of 100 blocks past
|
||||
static uint256 _GetVerusPOSHash(CPOSNonce *pNonce, const uint256 &txid, int32_t voutNum, int32_t height, const uint256 &pastHash, int64_t value)
|
||||
{
|
||||
pNonce->SetPOSEntropy(pastHash, txid, voutNum);
|
||||
CVerusHashWriter hashWriter = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION);
|
||||
|
||||
hashWriter << ASSETCHAINS_MAGIC;
|
||||
|
||||
// we only use the new style of POS hash after changeover and 100 blocks of enforced proper nonce updating
|
||||
if (CPOSNonce::NewPOSActive(height))
|
||||
{
|
||||
hashWriter << *pNonce;
|
||||
hashWriter << height;
|
||||
return ArithToUint256(UintToArith256(hashWriter.GetHash()) / value);
|
||||
}
|
||||
else
|
||||
{
|
||||
hashWriter << pastHash;
|
||||
hashWriter << height;
|
||||
hashWriter << txid;
|
||||
hashWriter << voutNum;
|
||||
return ArithToUint256(UintToArith256(hashWriter.GetHash()) / value);
|
||||
}
|
||||
}
|
||||
|
||||
// Nonce is modified to include the transaction information
|
||||
uint256 GetVerusPOSHash(CPOSNonce *pNonce, int32_t voutNum, int32_t height, const uint256 &pastHash) const
|
||||
{
|
||||
uint256 txid = GetHash();
|
||||
|
||||
if (voutNum >= vout.size())
|
||||
return uint256S("ff0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f");
|
||||
|
||||
return _GetVerusPOSHash(pNonce, txid, voutNum, height, pastHash, (uint64_t)vout[voutNum].nValue);
|
||||
}
|
||||
|
||||
std::string ToString() const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user