Add algorithm-aware mining difficulty

This commit is contained in:
Capri 2026-09-17 18:31:43 +00:00
commit 37d4ae0d1b
Signed by: VextaProject
SSH key fingerprint: SHA256:739BZv8LvIDY2tR7lXLy/IQ6MaGTQtYcG9GNvCjmpVM
4 changed files with 92 additions and 3 deletions

View file

@ -7,6 +7,8 @@
#include <stdlib.h>
#include <chain.h>
#include <chainparams.h>
#include <pow.h>
#include <rpc/blockchain.h>
#include <test/util/setup_common.h>
#include <util/string.h>
@ -74,4 +76,35 @@ BOOST_AUTO_TEST_CASE(get_difficulty_for_very_high_target)
TestDifficulty(0x12345678, 5913134931067755359633408.0);
}
BOOST_AUTO_TEST_CASE(get_algo_difficulty)
{
const auto chainParams =
CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
const auto& consensus = chainParams->GetConsensus();
CBlockIndex sha;
sha.nBits = UintToArith256(consensus.powLimit).GetCompact();
BOOST_CHECK_EQUAL(
GetAlgoDifficulty(&sha, consensus, ALGO_SHA256D),
GetDifficulty(&sha));
CBlockIndex randomx;
randomx.nBits =
UintToArith256(consensus.randomXInitialTarget).GetCompact();
RejectDifficultyMismatch(
GetAlgoDifficulty(&randomx, consensus, ALGO_RANDOMX),
1.0);
arith_uint256 harderRandomXTarget =
UintToArith256(consensus.randomXInitialTarget);
harderRandomXTarget /= 2;
randomx.nBits = harderRandomXTarget.GetCompact();
RejectDifficultyMismatch(
GetAlgoDifficulty(&randomx, consensus, ALGO_RANDOMX),
2.0);
}
BOOST_AUTO_TEST_SUITE_END()