mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
Add in-memory cache to CQuorumBlockProcessor::HasMinedCommitment
This commit is contained in:
parent
f305cf77b6
commit
677c0040cd
@ -199,6 +199,11 @@ bool CQuorumBlockProcessor::ProcessCommitment(const CBlockIndex* pindex, const C
|
|||||||
evoDb.Write(std::make_pair(DB_FIRST_MINED_COMMITMENT, (uint8_t)params.type), quorumHash);
|
evoDb.Write(std::make_pair(DB_FIRST_MINED_COMMITMENT, (uint8_t)params.type), quorumHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
LOCK(minableCommitmentsCs);
|
||||||
|
hasMinedCommitmentCache.erase(std::make_pair(params.type, quorumHash));
|
||||||
|
}
|
||||||
|
|
||||||
LogPrintf("CQuorumBlockProcessor::%s -- processed commitment from block. type=%d, quorumHash=%s, signers=%s, validMembers=%d, quorumPublicKey=%s\n", __func__,
|
LogPrintf("CQuorumBlockProcessor::%s -- processed commitment from block. type=%d, quorumHash=%s, signers=%s, validMembers=%d, quorumPublicKey=%s\n", __func__,
|
||||||
qc.llmqType, quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString());
|
qc.llmqType, quorumHash.ToString(), qc.CountSigners(), qc.CountValidMembers(), qc.quorumPublicKey.ToString());
|
||||||
|
|
||||||
@ -222,6 +227,10 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, const CBlockIndex* pi
|
|||||||
}
|
}
|
||||||
|
|
||||||
evoDb.Erase(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)));
|
evoDb.Erase(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(qc.llmqType, qc.quorumHash)));
|
||||||
|
{
|
||||||
|
LOCK(minableCommitmentsCs);
|
||||||
|
hasMinedCommitmentCache.erase(std::make_pair((Consensus::LLMQType)qc.llmqType, qc.quorumHash));
|
||||||
|
}
|
||||||
|
|
||||||
// if a reorg happened, we should allow to mine this commitment later
|
// if a reorg happened, we should allow to mine this commitment later
|
||||||
AddMinableCommitment(qc);
|
AddMinableCommitment(qc);
|
||||||
@ -309,8 +318,21 @@ uint256 CQuorumBlockProcessor::GetQuorumBlockHash(Consensus::LLMQType llmqType,
|
|||||||
|
|
||||||
bool CQuorumBlockProcessor::HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash)
|
bool CQuorumBlockProcessor::HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash)
|
||||||
{
|
{
|
||||||
|
auto cacheKey = std::make_pair(llmqType, quorumHash);
|
||||||
|
{
|
||||||
|
LOCK(minableCommitmentsCs);
|
||||||
|
auto cacheIt = hasMinedCommitmentCache.find(cacheKey);
|
||||||
|
if (cacheIt != hasMinedCommitmentCache.end()) {
|
||||||
|
return cacheIt->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto key = std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)llmqType, quorumHash));
|
auto key = std::make_pair(DB_MINED_COMMITMENT, std::make_pair((uint8_t)llmqType, quorumHash));
|
||||||
return evoDb.Exists(key);
|
bool ret = evoDb.Exists(key);
|
||||||
|
|
||||||
|
LOCK(minableCommitmentsCs);
|
||||||
|
hasMinedCommitmentCache.emplace(cacheKey, ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CQuorumBlockProcessor::GetMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash, CFinalCommitment& ret)
|
bool CQuorumBlockProcessor::GetMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash, CFinalCommitment& ret)
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
#define DASH_QUORUMS_BLOCKPROCESSOR_H
|
#define DASH_QUORUMS_BLOCKPROCESSOR_H
|
||||||
|
|
||||||
#include "llmq/quorums_commitment.h"
|
#include "llmq/quorums_commitment.h"
|
||||||
|
#include "llmq/quorums_utils.h"
|
||||||
|
|
||||||
#include "consensus/params.h"
|
#include "consensus/params.h"
|
||||||
#include "primitives/transaction.h"
|
#include "primitives/transaction.h"
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
class CNode;
|
class CNode;
|
||||||
class CConnman;
|
class CConnman;
|
||||||
@ -29,6 +31,8 @@ private:
|
|||||||
std::map<std::pair<Consensus::LLMQType, uint256>, uint256> minableCommitmentsByQuorum;
|
std::map<std::pair<Consensus::LLMQType, uint256>, uint256> minableCommitmentsByQuorum;
|
||||||
std::map<uint256, CFinalCommitment> minableCommitments;
|
std::map<uint256, CFinalCommitment> minableCommitments;
|
||||||
|
|
||||||
|
std::unordered_map<std::pair<Consensus::LLMQType, uint256>, bool> hasMinedCommitmentCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CQuorumBlockProcessor(CEvoDB& _evoDb) : evoDb(_evoDb) {}
|
CQuorumBlockProcessor(CEvoDB& _evoDb) : evoDb(_evoDb) {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user