text: // Copyright (c) 2019 The Trivechain developers
  // Distributed under the MIT software license, see the accompanying
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  
  #include "chainparams.h"
  #include "dsnotificationinterface.h"
  #include "instantx.h"
  #include "governance.h"
  #include "masternode-payments.h"
  #include "masternode-sync.h"
  #include "exclusivesend.h"
  #ifdef ENABLE_WALLET
  #include "exclusivesend-client.h"
  #endif // ENABLE_WALLET
  #include "validation.h"
  
  #include "evo/deterministicmns.h"
  #include "evo/mnauth.h"
  
  #include "llmq/quorums.h"
  #include "llmq/quorums_chainlocks.h"
  #include "llmq/quorums_directsend.h"
  #include "llmq/quorums_dkgsessionmgr.h"
  
  void CDSNotificationInterface::InitializeCurrentBlockTip()
  {
      LOCK(cs_main);
      UpdatedBlockTip(chainActive.Tip(), NULL, IsInitialBlockDownload());
  }
  
  void CDSNotificationInterface::AcceptedBlockHeader(const CBlockIndex *pindexNew)
  {
      llmq::chainLocksHandler->AcceptedBlockHeader(pindexNew);
      masternodeSync.AcceptedBlockHeader(pindexNew);
  }
  
  void CDSNotificationInterface::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload)
  {
      masternodeSync.NotifyHeaderTip(pindexNew, fInitialDownload, connman);
  }
  
  void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
  {
      if (pindexNew == pindexFork) // blocks were disconnected without any new ones
          return;
  
      deterministicMNManager->UpdatedBlockTip(pindexNew);
  
      masternodeSync.UpdatedBlockTip(pindexNew, fInitialDownload, connman);
  
      // Update global DIP0001 activation status
      fDIP0001ActiveAtTip = pindexNew->nHeight >= Params().GetConsensus().DIP0001Height;
      // update directsend autolock activation flag (we reuse the DIP3 deployment)
      directsend.isAutoLockBip9Active = pindexNew->nHeight + 1 >= Params().GetConsensus().DIP0003Height;
  
      if (fInitialDownload)
          return;
  
      if (fLiteMode)
          return;
  
      llmq::quorumDirectSendManager->UpdatedBlockTip(pindexNew);
      llmq::chainLocksHandler->UpdatedBlockTip(pindexNew);
  
      CExclusiveSend::UpdatedBlockTip(pindexNew);
  #ifdef ENABLE_WALLET
      exclusiveSendClient.UpdatedBlockTip(pindexNew);
  #endif // ENABLE_WALLET
      directsend.UpdatedBlockTip(pindexNew);
      governance.UpdatedBlockTip(pindexNew, connman);
      llmq::quorumManager->UpdatedBlockTip(pindexNew, fInitialDownload);
      llmq::quorumDKGSessionManager->UpdatedBlockTip(pindexNew, fInitialDownload);
  }
  
  void CDSNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlockIndex *pindex, int posInBlock)
  {
      llmq::quorumDirectSendManager->SyncTransaction(tx, pindex, posInBlock);
      llmq::chainLocksHandler->SyncTransaction(tx, pindex, posInBlock);
      directsend.SyncTransaction(tx, pindex, posInBlock);
      CExclusiveSend::SyncTransaction(tx, pindex, posInBlock);
  }
  
  void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff)
  {
      CMNAuth::NotifyMasternodeListChanged(undo, oldMNList, diff);
      governance.CheckMasternodeOrphanObjects(connman);
      governance.CheckMasternodeOrphanVotes(connman);
      governance.UpdateCachesAndClean();
  }
  
  void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex)
  {
      llmq::quorumDirectSendManager->NotifyChainLock(pindex);
  }
  