forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: resolve a lot of sonarlint and clang-tidy warnings in llmq code #5773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
PastaPastaPasta
merged 5 commits into
dashpay:develop
from
PastaPastaPasta:refactor-llmq2
Mar 23, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c2ac444
refactor: create a immediately executed llamda; use some structed bin…
PastaPastaPasta ee6dc2d
refactor: remove some nested code blocks
PastaPastaPasta 4804aad
refactor: a few more structured bindings
PastaPastaPasta 358ae32
refactor: add some const
PastaPastaPasta bf57b15
refactor: remove unneeded variable
PastaPastaPasta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 = [&]() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. smart :D I am always annoyed by passing variables out of LOCK scope |
||
| 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) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could do 22e9655 instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh; interesting, but I think it's fine as is