forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: share vecMasternodesUsed across all wallets, improve its handling
#6875
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 4 commits into
dashpay:develop
from
UdjinM6:fix_share_vecMasternodesUsed
Oct 28, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2c82532
feat: share `vecMasternodesUsed` across all wallets, improve its hand…
UdjinM6 13a28fa
perf: optimize CoinJoin masternode tracking with hybrid data structure
UdjinM6 f50d09a
fix: update `MasternodeMetaStore::ToString()`
UdjinM6 eb3be09
refactor: code style/log text adjustments
UdjinM6 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 |
|---|---|---|
|
|
@@ -248,7 +248,6 @@ void CCoinJoinClientSession::ResetPool() | |
| void CCoinJoinClientManager::ResetPool() | ||
| { | ||
| nCachedLastSuccessBlock = 0; | ||
| vecMasternodesUsed.clear(); | ||
| AssertLockNotHeld(cs_deqsessions); | ||
| LOCK(cs_deqsessions); | ||
| for (auto& session : deqSessions) { | ||
|
|
@@ -967,11 +966,14 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman | |
| // If we've used 90% of the Masternode list then drop the oldest first ~30% | ||
| int nThreshold_high = nMnCountEnabled * 0.9; | ||
| int nThreshold_low = nThreshold_high * 0.7; | ||
| WalletCJLogPrint(m_wallet, "Checking vecMasternodesUsed: size: %d, threshold: %d\n", (int)vecMasternodesUsed.size(), nThreshold_high); | ||
| size_t used_count{m_mn_metaman.GetUsedMasternodesCount()}; | ||
|
|
||
| if ((int)vecMasternodesUsed.size() > nThreshold_high) { | ||
| vecMasternodesUsed.erase(vecMasternodesUsed.begin(), vecMasternodesUsed.begin() + vecMasternodesUsed.size() - nThreshold_low); | ||
| WalletCJLogPrint(m_wallet, " vecMasternodesUsed: new size: %d, threshold: %d\n", (int)vecMasternodesUsed.size(), nThreshold_high); | ||
| WalletCJLogPrint(m_wallet, "Checking threshold - used: %d, threshold: %d\n", (int)used_count, nThreshold_high); | ||
|
|
||
| if ((int)used_count > nThreshold_high) { | ||
| m_mn_metaman.RemoveUsedMasternodes(used_count - nThreshold_low); | ||
| WalletCJLogPrint(m_wallet, " new used: %d, threshold: %d\n", (int)m_mn_metaman.GetUsedMasternodesCount(), | ||
| nThreshold_high); | ||
| } | ||
|
|
||
|
UdjinM6 marked this conversation as resolved.
|
||
| bool fResult = true; | ||
|
|
@@ -995,17 +997,17 @@ bool CCoinJoinClientManager::DoAutomaticDenominating(ChainstateManager& chainman | |
| return fResult; | ||
| } | ||
|
|
||
| void CCoinJoinClientManager::AddUsedMasternode(const COutPoint& outpointMn) | ||
| void CCoinJoinClientManager::AddUsedMasternode(const uint256& proTxHash) | ||
| { | ||
| vecMasternodesUsed.push_back(outpointMn); | ||
| m_mn_metaman.AddUsedMasternode(proTxHash); | ||
| } | ||
|
|
||
| CDeterministicMNCPtr CCoinJoinClientManager::GetRandomNotUsedMasternode() | ||
| { | ||
| auto mnList = m_dmnman.GetListAtChainTip(); | ||
|
|
||
| size_t nCountEnabled = mnList.GetValidMNsCount(); | ||
| size_t nCountNotExcluded = nCountEnabled - vecMasternodesUsed.size(); | ||
| size_t nCountNotExcluded{nCountEnabled - m_mn_metaman.GetUsedMasternodesCount()}; | ||
|
|
||
|
Comment on lines
+1010
to
1011
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. Fix potential size_t underflow and printf specifiers. If used_count > enabled, subtraction underflows; also %d mismatches size_t. Clamp and cast. - size_t nCountNotExcluded{nCountEnabled - m_mn_metaman.GetUsedMasternodesCount()};
-
- WalletCJLogPrint(m_wallet, "CCoinJoinClientManager::%s -- %d enabled masternodes, %d masternodes to choose from\n", __func__, nCountEnabled, nCountNotExcluded);
+ const size_t used_count = m_mn_metaman.GetUsedMasternodesCount();
+ const size_t nCountNotExcluded = nCountEnabled > used_count ? (nCountEnabled - used_count) : 0;
+
+ WalletCJLogPrint(m_wallet, "CCoinJoinClientManager::%s -- %d enabled masternodes, %d masternodes to choose from\n",
+ __func__, static_cast<int>(nCountEnabled), static_cast<int>(nCountNotExcluded));
🤖 Prompt for AI Agents |
||
| WalletCJLogPrint(m_wallet, "CCoinJoinClientManager::%s -- %d enabled masternodes, %d masternodes to choose from\n", __func__, nCountEnabled, nCountNotExcluded); | ||
| if (nCountNotExcluded < 1) { | ||
|
|
@@ -1022,15 +1024,14 @@ CDeterministicMNCPtr CCoinJoinClientManager::GetRandomNotUsedMasternode() | |
| // shuffle pointers | ||
| Shuffle(vpMasternodesShuffled.begin(), vpMasternodesShuffled.end(), FastRandomContext()); | ||
|
|
||
| std::set<COutPoint> excludeSet(vecMasternodesUsed.begin(), vecMasternodesUsed.end()); | ||
|
|
||
| // loop through | ||
| // loop through - using direct O(1) lookup instead of creating a set copy | ||
| for (const auto& dmn : vpMasternodesShuffled) { | ||
| if (excludeSet.count(dmn->collateralOutpoint)) { | ||
| if (m_mn_metaman.IsUsedMasternode(dmn->proTxHash)) { | ||
| continue; | ||
| } | ||
|
|
||
| WalletCJLogPrint(m_wallet, "CCoinJoinClientManager::%s -- found, masternode=%s\n", __func__, dmn->collateralOutpoint.ToStringShort()); | ||
| WalletCJLogPrint(m_wallet, "CCoinJoinClientManager::%s -- found, masternode=%s\n", __func__, | ||
| dmn->proTxHash.ToString()); | ||
| return dmn; | ||
| } | ||
|
|
||
|
|
@@ -1083,7 +1084,7 @@ bool CCoinJoinClientSession::JoinExistingQueue(CAmount nBalanceNeedsAnonymized, | |
| continue; | ||
| } | ||
|
|
||
| m_clientman.AddUsedMasternode(dsq.masternodeOutpoint); | ||
| m_clientman.AddUsedMasternode(dmn->proTxHash); | ||
|
|
||
| if (connman.IsMasternodeOrDisconnectRequested(dmn->pdmnState->netInfo->GetPrimary())) { | ||
| WalletCJLogPrint(m_wallet, /* Continued */ | ||
|
|
@@ -1137,7 +1138,7 @@ bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CCon | |
| return false; | ||
| } | ||
|
|
||
| m_clientman.AddUsedMasternode(dmn->collateralOutpoint); | ||
| m_clientman.AddUsedMasternode(dmn->proTxHash); | ||
|
|
||
| // skip next mn payments winners | ||
| if (dmn->pdmnState->nLastPaidHeight + nWeightedMnCount < mnList.GetHeight() + WinnersToSkip()) { | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.