2019-06-11 13:46:07 +02:00
|
|
|
// Copyright (c) 2018-2019 The Dash Core developers
|
2018-05-24 14:28:23 +02:00
|
|
|
// 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"
|
2018-12-13 09:11:50 +01:00
|
|
|
#include "uint256.h"
|
|
|
|
|
2019-07-09 07:59:57 +02:00
|
|
|
// "b_b" was used in the initial version of deterministic MN storage
|
|
|
|
// "b_b2" was used after compact diffs were introduced
|
|
|
|
static const std::string EVODB_BEST_BLOCK = "b_b2";
|
2018-05-24 14:28:23 +02:00
|
|
|
|
|
|
|
class CEvoDB
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
CCriticalSection cs;
|
|
|
|
CDBWrapper db;
|
2019-03-06 20:45:39 +01:00
|
|
|
|
|
|
|
typedef CDBTransaction<CDBWrapper, CDBBatch> RootTransaction;
|
|
|
|
typedef CDBTransaction<RootTransaction, RootTransaction> CurTransaction;
|
|
|
|
typedef CScopedDBTransaction<RootTransaction, RootTransaction> ScopedTransaction;
|
|
|
|
|
|
|
|
CDBBatch rootBatch;
|
|
|
|
RootTransaction rootDBTransaction;
|
|
|
|
CurTransaction curDBTransaction;
|
2018-05-24 14:28:23 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
CEvoDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
|
|
|
|
|
2019-03-06 20:45:39 +01:00
|
|
|
std::unique_ptr<ScopedTransaction> BeginTransaction()
|
2018-05-24 14:28:23 +02:00
|
|
|
{
|
|
|
|
LOCK(cs);
|
2019-03-06 20:45:39 +01:00
|
|
|
auto t = ScopedTransaction::Begin(curDBTransaction);
|
2018-05-24 14:28:23 +02:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2019-04-04 10:18:31 +02:00
|
|
|
CurTransaction& GetCurTransaction()
|
|
|
|
{
|
|
|
|
return curDBTransaction;
|
|
|
|
}
|
|
|
|
|
2018-11-06 09:54:23 +01:00
|
|
|
template <typename K, typename V>
|
2018-05-24 14:28:23 +02:00
|
|
|
bool Read(const K& key, V& value)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
2019-03-06 20:45:39 +01:00
|
|
|
return curDBTransaction.Read(key, value);
|
2018-05-24 14:28:23 +02:00
|
|
|
}
|
|
|
|
|
2018-11-06 09:54:23 +01:00
|
|
|
template <typename K, typename V>
|
2018-05-24 14:28:23 +02:00
|
|
|
void Write(const K& key, const V& value)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
2019-03-06 20:45:39 +01:00
|
|
|
curDBTransaction.Write(key, value);
|
2018-05-24 14:28:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename K>
|
|
|
|
bool Exists(const K& key)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
2019-03-06 20:45:39 +01:00
|
|
|
return curDBTransaction.Exists(key);
|
2018-05-24 14:28:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename K>
|
|
|
|
void Erase(const K& key)
|
|
|
|
{
|
|
|
|
LOCK(cs);
|
2019-03-06 20:45:39 +01:00
|
|
|
curDBTransaction.Erase(key);
|
2018-05-24 14:28:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CDBWrapper& GetRawDB()
|
|
|
|
{
|
|
|
|
return db;
|
|
|
|
}
|
2018-12-13 09:11:50 +01:00
|
|
|
|
2019-07-02 06:16:27 +02:00
|
|
|
size_t GetMemoryUsage()
|
|
|
|
{
|
|
|
|
return rootDBTransaction.GetMemoryUsage();
|
|
|
|
}
|
|
|
|
|
2019-03-06 20:45:39 +01:00
|
|
|
bool CommitRootTransaction();
|
|
|
|
|
2018-12-13 09:11:50 +01:00
|
|
|
bool VerifyBestBlock(const uint256& hash);
|
|
|
|
void WriteBestBlock(const uint256& hash);
|
2018-05-24 14:28:23 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern CEvoDB* evoDb;
|
|
|
|
|
2018-11-06 09:54:23 +01:00
|
|
|
#endif //DASH_EVODB_H
|