PoS improvements
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "arith_uint256.h"
|
||||
#include "consensus/consensus.h"
|
||||
#include "hash.h"
|
||||
#include "nonce.h"
|
||||
|
||||
#ifndef __APPLE__
|
||||
#include <stdint.h>
|
||||
@@ -474,25 +475,39 @@ public:
|
||||
}
|
||||
|
||||
// verus hash will be the same for a given txid, output number, block height, and blockhash of 100 blocks past
|
||||
static uint256 _GetVerusPOSHash(const uint256 &txid, int32_t voutNum, int32_t height, const uint256 &pastHash, int64_t value)
|
||||
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;
|
||||
hashWriter << pastHash;
|
||||
hashWriter << height;
|
||||
hashWriter << txid;
|
||||
hashWriter << voutNum;
|
||||
return hashWriter.GetHash();
|
||||
|
||||
// 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 hashWriter.GetHash();
|
||||
}
|
||||
else
|
||||
{
|
||||
hashWriter << pastHash;
|
||||
hashWriter << height;
|
||||
hashWriter << txid;
|
||||
hashWriter << voutNum;
|
||||
return hashWriter.GetHash();
|
||||
}
|
||||
}
|
||||
|
||||
uint256 GetVerusPOSHash(int32_t voutNum, int32_t height, const uint256 &pastHash) const
|
||||
// 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 ArithToUint256(UintToArith256(_GetVerusPOSHash(txid, voutNum, height, pastHash, (uint64_t)vout[voutNum].nValue)) / vout[voutNum].nValue);
|
||||
return ArithToUint256(UintToArith256(_GetVerusPOSHash(pNonce, txid, voutNum, height, pastHash, (uint64_t)vout[voutNum].nValue)) / vout[voutNum].nValue);
|
||||
}
|
||||
|
||||
std::string ToString() const;
|
||||
|
||||
Reference in New Issue
Block a user