LCOV - code coverage report
Current view: top level - src/evo - evodb.cpp (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 51 52 98.1 %
Date: 2026-06-25 07:23:51 Functions: 15 15 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2018-2025 The Dash Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #include <evo/evodb.h>
       6             : 
       7             : #include <uint256.h>
       8             : 
       9       99518 : CEvoDBScopedCommitter::CEvoDBScopedCommitter(CEvoDB &_evoDB) :
      10       49759 :     evoDB(_evoDB)
      11       49759 : {
      12       49759 : }
      13             : 
      14       99518 : CEvoDBScopedCommitter::~CEvoDBScopedCommitter()
      15       49759 : {
      16       49759 :     if (!didCommitOrRollback)
      17       24521 :         Rollback();
      18       99518 : }
      19             : 
      20       25238 : void CEvoDBScopedCommitter::Commit()
      21             : {
      22       25238 :     assert(!didCommitOrRollback);
      23       25238 :     didCommitOrRollback = true;
      24       25238 :     evoDB.CommitCurTransaction();
      25       25238 : }
      26             : 
      27       24521 : void CEvoDBScopedCommitter::Rollback()
      28             : {
      29       24521 :     assert(!didCommitOrRollback);
      30       24521 :     didCommitOrRollback = true;
      31       24521 :     evoDB.RollbackCurTransaction();
      32       24521 : }
      33             : 
      34        1610 : CEvoDB::CEvoDB(const util::DbWrapperParams& db_params) :
      35         805 :     db{util::MakeDbWrapper({db_params.path / "evodb", db_params.memory, db_params.wipe, /*cache_size=*/64 << 20})},
      36         805 :     rootBatch{*db},
      37         805 :     rootDBTransaction{*db, rootBatch},
      38         805 :     curDBTransaction{rootDBTransaction, rootDBTransaction}
      39         805 : {
      40        1610 : }
      41             : 
      42        1608 : CEvoDB::~CEvoDB() = default;
      43             : 
      44       25238 : void CEvoDB::CommitCurTransaction()
      45             : {
      46       25238 :     LOCK(cs);
      47       25238 :     curDBTransaction.Commit();
      48       25238 : }
      49             : 
      50       24521 : void CEvoDB::RollbackCurTransaction()
      51             : {
      52       24521 :     LOCK(cs);
      53       24521 :     curDBTransaction.Clear();
      54       24521 : }
      55             : 
      56         559 : bool CEvoDB::CommitRootTransaction()
      57             : {
      58         559 :     LOCK(cs);
      59         559 :     assert(curDBTransaction.IsClean());
      60         559 :     rootDBTransaction.Commit();
      61         559 :     bool ret = db->WriteBatch(rootBatch);
      62         559 :     rootBatch.Clear();
      63         559 :     return ret;
      64         559 : }
      65             : 
      66       18238 : bool CEvoDB::VerifyBestBlock(const uint256& hash)
      67             : {
      68             :     // Make sure evodb is consistent.
      69             :     // If we already have best block hash saved, the previous block should match it.
      70       18238 :     uint256 hashBestBlock;
      71       18238 :     if (!Read(EVODB_BEST_BLOCK, hashBestBlock)) {
      72           0 :         return false;
      73             :     }
      74       18238 :     return hashBestBlock == hash;
      75       18238 : }
      76             : 
      77       24886 : void CEvoDB::WriteBestBlock(const uint256& hash)
      78             : {
      79       24886 :     Write(EVODB_BEST_BLOCK, hash);
      80       24886 : }

Generated by: LCOV version 1.16