PIVX Core  5.6.99
P2P Digital Currency
quorums_blockprocessor.h
Go to the documentation of this file.
1 // Copyright (c) 2018-2021 The Dash Core developers
2 // Copyright (c) 2021 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_BLOCKPROCESSOR_H
7 #define PIVX_LLMQ_QUORUMS_BLOCKPROCESSOR_H
8 
9 #include "consensus/params.h"
11 #include "primitives/transaction.h"
12 #include "saltedhasher.h"
13 #include "sync.h"
14 #include "uint256.h"
15 #include "unordered_lru_cache.h"
16 
17 #include <map>
18 
19 class CBlock;
20 class CBlockIndex;
21 class CConnman;
22 class CDataStream;
23 class CEvoDB;
24 class CNode;
25 class CValidationState;
26 
27 namespace llmq
28 {
29 
31 {
32 private:
34 
35  // TODO cleanup
37  // <llmqType, quorumHash> --> commitment hash
38  std::map<std::pair<uint8_t, uint256>, uint256> minableCommitmentsByQuorum;
39  // commitment hash --> final commitment
40  std::map<uint256, CFinalCommitment> minableCommitments;
41  // for each llmqtype map quorum_hash --> (bool final_commitment_mined)
42  mutable std::map<Consensus::LLMQType, unordered_lru_cache<uint256, bool, StaticSaltedHasher>> mapHasMinedCommitmentCache GUARDED_BY(minableCommitmentsCs);
43 
44 public:
45  explicit CQuorumBlockProcessor(CEvoDB& _evoDb);
46 
47  void ProcessMessage(CNode* pfrom, CDataStream& vRecv, int& retMisbehavingScore);
48 
49  bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck);
50  bool UndoBlock(const CBlock& block, const CBlockIndex* pindex);
51 
52  void AddAndRelayMinableCommitment(const CFinalCommitment& fqc, uint256* cached_fqc_hash = nullptr);
53  bool HasMinableCommitment(const uint256& hash);
55  bool GetMinableCommitmentByHash(const uint256& commitmentHash, CFinalCommitment& ret);
56  bool GetMinableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment& ret);
57  bool GetMinableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef& ret);
58 
59  bool HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash);
60  bool GetMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash, CFinalCommitment& ret, uint256& retMinedBlockHash);
61 
62  std::vector<const CBlockIndex*> GetMinedCommitmentsUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t maxCount);
63  std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> GetMinedAndActiveCommitmentsUntilBlock(const CBlockIndex* pindex);
64 
65 private:
66  static bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::map<Consensus::LLMQType, CFinalCommitment>& ret, CValidationState& state);
67  bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state, bool fJustCheck);
68  static bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight);
69  bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight);
70  static uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight);
71 };
72 
73 extern std::unique_ptr<CQuorumBlockProcessor> quorumBlockProcessor;
74 
75 } // namespace llmq
76 
77 #endif // PIVX_LLMQ_QUORUMS_BLOCKPROCESSOR_H
Definition: block.h:80
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
Definition: net.h:145
Definition: evodb.h:32
Information about a peer.
Definition: net.h:669
Capture information about block/transaction validation.
Definition: validation.h:24
bool GetMinableCommitmentByHash(const uint256 &commitmentHash, CFinalCommitment &ret)
std::map< Consensus::LLMQType, unordered_lru_cache< uint256, bool, StaticSaltedHasher > > mapHasMinedCommitmentCache GUARDED_BY(minableCommitmentsCs)
bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight)
bool ProcessCommitment(int nHeight, const uint256 &blockHash, const CFinalCommitment &qc, CValidationState &state, bool fJustCheck)
std::map< uint256, CFinalCommitment > minableCommitments
bool HasBetterMinableCommitment(const CFinalCommitment &qc)
bool HasMinableCommitment(const uint256 &hash)
bool UndoBlock(const CBlock &block, const CBlockIndex *pindex)
static uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight)
std::map< std::pair< uint8_t, uint256 >, uint256 > minableCommitmentsByQuorum
bool ProcessBlock(const CBlock &block, const CBlockIndex *pindex, CValidationState &state, bool fJustCheck)
std::map< Consensus::LLMQType, std::vector< const CBlockIndex * > > GetMinedAndActiveCommitmentsUntilBlock(const CBlockIndex *pindex)
std::vector< const CBlockIndex * > GetMinedCommitmentsUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex *pindex, size_t maxCount)
bool GetMinableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment &ret)
bool GetMinedCommitment(Consensus::LLMQType llmqType, const uint256 &quorumHash, CFinalCommitment &ret, uint256 &retMinedBlockHash)
static bool GetCommitmentsFromBlock(const CBlock &block, const CBlockIndex *pindex, std::map< Consensus::LLMQType, CFinalCommitment > &ret, CValidationState &state)
bool HasMinedCommitment(Consensus::LLMQType llmqType, const uint256 &quorumHash)
static bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight)
void AddAndRelayMinableCommitment(const CFinalCommitment &fqc, uint256 *cached_fqc_hash=nullptr)
void ProcessMessage(CNode *pfrom, CDataStream &vRecv, int &retMisbehavingScore)
bool GetMinableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef &ret)
256-bit opaque blob.
Definition: uint256.h:138
LLMQType
Definition: params.h:90
Definition: quorums.cpp:26
std::unique_ptr< CQuorumBlockProcessor > quorumBlockProcessor
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:456