Remove buggy and confusing IncrementExtraNonce

This commit is contained in:
MarcoFalke
2022-04-01 10:26:54 +02:00
parent 7ab9fc32d6
commit fa38b1c8bd
7 changed files with 22 additions and 45 deletions

View File

@@ -7,6 +7,7 @@
#include <chainparams.h>
#include <consensus/amount.h>
#include <consensus/consensus.h>
#include <consensus/merkle.h>
#include <consensus/params.h>
#include <consensus/validation.h>
#include <core_io.h>
@@ -43,7 +44,6 @@
using node::BlockAssembler;
using node::CBlockTemplate;
using node::IncrementExtraNonce;
using node::NodeContext;
using node::RegenerateCommitments;
using node::UpdateTime;
@@ -116,14 +116,10 @@ static RPCHelpMan getnetworkhashps()
};
}
static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, unsigned int& extra_nonce, uint256& block_hash)
static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, uint256& block_hash)
{
block_hash.SetNull();
{
LOCK(cs_main);
IncrementExtraNonce(&block, chainman.ActiveChain().Tip(), extra_nonce);
}
block.hashMerkleRoot = BlockMerkleRoot(block);
CChainParams chainparams(Params());
@@ -157,7 +153,6 @@ static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& me
nHeight = chainman.ActiveChain().Height();
nHeightEnd = nHeight+nGenerate;
}
unsigned int nExtraNonce = 0;
UniValue blockHashes(UniValue::VARR);
while (nHeight < nHeightEnd && !ShutdownRequested())
{
@@ -167,7 +162,7 @@ static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& me
CBlock *pblock = &pblocktemplate->block;
uint256 block_hash;
if (!GenerateBlock(chainman, *pblock, nMaxTries, nExtraNonce, block_hash)) {
if (!GenerateBlock(chainman, *pblock, nMaxTries, block_hash)) {
break;
}
@@ -397,9 +392,8 @@ static RPCHelpMan generateblock()
uint256 block_hash;
uint64_t max_tries{DEFAULT_MAX_TRIES};
unsigned int extra_nonce{0};
if (!GenerateBlock(chainman, block, max_tries, extra_nonce, block_hash) || block_hash.IsNull()) {
if (!GenerateBlock(chainman, block, max_tries, block_hash) || block_hash.IsNull()) {
throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block.");
}