Expose RandomX seed in getblocktemplate

This commit is contained in:
Capri 2026-09-16 22:56:10 +00:00
commit 2c7dfb6a75
Signed by: VextaProject
SSH key fingerprint: SHA256:739BZv8LvIDY2tR7lXLy/IQ6MaGTQtYcG9GNvCjmpVM
2 changed files with 45 additions and 0 deletions

View file

@ -863,6 +863,10 @@ static RPCHelpMan getblocktemplate()
{RPCResult::Type::NUM_TIME, "curtime", "current timestamp in " + UNIX_EPOCH_TIME},
{RPCResult::Type::STR, "bits", "compressed target of next block"},
{RPCResult::Type::NUM, "height", "The height of the next block"},
{RPCResult::Type::NUM, "pow_algo_id", "Mining algorithm id: 0 for SHA256D, 1 for RandomX"},
{RPCResult::Type::STR, "pow_algo", "Mining algorithm name: sha256d or randomx"},
{RPCResult::Type::NUM, "randomx_seed_height", /* optional */ true, "Height of the block used as the RandomX seed source"},
{RPCResult::Type::STR_HEX, "randomx_seed", /* optional */ true, "RandomX seed key in raw uint256 byte order"},
{RPCResult::Type::STR, "default_witness_commitment", /* optional */ true, "a valid witness commitment for the unmodified block template"},
}},
},
@ -1212,6 +1216,31 @@ static RPCHelpMan getblocktemplate()
result.pushKV("bits", strprintf("%08x", pblock->nBits));
result.pushKV("height", (int64_t)(pindexPrev->nHeight+1));
result.pushKV("pow_algo_id", algo);
result.pushKV("pow_algo", GetMiningAlgoName(algo));
if (algo == ALGO_RANDOMX) {
const int blockHeight = pindexPrev->nHeight + 1;
const int seedHeight =
GetRandomXSeedHeight(blockHeight, consensusParams);
uint256 randomxSeed;
if (!GetRandomXSeed(
pindexPrev,
blockHeight,
consensusParams,
randomxSeed)) {
throw JSONRPCError(
RPC_INTERNAL_ERROR,
"Failed to resolve RandomX seed");
}
result.pushKV("randomx_seed_height", seedHeight);
result.pushKV(
"randomx_seed",
HexStr(MakeUCharSpan(randomxSeed)));
}
if (consensusParams.signet_blocks) {
result.pushKV("signet_challenge", HexStr(consensusParams.signet_challenge));
}