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: 2026-10-21 17:45:27 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       57469 : CEvoDBScopedCommitter::CEvoDBScopedCommitter(CEvoDB &_evoDB) :
      13       57469 :     evoDB(_evoDB)
      14             : {
      15       57469 : }
      16             : 
      17      114938 : CEvoDBScopedCommitter::~CEvoDBScopedCommitter()
      18             : {
      19       57469 :     if (!didCommitOrRollback)
      20       15269 :         Rollback();
      21       57469 : }
      22             : 
      23       42200 : void CEvoDBScopedCommitter::Commit()
      24             : {
      25       42200 :     assert(!didCommitOrRollback);
      26       42200 :     didCommitOrRollback = true;
      27       42200 :     evoDB.CommitCurTransaction();
      28       42200 : }
      29             : 
      30       15269 : void CEvoDBScopedCommitter::Rollback()
      31             : {
      32       15269 :     assert(!didCommitOrRollback);
      33       15269 :     didCommitOrRollback = true;
      34       15269 :     evoDB.RollbackCurTransaction();
      35       15269 : }
      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       42200 : void CEvoDB::CommitCurTransaction()
      45             : {
      46       42200 :     LOCK(cs);
      47       42200 :     curDBTransaction.Commit();
      48       42200 : }
      49             : 
      50       15269 : void CEvoDB::RollbackCurTransaction()
      51             : {
      52       15269 :     LOCK(cs);
      53       15269 :     curDBTransaction.Clear();
      54       15269 : }
      55             : 
      56         805 : bool CEvoDB::CommitRootTransaction()
      57             : {
      58         805 :     LOCK(cs);
      59         805 :     assert(curDBTransaction.IsClean());
      60         805 :     rootDBTransaction.Commit();
      61         805 :     bool ret = db.WriteBatch(rootBatch);
      62         805 :     rootBatch.Clear();
      63        1610 :     return ret;
      64             : }
      65             : 
      66       58138 : bool CEvoDB::VerifyBestBlock(const uint256& hash)
      67             : {
      68       58138 :     uint256 hashBestBlock;
      69       58138 :     return Read(EVODB_BEST_BLOCK, hashBestBlock) && hashBestBlock == hash;
      70             : }
      71             : 
      72       43013 : void CEvoDB::WriteBestBlock(const uint256& hash)
      73             : {
      74       43013 :     Write(EVODB_BEST_BLOCK, hash);
      75       43013 : }

Generated by: LCOV version 1.14