2023-01-12 22:26:21 +01:00
|
|
|
// Copyright (c) 2014-2023 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
|
2021-10-01 21:19:08 +02:00
|
|
|
#include <coinjoin/client.h>
|
2021-03-17 23:36:11 +01:00
|
|
|
#endif // ENABLE_WALLET
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <dsnotificationinterface.h>
|
|
|
|
#include <governance/governance.h>
|
2021-10-01 21:19:08 +02:00
|
|
|
#include <masternode/sync.h>
|
2020-03-19 23:46:56 +01:00
|
|
|
#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
|
|
|
|
2021-10-02 19:32:24 +02:00
|
|
|
#include <llmq/chainlocks.h>
|
2022-11-07 19:09:44 +01:00
|
|
|
#include <llmq/context.h>
|
2021-10-02 19:32:24 +02:00
|
|
|
#include <llmq/dkgsessionmgr.h>
|
2022-11-07 19:09:44 +01:00
|
|
|
#include <llmq/instantsend.h>
|
|
|
|
#include <llmq/quorums.h>
|
2019-01-22 14:20:32 +01:00
|
|
|
|
2022-09-22 13:14:48 +02:00
|
|
|
CDSNotificationInterface::CDSNotificationInterface(CConnman& _connman,
|
2023-06-04 22:26:23 +02:00
|
|
|
CMasternodeSync& _mn_sync, const std::unique_ptr<CDeterministicMNManager>& _dmnman,
|
|
|
|
CGovernanceManager& _govman, const std::unique_ptr<LLMQContext>& _llmq_ctx
|
refactor: begin to de-globalize masternodeSync (#5103)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
minimizing global uses
## What was done?
<!--- Describe your changes in detail -->
Started the deglobalization, a future PR should be done to continue this
deglobalization
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [x] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [x] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-01-04 21:37:20 +01:00
|
|
|
) : connman(_connman), m_mn_sync(_mn_sync), dmnman(_dmnman), govman(_govman), llmq_ctx(_llmq_ctx) {}
|
2022-09-22 13:14:48 +02:00
|
|
|
|
2017-08-29 01:51:33 +02:00
|
|
|
void CDSNotificationInterface::InitializeCurrentBlockTip()
|
2016-03-02 22:20:04 +01:00
|
|
|
{
|
2021-10-09 16:14:44 +02:00
|
|
|
SynchronousUpdatedBlockTip(::ChainActive().Tip(), nullptr, ::ChainstateActive().IsInitialBlockDownload());
|
|
|
|
UpdatedBlockTip(::ChainActive().Tip(), nullptr, ::ChainstateActive().IsInitialBlockDownload());
|
2016-03-02 22:20:04 +01:00
|
|
|
}
|
|
|
|
|
2017-09-03 15:30:08 +02:00
|
|
|
void CDSNotificationInterface::AcceptedBlockHeader(const CBlockIndex *pindexNew)
|
|
|
|
{
|
2022-11-07 19:09:44 +01:00
|
|
|
llmq_ctx->clhandler->AcceptedBlockHeader(pindexNew);
|
2023-06-04 22:26:23 +02:00
|
|
|
m_mn_sync.AcceptedBlockHeader(pindexNew);
|
2017-09-03 15:30:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDSNotificationInterface::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload)
|
|
|
|
{
|
2023-06-04 22:26:23 +02:00
|
|
|
m_mn_sync.NotifyHeaderTip(pindexNew, fInitialDownload);
|
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;
|
|
|
|
|
2022-09-22 13:14:48 +02:00
|
|
|
dmnman->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
|
|
|
|
2023-06-04 22:26:23 +02:00
|
|
|
m_mn_sync.UpdatedBlockTip(pindexNew, fInitialDownload);
|
2017-09-20 22:30:56 +02:00
|
|
|
|
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;
|
|
|
|
|
refactor: begin to de-globalize masternodeSync (#5103)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
minimizing global uses
## What was done?
<!--- Describe your changes in detail -->
Started the deglobalization, a future PR should be done to continue this
deglobalization
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [x] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [x] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-01-04 21:37:20 +01:00
|
|
|
CCoinJoin::UpdatedBlockTip(pindexNew, *llmq_ctx->clhandler, m_mn_sync);
|
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
|
|
|
|
|
2022-11-07 19:09:44 +01:00
|
|
|
llmq_ctx->isman->UpdatedBlockTip(pindexNew);
|
|
|
|
llmq_ctx->clhandler->UpdatedBlockTip();
|
2019-01-22 14:20:32 +01:00
|
|
|
|
2022-11-07 19:09:44 +01:00
|
|
|
llmq_ctx->qman->UpdatedBlockTip(pindexNew, fInitialDownload);
|
|
|
|
llmq_ctx->qdkgsman->UpdatedBlockTip(pindexNew, fInitialDownload);
|
2020-06-13 20:18:31 +02:00
|
|
|
|
2023-06-04 22:26:23 +02:00
|
|
|
if (!fDisableGovernance) govman.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
|
|
|
{
|
2022-11-07 19:09:44 +01:00
|
|
|
llmq_ctx->isman->TransactionAddedToMempool(ptx);
|
|
|
|
llmq_ctx->clhandler->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
|
|
|
{
|
2022-11-07 19:09:44 +01:00
|
|
|
llmq_ctx->isman->TransactionRemovedFromMempool(ptx);
|
2021-05-15 02:17:16 +02:00
|
|
|
}
|
|
|
|
|
2020-03-19 17:09:15 +01:00
|
|
|
void CDSNotificationInterface::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
|
2019-05-23 18:22:37 +02:00
|
|
|
{
|
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.
|
|
|
|
|
2020-03-19 17:09:15 +01:00
|
|
|
llmq_ctx->isman->BlockConnected(pblock, pindex);
|
|
|
|
llmq_ctx->clhandler->BlockConnected(pblock, pindex);
|
|
|
|
CCoinJoin::BlockConnected(pblock, pindex);
|
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
|
|
|
{
|
2022-11-07 19:09:44 +01:00
|
|
|
llmq_ctx->isman->BlockDisconnected(pblock, pindexDisconnected);
|
|
|
|
llmq_ctx->clhandler->BlockDisconnected(pblock, pindexDisconnected);
|
2021-03-17 23:36:11 +01:00
|
|
|
CCoinJoin::BlockDisconnected(pblock, pindexDisconnected);
|
2019-05-23 18:22:37 +02:00
|
|
|
}
|
|
|
|
|
2022-04-07 17:32:40 +02:00
|
|
|
void CDSNotificationInterface::NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman)
|
2019-01-03 10:17:43 +01:00
|
|
|
{
|
2022-04-07 17:32:40 +02:00
|
|
|
CMNAuth::NotifyMasternodeListChanged(undo, oldMNList, diff, connman);
|
2023-06-04 22:26:23 +02:00
|
|
|
govman.UpdateCachesAndClean();
|
2019-01-03 10:17:43 +01:00
|
|
|
}
|
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
|
|
|
{
|
2022-11-07 19:09:44 +01:00
|
|
|
llmq_ctx->isman->NotifyChainLock(pindex);
|
refactor: begin to de-globalize masternodeSync (#5103)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
minimizing global uses
## What was done?
<!--- Describe your changes in detail -->
Started the deglobalization, a future PR should be done to continue this
deglobalization
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
none
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [x] I have made corresponding changes to the documentation
**For repository code-owners and collaborators only**
- [x] I have assigned this pull request to a milestone
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-01-04 21:37:20 +01:00
|
|
|
CCoinJoin::NotifyChainLock(pindex, *llmq_ctx->clhandler, m_mn_sync);
|
2018-09-21 16:01:04 +02:00
|
|
|
}
|