mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Introduce CEvoDB for all evo related things, e.g. DIP3
Also add transaction handling to ConnectTip and DisconnectTip and a few other places where blocks are processed.
This commit is contained in:
parent
4531f6b896
commit
c9a72e8880
@ -106,6 +106,7 @@ BITCOIN_CORE_H = \
|
||||
core_io.h \
|
||||
core_memusage.h \
|
||||
cuckoocache.h \
|
||||
evo/evodb.h \
|
||||
evo/specialtx.h \
|
||||
privatesend.h \
|
||||
privatesend-client.h \
|
||||
@ -217,6 +218,7 @@ libdash_server_a_SOURCES = \
|
||||
chain.cpp \
|
||||
checkpoints.cpp \
|
||||
dsnotificationinterface.cpp \
|
||||
evo/evodb.cpp \
|
||||
evo/specialtx.cpp \
|
||||
httprpc.cpp \
|
||||
httpserver.cpp \
|
||||
|
13
src/evo/evodb.cpp
Normal file
13
src/evo/evodb.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2018 The Dash Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "evodb.h"
|
||||
|
||||
CEvoDB* evoDb;
|
||||
|
||||
CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) :
|
||||
db(GetDataDir() / "evodb", nCacheSize, fMemory, fWipe),
|
||||
dbTransaction(db)
|
||||
{
|
||||
}
|
64
src/evo/evodb.h
Normal file
64
src/evo/evodb.h
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2018 The Dash Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef DASH_EVODB_H
|
||||
#define DASH_EVODB_H
|
||||
|
||||
#include "dbwrapper.h"
|
||||
#include "sync.h"
|
||||
|
||||
class CEvoDB
|
||||
{
|
||||
private:
|
||||
CCriticalSection cs;
|
||||
CDBWrapper db;
|
||||
CDBTransaction dbTransaction;
|
||||
|
||||
public:
|
||||
CEvoDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
||||
|
||||
std::unique_ptr<CScopedDBTransaction> BeginTransaction()
|
||||
{
|
||||
LOCK(cs);
|
||||
auto t = CScopedDBTransaction::Begin(dbTransaction);
|
||||
return t;
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
bool Read(const K& key, V& value)
|
||||
{
|
||||
LOCK(cs);
|
||||
return dbTransaction.Read(key, value);
|
||||
}
|
||||
|
||||
template<typename K, typename V>
|
||||
void Write(const K& key, const V& value)
|
||||
{
|
||||
LOCK(cs);
|
||||
dbTransaction.Write(key, value);
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
bool Exists(const K& key)
|
||||
{
|
||||
LOCK(cs);
|
||||
return dbTransaction.Exists(key);
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
void Erase(const K& key)
|
||||
{
|
||||
LOCK(cs);
|
||||
dbTransaction.Erase(key);
|
||||
}
|
||||
|
||||
CDBWrapper& GetRawDB()
|
||||
{
|
||||
return db;
|
||||
}
|
||||
};
|
||||
|
||||
extern CEvoDB* evoDb;
|
||||
|
||||
#endif//DASH_EVODB_H
|
@ -293,6 +293,8 @@ void PrepareShutdown()
|
||||
pcoinsdbview = NULL;
|
||||
delete pblocktree;
|
||||
pblocktree = NULL;
|
||||
delete evoDb;
|
||||
evoDb = NULL;
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
if (pwalletMain)
|
||||
@ -1630,6 +1632,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
nTotalCache -= nCoinDBCache;
|
||||
nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
|
||||
int64_t nMempoolSizeMax = GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
|
||||
int64_t nEvoDbCache = 1024 * 1024 * 16; // TODO
|
||||
LogPrintf("Cache configuration:\n");
|
||||
LogPrintf("* Using %.1fMiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
|
||||
LogPrintf("* Using %.1fMiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
|
||||
@ -1652,6 +1655,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
delete pcoinsdbview;
|
||||
delete pcoinscatcher;
|
||||
delete pblocktree;
|
||||
delete evoDb;
|
||||
|
||||
evoDb = new CEvoDB(nEvoDbCache, false, fReindex || fReindexChainState);
|
||||
|
||||
pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex);
|
||||
pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex || fReindexChainState);
|
||||
|
@ -47,6 +47,7 @@ void RPCNestedTests::rpcNestedTests()
|
||||
dir.mkpath(".");
|
||||
ForceSetArg("-datadir", path);
|
||||
//mempool.setSanityCheck(1.0);
|
||||
evoDb = new CEvoDB(1 << 20, true, true);
|
||||
pblocktree = new CBlockTreeDB(1 << 20, true);
|
||||
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
||||
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
|
||||
|
@ -65,6 +65,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||
boost::filesystem::create_directories(pathTemp);
|
||||
ForceSetArg("-datadir", pathTemp.string());
|
||||
mempool.setSanityCheck(1.0);
|
||||
evoDb = new CEvoDB(1 << 20, true, true);
|
||||
pblocktree = new CBlockTreeDB(1 << 20, true);
|
||||
pcoinsdbview = new CCoinsViewDB(1 << 23, true);
|
||||
pcoinsTip = new CCoinsViewCache(pcoinsdbview);
|
||||
@ -91,6 +92,7 @@ TestingSetup::~TestingSetup()
|
||||
delete pcoinsTip;
|
||||
delete pcoinsdbview;
|
||||
delete pblocktree;
|
||||
delete evoDb;
|
||||
boost::filesystem::remove_all(pathTemp);
|
||||
}
|
||||
|
||||
|
@ -2631,11 +2631,15 @@ bool static DisconnectTip(CValidationState& state, const CChainParams& chainpara
|
||||
// Apply the block atomically to the chain state.
|
||||
int64_t nStart = GetTimeMicros();
|
||||
{
|
||||
auto dbTx = evoDb->BeginTransaction();
|
||||
|
||||
CCoinsViewCache view(pcoinsTip);
|
||||
if (DisconnectBlock(block, state, pindexDelete, view) != DISCONNECT_OK)
|
||||
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
|
||||
bool flushed = view.Flush();
|
||||
assert(flushed);
|
||||
bool committed = dbTx->Commit();
|
||||
assert(committed);
|
||||
}
|
||||
LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001);
|
||||
// Write the chain state to disk, if necessary.
|
||||
@ -2710,6 +2714,8 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
|
||||
int64_t nTime3;
|
||||
LogPrint("bench", " - Load block from disk: %.2fms [%.2fs]\n", (nTime2 - nTime1) * 0.001, nTimeReadFromDisk * 0.000001);
|
||||
{
|
||||
auto dbTx = evoDb->BeginTransaction();
|
||||
|
||||
CCoinsViewCache view(pcoinsTip);
|
||||
bool rv = ConnectBlock(blockConnecting, state, pindexNew, view, chainparams);
|
||||
GetMainSignals().BlockChecked(blockConnecting, state);
|
||||
@ -2722,6 +2728,8 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
|
||||
LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001);
|
||||
bool flushed = view.Flush();
|
||||
assert(flushed);
|
||||
bool committed = dbTx->Commit();
|
||||
assert(committed);
|
||||
}
|
||||
int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3;
|
||||
LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);
|
||||
@ -3729,6 +3737,9 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams,
|
||||
indexDummy.pprev = pindexPrev;
|
||||
indexDummy.nHeight = pindexPrev->nHeight + 1;
|
||||
|
||||
// begin tx and let it rollback
|
||||
auto dbTx = evoDb->BeginTransaction();
|
||||
|
||||
// NOTE: CheckBlockHeader is called by CheckBlock
|
||||
if (!ContextualCheckBlockHeader(block, state, chainparams.GetConsensus(), pindexPrev, GetAdjustedTime()))
|
||||
return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, FormatStateMessage(state));
|
||||
@ -4082,6 +4093,9 @@ bool CVerifyDB::VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview,
|
||||
if (chainActive.Tip() == NULL || chainActive.Tip()->pprev == NULL)
|
||||
return true;
|
||||
|
||||
// begin tx and let it rollback
|
||||
auto dbTx = evoDb->BeginTransaction();
|
||||
|
||||
// Verify blocks in the best chain
|
||||
if (nCheckDepth <= 0)
|
||||
nCheckDepth = 1000000000; // suffices until the year 19000
|
||||
|
Loading…
Reference in New Issue
Block a user