Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
quorums_blockprocessor.cpp
Go to the documentation of this file.
30 void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman)
44 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- null commitment from peer=%d\n", __func__, pfrom->GetId());
51 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- invalid commitment type %d from peer=%d\n", __func__,
59 // Verify that quorumHash is part of the active chain and that it's the first block in the DKG interval
64 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- unknown block %s in commitment, peer=%d\n", __func__,
66 // can't really punish the node here, as we might simply be the one that is on the wrong chain or not
72 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- block %s not in active chain, peer=%d\n", __func__,
79 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- block %s is not the first block in the DKG interval, peer=%d\n", __func__,
106 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- commitment for quorum %s:%d is not valid, peer=%d\n", __func__,
112 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- received commitment for quorum %s:%d, validMembers=%d, signers=%d, peer=%d\n", __func__,
113 qc.quorumHash.ToString(), qc.llmqType, qc.CountValidMembers(), qc.CountSigners(), pfrom->GetId());
119 bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state)
134 // The following checks make sure that there is always a (possibly null) commitment while in the mining phase
135 // until the first non-null commitment has been mined. After the non-null commitment, no other commitments are
145 // does the currently processed block contain a (possibly null) commitment for the current session?
150 // If we're either not in the mining phase or a non-null commitment was mined already, reject the block
155 // If no non-null commitment was mined for the mining phase yet and the new block does not include
177 static std::tuple<std::string, Consensus::LLMQType, uint32_t> BuildInversedHeightKey(Consensus::LLMQType llmqType, int nMinedHeight)
180 return std::make_tuple(DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT, llmqType, htobe32(std::numeric_limits<uint32_t>::max() - nMinedHeight));
183 bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state)
226 evoDb.Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(params.type, quorumHash)), std::make_pair(qc, blockHash));
234 LogPrint(BCLog::LLMQ, "CQuorumBlockProcessor::%s -- processed commitment from block. type=%d, quorumHash=%s, signers=%s, validMembers=%d, quorumPublicKey=%s\n", __func__,
235 qc.llmqType, quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString());
277 if (evoDb.GetRawDB().Read(DB_BEST_BLOCK_UPGRADE, bestBlock) && bestBlock == chainActive.Tip()->GetBlockHash()) {
288 throw std::runtime_error(std::string(__func__) + ": Quorum Commitments DB upgrade failed, you need to re-download the blockchain");
304 evoDb.GetRawDB().Write(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)), std::make_pair(qc, pindex->GetBlockHash()));
305 evoDb.GetRawDB().Write(BuildInversedHeightKey((Consensus::LLMQType)qc.llmqType, pindex->nHeight), quorumIndex->nHeight);
317 bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::map<Consensus::LLMQType, CFinalCommitment>& ret, CValidationState& state)
364 // perform extra check for quorumHash.IsNull as the quorum hash is unknown for the first block of a session
374 // WARNING: This method returns uint256() on the first block of the DKG interval (because the block hash is not known yet)
389 bool CQuorumBlockProcessor::HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash)
408 bool CQuorumBlockProcessor::GetMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash, CFinalCommitment& retQc, uint256& retMinedBlockHash)
421 std::vector<const CBlockIndex*> CQuorumBlockProcessor::GetMinedCommitmentsUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex* pindex, size_t maxCount)
441 if (std::get<0>(curKey) != DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT || std::get<1>(curKey) != llmqType) {
465 std::map<Consensus::LLMQType, std::vector<const CBlockIndex*>> CQuorumBlockProcessor::GetMinedAndActiveCommitmentsUntilBlock(const CBlockIndex* pindex)
472 auto commitments = GetMinedCommitmentsUntilBlock(p.second.type, pindex, p.second.signingActiveQuorumCount);
519 bool CQuorumBlockProcessor::GetMinableCommitmentByHash(const uint256& commitmentHash, llmq::CFinalCommitment& ret)
531 // Will return true and a null commitment if no minable commitment is known and none was mined yet
532 bool CQuorumBlockProcessor::GetMinableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment& ret)
561 bool CQuorumBlockProcessor::GetMinableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef& ret)
bool GetTxPayload(const std::vector< unsigned char > &payload, T &obj)
Definition: specialtx.h:21
bool GetBlockHash(uint256 &hashRet, int nBlockHeight)
Return true if hash can be found in chainActive at nBlockHeight height.
Definition: validation.cpp:1894
static const int DMN_PROTO_VERSION
introduction of DIP3/deterministic masternodes
Definition: version.h:48
void AddMinableCommitment(const CFinalCommitment &fqc)
Definition: quorums_blockprocessor.cpp:487
Definition: quorums_commitment.h:24
CCriticalSection minableCommitmentsCs
Definition: quorums_blockprocessor.h:31
bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight)
Definition: quorums_blockprocessor.cpp:360
Definition: block.h:72
CQuorumBlockProcessor * quorumBlockProcessor
Definition: quorums_blockprocessor.cpp:23
bool DoS(int level, bool ret=false, unsigned int chRejectCodeIn=0, const std::string &strRejectReasonIn="", bool corruptionIn=false, const std::string &strDebugMessageIn="")
Definition: validation.h:36
bool GetMinableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef &ret)
Definition: quorums_blockprocessor.cpp:561
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
Definition: deterministicmns.h:26
bool ProcessBlock(const CBlock &block, const CBlockIndex *pindex, CValidationState &state)
Definition: quorums_blockprocessor.cpp:119
static const std::string DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT
Definition: quorums_blockprocessor.cpp:26
bool HasMinedCommitment(Consensus::LLMQType llmqType, const uint256 &quorumHash)
Definition: quorums_blockprocessor.cpp:389
Definition: transaction.h:22
static const std::string DB_MINED_COMMITMENT
Definition: quorums_blockprocessor.cpp:25
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Compute the 256-bit hash of an object's serialization.
Definition: hash.h:254
Definition: util.h:137
void Misbehaving(NodeId pnode, int howmuch, const std::string &message)
Increase a node's misbehavior score.
Definition: net_processing.cpp:1024
std::map< Consensus::LLMQType, std::vector< const CBlockIndex * > > GetMinedAndActiveCommitmentsUntilBlock(const CBlockIndex *pindex)
Definition: quorums_blockprocessor.cpp:465
CFinalCommitment commitment
Definition: quorums_commitment.h:117
void ProcessMessage(CNode *pfrom, const std::string &strCommand, CDataStream &vRecv, CConnman &connman)
Definition: quorums_blockprocessor.cpp:30
Definition: protocol.h:416
CBLSPublicKey quorumPublicKey
Definition: quorums_commitment.h:36
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip...
Definition: chain.h:476
bool GetMinableCommitmentByHash(const uint256 &commitmentHash, CFinalCommitment &ret)
Definition: quorums_blockprocessor.cpp:519
bool HasMinableCommitment(const uint256 &hash)
Definition: quorums_blockprocessor.cpp:481
int DIP0003EnforcementHeight
Block height at which DIP0003 becomes enforced.
Definition: params.h:160
int CountValidMembers() const
Definition: quorums_commitment.h:50
bool GetMinedCommitment(Consensus::LLMQType llmqType, const uint256 &quorumHash, CFinalCommitment &ret, uint256 &retMinedBlockHash)
Definition: quorums_blockprocessor.cpp:408
bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight)
Definition: quorums_blockprocessor.cpp:350
bool Write(const K &key, const V &value, bool fSync=false)
Definition: dbwrapper.h:298
static const std::string DB_BEST_BLOCK_UPGRADE
Definition: quorums_blockprocessor.cpp:28
bool GetCommitmentsFromBlock(const CBlock &block, const CBlockIndex *pindex, std::map< Consensus::LLMQType, CFinalCommitment > &ret, CValidationState &state)
Definition: quorums_blockprocessor.cpp:317
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:947
bool UndoBlock(const CBlock &block, const CBlockIndex *pindex)
Definition: quorums_blockprocessor.cpp:240
std::map< std::pair< Consensus::LLMQType, uint256 >, uint256 > minableCommitmentsByQuorum
Definition: quorums_blockprocessor.h:32
std::unordered_map< std::pair< Consensus::LLMQType, uint256 >, bool, StaticSaltedHasher > hasMinedCommitmentCache
Definition: quorums_blockprocessor.h:35
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:453
bool GetMinableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment &ret)
Definition: quorums_blockprocessor.cpp:532
bool Verify(const std::vector< CDeterministicMNCPtr > &members, bool checkSigs) const
Definition: quorums_commitment.cpp:28
static std::tuple< std::string, Consensus::LLMQType, uint32_t > BuildInversedHeightKey(Consensus::LLMQType llmqType, int nMinedHeight)
Definition: quorums_blockprocessor.cpp:177
void EraseObjectRequest(CNodeState *nodestate, const CInv &inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: net_processing.cpp:676
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:54
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
Definition: validation.cpp:1043
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: chain.cpp:110
std::unique_ptr< CDBTransactionIterator< CDBTransaction > > NewIteratorUniquePtr()
Definition: dbwrapper.h:722
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:217
AssertLockHeld(g_cs_orphans)
std::vector< const CBlockIndex * > GetMinedCommitmentsUntilBlock(Consensus::LLMQType llmqType, const CBlockIndex *pindex, size_t maxCount)
Definition: quorums_blockprocessor.cpp:421
static std::vector< CDeterministicMNCPtr > GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum)
Definition: quorums_utils.cpp:18
std::map< uint256, CFinalCommitment > minableCommitments
Definition: quorums_blockprocessor.h:33
uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight)
Definition: quorums_blockprocessor.cpp:375
bool ProcessCommitment(int nHeight, const uint256 &blockHash, const CFinalCommitment &qc, CValidationState &state)
Definition: quorums_blockprocessor.cpp:183