Line data Source code
1 : // Copyright (c) 2014-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 : 6 : #include <dsnotificationinterface.h> 7 : 8 : #include <coinjoin/coinjoin.h> 9 : #include <evo/deterministicmns.h> 10 : #include <evo/mnauth.h> 11 : #include <governance/governance.h> 12 : #include <instantsend/instantsend.h> 13 : #include <masternode/sync.h> 14 : #include <util/check.h> 15 : #include <validation.h> 16 : 17 : 18 5714 : CDSNotificationInterface::CDSNotificationInterface(CConnman& connman, CDSTXManager& dstxman, CMasternodeSync& mn_sync, 19 : CGovernanceManager& govman, const ChainstateManager& chainman, 20 : const std::unique_ptr<CDeterministicMNManager>& dmnman) : 21 2857 : m_connman{connman}, 22 2857 : m_dstxman{dstxman}, 23 2857 : m_mn_sync{mn_sync}, 24 2857 : m_govman{govman}, 25 2857 : m_chainman{chainman}, 26 2857 : m_dmnman{dmnman} 27 5714 : { 28 5714 : } 29 : 30 8571 : CDSNotificationInterface::~CDSNotificationInterface() = default; 31 : 32 3491 : void CDSNotificationInterface::InitializeCurrentBlockTip(const CBlockIndex* tip, bool ibd) 33 : { 34 3491 : SynchronousUpdatedBlockTip(tip, nullptr, ibd); 35 3491 : UpdatedBlockTip(tip, nullptr, ibd); 36 3491 : } 37 : 38 244470 : void CDSNotificationInterface::AcceptedBlockHeader(const CBlockIndex *pindexNew) 39 : { 40 244470 : m_mn_sync.AcceptedBlockHeader(pindexNew); 41 244470 : } 42 : 43 192109 : void CDSNotificationInterface::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload) 44 : { 45 192109 : m_mn_sync.NotifyHeaderTip(pindexNew, fInitialDownload); 46 192109 : } 47 : 48 224210 : void CDSNotificationInterface::SynchronousUpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) 49 : { 50 224210 : if (pindexNew == pindexFork) // blocks were disconnected without any new ones 51 0 : return; 52 : 53 224210 : Assert(m_dmnman)->UpdatedBlockTip(pindexNew); 54 224210 : } 55 : 56 224210 : void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) 57 : { 58 224210 : if (pindexNew == pindexFork) // blocks were disconnected without any new ones 59 0 : return; 60 : 61 448420 : m_mn_sync.UpdatedBlockTip(WITH_LOCK(::cs_main, return m_chainman.m_best_header), pindexNew, fInitialDownload); 62 : 63 224210 : if (fInitialDownload) 64 16652 : return; 65 : 66 207558 : if (m_mn_sync.IsBlockchainSynced()) { 67 99319 : m_dstxman.UpdatedBlockTip(pindexNew); 68 99319 : } 69 : 70 207558 : if (m_govman.IsValid()) { 71 206314 : m_govman.UpdatedBlockTip(pindexNew); 72 206314 : } 73 224210 : } 74 : 75 36808 : void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime, 76 : uint64_t mempool_sequence) 77 : { 78 36808 : m_dstxman.TransactionAddedToMempool(ptx); 79 36808 : } 80 : 81 228492 : void CDSNotificationInterface::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) 82 : { 83 228492 : m_dstxman.BlockConnected(pblock, pindex); 84 228492 : } 85 : 86 14236 : void CDSNotificationInterface::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) 87 : { 88 14236 : m_dstxman.BlockDisconnected(pblock, pindexDisconnected); 89 14236 : } 90 : 91 99741 : void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) 92 : { 93 99741 : CMNAuth::NotifyMasternodeListChanged(undo, oldMNList, diff, m_connman); 94 99741 : if (m_govman.IsValid()) { 95 99741 : m_govman.CheckAndRemove(); 96 99741 : } 97 99741 : } 98 : 99 13549 : void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex, 100 : const std::shared_ptr<const chainlock::ChainLockSig>& clsig) 101 : { 102 13549 : if (m_mn_sync.IsBlockchainSynced()) { 103 13544 : m_dstxman.NotifyChainLock(pindex); 104 13544 : } 105 13549 : } 106 : 107 : std::unique_ptr<CDSNotificationInterface> g_ds_notification_interface;