Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correctly provide different template per algorithm #5

Merged
merged 2 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/multialgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

int defaultAlgo;

const int GetAlgoWorkFactor(int height, int algo, const Consensus::Params& params)
int GetAlgoWorkFactor(int height, int algo, const Consensus::Params& params)
{
if (height < params.nMultiAlgoStartBlock) {
return 1;
Expand All @@ -29,7 +29,7 @@ const int GetAlgoWorkFactor(int height, int algo, const Consensus::Params& param
}
}

const int GetVersionForAlgo(int algo)
int GetVersionForAlgo(int algo)
{
switch (algo) {
case ALGO_SCRYPT:
Expand All @@ -46,7 +46,7 @@ const int GetVersionForAlgo(int algo)
return 0;
}

const int GetAlgo(int nVersion)
int GetAlgo(int nVersion)
{
switch (nVersion & BLOCK_VERSION_ALGO) {
case BLOCK_VERSION_SCRYPT:
Expand Down Expand Up @@ -80,7 +80,7 @@ std::string GetAlgoName(int algo)
return std::string("unknown");
}

const int MatchAlgoName(std::string userAlgo)
int MatchAlgoName(std::string userAlgo)
{
for (unsigned int i = 0; i < NUM_ALGOS; i++) {
if (boost::to_lower_copy(userAlgo.substr(0,6)) == boost::to_lower_copy(GetAlgoName(i).substr(0,6))) {
Expand All @@ -91,7 +91,7 @@ const int MatchAlgoName(std::string userAlgo)
return ALGO_SCRYPT;
}

const int GetAlgoByIndex(const CBlockIndex* pindex)
int GetAlgoByIndex(const CBlockIndex* pindex)
{
return GetAlgo(pindex->GetBlockHeader().nVersion);
}
Expand Down
10 changes: 5 additions & 5 deletions src/multialgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ enum {
BLOCK_VERSION_BALLOON = (8 << 8),
};

const int GetAlgoWorkFactor(int height, int algo, const Consensus::Params& params);
const int GetVersionForAlgo(int algo);
const int GetAlgo(int nVersion);
const int GetAlgoByIndex(const CBlockIndex* pindex);
const int MatchAlgoName(std::string userAlgo);
int GetAlgoWorkFactor(int height, int algo, const Consensus::Params& params);
int GetVersionForAlgo(int algo);
int GetAlgo(int nVersion);
int GetAlgoByIndex(const CBlockIndex* pindex);
int MatchAlgoName(std::string userAlgo);
std::string GetAlgoName(int algo);
std::string GetAlgoNameByIndex(const CBlockIndex* pindex);
bool IsAlgoActive(const CBlockIndex* pindexPrev, int algo, const Consensus::Params& params);
Expand Down
10 changes: 6 additions & 4 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,7 @@ static RPCHelpMan getblocktemplate()
}},
},
"\"template_request\""},
{"algo", RPCArg::Type::STR, RPCArg::Optional::OMITTED_NAMED_ARG, "The algorithm if a different template is required."},
},
{
RPCResult{"If the proposal was accepted with mode=='proposal'", RPCResult::Type::NONE, "", ""},
Expand Down Expand Up @@ -797,18 +798,19 @@ static RPCHelpMan getblocktemplate()

// Update block
static CBlockIndex* pindexPrev;
static int64_t nStart;
static std::unique_ptr<CBlockTemplate> pblocktemplate;
if (pindexPrev != active_chain.Tip() ||
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5))
if (algoNum != defaultAlgo ||
pindexPrev != active_chain.Tip() ||
(mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast))
{
defaultAlgo = algoNum;

// Clear pindexPrev so future calls make a new block, despite any failures from here on
pindexPrev = nullptr;

// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex* pindexPrevNew = active_chain.Tip();
nStart = GetTime();

// Create new block
CScript scriptDummy = CScript() << OP_TRUE;
Expand Down