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:
14
src/rest.cpp
14
src/rest.cpp
@@ -151,6 +151,7 @@ static bool rest_headers(HTTPRequest* req,
|
||||
|
||||
std::vector<const CBlockIndex *> headers;
|
||||
headers.reserve(count);
|
||||
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
BlockMap::const_iterator it = mapBlockIndex.find(hash);
|
||||
@@ -161,11 +162,16 @@ static bool rest_headers(HTTPRequest* req,
|
||||
break;
|
||||
pindex = chainActive.Next(pindex);
|
||||
}
|
||||
}
|
||||
|
||||
CDataStream ssHeader(SER_NETWORK, PROTOCOL_VERSION);
|
||||
BOOST_FOREACH(const CBlockIndex *pindex, headers) {
|
||||
ssHeader << pindex->GetBlockHeader();
|
||||
if (rf == RF_BINARY || rf == RF_HEX) {
|
||||
try {
|
||||
for (const CBlockIndex *pindex : headers) {
|
||||
ssHeader << pindex->GetBlockHeader();
|
||||
}
|
||||
} catch (const std::runtime_error&) {
|
||||
return RESTERR(req, HTTP_INTERNAL_SERVER_ERROR, "Failed to read index entry");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (rf) {
|
||||
|
||||
Reference in New Issue
Block a user