2021-04-20 21:33:02 +02:00
|
|
|
// Copyright (c) 2014-2021 The Dash Core developers
|
2016-03-02 22:20:04 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <chainparams.h>
|
2021-03-17 23:36:11 +01:00
|
|
|
#include <coinjoin/coinjoin.h>
|
|
|
|
#ifdef ENABLE_WALLET
|
|
|
|
#include <coinjoin/coinjoin-client.h>
|
|
|
|
#endif // ENABLE_WALLET
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <dsnotificationinterface.h>
|
|
|
|
#include <governance/governance.h>
|
|
|
|
#include <masternode/masternode-sync.h>
|
|
|
|
#include <validation.h>
|
2016-03-02 22:20:04 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <evo/deterministicmns.h>
|
|
|
|
#include <evo/mnauth.h>
|
2018-02-14 14:43:03 +01:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <llmq/quorums.h>
|
|
|
|
#include <llmq/quorums_chainlocks.h>
|
|
|
|
#include <llmq/quorums_instantsend.h>
|
|
|
|
#include <llmq/quorums_dkgsessionmgr.h>
|
2019-01-22 14:20:32 +01:00
|
|
|
|
2017-08-29 01:51:33 +02:00
|
|
|
void CDSNotificationInterface::InitializeCurrentBlockTip()
|
2016-03-02 22:20:04 +01:00
|
|
|
{
|
2017-08-29 01:51:33 +02:00
|
|
|
LOCK(cs_main);
|
2020-03-20 17:11:54 +01:00
|
|
|
SynchronousUpdatedBlockTip(chainActive.Tip(), nullptr, IsInitialBlockDownload());
|
2019-08-06 05:08:33 +02:00
|
|
|
UpdatedBlockTip(chainActive.Tip(), nullptr, IsInitialBlockDownload());
|
2016-03-02 22:20:04 +01:00
|
|
|
}
|
|
|
|
|
2017-09-03 15:30:08 +02:00
|
|
|
void CDSNotificationInterface::AcceptedBlockHeader(const CBlockIndex *pindexNew)
|
|
|
|
{
|
2019-01-22 14:20:32 +01:00
|
|
|
llmq::chainLocksHandler->AcceptedBlockHeader(pindexNew);
|
2017-09-03 15:30:08 +02:00
|
|
|
masternodeSync.AcceptedBlockHeader(pindexNew);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDSNotificationInterface::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload)
|
|
|
|
{
|
2017-09-19 16:51:38 +02:00
|
|
|
masternodeSync.NotifyHeaderTip(pindexNew, fInitialDownload, connman);
|
2017-09-03 15:30:08 +02:00
|
|
|
}
|
|
|
|
|
2020-03-20 17:11:54 +01:00
|
|
|
void CDSNotificationInterface::SynchronousUpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
|
2016-03-02 22:20:04 +01:00
|
|
|
{
|
2017-09-20 22:30:56 +02:00
|
|
|
if (pindexNew == pindexFork) // blocks were disconnected without any new ones
|
|
|
|
return;
|
|
|
|
|
2018-02-14 14:43:03 +01:00
|
|
|
deterministicMNManager->UpdatedBlockTip(pindexNew);
|
2020-03-20 17:11:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
|
|
|
|
{
|
|
|
|
if (pindexNew == pindexFork) // blocks were disconnected without any new ones
|
|
|
|
return;
|
2018-02-14 14:43:03 +01:00
|
|
|
|
2017-09-20 22:30:56 +02:00
|
|
|
masternodeSync.UpdatedBlockTip(pindexNew, fInitialDownload, connman);
|
|
|
|
|
2017-12-07 10:43:23 +01:00
|
|
|
// Update global DIP0001 activation status
|
2018-03-08 13:18:24 +01:00
|
|
|
fDIP0001ActiveAtTip = pindexNew->nHeight >= Params().GetConsensus().DIP0001Height;
|
2017-09-22 03:54:14 +02:00
|
|
|
|
2017-10-09 20:25:24 +02:00
|
|
|
if (fInitialDownload)
|
2017-09-22 03:54:14 +02:00
|
|
|
return;
|
|
|
|
|
2021-03-17 23:36:11 +01:00
|
|
|
CCoinJoin::UpdatedBlockTip(pindexNew);
|
2019-06-27 22:24:43 +02:00
|
|
|
#ifdef ENABLE_WALLET
|
2021-03-17 23:36:11 +01:00
|
|
|
for (auto& pair : coinJoinClientManagers) {
|
2020-07-16 14:23:58 +02:00
|
|
|
pair.second->UpdatedBlockTip(pindexNew);
|
|
|
|
}
|
2019-06-27 22:24:43 +02:00
|
|
|
#endif // ENABLE_WALLET
|
|
|
|
|
2019-04-05 05:55:30 +02:00
|
|
|
llmq::quorumInstantSendManager->UpdatedBlockTip(pindexNew);
|
2019-04-30 14:48:21 +02:00
|
|
|
llmq::chainLocksHandler->UpdatedBlockTip(pindexNew);
|
2019-01-22 14:20:32 +01:00
|
|
|
|
2019-04-30 14:48:21 +02:00
|
|
|
llmq::quorumManager->UpdatedBlockTip(pindexNew, fInitialDownload);
|
|
|
|
llmq::quorumDKGSessionManager->UpdatedBlockTip(pindexNew, fInitialDownload);
|
2020-06-13 20:18:31 +02:00
|
|
|
|
2020-06-28 23:00:00 +02:00
|
|
|
if (!fDisableGovernance) governance.UpdatedBlockTip(pindexNew, connman);
|
2016-03-02 22:20:04 +01:00
|
|
|
}
|
2017-01-29 09:22:14 +01:00
|
|
|
|
2019-12-07 11:56:17 +01:00
|
|
|
void CDSNotificationInterface::TransactionAddedToMempool(const CTransactionRef& ptx, int64_t nAcceptTime)
|
2019-05-23 18:22:37 +02:00
|
|
|
{
|
2019-05-27 13:35:22 +02:00
|
|
|
llmq::quorumInstantSendManager->TransactionAddedToMempool(ptx);
|
2019-12-07 11:56:17 +01:00
|
|
|
llmq::chainLocksHandler->TransactionAddedToMempool(ptx, nAcceptTime);
|
2021-03-17 23:36:11 +01:00
|
|
|
CCoinJoin::TransactionAddedToMempool(ptx);
|
2019-05-23 18:22:37 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 01:02:31 +02:00
|
|
|
void CDSNotificationInterface::TransactionRemovedFromMempool(const CTransactionRef& ptx, MemPoolRemovalReason reason)
|
2021-05-15 02:17:16 +02:00
|
|
|
{
|
|
|
|
llmq::quorumInstantSendManager->TransactionRemovedFromMempool(ptx);
|
|
|
|
}
|
|
|
|
|
2019-05-23 18:22:37 +02:00
|
|
|
void CDSNotificationInterface::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex, const std::vector<CTransactionRef>& vtxConflicted)
|
|
|
|
{
|
2021-04-20 21:31:25 +02:00
|
|
|
// TODO: Temporarily ensure that mempool removals are notified before
|
2019-05-23 18:22:37 +02:00
|
|
|
// connected transactions. This shouldn't matter, but the abandoned
|
|
|
|
// state of transactions in our wallet is currently cleared when we
|
|
|
|
// receive another notification and there is a race condition where
|
|
|
|
// notification of a connected conflict might cause an outside process
|
2021-04-20 21:31:25 +02:00
|
|
|
// to abandon a transaction and then have it inadvertently cleared by
|
2019-05-23 18:22:37 +02:00
|
|
|
// the notification that the conflicted transaction was evicted.
|
|
|
|
|
2019-05-27 13:35:22 +02:00
|
|
|
llmq::quorumInstantSendManager->BlockConnected(pblock, pindex, vtxConflicted);
|
2019-05-27 13:48:01 +02:00
|
|
|
llmq::chainLocksHandler->BlockConnected(pblock, pindex, vtxConflicted);
|
2021-03-17 23:36:11 +01:00
|
|
|
CCoinJoin::BlockConnected(pblock, pindex, vtxConflicted);
|
2019-05-23 18:22:37 +02:00
|
|
|
}
|
|
|
|
|
2019-05-27 14:55:29 +02:00
|
|
|
void CDSNotificationInterface::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected)
|
2019-05-23 18:22:37 +02:00
|
|
|
{
|
2019-05-27 13:35:22 +02:00
|
|
|
llmq::quorumInstantSendManager->BlockDisconnected(pblock, pindexDisconnected);
|
2019-05-27 13:48:01 +02:00
|
|
|
llmq::chainLocksHandler->BlockDisconnected(pblock, pindexDisconnected);
|
2021-03-17 23:36:11 +01:00
|
|
|
CCoinJoin::BlockDisconnected(pblock, pindexDisconnected);
|
2019-05-23 18:22:37 +02:00
|
|
|
}
|
|
|
|
|
2019-04-09 13:26:33 +02:00
|
|
|
void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff)
|
2019-01-03 10:17:43 +01:00
|
|
|
{
|
2019-04-09 13:26:33 +02:00
|
|
|
CMNAuth::NotifyMasternodeListChanged(undo, oldMNList, diff);
|
2019-01-03 10:17:43 +01:00
|
|
|
governance.UpdateCachesAndClean();
|
|
|
|
}
|
2018-09-21 16:01:04 +02:00
|
|
|
|
2021-01-22 05:32:15 +01:00
|
|
|
void CDSNotificationInterface::NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig)
|
2018-09-21 16:01:04 +02:00
|
|
|
{
|
|
|
|
llmq::quorumInstantSendManager->NotifyChainLock(pindex);
|
2021-03-17 23:36:11 +01:00
|
|
|
CCoinJoin::NotifyChainLock(pindex);
|
2018-09-21 16:01:04 +02:00
|
|
|
}
|