From 7e13727738390eed8293d76d65a538e8d3a71407 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Fri, 1 Dec 2023 19:26:25 +0700 Subject: [PATCH] refactor: drop circular dependency validationinterface <-> governance/object --- src/coinjoin/coinjoin.cpp | 1 + src/governance/governance.cpp | 3 ++- src/governance/object.h | 5 +++++ src/validationinterface.cpp | 4 ++-- src/validationinterface.h | 10 +++++++--- src/zmq/zmqabstractnotifier.cpp | 2 +- src/zmq/zmqabstractnotifier.h | 8 ++++++-- src/zmq/zmqnotificationinterface.cpp | 2 +- src/zmq/zmqnotificationinterface.h | 2 +- src/zmq/zmqpublishnotifier.cpp | 8 ++++---- src/zmq/zmqpublishnotifier.h | 11 ++++++++--- test/lint/lint-circular-dependencies.sh | 1 - 12 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/coinjoin/coinjoin.cpp b/src/coinjoin/coinjoin.cpp index ebb7f967ba..09072bbf89 100644 --- a/src/coinjoin/coinjoin.cpp +++ b/src/coinjoin/coinjoin.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include diff --git a/src/governance/governance.cpp b/src/governance/governance.cpp index e4ed643552..7d741cceae 100644 --- a/src/governance/governance.cpp +++ b/src/governance/governance.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -333,7 +334,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman CheckOrphanVotes(govobj, connman); // SEND NOTIFICATION TO SCRIPT/ZMQ - GetMainSignals().NotifyGovernanceObject(std::make_shared(govobj)); + GetMainSignals().NotifyGovernanceObject(std::make_shared(govobj.Object())); } void CGovernanceManager::UpdateCachesAndClean() diff --git a/src/governance/object.h b/src/governance/object.h index 142b9e4d9f..da4c990a5c 100644 --- a/src/governance/object.h +++ b/src/governance/object.h @@ -145,6 +145,11 @@ public: // Public Getter methods + const Governance::Object& Object() const + { + return m_obj; + } + int64_t GetCreationTime() const { return m_obj.time; diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index ed014cb752..a293dc9dad 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -7,12 +7,12 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -295,7 +295,7 @@ void CMainSignals::NotifyGovernanceVote(const std::shared_ptrGetHash().ToString()); } -void CMainSignals::NotifyGovernanceObject(const std::shared_ptr& object) { +void CMainSignals::NotifyGovernanceObject(const std::shared_ptr& object) { auto event = [object, this] { m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NotifyGovernanceObject(object); }); }; diff --git a/src/validationinterface.h b/src/validationinterface.h index 90a5729239..25368aae98 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -20,13 +20,17 @@ struct CBlockLocator; class CConnman; class CValidationInterface; class CGovernanceVote; -class CGovernanceObject; class CDeterministicMNList; class CDeterministicMNListDiff; class uint256; class CScheduler; enum class MemPoolRemovalReason; +namespace Governance +{ + class Object; +} + namespace llmq { class CChainLockSig; struct CInstantSendLock; @@ -162,7 +166,7 @@ protected: virtual void NotifyTransactionLock(const CTransactionRef &tx, const std::shared_ptr& islock) {} virtual void NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr& clsig) {} virtual void NotifyGovernanceVote(const std::shared_ptr& vote) {} - virtual void NotifyGovernanceObject(const std::shared_ptr& object) {} + virtual void NotifyGovernanceObject(const std::shared_ptr& object) {} virtual void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx) {} virtual void NotifyRecoveredSig(const std::shared_ptr& sig) {} virtual void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) {} @@ -229,7 +233,7 @@ public: void NotifyTransactionLock(const CTransactionRef &tx, const std::shared_ptr& islock); void NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr& clsig); void NotifyGovernanceVote(const std::shared_ptr& vote); - void NotifyGovernanceObject(const std::shared_ptr& object); + void NotifyGovernanceObject(const std::shared_ptr& object); void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef ¤tTx, const CTransactionRef &previousTx); void NotifyRecoveredSig(const std::shared_ptr &sig); void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff); diff --git a/src/zmq/zmqabstractnotifier.cpp b/src/zmq/zmqabstractnotifier.cpp index 33bc248c3b..799bf859b1 100644 --- a/src/zmq/zmqabstractnotifier.cpp +++ b/src/zmq/zmqabstractnotifier.cpp @@ -38,7 +38,7 @@ bool CZMQAbstractNotifier::NotifyGovernanceVote(const std::shared_ptr & /*object*/) +bool CZMQAbstractNotifier::NotifyGovernanceObject(const std::shared_ptr & /*object*/) { return true; } diff --git a/src/zmq/zmqabstractnotifier.h b/src/zmq/zmqabstractnotifier.h index 16a2db9df7..1d22ae7e99 100644 --- a/src/zmq/zmqabstractnotifier.h +++ b/src/zmq/zmqabstractnotifier.h @@ -10,13 +10,17 @@ #include class CBlockIndex; -class CGovernanceObject; class CGovernanceVote; class CTransaction; class CZMQAbstractNotifier; typedef std::shared_ptr CTransactionRef; +namespace Governance +{ + class Object; +} //namespace Governance + namespace llmq { class CChainLockSig; struct CInstantSendLock; @@ -58,7 +62,7 @@ public: virtual bool NotifyTransaction(const CTransaction &transaction); virtual bool NotifyTransactionLock(const CTransactionRef& transaction, const std::shared_ptr& islock); virtual bool NotifyGovernanceVote(const std::shared_ptr& vote); - virtual bool NotifyGovernanceObject(const std::shared_ptr& object); + virtual bool NotifyGovernanceObject(const std::shared_ptr& object); virtual bool NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx); virtual bool NotifyRecoveredSig(const std::shared_ptr& sig); diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 073ba4ae9d..6db7ca667a 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -198,7 +198,7 @@ void CZMQNotificationInterface::NotifyGovernanceVote(const std::shared_ptr &object) +void CZMQNotificationInterface::NotifyGovernanceObject(const std::shared_ptr &object) { TryForEachAndRemoveFailed(notifiers, [&object](CZMQAbstractNotifier* notifier) { return notifier->NotifyGovernanceObject(object); diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index c17101fefb..8b380f32ae 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -33,7 +33,7 @@ protected: void NotifyChainLock(const CBlockIndex *pindex, const std::shared_ptr& clsig) override; void NotifyTransactionLock(const CTransactionRef &tx, const std::shared_ptr& islock) override; void NotifyGovernanceVote(const std::shared_ptr& vote) override; - void NotifyGovernanceObject(const std::shared_ptr& object) override; + void NotifyGovernanceObject(const std::shared_ptr& object) override; void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx) override; void NotifyRecoveredSig(const std::shared_ptr& sig) override; diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index fd10dce13c..c08ae206fe 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include @@ -245,7 +245,7 @@ bool CZMQPublishHashGovernanceVoteNotifier::NotifyGovernanceVote(const std::shar return SendZmqMessage(MSG_HASHGVOTE, data, 32); } -bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr& object) +bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr& object) { uint256 hash = object->GetHash(); LogPrint(BCLog::ZMQ, "zmq: Publish hashgovernanceobject %s\n", hash.GetHex()); @@ -378,10 +378,10 @@ bool CZMQPublishRawGovernanceVoteNotifier::NotifyGovernanceVote(const std::share return SendZmqMessage(MSG_RAWGVOTE, &(*ss.begin()), ss.size()); } -bool CZMQPublishRawGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr& govobj) +bool CZMQPublishRawGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr& govobj) { uint256 nHash = govobj->GetHash(); - LogPrint(BCLog::ZMQ, "zmq: Publish rawgovernanceobject: hash = %s to %s, type = %d\n", nHash.ToString(), this->address, ToUnderlying(govobj->GetObjectType())); + LogPrint(BCLog::ZMQ, "zmq: Publish rawgovernanceobject: hash = %s to %s, type = %d\n", nHash.ToString(), this->address, ToUnderlying(govobj->type)); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss << *govobj; return SendZmqMessage(MSG_RAWGOBJ, &(*ss.begin()), ss.size()); diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h index 6fc488eba4..68c64314d6 100644 --- a/src/zmq/zmqpublishnotifier.h +++ b/src/zmq/zmqpublishnotifier.h @@ -9,7 +9,12 @@ class CBlockIndex; class CGovernanceVote; -class CGovernanceObject; + +namespace Governance +{ + class Object; +} //namespace Governance + class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier { @@ -63,7 +68,7 @@ public: class CZMQPublishHashGovernanceObjectNotifier : public CZMQAbstractPublishNotifier { public: - bool NotifyGovernanceObject(const std::shared_ptr& object) override; + bool NotifyGovernanceObject(const std::shared_ptr& object) override; }; class CZMQPublishHashInstantSendDoubleSpendNotifier : public CZMQAbstractPublishNotifier @@ -123,7 +128,7 @@ public: class CZMQPublishRawGovernanceObjectNotifier : public CZMQAbstractPublishNotifier { public: - bool NotifyGovernanceObject(const std::shared_ptr& object) override; + bool NotifyGovernanceObject(const std::shared_ptr& object) override; }; class CZMQPublishRawInstantSendDoubleSpendNotifier : public CZMQAbstractPublishNotifier diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh index 3f91423783..0e96325ed9 100755 --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -97,7 +97,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=( "spork -> validation -> spork" "governance/governance -> validation -> governance/governance" "evo/deterministicmns -> validationinterface -> governance/vote -> evo/deterministicmns" - "governance/object -> validationinterface -> governance/object" "governance/vote -> validation -> validationinterface -> governance/vote" "llmq/signing -> masternode/node -> validationinterface -> llmq/signing" "evo/mnhftx -> validation -> evo/mnhftx"