Skip to content
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

refactor: introduce two new cache structures to minimize cs_main cont… #6418

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1206,17 +1206,22 @@ CQuorumCPtr CQuorumManager::SelectQuorumForSigning(const Consensus::LLMQParams&
{
size_t poolSize = llmq_params.signingActiveQuorumCount;

CBlockIndex* pindexStart;
auto pindexStart = [&]() -> const CBlockIndex*
{
LOCK(cs_main);
auto chainTip = cachedChainTip.load();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if cachedChainTip is null, better to load it from active_chain IMO

if (chainTip == nullptr) return nullptr;
auto cur_height = chainTip->nHeight;
if (signHeight == -1) {
signHeight = active_chain.Height();
signHeight = cur_height;
}
int startBlockHeight = signHeight - signOffset;
if (startBlockHeight > active_chain.Height() || startBlockHeight < 0) {
return {};
if (startBlockHeight > cur_height || startBlockHeight < 0) {
return nullptr;
}
pindexStart = active_chain[startBlockHeight];
return chainTip->GetAncestor(startBlockHeight);
}();
if (pindexStart == nullptr) {
return {};
}

if (IsQuorumRotationEnabled(llmq_params, pindexStart)) {
Expand Down
Loading