Reduce memory usage of CBlockIndex
Ported code from https://github.com/zcash/zcash/pull/6192 with various changes needed for the Hush codebase.
This commit is contained in:
@@ -147,7 +147,7 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex)
|
||||
result.push_back(Pair("finalsaplingroot", blockindex->hashFinalSaplingRoot.GetHex()));
|
||||
result.push_back(Pair("time", (int64_t)blockindex->nTime));
|
||||
result.push_back(Pair("nonce", blockindex->nNonce.GetHex()));
|
||||
result.push_back(Pair("solution", HexStr(blockindex->nSolution)));
|
||||
result.pushKV("solution", HexStr(blockindex->GetBlockHeader().nSolution));
|
||||
result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
|
||||
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
|
||||
result.push_back(Pair("chainwork", blockindex->chainPower.chainWork.GetHex()));
|
||||
@@ -694,15 +694,18 @@ UniValue getblockheader(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
|
||||
CBlockIndex* pblockindex = mapBlockIndex[hash];
|
||||
|
||||
if (!fVerbose)
|
||||
{
|
||||
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssBlock << pblockindex->GetBlockHeader();
|
||||
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
|
||||
return strHex;
|
||||
try {
|
||||
if (!fVerbose) {
|
||||
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssBlock << pblockindex->GetBlockHeader();
|
||||
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
|
||||
return strHex;
|
||||
} else {
|
||||
return blockheaderToJSON(pblockindex);
|
||||
}
|
||||
} catch (const runtime_error&) {
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Failed to read index entry");
|
||||
}
|
||||
|
||||
return blockheaderToJSON(pblockindex);
|
||||
}
|
||||
|
||||
UniValue getblock(const UniValue& params, bool fHelp, const CPubKey& mypk)
|
||||
|
||||
Reference in New Issue
Block a user