mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
41a6613fba
## Motivation CoinJoin's subsystems are initialized by variables and managers that occupy the global context. The _extent_ to which these subsystems entrench themselves into the codebase is difficult to assess and moving them out of the global context forces us to enumerate the subsystems in the codebase that rely on CoinJoin logic and enumerate the order in which components are initialized and destroyed. Keeping this in mind, the scope of this pull request aims to: * Reduce the amount of CoinJoin-specific entities present in the global scope * Make the remaining usage of these entities in the global scope explicit and easily searchable ## Additional Information * The initialization of `CCoinJoinClientQueueManager` is dependent on blocks-only mode being disabled (which can be alternatively interpreted as enabling the relay of transactions). The same applies to `CBlockPolicyEstimator`, which `CCoinJoinClientQueueManager` depends. Therefore, `CCoinJoinClientQueueManager` is only initialized if transaction relaying is enabled and so is its scheduled maintenance task. This can be found by looking at `init.cpp` [here](93f8df1c31/src/init.cpp (L1681-L1683)
), [here](93f8df1c31/src/init.cpp (L2253-L2255)
) and [here](93f8df1c31/src/init.cpp (L2326-L2327)
). For this reason, `CBlockPolicyEstimator` is not a member of `CJContext` and its usage is fulfilled by passing it as a reference when initializing the scheduling task. * `CJClientManager` has not used `CConnman` or `CTxMemPool` as `const` as existing code that is outside the scope of this PR would cast away constness, which would be unacceptable. Furthermore, some logical paths are taken that will grind to a halt if they are stored as `const`. Examples of such a call chains would be: * `CJClientManager::DoMaintenance > CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating > CCoinJoinClientSession::DoAutomaticDenominating > CCoinJoinClientSession::StartNewQueue > CConnman::AddPendingMasternode` which modifies `CConnman::vPendingMasternodes`, which is non-const behaviour * `CJClientManager::DoMaintenance > CCoinJoinClientManager::DoMaintenance > DoAutomaticDenominating > CCoinJoin::IsCollateralValid > AcceptToMemoryPool` which adds a transaction to the memory pool, which is non-const behaviour * There were cppcheck [linter failures](https://github.com/dashpay/dash/pull/5337#issuecomment-1685084688) that seemed to be caused by the usage of `Assert` in `coinjoin/client.h`. This seems to be resolved by backporting [bitcoin#24714](https://github.com/bitcoin/bitcoin/pull/24714). (Thanks @knst!) * Depends on #5546 --------- Co-authored-by: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Co-authored-by: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com>
54 lines
2.5 KiB
C++
54 lines
2.5 KiB
C++
// Copyright (c) 2015 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#ifndef BITCOIN_DSNOTIFICATIONINTERFACE_H
|
|
#define BITCOIN_DSNOTIFICATIONINTERFACE_H
|
|
|
|
#include <validationinterface.h>
|
|
|
|
class CConnman;
|
|
class CDeterministicMNManager;
|
|
class CGovernanceManager;
|
|
class CMasternodeSync;
|
|
struct CJContext;
|
|
struct LLMQContext;
|
|
|
|
class CDSNotificationInterface : public CValidationInterface
|
|
{
|
|
public:
|
|
explicit CDSNotificationInterface(CConnman& _connman,
|
|
CMasternodeSync& _mn_sync, const std::unique_ptr<CDeterministicMNManager>& _dmnman,
|
|
CGovernanceManager& _govman, const std::unique_ptr<LLMQContext>& _llmq_ctx,
|
|
const std::unique_ptr<CJContext>& _cj_ctx);
|
|
virtual ~CDSNotificationInterface() = default;
|
|
|
|
// a small helper to initialize current block height in sub-modules on startup
|
|
void InitializeCurrentBlockTip();
|
|
|
|
protected:
|
|
// CValidationInterface
|
|
void AcceptedBlockHeader(const CBlockIndex *pindexNew) override;
|
|
void NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload) override;
|
|
void SynchronousUpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
|
|
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override;
|
|
void TransactionAddedToMempool(const CTransactionRef& tx, int64_t nAcceptTime) override;
|
|
void TransactionRemovedFromMempool(const CTransactionRef& ptx, MemPoolRemovalReason reason) override;
|
|
void BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex) override;
|
|
void BlockDisconnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected) override;
|
|
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman) override;
|
|
void NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig) override;
|
|
|
|
private:
|
|
CConnman& connman;
|
|
|
|
CMasternodeSync& m_mn_sync;
|
|
const std::unique_ptr<CDeterministicMNManager>& dmnman;
|
|
CGovernanceManager& govman;
|
|
|
|
const std::unique_ptr<LLMQContext>& llmq_ctx;
|
|
const std::unique_ptr<CJContext>& cj_ctx;
|
|
};
|
|
|
|
#endif // BITCOIN_DSNOTIFICATIONINTERFACE_H
|