Add deterministic RandomX block header hashing

This commit is contained in:
Capri 2026-09-14 20:18:52 +00:00
commit 2431ea4588
Signed by: VextaProject
SSH key fingerprint: SHA256:739BZv8LvIDY2tR7lXLy/IQ6MaGTQtYcG9GNvCjmpVM
7 changed files with 84 additions and 8 deletions

View file

@ -5,11 +5,14 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <primitives/block.h>
#include <crypto/randomx_hash.h>
#include <crypto/common.h>
#include <consensus/consensus.h>
#include <chainparams.h>
#include <hash.h>
#include <streams.h>
#include <tinyformat.h>
#include <version.h>
#include <arith_uint256.h>
uint256 CBlockHeader::GetHash() const
@ -36,6 +39,25 @@ uint256 CBlockHeader::GetPoWAlgoHash(const Consensus::Params& params) const
return GetHash();
}
uint256 CBlockHeader::GetRandomXPoWHash(const uint256& seed) const
{
CDataStream stream(SER_GETHASH, PROTOCOL_VERSION);
stream << *this;
uint256 result;
if (!VextaRandomXHash(
stream.data(),
stream.size(),
seed.data(),
seed.size(),
result.begin())) {
result.SetNull();
}
return result;
}
std::string CBlock::ToString(const Consensus::Params& params) const
{
std::stringstream s;

View file

@ -96,6 +96,14 @@ public:
uint256 GetPoWAlgoHash(const Consensus::Params& params) const;
/**
* Calculate the RandomX proof-of-work hash using an explicit seed key.
*
* The input is the canonical serialized 80-byte block header.
* The seed is supplied in raw uint256 serialization byte order.
*/
uint256 GetRandomXPoWHash(const uint256& seed) const;
int64_t GetBlockTime() const
{
return (int64_t)nTime;