LCOV - code coverage report
Current view: top level - src/evo - evodb.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 42 42 100.0 %
Date: 2025-02-23 09:33:43 Functions: 10 10 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2018-2021 The Dash Core developers
       2             : // Copyright (c) 2021 The PIVX Core developers
       3             : // Distributed under the MIT software license, see the accompanying
       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5             : 
       6             : #include "evodb.h"
       7             : #include "clientversion.h"
       8             : #include "netaddress.h"
       9             : 
      10             : std::unique_ptr<CEvoDB> evoDb;
      11             : 
      12       57231 : CEvoDBScopedCommitter::CEvoDBScopedCommitter(CEvoDB &_evoDB) :
      13       57231 :     evoDB(_evoDB)
      14             : {
      15       57231 : }
      16             : 
      17      114462 : CEvoDBScopedCommitter::~CEvoDBScopedCommitter()
      18             : {
      19       57231 :     if (!didCommitOrRollback)
      20       15334 :         Rollback();
      21       57231 : }
      22             : 
      23       41897 : void CEvoDBScopedCommitter::Commit()
      24             : {
      25       41897 :     assert(!didCommitOrRollback);
      26       41897 :     didCommitOrRollback = true;
      27       41897 :     evoDB.CommitCurTransaction();
      28       41897 : }
      29             : 
      30       15334 : void CEvoDBScopedCommitter::Rollback()
      31             : {
      32       15334 :     assert(!didCommitOrRollback);
      33       15334 :     didCommitOrRollback = true;
      34       15334 :     evoDB.RollbackCurTransaction();
      35       15334 : }
      36             : 
      37        1129 : CEvoDB::CEvoDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(fMemory ? "" : (GetDataDir() / "evodb"), nCacheSize, fMemory, fWipe, CLIENT_VERSION | ADDRV2_FORMAT),
      38             :                                                               rootBatch(CLIENT_VERSION | ADDRV2_FORMAT),
      39         772 :                                                               rootDBTransaction(db, rootBatch, CLIENT_VERSION | ADDRV2_FORMAT),
      40        2316 :                                                               curDBTransaction(rootDBTransaction, rootDBTransaction, CLIENT_VERSION | ADDRV2_FORMAT)
      41             : {
      42         772 : }
      43             : 
      44       41897 : void CEvoDB::CommitCurTransaction()
      45             : {
      46       41897 :     LOCK(cs);
      47       41897 :     curDBTransaction.Commit();
      48       41897 : }
      49             : 
      50       15334 : void CEvoDB::RollbackCurTransaction()
      51             : {
      52       15334 :     LOCK(cs);
      53       15334 :     curDBTransaction.Clear();
      54       15334 : }
      55             : 
      56         807 : bool CEvoDB::CommitRootTransaction()
      57             : {
      58         807 :     LOCK(cs);
      59         807 :     assert(curDBTransaction.IsClean());
      60         807 :     rootDBTransaction.Commit();
      61         807 :     bool ret = db.WriteBatch(rootBatch);
      62         807 :     rootBatch.Clear();
      63        1614 :     return ret;
      64             : }
      65             : 
      66       57901 : bool CEvoDB::VerifyBestBlock(const uint256& hash)
      67             : {
      68       57901 :     uint256 hashBestBlock;
      69       57901 :     return Read(EVODB_BEST_BLOCK, hashBestBlock) && hashBestBlock == hash;
      70             : }
      71             : 
      72       42710 : void CEvoDB::WriteBestBlock(const uint256& hash)
      73             : {
      74       42710 :     Write(EVODB_BEST_BLOCK, hash);
      75       42710 : }

Generated by: LCOV version 1.14