PIVX Core  5.6.99
P2P Digital Currency
quorums_dkgsessionmgr.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 The Dash Core developers
2 // Copyright (c) 2022 The PIVX Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PIVX_LLMQ_QUORUMS_DKGSESSIONMGR_H
7 #define PIVX_LLMQ_QUORUMS_DKGSESSIONMGR_H
8 
9 #include "ctpl_stl.h"
11 #include "validation.h"
12 
13 class UniValue;
14 
15 namespace llmq
16 {
17 
19 {
20  static const int64_t MAX_CONTRIBUTION_CACHE_TIME = 60 * 1000;
21 
22 private:
25 
26  std::map<Consensus::LLMQType, CDKGSessionHandler> dkgSessionHandlers;
27 
33  bool operator<(const ContributionsCacheKey& r) const
34  {
35  if (llmqType != r.llmqType) return llmqType < r.llmqType;
36  if (quorumHash != r.quorumHash) return quorumHash < r.quorumHash;
37  return proTxHash < r.proTxHash;
38  }
39  };
41  int64_t entryTime;
44  };
45  std::map<ContributionsCacheKey, ContributionsCacheEntry> contributionsCache;
46 
47 public:
48  CDKGSessionManager(CDBWrapper& _evoDb, CBLSWorker& _blsWorker);
50 
51  void StartThreads();
52  void StopThreads();
53 
54  void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload);
55 
56  bool ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv);
57  bool AlreadyHave(const CInv& inv) const;
58  bool GetContribution(const uint256& hash, CDKGContribution& ret) const;
59  bool GetComplaint(const uint256& hash, CDKGComplaint& ret) const;
60  bool GetJustification(const uint256& hash, CDKGJustification& ret) const;
61  bool GetPrematureCommitment(const uint256& hash, CDKGPrematureCommitment& ret) const;
62 
63  // Verified contributions are written while in the DKG
64  void WriteVerifiedVvecContribution(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& proTxHash, const BLSVerificationVectorPtr& vvec);
65  void WriteVerifiedSkContribution(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& proTxHash, const CBLSSecretKey& skContribution);
66  bool GetVerifiedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const std::vector<bool>& validMembers, std::vector<uint16_t>& memberIndexesRet, std::vector<BLSVerificationVectorPtr>& vvecsRet, BLSSecretKeyVector& skContributionsRet);
67  bool GetVerifiedContribution(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& proTxHash, BLSVerificationVectorPtr& vvecRet, CBLSSecretKey& skContributionRet);
68 
69 private:
70  void CleanupCache();
71 };
72 
73 extern std::unique_ptr<CDKGSessionManager> quorumDKGSessionManager;
74 
75 }
76 
77 #endif // PIVX_LLMQ_QUORUMS_DKGSESSIONMGR_H
std::shared_ptr< BLSVerificationVector > BLSVerificationVectorPtr
Definition: bls_wrapper.h:415
std::vector< CBLSSecretKey > BLSSecretKeyVector
Definition: bls_wrapper.h:411
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
inv message data
Definition: protocol.h:466
Information about a peer.
Definition: net.h:669
bool AlreadyHave(const CInv &inv) const
bool GetVerifiedContribution(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &proTxHash, BLSVerificationVectorPtr &vvecRet, CBLSSecretKey &skContributionRet)
std::map< ContributionsCacheKey, ContributionsCacheEntry > contributionsCache
std::map< Consensus::LLMQType, CDKGSessionHandler > dkgSessionHandlers
static const int64_t MAX_CONTRIBUTION_CACHE_TIME
bool GetJustification(const uint256 &hash, CDKGJustification &ret) const
bool GetPrematureCommitment(const uint256 &hash, CDKGPrematureCommitment &ret) const
CDKGSessionManager(CDBWrapper &_evoDb, CBLSWorker &_blsWorker)
bool GetContribution(const uint256 &hash, CDKGContribution &ret) const
void WriteVerifiedSkContribution(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &proTxHash, const CBLSSecretKey &skContribution)
void WriteVerifiedVvecContribution(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256 &proTxHash, const BLSVerificationVectorPtr &vvec)
void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload)
bool ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv)
bool GetVerifiedContributions(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const std::vector< bool > &validMembers, std::vector< uint16_t > &memberIndexesRet, std::vector< BLSVerificationVectorPtr > &vvecsRet, BLSSecretKeyVector &skContributionsRet)
bool GetComplaint(const uint256 &hash, CDKGComplaint &ret) const
256-bit opaque blob.
Definition: uint256.h:138
LLMQType
Definition: params.h:90
Definition: quorums.cpp:26
std::unique_ptr< CDKGSessionManager > quorumDKGSessionManager
@ proTxHash
Definition: rpcevo.cpp:50
CBLSSecretKey skContribution
BLSVerificationVectorPtr vvec
int64_t entryTime
bool operator<(const ContributionsCacheKey &r) const