From 15414dac295812124612b27876a5ed703fc13234 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 10 Dec 2018 08:05:29 +0300 Subject: [PATCH] Refactor CQuorumBlockProcessor and CDeterministicMNManager (#2536) * Refactor CDeterministicMNManager::ProcessBlock: pintexPrev -> pindex->pprev and/or adjust logic accordingly * Refactor CQuorumBlockProcessor::ProcessBlock: pintexPrev -> pindex->pprev and/or adjust logic accordingly * Drop unused --- src/evo/deterministicmns.cpp | 8 ++++---- src/evo/deterministicmns.h | 2 +- src/evo/specialtx.cpp | 4 ++-- src/llmq/quorums_blockprocessor.cpp | 16 +++++----------- src/llmq/quorums_blockprocessor.h | 2 +- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 162d3029c5..c92ee43697 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -428,14 +428,14 @@ CDeterministicMNManager::CDeterministicMNManager(CEvoDB& _evoDb) : { } -bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& _state) +bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& _state) { LOCK(cs); - int nHeight = pindexPrev->nHeight + 1; + int nHeight = pindex->nHeight; CDeterministicMNList newList; - if (!BuildNewListFromBlock(block, pindexPrev, _state, newList, true)) { + if (!BuildNewListFromBlock(block, pindex->pprev, _state, newList, true)) { return false; } @@ -445,7 +445,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, const CBlockInde newList.SetBlockHash(block.GetHash()); - CDeterministicMNList oldList = GetListForBlock(pindexPrev->GetBlockHash()); + CDeterministicMNList oldList = GetListForBlock(pindex->pprev->GetBlockHash()); CDeterministicMNListDiff diff = oldList.BuildDiff(newList); evoDb.Write(std::make_pair(DB_LIST_DIFF, diff.blockHash), diff); diff --git a/src/evo/deterministicmns.h b/src/evo/deterministicmns.h index c4734e6c15..aeed32648c 100644 --- a/src/evo/deterministicmns.h +++ b/src/evo/deterministicmns.h @@ -453,7 +453,7 @@ private: public: CDeterministicMNManager(CEvoDB& _evoDb); - bool ProcessBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& state); + bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state); bool UndoBlock(const CBlock& block, const CBlockIndex* pindex); void UpdatedBlockTip(const CBlockIndex* pindex); diff --git a/src/evo/specialtx.cpp b/src/evo/specialtx.cpp index 7bd29ed51f..9e916bb456 100644 --- a/src/evo/specialtx.cpp +++ b/src/evo/specialtx.cpp @@ -98,11 +98,11 @@ bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CV } } - if (!llmq::quorumBlockProcessor->ProcessBlock(block, pindex->pprev, state)) { + if (!llmq::quorumBlockProcessor->ProcessBlock(block, pindex, state)) { return false; } - if (!deterministicMNManager->ProcessBlock(block, pindex->pprev, state)) { + if (!deterministicMNManager->ProcessBlock(block, pindex, state)) { return false; } diff --git a/src/llmq/quorums_blockprocessor.cpp b/src/llmq/quorums_blockprocessor.cpp index 5a3d1feb46..92442d4db6 100644 --- a/src/llmq/quorums_blockprocessor.cpp +++ b/src/llmq/quorums_blockprocessor.cpp @@ -105,19 +105,17 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC } } -bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& state) +bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state) { AssertLockHeld(cs_main); - bool fDIP0003Active = VersionBitsState(pindexPrev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE; + bool fDIP0003Active = VersionBitsState(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE; if (!fDIP0003Active) { return true; } - int nHeight = pindexPrev->nHeight + 1; - std::map qcs; - if (!GetCommitmentsFromBlock(block, pindexPrev, qcs, state)) { + if (!GetCommitmentsFromBlock(block, pindex->pprev, qcs, state)) { return false; } @@ -127,11 +125,9 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* for (const auto& p : Params().GetConsensus().llmqs) { auto type = p.first; - uint256 quorumHash = GetQuorumBlockHash(type, pindexPrev); - // does the currently processed block contain a (possibly null) commitment for the current session? bool hasCommitmentInNewBlock = qcs.count(type) != 0; - bool isCommitmentRequired = IsCommitmentRequired(type, pindexPrev); + bool isCommitmentRequired = IsCommitmentRequired(type, pindex->pprev); if (hasCommitmentInNewBlock && !isCommitmentRequired) { // If we're either not in the mining phase or a non-null commitment was mined already, reject the block @@ -147,7 +143,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* for (auto& p : qcs) { auto& qc = p.second; - if (!ProcessCommitment(pindexPrev, qc, state)) { + if (!ProcessCommitment(pindex->pprev, qc, state)) { return false; } } @@ -384,8 +380,6 @@ bool CQuorumBlockProcessor::GetMinableCommitment(Consensus::LLMQType llmqType, c { AssertLockHeld(cs_main); - int nHeight = pindexPrev->nHeight + 1; - if (!IsCommitmentRequired(llmqType, pindexPrev)) { // no commitment required return false; diff --git a/src/llmq/quorums_blockprocessor.h b/src/llmq/quorums_blockprocessor.h index ab1f34c968..4bfc018ffd 100644 --- a/src/llmq/quorums_blockprocessor.h +++ b/src/llmq/quorums_blockprocessor.h @@ -34,7 +34,7 @@ public: void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv, CConnman& connman); - bool ProcessBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& state); + bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state); bool UndoBlock(const CBlock& block, const CBlockIndex* pindex); void AddMinableCommitment(const CFinalCommitment& fqc);