mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Merge #5773: refactor: resolve a lot of sonarlint and clang-tidy warnings in llmq code
bf57b15496
refactor: remove unneeded variable (pasta)358ae3283d
refactor: add some const (pasta)4804aad2c9
refactor: a few more structured bindings (pasta)ee6dc2d6ab
refactor: remove some nested code blocks (pasta)c2ac444abf
refactor: create a immediately executed llamda; use some structed bindings inside of ti (pasta) Pull request description: ## Issue being fixed or feature implemented Resolve a lot of sonarlint and clang-tidy warnings. Please see individual commits ## What was done? ## How Has This Been Tested? `make check` ## Breaking Changes Should be none ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ Top commit has no ACKs. Tree-SHA512: 7481aaf5e5fae42fa896a9b770f41d9d3e1fa395569d2f9fffc952ec556737898283c5a4929063975852dd58fa857cd8374e78dd518983550870fd2683ad5f79
This commit is contained in:
commit
4301ab9dfb
@ -186,8 +186,7 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, gsl::not_null<cons
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& p : qcs) {
|
||||
const auto& qc = p.second;
|
||||
for (const auto& [_, qc] : qcs) {
|
||||
if (!ProcessCommitment(pindex->nHeight, blockHash, qc, state, fJustCheck, fBLSChecks)) {
|
||||
LogPrintf("[ProcessBlock] failed h[%d] llmqType[%d] version[%d] quorumIndex[%d] quorumHash[%s]\n", pindex->nHeight, ToUnderlying(qc.llmqType), qc.nVersion, qc.quorumIndex, qc.quorumHash.ToString());
|
||||
return false;
|
||||
@ -317,8 +316,8 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, gsl::not_null<const C
|
||||
return false;
|
||||
}
|
||||
|
||||
for (auto& p : qcs) {
|
||||
auto& qc = p.second;
|
||||
for (auto& [_, qc2] : qcs) {
|
||||
auto& qc = qc2; // cannot capture structured binding into lambda
|
||||
if (qc.IsNull()) {
|
||||
continue;
|
||||
}
|
||||
@ -334,10 +333,7 @@ bool CQuorumBlockProcessor::UndoBlock(const CBlock& block, gsl::not_null<const C
|
||||
m_evoDb.Erase(BuildInversedHeightKey(qc.llmqType, pindex->nHeight));
|
||||
}
|
||||
|
||||
{
|
||||
LOCK(minableCommitmentsCs);
|
||||
mapHasMinedCommitmentCache[qc.llmqType].erase(qc.quorumHash);
|
||||
}
|
||||
WITH_LOCK(minableCommitmentsCs, mapHasMinedCommitmentCache[qc.llmqType].erase(qc.quorumHash));
|
||||
|
||||
// if a reorg happened, we should allow to mine this commitment later
|
||||
AddMineableCommitment(qc);
|
||||
@ -452,11 +448,8 @@ uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& l
|
||||
bool CQuorumBlockProcessor::HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash) const
|
||||
{
|
||||
bool fExists;
|
||||
{
|
||||
LOCK(minableCommitmentsCs);
|
||||
if (mapHasMinedCommitmentCache[llmqType].get(quorumHash, fExists)) {
|
||||
return fExists;
|
||||
}
|
||||
if (LOCK(minableCommitmentsCs); mapHasMinedCommitmentCache[llmqType].get(quorumHash, fExists)) {
|
||||
return fExists;
|
||||
}
|
||||
|
||||
fExists = m_evoDb.Exists(std::make_pair(DB_MINED_COMMITMENT, std::make_pair(llmqType, quorumHash)));
|
||||
@ -646,28 +639,29 @@ bool CQuorumBlockProcessor::HasMineableCommitment(const uint256& hash) const
|
||||
|
||||
void CQuorumBlockProcessor::AddMineableCommitment(const CFinalCommitment& fqc)
|
||||
{
|
||||
bool relay = false;
|
||||
uint256 commitmentHash = ::SerializeHash(fqc);
|
||||
const uint256 commitmentHash = ::SerializeHash(fqc);
|
||||
|
||||
{
|
||||
const bool relay = [&]() {
|
||||
LOCK(minableCommitmentsCs);
|
||||
|
||||
auto k = std::make_pair(fqc.llmqType, fqc.quorumHash);
|
||||
auto ins = minableCommitmentsByQuorum.try_emplace(k, commitmentHash);
|
||||
if (ins.second) {
|
||||
auto [itInserted, successfullyInserted] = minableCommitmentsByQuorum.try_emplace(k, commitmentHash);
|
||||
if (successfullyInserted) {
|
||||
minableCommitments.try_emplace(commitmentHash, fqc);
|
||||
relay = true;
|
||||
return true;
|
||||
} else {
|
||||
const auto& oldFqc = minableCommitments.at(ins.first->second);
|
||||
auto& insertedQuorumHash = itInserted->second;
|
||||
const auto& oldFqc = minableCommitments.at(insertedQuorumHash);
|
||||
if (fqc.CountSigners() > oldFqc.CountSigners()) {
|
||||
// new commitment has more signers, so override the known one
|
||||
ins.first->second = commitmentHash;
|
||||
minableCommitments.erase(ins.first->second);
|
||||
insertedQuorumHash = commitmentHash;
|
||||
minableCommitments.erase(insertedQuorumHash);
|
||||
minableCommitments.try_emplace(commitmentHash, fqc);
|
||||
relay = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}();
|
||||
|
||||
// We only relay the new commitment if it's new or better then the old one
|
||||
if (relay) {
|
||||
|
@ -135,7 +135,7 @@ PeerMsgRet CChainLocksHandler::ProcessNewChainLock(const NodeId from, const llmq
|
||||
return {};
|
||||
}
|
||||
|
||||
CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(clsig.getBlockHash()));
|
||||
const CBlockIndex* pindex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(clsig.getBlockHash()));
|
||||
|
||||
{
|
||||
LOCK(cs);
|
||||
@ -428,7 +428,7 @@ CChainLocksHandler::BlockTxs::mapped_type CChainLocksHandler::GetBlockTxs(const
|
||||
}
|
||||
|
||||
ret = std::make_shared<std::unordered_set<uint256, StaticSaltedHasher>>();
|
||||
for (auto& tx : block.vtx) {
|
||||
for (const auto& tx : block.vtx) {
|
||||
if (tx->IsCoinBase() || tx->vin.empty()) {
|
||||
continue;
|
||||
}
|
||||
@ -495,9 +495,8 @@ void CChainLocksHandler::EnforceBestChainLock()
|
||||
LogPrint(BCLog::CHAINLOCKS, "CChainLocksHandler::%s -- enforcing block %s via CLSIG (%s)\n", __func__, pindex->GetBlockHash().ToString(), clsig->ToString());
|
||||
m_chainstate.EnforceBlock(dummy_state, pindex);
|
||||
|
||||
bool activateNeeded = WITH_LOCK(::cs_main, return m_chainstate.m_chain.Tip()->GetAncestor(currentBestChainLockBlockIndex->nHeight)) != currentBestChainLockBlockIndex;
|
||||
|
||||
if (activateNeeded) {
|
||||
if (/*activateNeeded =*/ WITH_LOCK(::cs_main, return m_chainstate.m_chain.Tip()->GetAncestor(currentBestChainLockBlockIndex->nHeight)) != currentBestChainLockBlockIndex) {
|
||||
if (!m_chainstate.ActivateBestChain(dummy_state)) {
|
||||
LogPrintf("CChainLocksHandler::%s -- ActivateBestChain failed: %s\n", __func__, dummy_state.ToString());
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user