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 6126 : 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 3063 : isman{isman}, 25 3063 : mn_sync{mn_sync}, 26 3063 : credit_pool_manager{std::make_unique<CCreditPoolManager>(evodb, chainman)}, 27 3063 : m_chainlocks{chainlocks}, 28 3063 : ehf_manager{std::make_unique<CMNHFManager>(evodb, chainman, qman)}, 29 3063 : superblocks{std::make_unique<governance::SuperblockManager>()}, 30 3063 : mn_payments{std::make_unique<CMNPaymentsProcessor>(dmnman, *superblocks, chainman, consensus_params)}, 31 6126 : special_tx{std::make_unique<CSpecialTxProcessor>(*credit_pool_manager, dmnman, *ehf_manager, qblockman, qsnapman, 32 3063 : chainman, consensus_params, chainlocks, qman)} 33 6126 : {} 34 : 35 6126 : CChainstateHelper::~CChainstateHelper() = default; 36 : 37 340870 : bool CChainstateHelper::IsSuperblockValidationRequired(const CBlockIndex* const pindex) 38 : { 39 340870 : if (m_chainlocks.GetBestChainLockHeight() >= pindex->nHeight) { 40 96 : LogPrint(BCLog::MNPAYMENTS, "%s -- validation of chainlocked block=%s is skipped\n", __func__, pindex->GetBlockHash().ToString()); 41 96 : return false; 42 : } 43 340774 : if (!mn_sync.IsSynced()) { 44 225698 : LogPrint(BCLog::MNPAYMENTS, "%s -- WARNING! Node is not fully synced, checked superblock for block=%s max bounds only\n", __func__, pindex->GetBlockHash().ToString()); 45 225698 : return false; 46 : } 47 115076 : return true; 48 340870 : } 49 : 50 : /** Passthrough functions to chainlock::Chainlocks */ 51 610220 : bool CChainstateHelper::HasConflictingChainLock(int nHeight, const uint256& blockHash) const 52 : { 53 610220 : return m_chainlocks.HasConflictingChainLock(nHeight, blockHash); 54 : } 55 : 56 323381 : bool CChainstateHelper::HasChainLock(int nHeight, const uint256& blockHash) const 57 : { 58 323381 : 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 23885 : CCreditPool CChainstateHelper::GetCreditPool(const CBlockIndex* const pindex) 65 : { 66 23885 : return credit_pool_manager->GetCreditPool(pindex); 67 : } 68 : 69 : /** Passthrough functions to CInstantSendManager */ 70 500749 : std::optional<std::pair</*islock_hash=*/uint256, /*txid=*/uint256>> CChainstateHelper::ConflictingISLockIfAny( 71 : const CTransaction& tx) const 72 : { 73 500749 : const auto islock = isman.GetConflictingLock(tx); 74 500749 : if (!islock) return std::nullopt; 75 93 : return std::make_pair(::SerializeHash(*islock), islock->txid); 76 500749 : } 77 : 78 59695 : bool CChainstateHelper::IsInstantSendWaitingForTx(const uint256& hash) const { return isman.IsWaitingForTx(hash); } 79 : 80 40 : bool CChainstateHelper::RemoveConflictingISLockByTx(const CTransaction& tx) 81 : { 82 40 : const auto islock = isman.GetConflictingLock(tx); 83 40 : if (!islock) return false; 84 40 : isman.RemoveConflictingLock(::SerializeHash(*islock), *islock); 85 40 : return true; 86 40 : } 87 : 88 15136 : std::unordered_map<uint8_t, int> CChainstateHelper::GetSignalsStage(const CBlockIndex* const pindexPrev) 89 : { 90 15136 : return ehf_manager->GetSignalsStage(pindexPrev); 91 : }