forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: efficient build mnlistdiffs in rotation info #6622
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 11 commits into
dashpay:develop
from
PastaPastaPasta:fix/perf_qr_rotation
Apr 3, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e8bbfd2
fix(perf): build mnlistdiffs in rotation info using dynamically the h…
ogabrielides 2a12ff6
bump guix
knst ec78465
fix: move BuildSimplifiedMNListDiff for block h
UdjinM6 810ecd8
fix: don't use `baseBlockIndexes.back()` for the tip
UdjinM6 1f16cf4
fix: sort indexes in GetLastBaseBlockHash
UdjinM6 ff16e68
refactor: clang-format
UdjinM6 71112dc
refactor: more clang-format
UdjinM6 bdfd597
feat: only use efficient qrinfo construction for new shared protocol …
PastaPastaPasta 7432879
fmt: apply clang-format suggestions
PastaPastaPasta 606719a
nit: s/use_leagcy_construction/use_legacy_construction/
PastaPastaPasta 03c15a3
fix: actually bump protocol version
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 |
|---|---|---|
|
|
@@ -87,7 +87,7 @@ UniValue CQuorumRotationInfo::ToJson() const | |
| bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotManager& qsnapman, | ||
| const ChainstateManager& chainman, const CQuorumManager& qman, | ||
| const CQuorumBlockProcessor& qblockman, const CGetQuorumRotationInfo& request, | ||
| CQuorumRotationInfo& response, std::string& errorRet) | ||
| bool use_legacy_construction, CQuorumRotationInfo& response, std::string& errorRet) | ||
| { | ||
| AssertLockHeld(cs_main); | ||
|
|
||
|
|
@@ -112,19 +112,23 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan | |
| } | ||
| baseBlockIndexes.push_back(blockIndex); | ||
| } | ||
| std::sort(baseBlockIndexes.begin(), baseBlockIndexes.end(), [](const CBlockIndex* a, const CBlockIndex* b) { | ||
| return a->nHeight < b->nHeight; | ||
| }); | ||
| if (use_legacy_construction) { | ||
| std::sort(baseBlockIndexes.begin(), baseBlockIndexes.end(), | ||
| [](const CBlockIndex* a, const CBlockIndex* b) { return a->nHeight < b->nHeight; }); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| const CBlockIndex* tipBlockIndex = chainman.ActiveChain().Tip(); | ||
| if (!tipBlockIndex) { | ||
| errorRet = strprintf("tip block not found"); | ||
| return false; | ||
| } | ||
| //Build MN list Diff always with highest baseblock | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, baseBlockIndexes.back()->GetBlockHash(), tipBlockIndex->GetBlockHash(), response.mnListDiffTip, errorRet)) { | ||
| return false; | ||
| if (use_legacy_construction) { | ||
| // Build MN list Diff always with highest baseblock | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, baseBlockIndexes.back()->GetBlockHash(), | ||
| tipBlockIndex->GetBlockHash(), response.mnListDiffTip, errorRet)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| const CBlockIndex* blockIndex = chainman.m_blockman.LookupBlockIndex(request.blockRequestHash); | ||
|
|
@@ -149,15 +153,19 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan | |
| return false; | ||
| } | ||
|
|
||
| const CBlockIndex* pWorkBlockIndex = hBlockIndex->GetAncestor(hBlockIndex->nHeight - workDiff); | ||
| if (!pWorkBlockIndex) { | ||
| const CBlockIndex* pWorkBlockHIndex = hBlockIndex->GetAncestor(hBlockIndex->nHeight - workDiff); | ||
| if (!pWorkBlockHIndex) { | ||
| errorRet = strprintf("Can not find work block H"); | ||
| return false; | ||
| } | ||
|
|
||
| //Build MN list Diff always with highest baseblock | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockIndex), pWorkBlockIndex->GetBlockHash(), response.mnListDiffH, errorRet)) { | ||
| return false; | ||
| if (use_legacy_construction) { | ||
| // Build MN list Diff always with highest baseblock | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHIndex, use_legacy_construction), | ||
| pWorkBlockHIndex->GetBlockHash(), response.mnListDiffH, errorRet)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| const CBlockIndex* pBlockHMinusCIndex = tipBlockIndex->GetAncestor(hBlockIndex->nHeight - cycleLength); | ||
|
|
@@ -202,8 +210,12 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan | |
| const CBlockIndex* pWorkBlockHMinus4CIndex = pBlockHMinus4CIndex->GetAncestor(pBlockHMinus4CIndex->nHeight - workDiff); | ||
| //Checked later if extraShare is on | ||
|
|
||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinusCIndex), pWorkBlockHMinusCIndex->GetBlockHash(), response.mnListDiffAtHMinusC, errorRet)) { | ||
| return false; | ||
| if (use_legacy_construction) { | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinusCIndex, use_legacy_construction), | ||
| pWorkBlockHMinusCIndex->GetBlockHash(), response.mnListDiffAtHMinusC, errorRet)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| auto snapshotHMinusC = qsnapman.GetSnapshotForBlock(llmqType, pBlockHMinusCIndex); | ||
|
|
@@ -214,8 +226,13 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan | |
| response.quorumSnapshotAtHMinusC = std::move(snapshotHMinusC.value()); | ||
| } | ||
|
|
||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus2CIndex), pWorkBlockHMinus2CIndex->GetBlockHash(), response.mnListDiffAtHMinus2C, errorRet)) { | ||
| return false; | ||
| if (use_legacy_construction) { | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus2CIndex, | ||
| use_legacy_construction), | ||
| pWorkBlockHMinus2CIndex->GetBlockHash(), response.mnListDiffAtHMinus2C, errorRet)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| auto snapshotHMinus2C = qsnapman.GetSnapshotForBlock(llmqType, pBlockHMinus2CIndex); | ||
|
|
@@ -226,8 +243,13 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan | |
| response.quorumSnapshotAtHMinus2C = std::move(snapshotHMinus2C.value()); | ||
| } | ||
|
|
||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus3CIndex), pWorkBlockHMinus3CIndex->GetBlockHash(), response.mnListDiffAtHMinus3C, errorRet)) { | ||
| return false; | ||
| if (use_legacy_construction) { | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus3CIndex, | ||
| use_legacy_construction), | ||
| pWorkBlockHMinus3CIndex->GetBlockHash(), response.mnListDiffAtHMinus3C, errorRet)) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| auto snapshotHMinus3C = qsnapman.GetSnapshotForBlock(llmqType, pBlockHMinus3CIndex); | ||
|
|
@@ -255,10 +277,15 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan | |
| } | ||
|
|
||
| CSimplifiedMNListDiff mn4c; | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus4CIndex), pWorkBlockHMinus4CIndex->GetBlockHash(), mn4c, errorRet)) { | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus4CIndex, | ||
| use_legacy_construction), | ||
| pWorkBlockHMinus4CIndex->GetBlockHash(), mn4c, errorRet)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!use_legacy_construction) { | ||
| baseBlockIndexes.push_back(pWorkBlockHMinus4CIndex); | ||
| } | ||
| response.mnListDiffAtHMinus4C = std::move(mn4c); | ||
| } else { | ||
| response.extraShare = false; | ||
|
|
@@ -311,19 +338,65 @@ bool BuildQuorumRotationInfo(CDeterministicMNManager& dmnman, CQuorumSnapshotMan | |
| } | ||
|
|
||
| CSimplifiedMNListDiff mnhneeded; | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, GetLastBaseBlockHash(baseBlockIndexes, pNeededWorkBlockIndex), pNeededWorkBlockIndex->GetBlockHash(), mnhneeded, errorRet)) { | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pNeededWorkBlockIndex, use_legacy_construction), | ||
| pNeededWorkBlockIndex->GetBlockHash(), mnhneeded, errorRet)) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!use_legacy_construction) { | ||
| baseBlockIndexes.push_back(pNeededWorkBlockIndex); | ||
| } | ||
| response.mnListDiffList.push_back(mnhneeded); | ||
| } | ||
|
|
||
| if (!use_legacy_construction) { | ||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus3CIndex, | ||
| use_legacy_construction), | ||
| pWorkBlockHMinus3CIndex->GetBlockHash(), response.mnListDiffAtHMinus3C, errorRet)) { | ||
| return false; | ||
| } | ||
| baseBlockIndexes.push_back(pWorkBlockHMinus3CIndex); | ||
|
|
||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinus2CIndex, | ||
| use_legacy_construction), | ||
| pWorkBlockHMinus2CIndex->GetBlockHash(), response.mnListDiffAtHMinus2C, errorRet)) { | ||
| return false; | ||
| } | ||
| baseBlockIndexes.push_back(pWorkBlockHMinus2CIndex); | ||
|
|
||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHMinusCIndex, use_legacy_construction), | ||
| pWorkBlockHMinusCIndex->GetBlockHash(), response.mnListDiffAtHMinusC, errorRet)) { | ||
| return false; | ||
| } | ||
| baseBlockIndexes.push_back(pWorkBlockHMinusCIndex); | ||
|
|
||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, pWorkBlockHIndex, use_legacy_construction), | ||
| pWorkBlockHIndex->GetBlockHash(), response.mnListDiffH, errorRet)) { | ||
| return false; | ||
| } | ||
| baseBlockIndexes.push_back(pWorkBlockHIndex); | ||
|
|
||
| if (!BuildSimplifiedMNListDiff(dmnman, chainman, qblockman, qman, | ||
| GetLastBaseBlockHash(baseBlockIndexes, tipBlockIndex, use_legacy_construction), | ||
| tipBlockIndex->GetBlockHash(), response.mnListDiffTip, errorRet)) { | ||
| return false; | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return true; | ||
| } | ||
|
|
||
| uint256 GetLastBaseBlockHash(Span<const CBlockIndex*> baseBlockIndexes, const CBlockIndex* blockIndex) | ||
| uint256 GetLastBaseBlockHash(Span<const CBlockIndex*> baseBlockIndexes, const CBlockIndex* blockIndex, | ||
| bool use_legacy_construction) | ||
| { | ||
| uint256 hash; | ||
| if (!use_legacy_construction) { | ||
| std::sort(baseBlockIndexes.begin(), baseBlockIndexes.end(), | ||
| [](const CBlockIndex* a, const CBlockIndex* b) { return a->nHeight < b->nHeight; }); | ||
| } | ||
|
Comment on lines
+396
to
+399
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. 🛠️ Refactor suggestion Unify sorting strategy. |
||
| for (const auto baseBlock : baseBlockIndexes) { | ||
| if (baseBlock->nHeight >= blockIndex->nHeight) | ||
| break; | ||
|
|
||
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
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
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
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
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
Oops, something went wrong.
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.
💡 Verification agent
🧩 Analysis chain
Ensure this API change is documented in the project
The function signature has been updated to include the new parameter
bool use_legacy_construction. This is a significant change that affects how quorum rotation information is built. Make sure this change is properly documented and that callers of this function are updated accordingly.🏁 Script executed:
Length of output: 2565
API Change: Update Documentation for New Parameter
The updated function signature in src/llmq/snapshot.cpp and its corresponding header now includes the new parameter
bool use_legacy_construction. Verification shows that the callers in both src/net_processing.cpp and src/rpc/quorums.cpp have been updated accordingly.Please ensure that this significant API change is also reflected in the project documentation (e.g., API docs, changelog, or README) so that downstream users are aware of the new behavior.