From 69f9009cc2edf6ff78813ffe7ae948aec8ee7d1b Mon Sep 17 00:00:00 2001 From: Jeff Hodges - Desktop Date: Mon, 2 Jul 2018 21:18:14 -0700 Subject: [PATCH 01/10] Added rawgovernanceobject and rawgovernancevote to ZMQ. --- src/zmq/zmqnotificationinterface.cpp | 2 ++ src/zmq/zmqpublishnotifier.cpp | 23 +++++++++++++++++++++-- src/zmq/zmqpublishnotifier.h | 14 +++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp index 5766f3305191..8f1453b725e8 100644 --- a/src/zmq/zmqnotificationinterface.cpp +++ b/src/zmq/zmqnotificationinterface.cpp @@ -43,6 +43,8 @@ CZMQNotificationInterface* CZMQNotificationInterface::Create() factories["pubrawtxlock"] = CZMQAbstractNotifier::Create; factories["pubhashgovernancevote"] = CZMQAbstractNotifier::Create; factories["pubhashgovernanceobject"] = CZMQAbstractNotifier::Create; + factories["pubrawgovernanceobject"] = CZMQAbstractNotifier::Create; + factories["pubrawgovernancevote"] = CZMQAbstractNotifier::Create; for (std::map::const_iterator it = factories.begin(); it != factories.end(); ++it) { diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index 221652f2e4b7..7f85d6da3998 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -13,11 +13,13 @@ static std::multimap mapPublishNotifi static const char *MSG_HASHBLOCK = "hashblock"; static const char *MSG_HASHTX = "hashtx"; static const char *MSG_HASHTXLOCK = "hashtxlock"; +static const char *MSG_HASHGVOTE = "hashgovernancevote"; +static const char *MSG_HASHGOBJ = "hashgovernanceobject"; static const char *MSG_RAWBLOCK = "rawblock"; static const char *MSG_RAWTX = "rawtx"; static const char *MSG_RAWTXLOCK = "rawtxlock"; -static const char *MSG_HASHGVOTE = "hashgovernancevote"; -static const char *MSG_HASHGOBJ = "hashgovernanceobject"; +static const char *MSG_RAWGOVERNANCEOBJECT = "rawgobject"; +static const char *MSG_RAWGOVERNANCEVOTE = "rawgobjectvote"; // Internal function to send multipart message @@ -239,3 +241,20 @@ bool CZMQPublishHashGovernanceObjectNotifier::NotifyGovernanceObject(const CGove data[31 - i] = hashData[i]; return SendMessage(MSG_HASHGOBJ, data, 32); } + +bool CZMQPublishRawGovernanceObjectNotifier::NotifyGovernanceObject(const CGovernanceObject& govobj) +{ + uint256 nHash = govobj.GetHash(); + LogPrint("gobject", "gobject: Publish rawgovernanceobject: hash = %s, type = %d\n", nHash.ToString(), govobj.GetObjectType()); + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << govobj; + return SendMessage(MSG_RAWGOVERNANCEOBJECT, &(*ss.begin()), ss.size()); +} + +bool CZMQPublishRawGovernanceVoteNotifier::NotifyGovernanceVote(const CGovernanceVote& vote) +{ + uint256 nHash = vote.GetHash(); + LogPrint("gobject", "gobject: Publish rawgovernancevote: hash = %s, vote = %s\n", nHash.ToString(), vote.ToString()); + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << vote; + return SendMessage(MSG_RAWGOVERNANCEVOTE, &(*ss.begin()), ss.size()); \ No newline at end of file diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h index d2f3b8bec542..459ac8a1233b 100644 --- a/src/zmq/zmqpublishnotifier.h +++ b/src/zmq/zmqpublishnotifier.h @@ -76,4 +76,16 @@ class CZMQPublishHashGovernanceObjectNotifier : public CZMQAbstractPublishNotifi public: bool NotifyGovernanceObject(const CGovernanceObject &object) override; }; -#endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H +class CZMQPublishRawGovernanceObjectNotifier : public CZMQAbstractPublishNotifier +{ +public: + bool NotifyGovernanceObject(const CGovernanceObject& govobj); +}; + +class CZMQPublishRawGovernanceVoteNotifier : public CZMQAbstractPublishNotifier +{ +public: + bool NotifyGovernanceVote(const CGovernanceVote& vote); +}; + +#endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H \ No newline at end of file From 6471d44ff75991e654f0952a1e9afef6971f95fc Mon Sep 17 00:00:00 2001 From: Jeff Hodges - Desktop Date: Mon, 2 Jul 2018 22:54:22 -0700 Subject: [PATCH 02/10] Fixed missing brace --- src/zmq/zmqpublishnotifier.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index 7f85d6da3998..120f63be12a2 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -18,8 +18,8 @@ static const char *MSG_HASHGOBJ = "hashgovernanceobject"; static const char *MSG_RAWBLOCK = "rawblock"; static const char *MSG_RAWTX = "rawtx"; static const char *MSG_RAWTXLOCK = "rawtxlock"; -static const char *MSG_RAWGOVERNANCEOBJECT = "rawgobject"; -static const char *MSG_RAWGOVERNANCEVOTE = "rawgobjectvote"; +static const char *MSG_RAWGOVERNANCEOBJECT = "rawgovernanceobject"; +static const char *MSG_RAWGOVERNANCEVOTE = "rawgovernanceobjectvote"; // Internal function to send multipart message @@ -257,4 +257,5 @@ bool CZMQPublishRawGovernanceVoteNotifier::NotifyGovernanceVote(const CGovernanc LogPrint("gobject", "gobject: Publish rawgovernancevote: hash = %s, vote = %s\n", nHash.ToString(), vote.ToString()); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); ss << vote; - return SendMessage(MSG_RAWGOVERNANCEVOTE, &(*ss.begin()), ss.size()); \ No newline at end of file + return SendMessage(MSG_RAWGOVERNANCEVOTE, &(*ss.begin()), ss.size()); +} \ No newline at end of file From f637c7ec4f75ca8ff6eff7f044f96f99f032de27 Mon Sep 17 00:00:00 2001 From: Jeff Hodges - Desktop Date: Tue, 3 Jul 2018 00:46:47 -0700 Subject: [PATCH 03/10] Fixed rawgovernancevote naming --- src/zmq/zmqpublishnotifier.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index 120f63be12a2..fb3e4e47b200 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -19,7 +19,7 @@ static const char *MSG_RAWBLOCK = "rawblock"; static const char *MSG_RAWTX = "rawtx"; static const char *MSG_RAWTXLOCK = "rawtxlock"; static const char *MSG_RAWGOVERNANCEOBJECT = "rawgovernanceobject"; -static const char *MSG_RAWGOVERNANCEVOTE = "rawgovernanceobjectvote"; +static const char *MSG_RAWGOVERNANCEVOTE = "rawgovernancevote"; // Internal function to send multipart message From 977d7076afdd9aa36269c90b35dc9e137ac80084 Mon Sep 17 00:00:00 2001 From: Jeff Hodges - Desktop Date: Tue, 3 Jul 2018 15:34:34 -0700 Subject: [PATCH 04/10] Small tweaks, improvements to gobject and gobejct votes. --- src/governance.cpp | 5 ++++- src/zmq/zmqabstractnotifier.h | 4 ++-- src/zmq/zmqpublishnotifier.h | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 51729541cb9c..d823a93815f7 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -256,6 +256,9 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- %s new\n", strHash); masternodeSync.BumpAssetLastTime("MNGOVERNANCEOBJECTVOTE"); vote.Relay(connman); + + // SEND NOTIFICATION TO ZMQ + GetMainSignals().NotifyGovernanceVote(vote) } else { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what()); @@ -362,7 +365,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman CGovernanceException exception; CheckOrphanVotes(govobj, exception, connman); - //Send notifications to scripts / zmq + // SEND NOTIFICATION TO ZMQ GetMainSignals().NotifyGovernanceObject(govobj); diff --git a/src/zmq/zmqabstractnotifier.h b/src/zmq/zmqabstractnotifier.h index e1e73011d24f..ee6aa3ad7e2c 100644 --- a/src/zmq/zmqabstractnotifier.h +++ b/src/zmq/zmqabstractnotifier.h @@ -37,8 +37,8 @@ class CZMQAbstractNotifier virtual bool NotifyBlock(const CBlockIndex *pindex); virtual bool NotifyTransaction(const CTransaction &transaction); virtual bool NotifyTransactionLock(const CTransaction &transaction); - virtual bool NotifyGovernanceVote(const CGovernanceVote& vote); - virtual bool NotifyGovernanceObject(const CGovernanceObject& object); + virtual bool NotifyGovernanceVote(const CGovernanceVote &vote); + virtual bool NotifyGovernanceObject(const CGovernanceObject &object); protected: diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h index 459ac8a1233b..3558cf5d8283 100644 --- a/src/zmq/zmqpublishnotifier.h +++ b/src/zmq/zmqpublishnotifier.h @@ -71,21 +71,23 @@ class CZMQPublishHashGovernanceVoteNotifier : public CZMQAbstractPublishNotifier public: bool NotifyGovernanceVote(const CGovernanceVote &vote) override; }; + class CZMQPublishHashGovernanceObjectNotifier : public CZMQAbstractPublishNotifier { public: bool NotifyGovernanceObject(const CGovernanceObject &object) override; }; + class CZMQPublishRawGovernanceObjectNotifier : public CZMQAbstractPublishNotifier { public: - bool NotifyGovernanceObject(const CGovernanceObject& govobj); + bool NotifyGovernanceObject(const CGovernanceObject &govobj); }; class CZMQPublishRawGovernanceVoteNotifier : public CZMQAbstractPublishNotifier { public: - bool NotifyGovernanceVote(const CGovernanceVote& vote); + bool NotifyGovernanceVote(const CGovernanceVote &vote); }; #endif // BITCOIN_ZMQ_ZMQPUBLISHNOTIFIER_H \ No newline at end of file From a6fad3c0e7b65584281330a8ce12955acd21ec05 Mon Sep 17 00:00:00 2001 From: Jeff Hodges - Desktop Date: Tue, 3 Jul 2018 15:40:39 -0700 Subject: [PATCH 05/10] Forgot semi-colon --- src/governance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/governance.cpp b/src/governance.cpp index d823a93815f7..2184370a4e41 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -258,7 +258,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm vote.Relay(connman); // SEND NOTIFICATION TO ZMQ - GetMainSignals().NotifyGovernanceVote(vote) + GetMainSignals().NotifyGovernanceVote(vote); } else { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what()); From 2d0b75ab44c4f48af24ab276b52cef0fe565f107 Mon Sep 17 00:00:00 2001 From: Jeff Hodges - Desktop Date: Tue, 3 Jul 2018 23:21:26 -0700 Subject: [PATCH 06/10] Added missing validation interface --- src/validationinterface.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index 56620c929479..436cedf1019c 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -26,6 +26,8 @@ void RegisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.ScriptForMining.connect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1)); g_signals.BlockFound.connect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1)); g_signals.NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); + g_signals.NotifyGovernanceObject.connect(boost::bind(&CValidationInterface::NotifyGovernanceObject, pwalletIn, _1)); + g_signals.NotifyGovernanceVote.connect(boost::bind(&CValidationInterface::NotifyGovernanceVote, pwalletIn, _1)); } void UnregisterValidationInterface(CValidationInterface* pwalletIn) { @@ -42,6 +44,8 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn) { g_signals.NewPoWValidBlock.disconnect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); g_signals.NotifyHeaderTip.disconnect(boost::bind(&CValidationInterface::NotifyHeaderTip, pwalletIn, _1, _2)); g_signals.AcceptedBlockHeader.disconnect(boost::bind(&CValidationInterface::AcceptedBlockHeader, pwalletIn, _1)); + g_signals.NotifyGovernanceObject.disconnect(boost::bind(&CValidationInterface::NotifyGovernanceObject, pwalletIn, _1)); + g_signals.NotifyGovernanceVote.disconnect(boost::bind(&CValidationInterface::NotifyGovernanceVote, pwalletIn, _1)); } void UnregisterAllValidationInterfaces() { @@ -58,4 +62,6 @@ void UnregisterAllValidationInterfaces() { g_signals.NewPoWValidBlock.disconnect_all_slots(); g_signals.NotifyHeaderTip.disconnect_all_slots(); g_signals.AcceptedBlockHeader.disconnect_all_slots(); + g_signals.NotifyGovernanceObject.disconnect_all_slots(); + g_signals.NotifyGovernanceVote.disconnect_all_slots(); } From 774f2078a61d2906dd9b27bd8027a619a8d0fca6 Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Wed, 4 Jul 2018 16:18:36 -0700 Subject: [PATCH 07/10] Trying out ToJson() on objects --- src/governance.cpp | 4 ++-- src/zmq/zmqnotificationinterface.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 2184370a4e41..429b620f2577 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -258,7 +258,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm vote.Relay(connman); // SEND NOTIFICATION TO ZMQ - GetMainSignals().NotifyGovernanceVote(vote); + GetMainSignals().NotifyGovernanceVote(vote.ToJson()); } else { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what()); @@ -366,7 +366,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman CheckOrphanVotes(govobj, exception, connman); // SEND NOTIFICATION TO ZMQ - GetMainSignals().NotifyGovernanceObject(govobj); + GetMainSignals().NotifyGovernanceObject(govobj.ToJson()); DBG( std::cout << "CGovernanceManager::AddGovernanceObject END" << std::endl; ); diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h index aeaed254a007..164e41de9696 100644 --- a/src/zmq/zmqnotificationinterface.h +++ b/src/zmq/zmqnotificationinterface.h @@ -26,7 +26,7 @@ class CZMQNotificationInterface : public CValidationInterface // CValidationInterface void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, int posInBlock) override; void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override; - void NotifyTransactionLock(const CTransaction &tx) override; + void NotifyTransactionLock(const CTransaction& tx) override; void NotifyGovernanceVote(const CGovernanceVote& vote) override; void NotifyGovernanceObject(const CGovernanceObject& object) override; From 1724e20bceac66f0c50698ab5d49c77c3dd8e9b3 Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Wed, 4 Jul 2018 16:48:18 -0700 Subject: [PATCH 08/10] Changed ToJson() to ToString() --- src/governance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index 429b620f2577..ae477b2d5f8a 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -258,7 +258,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm vote.Relay(connman); // SEND NOTIFICATION TO ZMQ - GetMainSignals().NotifyGovernanceVote(vote.ToJson()); + GetMainSignals().NotifyGovernanceVote(vote.ToString()); } else { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what()); @@ -366,7 +366,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman CheckOrphanVotes(govobj, exception, connman); // SEND NOTIFICATION TO ZMQ - GetMainSignals().NotifyGovernanceObject(govobj.ToJson()); + GetMainSignals().NotifyGovernanceObject(govobj.ToString()); DBG( std::cout << "CGovernanceManager::AddGovernanceObject END" << std::endl; ); From 2477ad2db4eddba8c7a2f92dbedf67e31a4cecfa Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Wed, 4 Jul 2018 16:50:35 -0700 Subject: [PATCH 09/10] Removed ToJson() on govobj --- src/governance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/governance.cpp b/src/governance.cpp index ae477b2d5f8a..c8bcd6c77ae4 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -366,7 +366,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman CheckOrphanVotes(govobj, exception, connman); // SEND NOTIFICATION TO ZMQ - GetMainSignals().NotifyGovernanceObject(govobj.ToString()); + GetMainSignals().NotifyGovernanceObject(govobj); DBG( std::cout << "CGovernanceManager::AddGovernanceObject END" << std::endl; ); From 8f9d4c9deb6c7620372da6d21efb36c007acc85d Mon Sep 17 00:00:00 2001 From: Jeff Hodges Date: Wed, 4 Jul 2018 16:53:35 -0700 Subject: [PATCH 10/10] Removed ToString() entirely. --- src/governance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/governance.cpp b/src/governance.cpp index c8bcd6c77ae4..2184370a4e41 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -258,7 +258,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& strComm vote.Relay(connman); // SEND NOTIFICATION TO ZMQ - GetMainSignals().NotifyGovernanceVote(vote.ToString()); + GetMainSignals().NotifyGovernanceVote(vote); } else { LogPrint("gobject", "MNGOVERNANCEOBJECTVOTE -- Rejected vote, error = %s\n", exception.what());