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,3 +1,6 @@
#include <crypto/randomx_hash.h>
#include <thread>
#include <array>
// Copyright (c) 2009-2020 The Bitcoin Core developers
// Copyright (c) 2014-2020 The DigiByte Core developers
// Distributed under the MIT/X11 software license, see the accompanying
@ -1259,4 +1262,72 @@ BOOST_AUTO_TEST_CASE(RandomX_header_hash_vector_test)
"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()