Line data Source code
1 : // Copyright (c) 2024-2025 The Dash Core developers 2 : // Distributed under the MIT/X11 software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #include <evo/chainhelper.h> 6 : 7 : #include <chainlock/chainlock.h> 8 : #include <chainparams.h> 9 : #include <evo/creditpool.h> 10 : #include <evo/mnhftx.h> 11 : #include <evo/specialtxman.h> 12 : #include <governance/superblock.h> 13 : #include <instantsend/instantsend.h> 14 : #include <instantsend/lock.h> 15 : #include <logging.h> 16 : #include <masternode/payments.h> 17 : #include <masternode/sync.h> 18 : 19 360 : CChainstateHelper::CChainstateHelper(CEvoDB& evodb, CDeterministicMNManager& dmnman, const CMasternodeSync& mn_sync, 20 : llmq::CInstantSendManager& isman, llmq::CQuorumBlockProcessor& qblockman, 21 : llmq::CQuorumSnapshotManager& qsnapman, const ChainstateManager& chainman, 22 : const Consensus::Params& consensus_params, const chainlock::Chainlocks& chainlocks, 23 : const llmq::CQuorumManager& qman) : 24 180 : isman{isman}, 25 180 : mn_sync{mn_sync}, 26 180 : credit_pool_manager{std::make_unique<CCreditPoolManager>(evodb, chainman)}, 27 180 : m_chainlocks{chainlocks}, 28 180 : ehf_manager{std::make_unique<CMNHFManager>(evodb, chainman, qman)}, 29 180 : superblocks{std::make_unique<governance::SuperblockManager>()}, 30 180 : mn_payments{std::make_unique<CMNPaymentsProcessor>(dmnman, *superblocks, chainman, consensus_params)}, 31 360 : special_tx{std::make_unique<CSpecialTxProcessor>(*credit_pool_manager, dmnman, *ehf_manager, qblockman, qsnapman, 32 180 : chainman, consensus_params, chainlocks, qman)} 33 360 : {} 34 : 35 360 : CChainstateHelper::~CChainstateHelper() = default; 36 : 37 49009 : bool CChainstateHelper::IsSuperblockValidationRequired(const CBlockIndex* const pindex) 38 : { 39 49009 : if (m_chainlocks.GetBestChainLockHeight() >= pindex->nHeight) { 40 0 : LogPrint(BCLog::MNPAYMENTS, "%s -- validation of chainlocked block=%s is skipped\n", __func__, pindex->GetBlockHash().ToString()); 41 0 : return false; 42 : } 43 49009 : if (!mn_sync.IsSynced()) { 44 49009 : LogPrint(BCLog::MNPAYMENTS, "%s -- WARNING! Node is not fully synced, checked superblock for block=%s max bounds only\n", __func__, pindex->GetBlockHash().ToString()); 45 49009 : return false; 46 : } 47 0 : return true; 48 49009 : } 49 : 50 : /** Passthrough functions to chainlock::Chainlocks */ 51 73548 : bool CChainstateHelper::HasConflictingChainLock(int nHeight, const uint256& blockHash) const 52 : { 53 73548 : return m_chainlocks.HasConflictingChainLock(nHeight, blockHash); 54 : } 55 : 56 47157 : bool CChainstateHelper::HasChainLock(int nHeight, const uint256& blockHash) const 57 : { 58 47157 : return m_chainlocks.HasChainLock(nHeight, blockHash); 59 : } 60 : 61 0 : int32_t CChainstateHelper::GetBestChainLockHeight() const { return m_chainlocks.GetBestChainLockHeight(); } 62 : 63 : /** Passthrough functions to CCreditPoolManager */ 64 7631 : CCreditPool CChainstateHelper::GetCreditPool(const CBlockIndex* const pindex) 65 : { 66 7631 : return credit_pool_manager->GetCreditPool(pindex); 67 : } 68 : 69 : /** Passthrough functions to CInstantSendManager */ 70 47324 : std::optional<std::pair</*islock_hash=*/uint256, /*txid=*/uint256>> CChainstateHelper::ConflictingISLockIfAny( 71 : const CTransaction& tx) const 72 : { 73 47324 : const auto islock = isman.GetConflictingLock(tx); 74 47324 : if (!islock) return std::nullopt; 75 0 : return std::make_pair(::SerializeHash(*islock), islock->txid); 76 47324 : } 77 : 78 95 : bool CChainstateHelper::IsInstantSendWaitingForTx(const uint256& hash) const { return isman.IsWaitingForTx(hash); } 79 : 80 0 : bool CChainstateHelper::RemoveConflictingISLockByTx(const CTransaction& tx) 81 : { 82 0 : const auto islock = isman.GetConflictingLock(tx); 83 0 : if (!islock) return false; 84 0 : isman.RemoveConflictingLock(::SerializeHash(*islock), *islock); 85 0 : return true; 86 0 : } 87 : 88 0 : std::unordered_map<uint8_t, int> CChainstateHelper::GetSignalsStage(const CBlockIndex* const pindexPrev) 89 : { 90 0 : return ehf_manager->GetSignalsStage(pindexPrev); 91 : }