Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

quorums.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2019 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef DASH_QUORUMS_H
6 #define DASH_QUORUMS_H
7 
8 #include <evo/evodb.h>
9 #include <evo/deterministicmns.h>
11 
12 #include <validationinterface.h>
13 #include <consensus/params.h>
14 #include <saltedhasher.h>
15 #include <unordered_lru_cache.h>
16 
17 #include <bls/bls.h>
18 #include <bls/bls_worker.h>
19 
20 namespace llmq
21 {
22 
23 class CDKGSessionManager;
24 
34 class CQuorum
35 {
36  friend class CQuorumManager;
37 public:
42  std::vector<CDeterministicMNCPtr> members;
43 
44  // These are only valid when we either participated in the DKG or fully watched it
47 
48 private:
49  // Recovery of public key shares is very slow, so we start a background thread that pre-populates a cache so that
50  // the public key shares are ready when needed later
52  std::atomic<bool> stopCachePopulatorThread;
53  std::thread cachePopulatorThread;
54 
55 public:
56  CQuorum(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker) : params(_params), blsCache(_blsWorker), stopCachePopulatorThread(false) {}
57  ~CQuorum();
58  void Init(const CFinalCommitment& _qc, const CBlockIndex* _pindexQuorum, const uint256& _minedBlockHash, const std::vector<CDeterministicMNCPtr>& _members);
59 
60  bool IsMember(const uint256& proTxHash) const;
61  bool IsValidMember(const uint256& proTxHash) const;
62  int GetMemberIndex(const uint256& proTxHash) const;
63 
64  CBLSPublicKey GetPubKeyShare(size_t memberIdx) const;
65  CBLSSecretKey GetSkShare() const;
66 
67 private:
70  static void StartCachePopulatorThread(std::shared_ptr<CQuorum> _this);
71 };
72 typedef std::shared_ptr<CQuorum> CQuorumPtr;
73 typedef std::shared_ptr<const CQuorum> CQuorumCPtr;
74 
82 {
83 private:
87 
89  std::map<std::pair<Consensus::LLMQType, uint256>, CQuorumPtr> quorumsCache;
91 
92 public:
93  CQuorumManager(CEvoDB& _evoDb, CBLSWorker& _blsWorker, CDKGSessionManager& _dkgManager);
94 
95  void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload);
96 
97  bool HasQuorum(Consensus::LLMQType llmqType, const uint256& quorumHash);
98 
99  // all these methods will lock cs_main for a short period of time
100  CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, const uint256& quorumHash);
101  std::vector<CQuorumCPtr> ScanQuorums(Consensus::LLMQType llmqType, size_t maxCount);
102 
103  // this one is cs_main-free
104  std::vector<CQuorumCPtr> ScanQuorums(Consensus::LLMQType llmqType, const CBlockIndex* pindexStart, size_t maxCount);
105 
106 private:
107  // all private methods here are cs_main-free
108  void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexNew);
109 
110  bool BuildQuorumFromCommitment(const CFinalCommitment& qc, const CBlockIndex* pindexQuorum, const uint256& minedBlockHash, std::shared_ptr<CQuorum>& quorum) const;
111  bool BuildQuorumContributions(const CFinalCommitment& fqc, std::shared_ptr<CQuorum>& quorum) const;
112 
113  CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, const CBlockIndex* pindex);
114 };
115 
117 
118 } // namespace llmq
119 
120 #endif //DASH_QUORUMS_H
CBLSWorkerCache blsCache
Definition: quorums.h:51
unordered_lru_cache< std::pair< Consensus::LLMQType, uint256 >, std::vector< CQuorumCPtr >, StaticSaltedHasher, 32 > scanQuorumsCache
Definition: quorums.h:90
UniValue quorum(const JSONRPCRequest &request)
Definition: rpcquorums.cpp:492
CCriticalSection quorumsCacheCs
Definition: quorums.h:88
Definition: evodb.h:32
uint256 minedBlockHash
Definition: quorums.h:41
std::atomic< bool > stopCachePopulatorThread
Definition: quorums.h:52
std::map< std::pair< Consensus::LLMQType, uint256 >, CQuorumPtr > quorumsCache
Definition: quorums.h:89
std::unique_ptr< CEvoDB > evoDb
Definition: evodb.cpp:7
An object of this class represents a quorum which was mined on-chain (through a quorum commitment) It...
Definition: quorums.h:34
std::vector< CQuorumCPtr > ScanQuorums(Consensus::LLMQType llmqType, size_t maxCount)
Definition: quorums.cpp:279
CEvoDB & evoDb
Definition: quorums.h:84
bool ReadContributions(CEvoDB &evoDb)
Definition: quorums.cpp:118
void Init(const CFinalCommitment &_qc, const CBlockIndex *_pindexQuorum, const uint256 &_minedBlockHash, const std::vector< CDeterministicMNCPtr > &_members)
Definition: quorums.cpp:54
bool BuildQuorumContributions(const CFinalCommitment &fqc, std::shared_ptr< CQuorum > &quorum) const
Definition: quorums.cpp:238
static void StartCachePopulatorThread(std::shared_ptr< CQuorum > _this)
Definition: quorums.cpp:136
CQuorumManager * quorumManager
Definition: quorums.cpp:30
std::shared_ptr< CQuorum > CQuorumPtr
Definition: quorums.h:72
void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexNew)
Definition: quorums.cpp:176
CBLSPublicKey GetPubKeyShare(size_t memberIdx) const
Definition: quorums.cpp:82
const Consensus::LLMQParams & params
Definition: quorums.h:38
LLMQType
Definition: params.h:48
false
Definition: bls_dkg.cpp:168
std::shared_ptr< BLSVerificationVector > BLSVerificationVectorPtr
Definition: bls.h:471
int GetMemberIndex(const uint256 &proTxHash) const
Definition: quorums.cpp:96
The quorum manager maintains quorums which were mined on chain.
Definition: quorums.h:81
void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload)
Definition: quorums.cpp:165
bool IsValidMember(const uint256 &proTxHash) const
Definition: quorums.cpp:72
const CBlockIndex * pindexQuorum
Definition: quorums.h:40
BLSVerificationVectorPtr quorumVvec
Definition: quorums.h:45
bool IsMember(const uint256 &proTxHash) const
Definition: quorums.cpp:62
void WriteContributions(CEvoDB &evoDb)
Definition: quorums.cpp:106
CFinalCommitment qc
Definition: quorums.h:39
256-bit opaque blob.
Definition: uint256.h:123
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
bool HasQuorum(Consensus::LLMQType llmqType, const uint256 &quorumHash)
Definition: quorums.cpp:274
std::shared_ptr< const CQuorum > CQuorumCPtr
Definition: quorums.h:73
CQuorum(const Consensus::LLMQParams &_params, CBLSWorker &_blsWorker)
Definition: quorums.h:56
CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, const uint256 &quorumHash)
Definition: quorums.cpp:337
CBLSWorker & blsWorker
Definition: quorums.h:85
CDKGSessionManager & dkgManager
Definition: quorums.h:86
CBLSSecretKey skShare
Definition: quorums.h:46
std::vector< CDeterministicMNCPtr > members
Definition: quorums.h:42
bool BuildQuorumFromCommitment(const CFinalCommitment &qc, const CBlockIndex *pindexQuorum, const uint256 &minedBlockHash, std::shared_ptr< CQuorum > &quorum) const
Definition: quorums.cpp:207
std::thread cachePopulatorThread
Definition: quorums.h:53
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
CQuorumManager(CEvoDB &_evoDb, CBLSWorker &_blsWorker, CDKGSessionManager &_dkgManager)
Definition: quorums.cpp:158
CBLSSecretKey GetSkShare() const
Definition: quorums.cpp:91
Released under the MIT license