Skip to content

Commit

Permalink
Refactor CQuorumBlockProcessor and CDeterministicMNManager (#2536)
Browse files Browse the repository at this point in the history
* Refactor CDeterministicMNManager::ProcessBlock: pintexPrev -> pindex->pprev and/or adjust logic accordingly

* Refactor CQuorumBlockProcessor::ProcessBlock: pintexPrev -> pindex->pprev and/or adjust logic accordingly

* Drop unused
  • Loading branch information
UdjinM6 authored and codablock committed Dec 10, 2018
1 parent 63b58b1 commit 15414da
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class CDeterministicMNManager
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);
Expand Down
4 changes: 2 additions & 2 deletions src/evo/specialtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 5 additions & 11 deletions src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Consensus::LLMQType, CFinalCommitment> qcs;
if (!GetCommitmentsFromBlock(block, pindexPrev, qcs, state)) {
if (!GetCommitmentsFromBlock(block, pindex->pprev, qcs, state)) {
return false;
}

Expand All @@ -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
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/llmq/quorums_blockprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CQuorumBlockProcessor

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);
Expand Down

0 comments on commit 15414da

Please sign in to comment.