Vexta Core v0.3.1 release
Some checks failed
Vexta CI / Ubuntu build smoke test (push) Has been cancelled

This commit is contained in:
Capri 2026-11-15 20:44:09 +00:00
commit 997aaf5716
27 changed files with 508 additions and 118 deletions

View file

@ -1,13 +1,13 @@
AC_PREREQ([2.69]) AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 3) define(_CLIENT_VERSION_MINOR, 3)
define(_CLIENT_VERSION_BUILD, 0) define(_CLIENT_VERSION_BUILD, 1)
define(_CLIENT_VERSION_RC, 1) define(_CLIENT_VERSION_RC, 1)
define(_CLIENT_VERSION_IS_RELEASE, true) define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2026) define(_COPYRIGHT_YEAR, 2026)
define(_COPYRIGHT_HOLDERS,[The %s developers]) define(_COPYRIGHT_HOLDERS,[The %s developers])
define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Vexta Core]]) define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Vexta Core]])
AC_INIT([Vexta Core],m4_join([.], _CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MINOR, _CLIENT_VERSION_BUILD),[https://github.com/VextaProject/vexta/issues],[vexta],[https://vextaproject.org/]) AC_INIT([Vexta Core],m4_join([.], _CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MINOR, _CLIENT_VERSION_BUILD),[https://vextaproject.org/vextahub/VextaProject/Vexta/issues],[vexta],[https://vextaproject.org/])
AC_CONFIG_SRCDIR([src/validation.cpp]) AC_CONFIG_SRCDIR([src/validation.cpp])
AC_CONFIG_HEADERS([src/config/vexta-config.h]) AC_CONFIG_HEADERS([src/config/vexta-config.h])
AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_AUX_DIR([build-aux])

View file

@ -124,7 +124,7 @@ Copyright (C) 2009-2018 The Vexta Core developers
Please contribute if you find Vexta Core useful. Visit Please contribute if you find Vexta Core useful. Visit
<https://vexta.org> for further information about the software. <https://vexta.org> for further information about the software.
The source code is available from <https://github.com/vexta/vexta>. The source code is available from <https://vextaproject.org/vextahub/VextaProject/Vexta>.
This is experimental software. This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING Distributed under the MIT software license, see the accompanying file COPYING

View file

@ -608,7 +608,7 @@ Copyright (C) 2009-2018 The DigiByte Core developers
Please contribute if you find DigiByte Core useful. Visit Please contribute if you find DigiByte Core useful. Visit
<https://vexta-pool.co.uk> for further information about the software. <https://vexta-pool.co.uk> for further information about the software.
The source code is available from <https://github.com/Vexta-Core/vexta>. The source code is available from <https://vextaproject.org/vextahub/VextaProject/Vexta>.
This is experimental software. This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING Distributed under the MIT software license, see the accompanying file COPYING

View file

@ -109,7 +109,7 @@ Copyright (C) 2009-2018 The Vexta Core developers
Please contribute if you find Vexta Core useful. Visit Please contribute if you find Vexta Core useful. Visit
<https://vexta.org> for further information about the software. <https://vexta.org> for further information about the software.
The source code is available from <https://github.com/vexta/vexta>. The source code is available from <https://vextaproject.org/vextahub/VextaProject/Vexta>.
This is experimental software. This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING Distributed under the MIT software license, see the accompanying file COPYING

View file

@ -585,7 +585,7 @@ Copyright (C) 2009-2018 The Vexta Core developers
Please contribute if you find Vexta Core useful. Visit Please contribute if you find Vexta Core useful. Visit
<https://vexta.org> for further information about the software. <https://vexta.org> for further information about the software.
The source code is available from <https://github.com/vexta/vexta>. The source code is available from <https://vextaproject.org/vextahub/VextaProject/Vexta>.
This is experimental software. This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING Distributed under the MIT software license, see the accompanying file COPYING

View file

@ -9,17 +9,42 @@ struct VextaRandomXHasher::Impl
Impl(const void* key, std::size_t key_size) Impl(const void* key, std::size_t key_size)
{ {
cache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT); // JIT is an execution optimization, not a consensus rule.
// Use the portable interpreter if JIT is unavailable.
randomx_flags flags = RANDOMX_FLAG_DEFAULT;
if (randomx_get_flags() & RANDOMX_FLAG_JIT) {
flags = RANDOMX_FLAG_JIT;
}
cache = randomx_alloc_cache(flags);
if (cache == nullptr && flags == RANDOMX_FLAG_JIT) {
flags = RANDOMX_FLAG_DEFAULT;
cache = randomx_alloc_cache(flags);
}
if (cache == nullptr) { if (cache == nullptr) {
return; return;
} }
randomx_init_cache(cache, key, key_size); randomx_init_cache(cache, key, key_size);
vm = randomx_create_vm( vm = randomx_create_vm(flags, cache, nullptr);
RANDOMX_FLAG_DEFAULT,
cache, if (vm == nullptr && flags == RANDOMX_FLAG_JIT) {
nullptr); // Reinitialize a portable cache before fallback.
randomx_release_cache(cache);
flags = RANDOMX_FLAG_DEFAULT;
cache = randomx_alloc_cache(flags);
if (cache == nullptr) {
return;
}
randomx_init_cache(cache, key, key_size);
vm = randomx_create_vm(flags, cache, nullptr);
}
if (vm == nullptr) { if (vm == nullptr) {
randomx_release_cache(cache); randomx_release_cache(cache);

View file

@ -31,8 +31,8 @@ private:
/** /**
* Calculate a RandomX hash using an explicit key. * Calculate a RandomX hash using an explicit key.
* *
* This wrapper intentionally uses RANDOMX_FLAG_DEFAULT so consensus hashing * JIT may accelerate execution when supported, with an interpreted fallback.
* does not depend on CPU-specific runtime feature detection. * All execution modes must produce identical consensus hashes.
* *
* Returns false if RandomX cache or VM allocation fails. * Returns false if RandomX cache or VM allocation fails.
*/ */

View file

@ -571,7 +571,7 @@ void SetupServerArgs(ArgsManager& argsman)
std::string LicenseInfo() std::string LicenseInfo()
{ {
const std::string URL_SOURCE_CODE = "<https://github.com/VextaProject/vexta>"; const std::string URL_SOURCE_CODE = "<https://vextaproject.org/vextahub/VextaProject/Vexta>";
return CopyrightHolders(strprintf(_("Copyright (C) %i").translated, COPYRIGHT_YEAR) + " ") + "\n" + return CopyrightHolders(strprintf(_("Copyright (C) %i").translated, COPYRIGHT_YEAR) + " ") + "\n" +
"\n" + "\n" +

View file

@ -3018,7 +3018,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId()); LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
if ((!m_chainman.ActiveChainstate().IsInitialBlockDownload() && if ((!m_chainman.ActiveChainstate().IsInitialBlockDownload() &&
m_connman.isDandelionInbound(&pfrom)) || inv.hash != DANDELION_DISCOVERYHASH) { m_connman.isDandelionInbound(&pfrom)) || inv.hash != DANDELION_DISCOVERYHASH) {
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETDATA, inv)); m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETDATA, std::vector<CInv>{inv}));
} }
} else if (inv.IsMsgBlk()) { } else if (inv.IsMsgBlk()) {
const bool fAlreadyHave = AlreadyHaveBlock(inv.hash); const bool fAlreadyHave = AlreadyHaveBlock(inv.hash);
@ -3057,7 +3057,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId()); LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
if ((!fAlreadyHave && !m_chainman.ActiveChainstate().IsInitialBlockDownload() && if ((!fAlreadyHave && !m_chainman.ActiveChainstate().IsInitialBlockDownload() &&
m_connman.isDandelionInbound(&pfrom)) || (inv.hash == DANDELION_DISCOVERYHASH)) { m_connman.isDandelionInbound(&pfrom)) || (inv.hash == DANDELION_DISCOVERYHASH)) {
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETDATA, inv)); m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::GETDATA, std::vector<CInv>{inv}));
} }
} else { } else {
LogPrint(BCLog::NET, "Unknown inv type \"%s\" received from peer=%d\n", inv.ToString(), pfrom.GetId()); LogPrint(BCLog::NET, "Unknown inv type \"%s\" received from peer=%d\n", inv.ToString(), pfrom.GetId());

View file

@ -388,7 +388,13 @@ bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::P
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
} }
} else if (block.GetAlgo() != ALGO_RANDOMX) { } else if (block.GetAlgo() != ALGO_RANDOMX) {
return error("ReadBlockFromDisk: Unknown proof-of-work algorithm at %s", pos.ToString()); // Historical SHA256D blocks may contain version-rolling bits
// that predate the multi-algo encoding. Verify their SHA256D
// PoW here; height-dependent acceptance is checked elsewhere.
if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) {
return error("ReadBlockFromDisk: Historical SHA256D proof of work failed at %s",
pos.ToString());
}
} }
// Signet only: check block solution // Signet only: check block solution
@ -411,7 +417,24 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus
pindex->ToString(), block_pos.ToString()); pindex->ToString(), block_pos.ToString());
} }
if (block.GetHash() != consensusParams.hashGenesisBlock && // Preserve SHA256D proof-of-work for every pre-activation block,
// including historical versions with RandomX algorithm bits.
if (pindex->nHeight < consensusParams.randomXActivationHeight &&
block.GetHash() != consensusParams.hashGenesisBlock &&
block.GetAlgo() == ALGO_RANDOMX &&
!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) {
return error("ReadBlockFromDisk: Historical SHA256D proof of work failed");
}
// Reject unknown algorithm encodings after multi-algo activation.
if (pindex->nHeight >= consensusParams.randomXActivationHeight &&
block.GetAlgo() != ALGO_SHA256D &&
block.GetAlgo() != ALGO_RANDOMX) {
return error("ReadBlockFromDisk: Unknown post-activation proof-of-work algorithm");
}
if (pindex->nHeight >= consensusParams.randomXActivationHeight &&
block.GetHash() != consensusParams.hashGenesisBlock &&
block.GetAlgo() == ALGO_RANDOMX) { block.GetAlgo() == ALGO_RANDOMX) {
if (pindex->pprev == nullptr) { if (pindex->pprev == nullptr) {
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): RandomX block has no previous block index for %s at %s", return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): RandomX block has no previous block index for %s at %s",

View file

@ -12,7 +12,7 @@
#include <string> #include <string>
const std::string CURRENCY_UNIT = "DGB"; // One formatted unit const std::string CURRENCY_UNIT = "VTX"; // One formatted unit
const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit
/* Used to determine type of fee estimation requested */ /* Used to determine type of fee estimation requested */

View file

@ -5,6 +5,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <primitives/block.h> #include <primitives/block.h>
#include <memory>
#include <crypto/randomx_hash.h> #include <crypto/randomx_hash.h>
#include <crypto/common.h> #include <crypto/common.h>
#include <consensus/consensus.h> #include <consensus/consensus.h>
@ -34,13 +35,24 @@ int CBlockHeader::GetAlgo() const
bool CBlockHeader::GetRandomXPoWHash(const uint256& seed, uint256& result) const bool CBlockHeader::GetRandomXPoWHash(const uint256& seed, uint256& result) const
{ {
VextaRandomXHasher hasher(seed.data(), seed.size()); // Keep an independent RandomX VM per thread and reuse its initialized
// cache while the deterministic epoch seed remains unchanged.
static thread_local uint256 cached_seed;
static thread_local std::unique_ptr<VextaRandomXHasher> cached_hasher;
if (!hasher.IsValid()) { if (!cached_hasher || cached_seed != seed) {
return false; auto replacement = std::make_unique<VextaRandomXHasher>(
seed.data(), seed.size());
if (!replacement->IsValid()) {
return false;
}
cached_hasher = std::move(replacement);
cached_seed = seed;
} }
return GetRandomXPoWHash(hasher, result); return GetRandomXPoWHash(*cached_hasher, result);
} }
bool CBlockHeader::GetRandomXPoWHash( bool CBlockHeader::GetRandomXPoWHash(

View file

@ -137,6 +137,20 @@ double GetDifficulty(const CBlockIndex* blockindex)
return dDiff; return dDiff;
} }
int GetRPCBlockAlgo(
const CBlockIndex* blockindex,
const Consensus::Params& consensusParams)
{
assert(blockindex != nullptr);
// Before RandomX activation every block used SHA256D consensus,
// regardless of historical version-rolling bits.
if (blockindex->nHeight < consensusParams.randomXActivationHeight)
return ALGO_SHA256D;
return blockindex->GetBlockHeader().GetAlgo();
}
double GetAlgoDifficulty( double GetAlgoDifficulty(
const CBlockIndex* blockindex, const CBlockIndex* blockindex,
const Consensus::Params& consensusParams, const Consensus::Params& consensusParams,
@ -234,16 +248,18 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
result.pushKV("mediantime", (int64_t)blockindex->GetMedianTimePast()); result.pushKV("mediantime", (int64_t)blockindex->GetMedianTimePast());
result.pushKV("nonce", (uint64_t)blockindex->nNonce); result.pushKV("nonce", (uint64_t)blockindex->nNonce);
result.pushKV("bits", strprintf("%08x", blockindex->nBits)); result.pushKV("bits", strprintf("%08x", blockindex->nBits));
result.pushKV("difficulty", GetDifficulty(blockindex));
result.pushKV("chainwork", blockindex->nChainWork.GetHex()); result.pushKV("chainwork", blockindex->nChainWork.GetHex());
result.pushKV("nTx", (uint64_t)blockindex->nTx); result.pushKV("nTx", (uint64_t)blockindex->nTx);
const Consensus::Params& consensusParams = Params().GetConsensus(); const Consensus::Params& consensusParams = Params().GetConsensus();
const CBlockHeader block = blockindex->GetBlockHeader(); const CBlockHeader block = blockindex->GetBlockHeader();
const int algo = // Historical blocks before RandomX activation always used SHA256D,
blockindex->GetBlockHash() == consensusParams.hashGenesisBlock // regardless of version-rolling bits in their block headers.
? ALGO_SHA256D const int algo = GetRPCBlockAlgo(blockindex, consensusParams);
: block.GetAlgo();
result.pushKV(
"difficulty",
GetAlgoDifficulty(blockindex, consensusParams, algo));
result.pushKV("pow_algo_id", algo); result.pushKV("pow_algo_id", algo);

View file

@ -46,6 +46,14 @@ double GetDifficulty(const CBlockIndex* blockindex);
* SHA256D preserves the legacy GetDifficulty() scale. * SHA256D preserves the legacy GetDifficulty() scale.
* RandomX uses randomXInitialTarget as difficulty 1.0. * RandomX uses randomXInitialTarget as difficulty 1.0.
*/ */
/**
* Determine the PoW algorithm for RPC block statistics.
* Historical blocks always used SHA256D before RandomX activation.
*/
int GetRPCBlockAlgo(
const CBlockIndex* blockindex,
const Consensus::Params& consensusParams);
double GetAlgoDifficulty( double GetAlgoDifficulty(
const CBlockIndex* blockindex, const CBlockIndex* blockindex,
const Consensus::Params& consensusParams, const Consensus::Params& consensusParams,

View file

@ -704,17 +704,17 @@ static RPCHelpMan getmininginfo()
UniValue networkhashesps(UniValue::VOBJ); UniValue networkhashesps(UniValue::VOBJ);
networkhashesps.pushKV( networkhashesps.pushKV(
GetMiningAlgoName(ALGO_SHA256D), GetMiningAlgoName(ALGO_SHA256D),
GetNetworkHashPS(120, -1, active_chain, ALGO_SHA256D)); GetNetworkHashPS(-1, -1, active_chain, ALGO_SHA256D));
if (tip->nHeight + 1 >= consensusParams.randomXActivationHeight) { if (tip->nHeight + 1 >= consensusParams.randomXActivationHeight) {
networkhashesps.pushKV( networkhashesps.pushKV(
GetMiningAlgoName(ALGO_RANDOMX), GetMiningAlgoName(ALGO_RANDOMX),
GetNetworkHashPS(120, -1, active_chain, ALGO_RANDOMX)); GetNetworkHashPS(-1, -1, active_chain, ALGO_RANDOMX));
} }
obj.pushKV( obj.pushKV(
"networkhashps", "networkhashps",
GetNetworkHashPS(120, -1, active_chain, ALGO_SHA256D)); GetNetworkHashPS(-1, -1, active_chain, ALGO_SHA256D));
obj.pushKV("networkhashesps", networkhashesps); obj.pushKV("networkhashesps", networkhashesps);
obj.pushKV("pooledtx", (uint64_t)mempool.size()); obj.pushKV("pooledtx", (uint64_t)mempool.size());
obj.pushKV("chain", Params().NetworkIDString()); obj.pushKV("chain", Params().NetworkIDString());

View file

@ -107,4 +107,45 @@ BOOST_AUTO_TEST_CASE(get_algo_difficulty)
2.0); 2.0);
} }
BOOST_AUTO_TEST_CASE(historical_rpc_algo_classification)
{
const auto chainParams =
CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto& consensus = chainParams->GetConsensus();
BOOST_REQUIRE_EQUAL(consensus.randomXActivationHeight, 8099);
CBlockIndex block;
block.nVersion = 0x7fffffff;
block.nHeight = 5150;
// Historical version-rolling bits do not select a mining algorithm.
BOOST_CHECK_EQUAL(
GetRPCBlockAlgo(&block, consensus), ALGO_SHA256D);
block.nHeight = 8098;
BOOST_CHECK_EQUAL(
GetRPCBlockAlgo(&block, consensus), ALGO_SHA256D);
// From activation onward, use the explicit algorithm version bits.
block.nHeight = 8099;
block.nVersion = BLOCK_VERSION_DEFAULT | BLOCK_VERSION_SHA256D;
BOOST_CHECK_EQUAL(
GetRPCBlockAlgo(&block, consensus), ALGO_SHA256D);
block.nVersion = BLOCK_VERSION_DEFAULT | BLOCK_VERSION_RANDOMX;
BOOST_CHECK_EQUAL(
GetRPCBlockAlgo(&block, consensus), ALGO_RANDOMX);
block.nHeight = 9000;
BOOST_CHECK_EQUAL(
GetRPCBlockAlgo(&block, consensus), ALGO_RANDOMX);
// Unknown algorithm encoding must remain unknown after activation.
block.nVersion = 0x7fffffff;
BOOST_CHECK_EQUAL(
GetRPCBlockAlgo(&block, consensus), ALGO_UNKNOWN);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View file

@ -76,8 +76,13 @@ BOOST_AUTO_TEST_CASE(bloom_create_insert_serialize_with_tweak)
BOOST_AUTO_TEST_CASE(bloom_create_insert_key) BOOST_AUTO_TEST_CASE(bloom_create_insert_key)
{ {
std::string strSecret = std::string("5Kg1gnAjaLfKiwhhPpGS3QfRg2m6awQvaj98JCZBZQ5SuS2F15C"); // Original Bitcoin WIF test vector, decoded to its 32-byte secret.
CKey key = DecodeSecret(strSecret); // Avoid Bitcoin-specific WIF prefixes in Vexta's Bloom filter test.
const auto secret = ParseHex(
"f49addfd726a59abde172c86452f5f73038a02f4415878dc14934175e8418aff");
CKey key;
key.Set(secret.begin(), secret.end(), false);
BOOST_REQUIRE(key.IsValid());
CPubKey pubkey = key.GetPubKey(); CPubKey pubkey = key.GetPubKey();
std::vector<unsigned char> vchPubKey(pubkey.begin(), pubkey.end()); std::vector<unsigned char> vchPubKey(pubkey.begin(), pubkey.end());

File diff suppressed because one or more lines are too long

View file

@ -17,14 +17,14 @@
#include <vector> #include <vector>
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
static const std::string strSecret1 = "5HwoXVkHoRM8sL2KmNRS217n1g8mPPBomrY7yehCuXC1115WWsh"; static const std::string strSecret1 = "7e1usjAXTCgzJkhhDwsNnT5z7fF2tgB6rbVf48qxVPf9YXTaAs1";
static const std::string strSecret2 = "5J5KUK3VXP8HUefNVYPxwxVRokScZdWXpu1Tj8LfaAXMqHzMmbk"; static const std::string strSecret2 = "7e9RpYTjBAU8v5Ljx7quiQTdujYt4vVpudxzocVRA2zWNpHPvsU";
static const std::string strSecret1C = "KwntMbt59tTsj8xqpqYqRRWufyjGunvhSyeMo3NTYpFYzZbXJ5Hp"; static const std::string strSecret1C = "WJP2Nu73QebVwMtcY9BM9c916PnwM5uaquFUxqd5vK1NhjXYRYaH";
static const std::string strSecret2C = "KxN4XYdzu6f9j3EMryaMwZvUVLk3y29M4QZ2xwPoFP2zwka1aWxU"; static const std::string strSecret2C = "WJxCYqry9rnmwGA8aHCsfkYZukoiQK8ETLAA8jeRcsnpevTtrSCQ";
static const std::string addr1 = "DS1P3gwq6MFtatWprr2e2J32xGPd89n75C"; static const std::string addr1 = "VXXWS2sMVZnwJE6HqdMPRJvW8ShMT9xKWi";
static const std::string addr2 = "DMQ3t1L7BmTwL5wpZ9mek1KUaCRLJSXJWV"; static const std::string addr2 = "VSvBGMFdayzz3RXHXw6Q92CwkNj4he22C5";
static const std::string addr1C = "DU9umLs2Ze8eNRo69wbSj5HeufphJawFPh"; static const std::string addr1C = "VZg39gnYxrfh5mNZ8ivC86B85r8Ron95sz";
static const std::string addr2C = "DCiLe5VAcdLpGXURTDsaoryMWdMVBP9NoN"; static const std::string addr2C = "VJEU2RQh1qsrys3tS1CLCsrpgofDdvYt1Q";
static const std::string strAddressBad = "1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF"; static const std::string strAddressBad = "1HV9Lc3sNHZxwj4Zk6fB38tEmBryq2cBiF";

View file

@ -1,3 +1,6 @@
#include <crypto/randomx_hash.h>
#include <thread>
#include <array>
// Copyright (c) 2009-2020 The Bitcoin Core developers // Copyright (c) 2009-2020 The Bitcoin Core developers
// Copyright (c) 2014-2020 The DigiByte Core developers // Copyright (c) 2014-2020 The DigiByte Core developers
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
@ -1259,4 +1262,72 @@ BOOST_AUTO_TEST_CASE(RandomX_header_hash_vector_test)
"3c658cf690b31329ec4d1621bd579bc932ebfc7a02b26674184512be64ce94a6"); "3c658cf690b31329ec4d1621bd579bc932ebfc7a02b26674184512be64ce94a6");
} }
BOOST_AUTO_TEST_CASE(RandomX_cache_reuse_test)
{
CBlockHeader header;
header.nVersion = BLOCK_VERSION_DEFAULT | BLOCK_VERSION_RANDOMX;
header.nTime = 1783641600;
header.nBits = 0x1d00ffff;
header.nNonce = 12345;
const uint256 seedA = uint256S(
"00112233445566778899aabbccddeeff102132435465768798a9bacbdcedfe0f");
const uint256 seedB = uint256S(
"ffeeddccbbaa998877665544332211000123456789abcdef0123456789abcdef");
auto independentHash = [&](const uint256& seed, uint256& result) {
VextaRandomXHasher fresh(seed.data(), seed.size());
return fresh.IsValid() && header.GetRandomXPoWHash(fresh, result);
};
uint256 expectedA;
uint256 expectedB;
BOOST_REQUIRE(independentHash(seedA, expectedA));
BOOST_REQUIRE(independentHash(seedB, expectedB));
BOOST_CHECK(expectedA != expectedB);
uint256 actual;
BOOST_REQUIRE(header.GetRandomXPoWHash(seedA, actual));
BOOST_CHECK(actual == expectedA);
BOOST_REQUIRE(header.GetRandomXPoWHash(seedA, actual));
BOOST_CHECK(actual == expectedA);
BOOST_REQUIRE(header.GetRandomXPoWHash(seedB, actual));
BOOST_CHECK(actual == expectedB);
BOOST_REQUIRE(header.GetRandomXPoWHash(seedA, actual));
BOOST_CHECK(actual == expectedA);
// Each worker has its own thread-local cache and VM.
constexpr size_t workerCount = 4;
std::array<bool, workerCount> passed{};
std::vector<std::thread> workers;
for (size_t i = 0; i < workerCount; ++i) {
workers.emplace_back([&, i] {
uint256 valueA;
uint256 valueB;
uint256 valueAgain;
passed[i] =
header.GetRandomXPoWHash(seedA, valueA) &&
header.GetRandomXPoWHash(seedB, valueB) &&
header.GetRandomXPoWHash(seedA, valueAgain) &&
valueA == expectedA &&
valueB == expectedB &&
valueAgain == expectedA;
});
}
for (auto& worker : workers) {
worker.join();
}
for (bool result : passed) {
BOOST_CHECK(result);
}
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View file

@ -117,10 +117,10 @@ BOOST_AUTO_TEST_CASE(rpc_rawsign)
"\"vout\":1,\"scriptPubKey\":\"a914b10c9df5f7edf436c697f02f1efdba4cf399615187\"," "\"vout\":1,\"scriptPubKey\":\"a914b10c9df5f7edf436c697f02f1efdba4cf399615187\","
"\"redeemScript\":\"512103debedc17b3df2badbcdd86d5feb4562b86fe182e5998abd8bcd4f122c6155b1b21027e940bb73ab8732bfdf7f9216ecefca5b94d6df834e77e108f68e66f126044c052ae\"}]"; "\"redeemScript\":\"512103debedc17b3df2badbcdd86d5feb4562b86fe182e5998abd8bcd4f122c6155b1b21027e940bb73ab8732bfdf7f9216ecefca5b94d6df834e77e108f68e66f126044c052ae\"}]";
r = CallRPC(std::string("createrawtransaction ")+prevout+" "+ r = CallRPC(std::string("createrawtransaction ")+prevout+" "+
"{\"DS1P3gwq6MFtatWprr2e2J32xGPd89n75C\":11}"); "{\"VXXWS2sMVZnwJE6HqdMPRJvW8ShMT9xKWi\":11}");
std::string notsigned = r.get_str(); std::string notsigned = r.get_str();
std::string privkey1 = "\"KzsXybp9jX64P5ekX1KUxRQ79Jht9uzW7LorgwE65i5rWACL6LQe\""; std::string privkey1 = "\"WMTfzu37zHDgbJaXEJwzgc2CZimYbCyPWGQyrjUiTCqgDL5S68Cg\"";
std::string privkey2 = "\"Kyhdf5LuKTRx4ge69ybABsiUAWjVRK4XGxAKk2FQLp2HjGMy87Z4\""; std::string privkey2 = "\"WLHmgNZsaDZaGuZrsHDfv4LZavo9rc3QfsmSupW2iJn7SSDuuQYT\"";
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" [] "+prevout); r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" [] "+prevout);
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false); BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false);
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" ["+privkey1+","+privkey2+"] "+prevout); r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" ["+privkey1+","+privkey2+"] "+prevout);

