mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 05:49:11 +01:00
033623ebec
Just return the result of the comparison in case there is a block and false otherwise. This should allow to reach the currently unreachable two error cases below instead of crashing because the assert doesn't pass in case of inconsistency.c2d7d0cab4/src/validation.cpp (L1687-L1691)
c2d7d0cab4/src/validation.cpp (L2094-L2098)
79 lines
1.7 KiB
C++
79 lines
1.7 KiB
C++
// Copyright (c) 2018-2019 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 <evo/evodb.h>
|
|
|
|
std::unique_ptr<CEvoDB> evoDb;
|
|
|
|
CEvoDBScopedCommitter::CEvoDBScopedCommitter(CEvoDB &_evoDB) :
|
|
evoDB(_evoDB)
|
|
{
|
|
}
|
|
|
|
CEvoDBScopedCommitter::~CEvoDBScopedCommitter()
|
|
{
|
|
if (!didCommitOrRollback)
|
|
Rollback();
|
|
}
|
|
|
|
void CEvoDBScopedCommitter::Commit()
|
|
{
|
|
assert(!didCommitOrRollback);
|
|
didCommitOrRollback = true;
|
|
evoDB.CommitCurTransaction();
|
|
}
|
|
|
|
void CEvoDBScopedCommitter::Rollback()
|
|
{
|
|
assert(!didCommitOrRollback);
|
|
didCommitOrRollback = true;
|
|
evoDB.RollbackCurTransaction();
|
|
}
|
|
|
|
CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) :
|
|
db(fMemory ? "" : (GetDataDir() / "evodb"), nCacheSize, fMemory, fWipe),
|
|
rootBatch(db),
|
|
rootDBTransaction(db, rootBatch),
|
|
curDBTransaction(rootDBTransaction, rootDBTransaction)
|
|
{
|
|
}
|
|
|
|
void CEvoDB::CommitCurTransaction()
|
|
{
|
|
LOCK(cs);
|
|
curDBTransaction.Commit();
|
|
}
|
|
|
|
void CEvoDB::RollbackCurTransaction()
|
|
{
|
|
LOCK(cs);
|
|
curDBTransaction.Clear();
|
|
}
|
|
|
|
bool CEvoDB::CommitRootTransaction()
|
|
{
|
|
LOCK(cs);
|
|
assert(curDBTransaction.IsClean());
|
|
rootDBTransaction.Commit();
|
|
bool ret = db.WriteBatch(rootBatch);
|
|
rootBatch.Clear();
|
|
return ret;
|
|
}
|
|
|
|
bool CEvoDB::VerifyBestBlock(const uint256& hash)
|
|
{
|
|
// Make sure evodb is consistent.
|
|
// If we already have best block hash saved, the previous block should match it.
|
|
uint256 hashBestBlock;
|
|
if (!Read(EVODB_BEST_BLOCK, hashBestBlock)) {
|
|
return false;
|
|
}
|
|
return hashBestBlock == hash;
|
|
}
|
|
|
|
void CEvoDB::WriteBestBlock(const uint256& hash)
|
|
{
|
|
Write(EVODB_BEST_BLOCK, hash);
|
|
}
|