refactor: drop circular dependency validationinterface <-> governance/object

This commit is contained in:
Konstantin Akimov 2023-12-01 19:26:25 +07:00 committed by pasta
parent 4de30f4b61
commit 7e13727738
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
12 changed files with 38 additions and 19 deletions

View File

@ -8,6 +8,7 @@
#include <chain.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <governance/common.h>
#include <llmq/chainlocks.h>
#include <llmq/instantsend.h>
#include <llmq/utils.h>

View File

@ -12,6 +12,7 @@
#include <evo/deterministicmns.h>
#include <flat-database.h>
#include <governance/classes.h>
#include <governance/common.h>
#include <governance/validators.h>
#include <masternode/meta.h>
#include <masternode/node.h>
@ -333,7 +334,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
CheckOrphanVotes(govobj, connman);
// SEND NOTIFICATION TO SCRIPT/ZMQ
GetMainSignals().NotifyGovernanceObject(std::make_shared<const CGovernanceObject>(govobj));
GetMainSignals().NotifyGovernanceObject(std::make_shared<const Governance::Object>(govobj.Object()));
}
void CGovernanceManager::UpdateCachesAndClean()

View File

@ -145,6 +145,11 @@ public:
// Public Getter methods
const Governance::Object& Object() const
{
return m_obj;
}
int64_t GetCreationTime() const
{
return m_obj.time;

View File

@ -7,12 +7,12 @@
#include <chain.h>
#include <consensus/validation.h>
#include <governance/common.h>
#include <logging.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <scheduler.h>
#include <governance/object.h>
#include <governance/vote.h>
#include <llmq/clsig.h>
#include <llmq/signing.h>
@ -295,7 +295,7 @@ void CMainSignals::NotifyGovernanceVote(const std::shared_ptr<const CGovernanceV
ENQUEUE_AND_LOG_EVENT(event, "%s: notify governance vote: %s", __func__, vote->GetHash().ToString());
}
void CMainSignals::NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object) {
void CMainSignals::NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object) {
auto event = [object, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.NotifyGovernanceObject(object); });
};

View File

@ -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<const llmq::CInstantSendLock>& islock) {}
virtual void NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig) {}
virtual void NotifyGovernanceVote(const std::shared_ptr<const CGovernanceVote>& vote) {}
virtual void NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object) {}
virtual void NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object) {}
virtual void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx) {}
virtual void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& 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<const llmq::CInstantSendLock>& islock);
void NotifyChainLock(const CBlockIndex* pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig);
void NotifyGovernanceVote(const std::shared_ptr<const CGovernanceVote>& vote);
void NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object);
void NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object);
void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef &currentTx, const CTransactionRef &previousTx);
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig> &sig);
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff);

View File

@ -38,7 +38,7 @@ bool CZMQAbstractNotifier::NotifyGovernanceVote(const std::shared_ptr<const CGov
return true;
}
bool CZMQAbstractNotifier::NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject> & /*object*/)
bool CZMQAbstractNotifier::NotifyGovernanceObject(const std::shared_ptr<const Governance::Object> & /*object*/)
{
return true;
}

View File

@ -10,13 +10,17 @@
#include <string>
class CBlockIndex;
class CGovernanceObject;
class CGovernanceVote;
class CTransaction;
class CZMQAbstractNotifier;
typedef std::shared_ptr<const CTransaction> 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<const llmq::CInstantSendLock>& islock);
virtual bool NotifyGovernanceVote(const std::shared_ptr<const CGovernanceVote>& vote);
virtual bool NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object);
virtual bool NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object);
virtual bool NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx);
virtual bool NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig);

View File

@ -198,7 +198,7 @@ void CZMQNotificationInterface::NotifyGovernanceVote(const std::shared_ptr<const
});
}
void CZMQNotificationInterface::NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject> &object)
void CZMQNotificationInterface::NotifyGovernanceObject(const std::shared_ptr<const Governance::Object> &object)
{
TryForEachAndRemoveFailed(notifiers, [&object](CZMQAbstractNotifier* notifier) {
return notifier->NotifyGovernanceObject(object);

View File

@ -33,7 +33,7 @@ protected:
void NotifyChainLock(const CBlockIndex *pindex, const std::shared_ptr<const llmq::CChainLockSig>& clsig) override;
void NotifyTransactionLock(const CTransactionRef &tx, const std::shared_ptr<const llmq::CInstantSendLock>& islock) override;
void NotifyGovernanceVote(const std::shared_ptr<const CGovernanceVote>& vote) override;
void NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object) override;
void NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object) override;
void NotifyInstantSendDoubleSpendAttempt(const CTransactionRef& currentTx, const CTransactionRef& previousTx) override;
void NotifyRecoveredSig(const std::shared_ptr<const llmq::CRecoveredSig>& sig) override;

View File

@ -11,7 +11,7 @@
#include <validation.h>
#include <zmq/zmqutil.h>
#include <governance/object.h>
#include <governance/common.h>
#include <governance/vote.h>
#include <llmq/chainlocks.h>
@ -245,7 +245,7 @@ bool CZMQPublishHashGovernanceVoteNotifier::NotifyGovernanceVote(const std::shar
return SendZmqMessage(MSG_HASHGVOTE, data, 32);
}
bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object)
bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& 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<const CGovernanceObject>& govobj)
bool CZMQPublishRawGovernanceObjectNotifier::NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& 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());

View File

@ -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<const CGovernanceObject>& object) override;
bool NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object) override;
};
class CZMQPublishHashInstantSendDoubleSpendNotifier : public CZMQAbstractPublishNotifier
@ -123,7 +128,7 @@ public:
class CZMQPublishRawGovernanceObjectNotifier : public CZMQAbstractPublishNotifier
{
public:
bool NotifyGovernanceObject(const std::shared_ptr<const CGovernanceObject>& object) override;
bool NotifyGovernanceObject(const std::shared_ptr<const Governance::Object>& object) override;
};
class CZMQPublishRawInstantSendDoubleSpendNotifier : public CZMQAbstractPublishNotifier

View File

@ -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"