Increase default dbcache size

Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
This commit is contained in:
Anthony Fieroni 2018-11-23 14:41:16 +02:00 committed by Brannon King
parent 10c4254c64
commit e89d748b2f
4 changed files with 48 additions and 62 deletions

View file

@ -4264,45 +4264,6 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
return true; return true;
} }
bool RollBackTo(const CBlockIndex* targetIndex, CCoinsViewCache& coinsCache, CClaimTrieCache& trieCache)
{
AssertLockHeld(cs_main);
for (CBlockIndex* index = chainActive.Tip(); index && index != targetIndex; index = index->pprev) {
boost::this_thread::interruption_point();
CBlock block;
if (!ReadBlockFromDisk(block, index, Params().GetConsensus()))
return false; // return error() instead?
if (coinsCache.DynamicMemoryUsage() + pcoinsTip->DynamicMemoryUsage() > nCoinCacheUsage)
return false; // don't allow a single query to chew up all our memory?
if (ShutdownRequested())
return false;
CValidationState state;
if (!DisconnectBlock(block, state, index, coinsCache, trieCache))
return false;
if (state.IsError())
return false;
}
return true;
}
bool GetProofForName(const CBlockIndex* pindexProof, const std::string& name, CClaimTrieProof& proof)
{
AssertLockHeld(cs_main);
if (!chainActive.Contains(pindexProof))
return false;
CCoinsViewCache coinsCache(pcoinsTip);
CClaimTrieCache trieCache(pclaimTrie);
if (RollBackTo(pindexProof, coinsCache, trieCache))
return trieCache.getProofForName(name, proof);
return false;
}
void UnloadBlockIndex() void UnloadBlockIndex()
{ {
LOCK(cs_main); LOCK(cs_main);

View file

@ -225,10 +225,6 @@ FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false); FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false);
/** Translation to a filesystem path */ /** Translation to a filesystem path */
boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix); boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
/** Utility method for going back to a previous state **/
bool RollBackTo(const CBlockIndex* targetIndex, CCoinsViewCache& coinsCache, CClaimTrieCache& trieCache);
/** Get a cryptographic proof that a name maps to a value **/
bool GetProofForName(const CBlockIndex* pindexProof, const std::string& name, CClaimTrieProof& proof);
/** Import blocks from an external file */ /** Import blocks from an external file */
bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = NULL); bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = NULL);
/** Initialize a new block tree database + block data on disk */ /** Initialize a new block tree database + block data on disk */

View file

