Make RandomX block templates activation-aware

This commit is contained in:
Capri 2026-09-15 20:02:12 +00:00
commit 00158bc780
Signed by: VextaProject
SSH key fingerprint: SHA256:739BZv8LvIDY2tR7lXLy/IQ6MaGTQtYcG9GNvCjmpVM
7 changed files with 104 additions and 12 deletions

View file

@ -639,7 +639,12 @@ static RPCHelpMan getblocktemplate()
if (strAlgo == "sha256d") {
algo = ALGO_SHA256D;
} else if (strAlgo == "randomx") {
throw JSONRPCError(RPC_INVALID_PARAMETER, "RandomX is not active yet");
const CBlockIndex* tip = chainman.ActiveChain().Tip();
if (tip == nullptr ||
tip->nHeight + 1 < Params().GetConsensus().randomXActivationHeight) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "RandomX is not active yet");
}
algo = ALGO_RANDOMX;
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proof-of-work algorithm");
}
@ -809,7 +814,7 @@ static RPCHelpMan getblocktemplate()
CBlock* pblock = &pblocktemplate->block; // pointer for convenience
// Update nTime
UpdateTime(pblock, consensusParams, pindexPrev);
UpdateTime(pblock, consensusParams, pindexPrev, algo);
pblock->nNonce = 0;
// NOTE: If at some point we support pre-segwit miners post-segwit-activation, this needs to take segwit support into consideration