Skip to content

Commit 9974e54

Browse files
committed
Add RPCs for external RandomX mining
1 parent b2b688a commit 9974e54

File tree

7 files changed

+314
-168
lines changed

7 files changed

+314
-168
lines changed

src/miner.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ void BlockAssembler::resetBlock()
128128
nFees = 0;
129129
}
130130

131-
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx, bool fProofOfStake, bool fProofOfFullNode)
131+
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx, bool fProofOfStake, bool fProofOfFullNode, int nPoWType)
132132
{
133133
int64_t nTimeStart = GetTimeMicros();
134134
int64_t nComputeTimeStart = GetTimeMillis();
@@ -207,7 +207,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
207207
}
208208
}
209209

210-
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus(), pblock->nTime, !fProofOfStake);
210+
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus(), pblock->nTime, !fProofOfStake, nPoWType);
211211
// -regtest only: allow overriding block.nVersion with
212212
// -blockversion=N to test forking scenarios
213213
if (chainparams.MineBlocksOnDemand())

src/miner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class BlockAssembler
208208
BlockAssembler(const CChainParams& params, const Options& options);
209209

210210
/** Construct a new block template with coinbase to scriptPubKeyIn */
211-
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true, bool fProofOfStake=false, bool fProofOfFullNode = false);
211+
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true, bool fProofOfStake=false, bool fProofOfFullNode = false, int nPoWType = 0);
212212

213213
private:
214214
// utility functions

src/rpc/mining.cpp

+301-159
Large diffs are not rendered by default.

src/util/strencodings.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,15 @@ bool ParseInt64(const std::string& str, int64_t *out)
304304
n <= std::numeric_limits<int64_t>::max();
305305
}
306306

307-
bool ParseUInt32(const std::string& str, uint32_t *out)
307+
bool ParseUInt32(const std::string& str, uint32_t *out, int base)
308308
{
309309
if (!ParsePrechecks(str))
310310
return false;
311311
if (str.size() >= 1 && str[0] == '-') // Reject negative values, unfortunately strtoul accepts these by default if they fit in the range
312312
return false;
313313
char *endp = nullptr;
314314
errno = 0; // strtoul will not set errno if valid
315-
unsigned long int n = strtoul(str.c_str(), &endp, 10);
315+
unsigned long int n = strtoul(str.c_str(), &endp, base);
316316
if(out) *out = (uint32_t)n;
317317
// Note that strtoul returns a *unsigned long int*, so even if it doesn't report an over/underflow
318318
// we still have to check that the returned value is within the range of an *uint32_t*. On 64-bit

src/util/strencodings.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ bool ParseInt64(const std::string& str, int64_t *out);
9393
* @returns true if the entire string could be parsed as valid integer,
9494
* false if not the entire string could be parsed or when overflow or underflow occurred.
9595
*/
96-
bool ParseUInt32(const std::string& str, uint32_t *out);
96+
bool ParseUInt32(const std::string& str, uint32_t *out, int base = 10);
9797

9898
/**
9999
* Convert decimal string to unsigned 64-bit integer with strict parse error feedback.

src/validation.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ void ThreadScriptCheck() {
21372137
// Protected by cs_main
21382138
VersionBitsCache versionbitscache;
21392139

2140-
int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, const uint32_t& blockTime, const bool& fProofOfWork)
2140+
int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, const uint32_t& blockTime, const bool& fProofOfWork, int nPoWType)
21412141
{
21422142
LOCK(cs_main);
21432143
int32_t nVersion = VERSIONBITS_OLD_POW_VERSION;
@@ -2146,7 +2146,11 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para
21462146
nVersion = VERSIONBITS_NEW_POW_VERSION;
21472147

21482148
if (fProofOfWork) {
2149-
if (GetMiningAlgorithm() == MINE_PROGPOW) {
2149+
if (nPoWType == CBlockHeader::PROGPOW_BLOCK ||
2150+
nPoWType == CBlockHeader::RANDOMX_BLOCK ||
2151+
nPoWType == CBlockHeader::SHA256D_BLOCK) {
2152+
nVersion |= nPoWType;
2153+
} else if (GetMiningAlgorithm() == MINE_PROGPOW) {
21502154
nVersion |= CBlockHeader::PROGPOW_BLOCK;
21512155
} else if (GetMiningAlgorithm() == MINE_SHA256D) {
21522156
nVersion |= CBlockHeader::SHA256D_BLOCK;

src/validation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ extern VersionBitsCache versionbitscache;
536536
/**
537537
* Determine what nVersion a new block should use.
538538
*/
539-
int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, const uint32_t& blockTime, const bool& fProofOfWork);
539+
int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, const uint32_t& blockTime, const bool& fProofOfWork, int nPoWType = 0);
540540

541541
/** Reject codes greater or equal to this can be returned by AcceptToMemPool
542542
* for transactions, to signal internal conditions. They cannot and should not

0 commit comments

Comments
 (0)