Skip to content

Commit

Permalink
llmq: Avoid writing commitments to evodb and altering caches when all…
Browse files Browse the repository at this point in the history
… we want is to check block candidate validity (#3980)

* llmq: Avoid writing commitments to evodb and altering caches when all we want is to check block candidate validity

* tests: call `getblocktemplate` to trigger `CreateNewBlock` before quorum commitment is mined
  • Loading branch information
UdjinM6 authored Feb 4, 2021
1 parent bbf8eac commit 4c1a04a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/evo/specialtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool ProcessSpecialTxsInBlock(const CBlock& block, const CBlockIndex* pindex, CV
int64_t nTime2 = GetTimeMicros(); nTimeLoop += nTime2 - nTime1;
LogPrint(BCLog::BENCHMARK, " - Loop: %.2fms [%.2fs]\n", 0.001 * (nTime2 - nTime1), nTimeLoop * 0.000001);

if (!llmq::quorumBlockProcessor->ProcessBlock(block, pindex, state)) {
if (!llmq::quorumBlockProcessor->ProcessBlock(block, pindex, state, fJustCheck)) {
// pass the state returned by the function above
return false;
}
Expand Down
10 changes: 7 additions & 3 deletions src/llmq/quorums_blockprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void CQuorumBlockProcessor::ProcessMessage(CNode* pfrom, const std::string& strC
}
}

bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state)
bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck)
{
AssertLockHeld(cs_main);

Expand Down Expand Up @@ -165,7 +165,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex*

for (auto& p : qcs) {
auto& qc = p.second;
if (!ProcessCommitment(pindex->nHeight, blockHash, qc, state)) {
if (!ProcessCommitment(pindex->nHeight, blockHash, qc, state, fJustCheck)) {
return false;
}
}
Expand All @@ -183,7 +183,7 @@ static std::tuple<std::string, Consensus::LLMQType, uint32_t> BuildInversedHeigh
return std::make_tuple(DB_MINED_COMMITMENT_BY_INVERSED_HEIGHT, llmqType, htobe32(std::numeric_limits<uint32_t>::max() - nMinedHeight));
}

bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state)
bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state, bool fJustCheck)
{
auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)qc.llmqType);

Expand Down Expand Up @@ -225,6 +225,10 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH
return state.DoS(100, false, REJECT_INVALID, "bad-qc-invalid");
}

if (fJustCheck) {
return true;
}

// Store commitment in DB
auto cacheKey = std::make_pair(params.type, quorumHash);
evoDb.Write(std::make_pair(DB_MINED_COMMITMENT, cacheKey), std::make_pair(qc, blockHash));
Expand Down
4 changes: 2 additions & 2 deletions src/llmq/quorums_blockprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CQuorumBlockProcessor

void ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStream& vRecv);

bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state);
bool ProcessBlock(const CBlock& block, const CBlockIndex* pindex, CValidationState& state, bool fJustCheck);
bool UndoBlock(const CBlock& block, const CBlockIndex* pindex);

void AddMinableCommitment(const CFinalCommitment& fqc);
Expand All @@ -59,7 +59,7 @@ class CQuorumBlockProcessor

private:
static bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::map<Consensus::LLMQType, CFinalCommitment>& ret, CValidationState& state);
bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state);
bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state, bool fJustCheck);
static bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight);
bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight);
static uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight);
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ def mine_quorum(self, expected_connections=None, expected_members=None, expected

self.log.info("Mining final commitment")
self.bump_mocktime(1, nodes=nodes)
self.nodes[0].getblocktemplate() # this calls CreateNewBlock
self.nodes[0].generate(1)
sync_blocks(nodes)

Expand Down

0 comments on commit 4c1a04a

Please sign in to comment.