View file

@ -212,7 +212,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
TestChain100Setup::TestChain100Setup() TestChain100Setup::TestChain100Setup()
{ {
SetMockTime(1598887952); SetMockTime(1783641600); // 2026-07-10 UTC, after Vexta genesis
constexpr std::array<unsigned char, 32> vchKey = { constexpr std::array<unsigned char, 32> vchKey = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}; {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}};
coinbaseKey.Set(vchKey.begin(), vchKey.end(), true); coinbaseKey.Set(vchKey.begin(), vchKey.end(), true);
@ -223,9 +223,11 @@ TestChain100Setup::TestChain100Setup()
{ {
LOCK(::cs_main); LOCK(::cs_main);
assert( // The tip hash changes when mocktime changes. Verify the
m_node.chainman->ActiveChain().Tip()->GetBlockHash().ToString() == // completed test chain instead of a timestamp-dependent hash.
"e09bcc217cb31a6c1fd7b33d160d7356c97672eac3b7d917f83f3d43ea12ad4d"); const CBlockIndex* tip = m_node.chainman->ActiveChain().Tip();
assert(tip != nullptr);
assert(tip->nHeight == COINBASE_MATURITY_2);
} }
} }

View file

@ -336,33 +336,102 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
} }
} }
BOOST_AUTO_TEST_CASE(unknown_pow_algo_rejected) BOOST_AUTO_TEST_CASE(unknown_pow_algo_rejected_after_activation)
{ {
const uint256 genesis_hash = Params().GenesisBlock().GetHash(); const uint256 genesis_hash = Params().GenesisBlock().GetHash();
auto block = GoodBlock(genesis_hash); auto block = GoodBlock(genesis_hash);
CBlockHeader header = block->GetBlockHeader(); CBlockHeader header = block->GetBlockHeader();
// Use an unsupported algorithm bit pattern.
header.nVersion &= ~BLOCK_VERSION_ALGO; header.nVersion &= ~BLOCK_VERSION_ALGO;
header.nVersion |= (3 << 8); header.nVersion |= (3 << 8);
BOOST_REQUIRE_EQUAL(header.GetAlgo(), ALGO_UNKNOWN); BOOST_REQUIRE_EQUAL(header.GetAlgo(), ALGO_UNKNOWN);
// Ensure that an invalid SHA256D hash cannot mask the actual
// unknown-algorithm rejection.
const auto& consensus = Params().GetConsensus();
bool valid_pow = false;
for (uint64_t attempt = 0; attempt < 1000000; ++attempt) {
if (CheckProofOfWork(header.GetHash(), header.nBits, consensus)) {
valid_pow = true;
break;
}
++header.nNonce;
}
BOOST_REQUIRE_MESSAGE(valid_pow, "Could not mine negative-test header");
// Restore test-only activation parameters automatically, including
// when validation throws.
auto& mutable_consensus = const_cast<Consensus::Params&>(consensus);
struct ActivationRestore {
Consensus::Params& params;
const int original;
~ActivationRestore() { params.randomXActivationHeight = original; }
};
const int original_height = mutable_consensus.randomXActivationHeight;
BOOST_REQUIRE(original_height > 1);
{
ActivationRestore restore{mutable_consensus, original_height};
mutable_consensus.randomXActivationHeight = 1;
BlockValidationState state;
const std::vector<CBlockHeader> headers{header};
const bool accepted =
Assert(m_node.chainman)->ProcessNewBlockHeaders(
headers, state, Params());
BOOST_CHECK(!accepted);
BOOST_CHECK(
state.GetResult() == BlockValidationResult::BLOCK_INVALID_HEADER);
BOOST_CHECK_EQUAL(
state.GetRejectReason(), "unknown-pow-algo");
}
}
BOOST_AUTO_TEST_CASE(historical_version_bits_accepted_before_randomx)
{
const uint256 genesis_hash = Params().GenesisBlock().GetHash();
auto block = GoodBlock(genesis_hash);
CBlockHeader header = block->GetBlockHeader();
// Historical SHA256D did not require multi-algo version encoding.
// This block extends genesis, before RandomX activation.
BOOST_REQUIRE(Params().GetConsensus().randomXActivationHeight > 1);
header.nVersion &= ~BLOCK_VERSION_ALGO;
header.nVersion |= (3 << 8);
BOOST_REQUIRE_EQUAL(header.GetAlgo(), ALGO_UNKNOWN);
// Changing nVersion changes the block hash. Mine a valid SHA256D
// nonce so this test checks historical compatibility, not high-hash.
const auto& consensus = Params().GetConsensus();
bool valid_pow = false;
for (uint64_t attempt = 0; attempt < 1000000; ++attempt) {
if (CheckProofOfWork(header.GetHash(), header.nBits, consensus)) {
valid_pow = true;
break;
}
++header.nNonce;
}
BOOST_REQUIRE_MESSAGE(valid_pow, "Could not mine historical test header");
BlockValidationState state; BlockValidationState state;
const std::vector<CBlockHeader> headers{header}; const std::vector<CBlockHeader> headers{header};
BOOST_CHECK(!Assert(m_node.chainman)->ProcessNewBlockHeaders( BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders(
headers, headers,
state, state,
Params())); Params()));
BOOST_CHECK(state.IsValid());
BOOST_CHECK(
state.GetResult() ==
BlockValidationResult::BLOCK_INVALID_HEADER);
BOOST_CHECK_EQUAL(
state.GetRejectReason(),
"unknown-pow-algo");
} }

