16
16
#include < masternode/node.h>
17
17
#include < masternode/sync.h>
18
18
#include < net.h>
19
- #include < net_processing.h>
20
19
#include < netmessagemaker.h>
21
20
#include < univalue.h>
22
21
#include < util/irange.h>
@@ -189,16 +188,14 @@ bool CQuorum::ReadContributions(CEvoDB& evoDb)
189
188
}
190
189
191
190
CQuorumManager::CQuorumManager (CBLSWorker& _blsWorker, CChainState& chainstate, CConnman& _connman, CDKGSessionManager& _dkgManager,
192
- CEvoDB& _evoDb, CQuorumBlockProcessor& _quorumBlockProcessor, const std::unique_ptr<CMasternodeSync>& mn_sync,
193
- const std::unique_ptr<PeerManager>& peerman) :
191
+ CEvoDB& _evoDb, CQuorumBlockProcessor& _quorumBlockProcessor, const std::unique_ptr<CMasternodeSync>& mn_sync) :
194
192
blsWorker (_blsWorker),
195
193
m_chainstate (chainstate),
196
194
connman (_connman),
197
195
dkgManager (_dkgManager),
198
196
m_evoDb (_evoDb),
199
197
quorumBlockProcessor (_quorumBlockProcessor),
200
- m_mn_sync (mn_sync),
201
- m_peerman (peerman)
198
+ m_mn_sync (mn_sync)
202
199
{
203
200
utils::InitQuorumsCache (mapQuorumsCache, false );
204
201
quorumThreadInterrupt.reset ();
@@ -644,37 +641,38 @@ size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorumCPtr pQuorum, c
644
641
return nIndex % pQuorum->qc ->validMembers .size ();
645
642
}
646
643
647
- void CQuorumManager::ProcessMessage (CNode& pfrom, const std::string& msg_type, CDataStream& vRecv)
644
+ PeerMsgRet CQuorumManager::ProcessMessage (CNode& pfrom, const std::string& msg_type, CDataStream& vRecv)
648
645
{
649
646
auto strFunc = __func__;
650
- auto errorHandler = [&](const std::string& strError, int nScore = 10 ) {
647
+ auto errorHandler = [&](const std::string& strError, int nScore = 10 ) -> PeerMsgRet {
651
648
LogPrint (BCLog::LLMQ, " CQuorumManager::%s -- %s: %s, from peer=%d\n " , strFunc, msg_type, strError, pfrom.GetId ());
652
649
if (nScore > 0 ) {
653
- m_peerman-> Misbehaving (pfrom. GetId (), nScore) ;
650
+ return tl::unexpected{ nScore} ;
654
651
}
652
+ return {};
655
653
};
656
654
657
655
if (msg_type == NetMsgType::QGETDATA) {
658
656
659
657
if (!fMasternodeMode || (pfrom.GetVerifiedProRegTxHash ().IsNull () && !pfrom.qwatch )) {
660
- errorHandler (" Not a verified masternode or a qwatch connection" );
661
- return ;
658
+ return errorHandler (" Not a verified masternode or a qwatch connection" );
662
659
}
663
660
664
661
CQuorumDataRequest request;
665
662
vRecv >> request;
666
663
667
664
auto sendQDATA = [&](CQuorumDataRequest::Errors nError,
668
665
bool request_limit_exceeded,
669
- const CDataStream& body = CDataStream (SER_NETWORK, PROTOCOL_VERSION)) {
666
+ const CDataStream& body = CDataStream (SER_NETWORK, PROTOCOL_VERSION)) -> PeerMsgRet {
667
+ PeerMsgRet ret{};
670
668
switch (nError) {
671
669
case (CQuorumDataRequest::Errors::NONE):
672
670
case (CQuorumDataRequest::Errors::QUORUM_TYPE_INVALID):
673
671
case (CQuorumDataRequest::Errors::QUORUM_BLOCK_NOT_FOUND):
674
672
case (CQuorumDataRequest::Errors::QUORUM_NOT_FOUND):
675
673
case (CQuorumDataRequest::Errors::MASTERNODE_IS_NO_MEMBER):
676
674
case (CQuorumDataRequest::Errors::UNDEFINED):
677
- if (request_limit_exceeded) errorHandler (" Request limit exceeded" , 25 );
675
+ if (request_limit_exceeded) ret = errorHandler (" Request limit exceeded" , 25 );
678
676
break ;
679
677
case (CQuorumDataRequest::Errors::QUORUM_VERIFICATION_VECTOR_MISSING):
680
678
case (CQuorumDataRequest::Errors::ENCRYPTED_CONTRIBUTIONS_MISSING):
@@ -684,6 +682,7 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
684
682
request.SetError (nError);
685
683
CDataStream ssResponse (SER_NETWORK, pfrom.GetSendVersion (), request, body);
686
684
connman.PushMessage (&pfrom, CNetMsgMaker (pfrom.GetSendVersion ()).Make (NetMsgType::QDATA, ssResponse));
685
+ return ret;
687
686
};
688
687
689
688
bool request_limit_exceeded (false );
@@ -701,29 +700,25 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
701
700
}
702
701
703
702
if (!GetLLMQParams (request.GetLLMQType ()).has_value ()) {
704
- sendQDATA (CQuorumDataRequest::Errors::QUORUM_TYPE_INVALID, request_limit_exceeded);
705
- return ;
703
+ return sendQDATA (CQuorumDataRequest::Errors::QUORUM_TYPE_INVALID, request_limit_exceeded);
706
704
}
707
705
708
706
const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK (cs_main, return m_chainstate.m_blockman .LookupBlockIndex (request.GetQuorumHash ()));
709
707
if (pQuorumBaseBlockIndex == nullptr ) {
710
- sendQDATA (CQuorumDataRequest::Errors::QUORUM_BLOCK_NOT_FOUND, request_limit_exceeded);
711
- return ;
708
+ return sendQDATA (CQuorumDataRequest::Errors::QUORUM_BLOCK_NOT_FOUND, request_limit_exceeded);
712
709
}
713
710
714
711
const CQuorumCPtr pQuorum = GetQuorum (request.GetLLMQType (), pQuorumBaseBlockIndex);
715
712
if (pQuorum == nullptr ) {
716
- sendQDATA (CQuorumDataRequest::Errors::QUORUM_NOT_FOUND, request_limit_exceeded);
717
- return ;
713
+ return sendQDATA (CQuorumDataRequest::Errors::QUORUM_NOT_FOUND, request_limit_exceeded);
718
714
}
719
715
720
716
CDataStream ssResponseData (SER_NETWORK, pfrom.GetSendVersion ());
721
717
722
718
// Check if request wants QUORUM_VERIFICATION_VECTOR data
723
719
if (request.GetDataMask () & CQuorumDataRequest::QUORUM_VERIFICATION_VECTOR) {
724
720
if (!pQuorum->HasVerificationVector ()) {
725
- sendQDATA (CQuorumDataRequest::Errors::QUORUM_VERIFICATION_VECTOR_MISSING, request_limit_exceeded);
726
- return ;
721
+ return sendQDATA (CQuorumDataRequest::Errors::QUORUM_VERIFICATION_VECTOR_MISSING, request_limit_exceeded);
727
722
}
728
723
729
724
WITH_LOCK (pQuorum->cs , ssResponseData << *pQuorum->quorumVvec );
@@ -734,27 +729,23 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
734
729
735
730
int memberIdx = pQuorum->GetMemberIndex (request.GetProTxHash ());
736
731
if (memberIdx == -1 ) {
737
- sendQDATA (CQuorumDataRequest::Errors::MASTERNODE_IS_NO_MEMBER, request_limit_exceeded);
738
- return ;
732
+ return sendQDATA (CQuorumDataRequest::Errors::MASTERNODE_IS_NO_MEMBER, request_limit_exceeded);
739
733
}
740
734
741
735
std::vector<CBLSIESEncryptedObject<CBLSSecretKey>> vecEncrypted;
742
736
if (!dkgManager.GetEncryptedContributions (request.GetLLMQType (), pQuorumBaseBlockIndex, pQuorum->qc ->validMembers , request.GetProTxHash (), vecEncrypted)) {
743
- sendQDATA (CQuorumDataRequest::Errors::ENCRYPTED_CONTRIBUTIONS_MISSING, request_limit_exceeded);
744
- return ;
737
+ return sendQDATA (CQuorumDataRequest::Errors::ENCRYPTED_CONTRIBUTIONS_MISSING, request_limit_exceeded);
745
738
}
746
739
747
740
ssResponseData << vecEncrypted;
748
741
}
749
742
750
- sendQDATA (CQuorumDataRequest::Errors::NONE, request_limit_exceeded, ssResponseData);
751
- return ;
743
+ return sendQDATA (CQuorumDataRequest::Errors::NONE, request_limit_exceeded, ssResponseData);
752
744
}
753
745
754
746
if (msg_type == NetMsgType::QDATA) {
755
747
if ((!fMasternodeMode && !utils::IsWatchQuorumsEnabled ()) || pfrom.GetVerifiedProRegTxHash ().IsNull ()) {
756
- errorHandler (" Not a verified masternode and -watchquorums is not enabled" );
757
- return ;
748
+ return errorHandler (" Not a verified masternode and -watchquorums is not enabled" );
758
749
}
759
750
760
751
CQuorumDataRequest request;
@@ -765,30 +756,25 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
765
756
const CQuorumDataRequestKey key (pfrom.GetVerifiedProRegTxHash (), true , request.GetQuorumHash (), request.GetLLMQType ());
766
757
auto it = mapQuorumDataRequests.find (key);
767
758
if (it == mapQuorumDataRequests.end ()) {
768
- errorHandler (" Not requested" );
769
- return ;
759
+ return errorHandler (" Not requested" );
770
760
}
771
761
if (it->second .IsProcessed ()) {
772
- errorHandler (" Already received" );
773
- return ;
762
+ return errorHandler (" Already received" );
774
763
}
775
764
if (request != it->second ) {
776
- errorHandler (" Not like requested" );
777
- return ;
765
+ return errorHandler (" Not like requested" );
778
766
}
779
767
it->second .SetProcessed ();
780
768
}
781
769
782
770
if (request.GetError () != CQuorumDataRequest::Errors::NONE) {
783
- errorHandler (strprintf (" Error %d (%s)" , request.GetError (), request.GetErrorString ()), 0 );
784
- return ;
771
+ return errorHandler (strprintf (" Error %d (%s)" , request.GetError (), request.GetErrorString ()), 0 );
785
772
}
786
773
787
774
CQuorumPtr pQuorum;
788
775
{
789
776
if (LOCK (cs_map_quorums); !mapQuorumsCache[request.GetLLMQType ()].get (request.GetQuorumHash (), pQuorum)) {
790
- errorHandler (" Quorum not found" , 0 ); // Don't bump score because we asked for it
791
- return ;
777
+ return errorHandler (" Quorum not found" , 0 ); // Don't bump score because we asked for it
792
778
}
793
779
}
794
780
@@ -801,23 +787,20 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
801
787
if (pQuorum->SetVerificationVector (verificationVector)) {
802
788
StartCachePopulatorThread (pQuorum);
803
789
} else {
804
- errorHandler (" Invalid quorum verification vector" );
805
- return ;
790
+ return errorHandler (" Invalid quorum verification vector" );
806
791
}
807
792
}
808
793
809
794
// Check if request has ENCRYPTED_CONTRIBUTIONS data
810
795
if (request.GetDataMask () & CQuorumDataRequest::ENCRYPTED_CONTRIBUTIONS) {
811
796
812
797
if (WITH_LOCK (pQuorum->cs , return pQuorum->quorumVvec ->size () != size_t (pQuorum->params .threshold ))) {
813
- errorHandler (" No valid quorum verification vector available" , 0 ); // Don't bump score because we asked for it
814
- return ;
798
+ return errorHandler (" No valid quorum verification vector available" , 0 ); // Don't bump score because we asked for it
815
799
}
816
800
817
801
int memberIdx = pQuorum->GetMemberIndex (request.GetProTxHash ());
818
802
if (memberIdx == -1 ) {
819
- errorHandler (" Not a member of the quorum" , 0 ); // Don't bump score because we asked for it
820
- return ;
803
+ return errorHandler (" Not a member of the quorum" , 0 ); // Don't bump score because we asked for it
821
804
}
822
805
823
806
std::vector<CBLSIESEncryptedObject<CBLSSecretKey>> vecEncrypted;
@@ -828,20 +811,19 @@ void CQuorumManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, C
828
811
auto secret = WITH_LOCK (activeMasternodeInfoCs, return *activeMasternodeInfo.blsKeyOperator );
829
812
for (const auto i : irange::range (vecEncrypted.size ())) {
830
813
if (!vecEncrypted[i].Decrypt (memberIdx, secret, vecSecretKeys[i], PROTOCOL_VERSION)) {
831
- errorHandler (" Failed to decrypt" );
832
- return ;
814
+ return errorHandler (" Failed to decrypt" );
833
815
}
834
816
}
835
817
836
818
CBLSSecretKey secretKeyShare = blsWorker.AggregateSecretKeys (vecSecretKeys);
837
819
if (!pQuorum->SetSecretKeyShare (secretKeyShare)) {
838
- errorHandler (" Invalid secret key share received" );
839
- return ;
820
+ return errorHandler (" Invalid secret key share received" );
840
821
}
841
822
}
842
823
pQuorum->WriteContributions (m_evoDb);
843
- return ;
824
+ return {} ;
844
825
}
826
+ return {};
845
827
}
846
828
847
829
void CQuorumManager::StartCachePopulatorThread (const CQuorumCPtr pQuorum) const
0 commit comments