@ -1,13 +1,15 @@
#include "boost/scope_exit.hpp" #include "boost/scope_exit.hpp"
#include "consensus/validation.h" #include "consensus/validation.h"
#include "init.h"
#include "main.h" #include "main.h"
#include "nameclaim.h" #include "nameclaim.h"
#include "rpc/server.h" #include "rpc/server.h"
#include "txmempool.h" #include "txmempool.h"
#include "univalue.h" #include "univalue.h"
// Maximum block decrement that is allowed from rpc calls #include <boost/thread.hpp>
const int MAX_RPC_BLOCK_DECREMENTS = 50;
#include <cmath>
uint160 ParseClaimtrieId(const UniValue& v, const std::string& strName) uint160 ParseClaimtrieId(const UniValue& v, const std::string& strName)
{ {
@ -35,10 +37,39 @@ static CBlockIndex* BlockHashIndex(const uint256& blockHash)
if (!chainActive.Contains(pblockIndex)) if (!chainActive.Contains(pblockIndex))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
if (chainActive.Tip()->nHeight > (pblockIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS)) return pblockIndex;
}
#define MAX_RPC_BLOCK_DECREMENTS 500
void RollBackTo(const CBlockIndex* targetIndex, CCoinsViewCache& coinsCache, CClaimTrieCache& trieCache)
{
AssertLockHeld(cs_main);
const CBlockIndex* activeIndex = chainActive.Tip();
if (activeIndex->nHeight > (targetIndex->nHeight + MAX_RPC_BLOCK_DECREMENTS))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block is too deep"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Block is too deep");
return pblockIndex; const size_t currentMemoryUsage = pcoinsTip->DynamicMemoryUsage();
for (; activeIndex && activeIndex != targetIndex; activeIndex = activeIndex->pprev) {
boost::this_thread::interruption_point();
CBlock block;
if (!ReadBlockFromDisk(block, activeIndex, Params().GetConsensus()))
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Failed to read %s", activeIndex->ToString()));
if (coinsCache.DynamicMemoryUsage() + currentMemoryUsage > nCoinCacheUsage)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Out of memory, you may want to increase dbcache size");
if (ShutdownRequested())
throw JSONRPCError(RPC_INTERNAL_ERROR, "Shutdown requested");
CValidationState state;
if (!DisconnectBlock(block, state, activeIndex, coinsCache, trieCache))
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Failed to disconnect %s", block.ToString()));
}
} }
UniValue getclaimsintrie(const UniValue& params, bool fHelp) UniValue getclaimsintrie(const UniValue& params, bool fHelp)
@ -78,8 +109,7 @@ UniValue getclaimsintrie(const UniValue& params, bool fHelp)
if (!params.empty()) { if (!params.empty()) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[0], "blockhash (optional parameter 1)")); CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[0], "blockhash (optional parameter 1)"));
if (!RollBackTo(blockIndex, coinsCache, trieCache)) RollBackTo(blockIndex, coinsCache, trieCache);
throw JSONRPCError(RPC_INTERNAL_ERROR, "Rollback failure");
} }
UniValue ret(UniValue::VARR); UniValue ret(UniValue::VARR);
@ -155,8 +185,7 @@ UniValue getclaimtrie(const UniValue& params, bool fHelp)
if (!params.empty()) { if (!params.empty()) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[0], "blockhash (optional parameter 1)")); CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[0], "blockhash (optional parameter 1)"));
if (!RollBackTo(blockIndex, coinsCache, trieCache)) RollBackTo(blockIndex, coinsCache, trieCache);
throw JSONRPCError(RPC_INTERNAL_ERROR, "Rollback failure");
} }
UniValue ret(UniValue::VARR); UniValue ret(UniValue::VARR);
@ -245,8 +274,7 @@ UniValue getvalueforname(const UniValue& params, bool fHelp)
if (params.size() > 1) { if (params.size() > 1) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[1], "blockhash (optional parameter 2)")); CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[1], "blockhash (optional parameter 2)"));
if (!RollBackTo(blockIndex, coinsCache, trieCache)) RollBackTo(blockIndex, coinsCache, trieCache);
throw JSONRPCError(RPC_INTERNAL_ERROR, "Rollback failure");
} }
CClaimValue claim; CClaimValue claim;
@ -362,8 +390,7 @@ UniValue getclaimsforname(const UniValue& params, bool fHelp)
if (params.size() > 1) { if (params.size() > 1) {
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[1], "blockhash (optional parameter 2)")); CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(params[1], "blockhash (optional parameter 2)"));
if (!RollBackTo(blockIndex, coinsCache, trieCache)) RollBackTo(blockIndex, coinsCache, trieCache);
throw JSONRPCError(RPC_INTERNAL_ERROR, "Rollback failure");
} }
std::string name = params[0].get_str(); std::string name = params[0].get_str();
@ -784,16 +811,18 @@ UniValue getnameproof(const UniValue& params, bool fHelp)
"}\n"); "}\n");
LOCK(cs_main); LOCK(cs_main);
std::string strName = params[0].get_str();
CBlockIndex* pblockIndex; CCoinsViewCache coinsCache(pcoinsTip);
CClaimTrieCache trieCache(pclaimTrie);
if (params.size() == 2) { if (params.size() == 2) {
pblockIndex = BlockHashIndex(ParseHashV(params[1], "blockhash (optional parameter 2)")); CBlockIndex* pblockIndex = BlockHashIndex(ParseHashV(params[1], "blockhash (optional parameter 2)"));
} else { RollBackTo(pblockIndex, coinsCache, trieCache);
pblockIndex = mapBlockIndex[chainActive.Tip()->GetBlockHash()];
} }
CClaimTrieProof proof; CClaimTrieProof proof;
if (!GetProofForName(pblockIndex, strName, proof)) std::string name = params[0].get_str();
if (!trieCache.getProofForName(name, proof))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed to generate proof"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed to generate proof");
return proofToJSON(proof); return proofToJSON(proof);

View file

@ -20,7 +20,7 @@ struct CDiskTxPos;
class uint256; class uint256;
//! -dbcache default (MiB) //! -dbcache default (MiB)
static const int64_t nDefaultDbCache = 100; static const int64_t nDefaultDbCache = sizeof(void*) > 4 ? 700 : 500;
//! max. -dbcache in (MiB) //! max. -dbcache in (MiB)
static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024; static const int64_t nMaxDbCache = sizeof(void*) > 4 ? 16384 : 1024;
//! min. -dbcache in (MiB) //! min. -dbcache in (MiB)