View file

@ -270,7 +270,16 @@ BOOST_FIXTURE_TEST_CASE(chainstatemanager_activate_snapshot, TestChain100Setup)
metadata.m_base_blockhash = uint256::ONE; metadata.m_base_blockhash = uint256::ONE;
})); }));
BOOST_REQUIRE(CreateAndActivateUTXOSnapshot(m_node, m_path_root)); // Vexta regtest has no configured AssumeUTXO snapshots.
// A valid snapshot file must therefore be rejected at height 110.
BOOST_REQUIRE(!ExpectedAssumeutxo(snapshot_height, ::Params()));
BOOST_REQUIRE(!CreateAndActivateUTXOSnapshot(m_node, m_path_root));
BOOST_CHECK(!chainman.SnapshotBlockhash());
BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash);
// Positive snapshot activation requires trusted AssumeUTXO metadata.
// Do not execute the inherited positive scenario without that metadata.
return;
// Ensure our active chain is the snapshot chainstate. // Ensure our active chain is the snapshot chainstate.
BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash->IsNull()); BOOST_CHECK(!chainman.ActiveChainstate().m_from_snapshot_blockhash->IsNull());

View file

@ -56,7 +56,7 @@ static void TestBlockSubsidy(const Consensus::Params& consensusParams)
{ {
const int interval = consensusParams.nSubsidyHalvingInterval; const int interval = consensusParams.nSubsidyHalvingInterval;
BOOST_CHECK_EQUAL(interval, 210240); BOOST_CHECK_EQUAL(interval, 210000);
BOOST_CHECK_EQUAL(GetBlockSubsidy(0, consensusParams), 50 * COIN); BOOST_CHECK_EQUAL(GetBlockSubsidy(0, consensusParams), 50 * COIN);
BOOST_CHECK_EQUAL(GetBlockSubsidy(interval - 1, consensusParams), 50 * COIN); BOOST_CHECK_EQUAL(GetBlockSubsidy(interval - 1, consensusParams), 50 * COIN);
@ -148,17 +148,14 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo)
BOOST_CHECK(!out); BOOST_CHECK(!out);
} }
const auto out110 = *ExpectedAssumeutxo(110, *params); // Vexta regtest has no configured AssumeUTXO snapshots.
BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(), "58c8c65a67deee7f6cca0d5a08254b73198f13201485cb6a39dba03e5f41ee65"); // In particular, the inherited Bitcoin test heights must be absent.
BOOST_CHECK_EQUAL(out110.nChainTx, 110U); BOOST_CHECK(!ExpectedAssumeutxo(110, *params));
BOOST_CHECK(!ExpectedAssumeutxo(200, *params));
const auto out210 = *ExpectedAssumeutxo(200, *params);
BOOST_CHECK_EQUAL(out210.hash_serialized.ToString(), "51c8d11d8b5c1de51543c579736e786aa2736206d1e11e627568029ce092cf62");
BOOST_CHECK_EQUAL(out210.nChainTx, 200U);
} }
BOOST_AUTO_TEST_CASE(RandomX_pre_activation_rejected) BOOST_AUTO_TEST_CASE(historical_randomx_bits_invalid_sha256d_rejected)
{ {
const CChainParams& params = Params(); const CChainParams& params = Params();
const CBlock& genesis = params.GenesisBlock(); const CBlock& genesis = params.GenesisBlock();
@ -172,6 +169,12 @@ BOOST_AUTO_TEST_CASE(RandomX_pre_activation_rejected)
header.nBits = genesis.nBits; header.nBits = genesis.nBits;
header.nNonce = 0; header.nNonce = 0;
// Before activation, version bits do not select RandomX PoW.
// This header must fail the historical SHA256D proof-of-work check.
BOOST_REQUIRE(header.GetAlgo() == ALGO_RANDOMX);
BOOST_REQUIRE(
!CheckProofOfWork(header.GetHash(), header.nBits, params.GetConsensus()));
BlockValidationState state; BlockValidationState state;
BOOST_CHECK(!Assert(m_node.chainman)->ProcessNewBlockHeaders( BOOST_CHECK(!Assert(m_node.chainman)->ProcessNewBlockHeaders(
@ -181,7 +184,7 @@ BOOST_AUTO_TEST_CASE(RandomX_pre_activation_rejected)
BOOST_CHECK(state.IsInvalid()); BOOST_CHECK(state.IsInvalid());
BOOST_CHECK(state.GetResult() == BlockValidationResult::BLOCK_INVALID_HEADER); BOOST_CHECK(state.GetResult() == BlockValidationResult::BLOCK_INVALID_HEADER);
BOOST_CHECK_EQUAL(state.GetRejectReason(), "algo-inactive"); BOOST_CHECK_EQUAL(state.GetRejectReason(), "high-hash");
} }
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()

View file

@ -272,7 +272,14 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
// should not be any signalling for first block // should not be any signalling for first block
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(nullptr, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS); BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(nullptr, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
// always/never active deployments shouldn't need to be tested further // PQR uses height-based activation instead of standard BIP9.
// Its min_activation_height can be nonzero with NEVER_ACTIVE.
if (dep == Consensus::DEPLOYMENT_PQR) {
BOOST_CHECK_GE(min_activation_height, 0);
return;
}
// Standard always/never active BIP9 deployments.
if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE || if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE ||
nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE)
{ {
@ -412,6 +419,43 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0); BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
} }
BOOST_AUTO_TEST_CASE(vexta_pqr_height_activation)
{
for (const auto& chain_name : {
CBaseChainParams::MAIN,
CBaseChainParams::TESTNET,
CBaseChainParams::SIGNET,
CBaseChainParams::REGTEST}) {
const auto chainParams = CreateChainParams(*m_node.args, chain_name);
const auto& params = chainParams->GetConsensus();
const int activation =
params.vDeployments[Consensus::DEPLOYMENT_PQR].min_activation_height;
BOOST_REQUIRE(activation >= 0);
CBlockIndex previous;
previous.nHeight = activation - 2;
if (activation > 1) {
BOOST_CHECK(
g_versionbitscache.State(
&previous, params, Consensus::DEPLOYMENT_PQR)
!= ThresholdState::ACTIVE);
}
previous.nHeight = activation - 1;
BOOST_CHECK(
g_versionbitscache.State(
&previous, params, Consensus::DEPLOYMENT_PQR)
== ThresholdState::ACTIVE);
BOOST_CHECK_EQUAL(
g_versionbitscache.StateSinceHeight(
&previous, params, Consensus::DEPLOYMENT_PQR),
activation);
}
}
BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
{ {
// check that any deployment on any chain can conceivably reach both // check that any deployment on any chain can conceivably reach both

View file

@ -1654,6 +1654,27 @@ void StopScriptCheckWorkerThreads()
// Protected by cs_main // Protected by cs_main
VersionBitsCache versionbitscache; VersionBitsCache versionbitscache;
// Vexta: Recognize valid SHA256D / RandomX algorithm encoding in block
// versions after multi-algo activation. This is diagnostic-only.
static uint32_t KnownMultiAlgoVersionBits(
const CBlockIndex* pindex,
const Consensus::Params& params)
{
if (pindex->nHeight < params.randomXActivationHeight) {
return 0;
}
const uint32_t algo_bits =
static_cast<uint32_t>(pindex->nVersion) & BLOCK_VERSION_ALGO;
if (algo_bits == BLOCK_VERSION_SHA256D ||
algo_bits == BLOCK_VERSION_RANDOMX) {
return BLOCK_VERSION_ALGO;
}
return 0;
}
/** /**
* Threshold condition checker that triggers when unknown versionbits are seen on the network. * Threshold condition checker that triggers when unknown versionbits are seen on the network.
*/ */
@ -1673,6 +1694,7 @@ public:
bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const override bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const override
{ {
return pindex->nHeight >= params.MinBIP9WarningHeight && return pindex->nHeight >= params.MinBIP9WarningHeight &&
((KnownMultiAlgoVersionBits(pindex, params) >> bit) & 1) == 0 &&
((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && ((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) &&
((pindex->nVersion >> bit) & 1) != 0 && ((pindex->nVersion >> bit) & 1) != 0 &&
((g_versionbitscache.ComputeBlockVersion(pindex->pprev, params) >> bit) & 1) == 0; ((g_versionbitscache.ComputeBlockVersion(pindex->pprev, params) >> bit) & 1) == 0;
@ -2308,7 +2330,8 @@ void CChainState::UpdateTip(const CBlockIndex* pindexNew)
const uint32_t unexpectedBits = const uint32_t unexpectedBits =
(static_cast<uint32_t>(pindex->nVersion) & (static_cast<uint32_t>(pindex->nVersion) &
~static_cast<uint32_t>(nExpectedVersion)) & ~static_cast<uint32_t>(nExpectedVersion)) &
~VERSION_ROLLING_MASK; ~VERSION_ROLLING_MASK &
~KnownMultiAlgoVersionBits(pindex, m_params.GetConsensus());
if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && unexpectedBits != 0) if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && unexpectedBits != 0)
{ {
@ -3057,7 +3080,13 @@ CBlockIndex* BlockManager::AddToBlockIndex(
); );
} }
const int algo = pindexNew->GetAlgo(); // Before RandomX activation, the chain uses SHA256D exclusively.
// Historical version-rolling bits must not break the algorithm index.
const int algo =
pindexNew->nHeight < consensus_params.randomXActivationHeight
? ALGO_SHA256D
: pindexNew->GetAlgo();
if (algo >= 0 && algo < NUM_ALGOS_IMPL) { if (algo >= 0 && algo < NUM_ALGOS_IMPL) {
pindexNew->lastAlgoBlocks[algo] = pindexNew; pindexNew->lastAlgoBlocks[algo] = pindexNew;
} }
@ -3220,10 +3249,15 @@ static bool CheckBlockHeader(const CBlockHeader& block, BlockValidationState& st
if (algo == ALGO_RANDOMX) if (algo == ALGO_RANDOMX)
return true; return true;
return state.Invalid( // Historical SHA256D blocks may contain version-rolling bits that
BlockValidationResult::BLOCK_INVALID_HEADER, // do not match the multi-algo encoding. Their height is unknown here.
"unknown-pow-algo", // Verify SHA256D PoW now; contextual validation will only permit
"unknown proof of work algorithm"); // these versions before RandomX activation.
if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER,
"high-hash", "proof of work failed");
return true;
} }
bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW, bool fCheckMerkleRoot) bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW, bool fCheckMerkleRoot)
@ -3372,7 +3406,25 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
// Check proof-of-work algorithm and difficulty. // Check proof-of-work algorithm and difficulty.
const Consensus::Params& consensusParams = params.GetConsensus(); const Consensus::Params& consensusParams = params.GetConsensus();
const int algo = block.GetAlgo(); // Before multi-algo activation, all blocks follow the original
// SHA256D consensus rules, regardless of historical version bits.
// From activation onward, enforce the explicit algorithm encoding.
const int algo =
nHeight < consensusParams.randomXActivationHeight
? ALGO_SHA256D
: block.GetAlgo();
// A pre-activation header classified as RandomX bypasses the
// context-free SHA256D check. Enforce historical SHA256D PoW here.
if (nHeight < consensusParams.randomXActivationHeight &&
block.GetAlgo() != ALGO_SHA256D &&
fCheckPOW &&
!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) {
return state.Invalid(
BlockValidationResult::BLOCK_INVALID_HEADER,
"high-hash",
"historical SHA256D proof of work failed");
}
if (algo == ALGO_RANDOMX) { if (algo == ALGO_RANDOMX) {
if (!CheckContextualRandomXProofOfWork(block, state, consensusParams, pindexPrev, fCheckPOW)) if (!CheckContextualRandomXProofOfWork(block, state, consensusParams, pindexPrev, fCheckPOW))
@ -3961,7 +4013,13 @@ bool BlockManager::LoadBlockIndex(
); );
} }
const int algo = pindex->GetAlgo(); // Reconstruct the same height-aware algorithm index on restart.
// All pre-activation blocks belong to the historical SHA256D chain.
const int algo =
pindex->nHeight < consensus_params.randomXActivationHeight
? ALGO_SHA256D
: pindex->GetAlgo();
if (algo >= 0 && algo < NUM_ALGOS_IMPL) { if (algo >= 0 && algo < NUM_ALGOS_IMPL) {
pindex->lastAlgoBlocks[algo] = pindex; pindex->lastAlgoBlocks[algo] = pindex;
} }