aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-03-10 10:45:28 +0100
committerMarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>2023-03-10 10:39:08 +0100
commitfab9a08e145dc5a1d9576bf062473f1095b56a16 (patch)
tree33430d7f67be4db81133cb992d9ad6da5883cbc1
parent8d12127a9c19cb218d661a88ab9b6871c9d853b9 (diff)
refactor: Replace block_hash with block_out
-rw-r--r--src/rpc/mining.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 8753f845a5..0df43d1b41 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -115,9 +115,9 @@ static RPCHelpMan getnetworkhashps()
};
}
-static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, uint256& block_hash)
+static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& max_tries, std::shared_ptr<const CBlock>& block_out)
{
- block_hash.SetNull();
+ block_out.reset();
block.hashMerkleRoot = BlockMerkleRoot(block);
while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainman.GetConsensus()) && !ShutdownRequested()) {
@@ -131,12 +131,11 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t&
return true;
}
- std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
- if (!chainman.ProcessNewBlock(shared_pblock, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr)) {
+ block_out = std::make_shared<const CBlock>(block);
+ if (!chainman.ProcessNewBlock(block_out, /*force_processing=*/true, /*min_pow_checked=*/true, nullptr)) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted");
}
- block_hash = block.GetHash();
return true;
}
@@ -147,16 +146,15 @@ static UniValue generateBlocks(ChainstateManager& chainman, const CTxMemPool& me
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler{chainman.ActiveChainstate(), &mempool}.CreateNewBlock(coinbase_script));
if (!pblocktemplate.get())
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
- CBlock *pblock = &pblocktemplate->block;
- uint256 block_hash;
- if (!GenerateBlock(chainman, *pblock, nMaxTries, block_hash)) {
+ std::shared_ptr<const CBlock> block_out;
+ if (!GenerateBlock(chainman, pblocktemplate->block, nMaxTries, block_out)) {
break;
}
- if (!block_hash.IsNull()) {
+ if (block_out) {
--nGenerate;
- blockHashes.push_back(block_hash.GetHex());
+ blockHashes.push_back(block_out->GetHash().GetHex());
}
}
return blockHashes;
@@ -376,15 +374,15 @@ static RPCHelpMan generateblock()
}
}
- uint256 block_hash;
+ std::shared_ptr<const CBlock> block_out;
uint64_t max_tries{DEFAULT_MAX_TRIES};
- if (!GenerateBlock(chainman, block, max_tries, block_hash) || block_hash.IsNull()) {
+ if (!GenerateBlock(chainman, block, max_tries, block_out) || !block_out) {
throw JSONRPCError(RPC_MISC_ERROR, "Failed to make block.");
}
UniValue obj(UniValue::VOBJ);
- obj.pushKV("hash", block_hash.GetHex());
+ obj.pushKV("hash", block_out->GetHash().GetHex());
return obj;
},
};