forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: use a vector; introduce instantsend::PendingISLockFromPeer #6956
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 3 commits into
dashpay:develop
from
PastaPastaPasta:refac/vector-not-hash-map
Nov 13, 2025
+34
−26
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -168,13 +168,13 @@ MessageProcessingResult CInstantSendManager::ProcessMessage(NodeId from, std::st | |
| } | ||
|
|
||
| LOCK(cs_pendingLocks); | ||
| pendingInstantSendLocks.emplace(hash, std::make_pair(from, islock)); | ||
| pendingInstantSendLocks.emplace(hash, instantsend::PendingISLockFromPeer{from, islock}); | ||
| return ret; | ||
| } | ||
|
|
||
| instantsend::PendingState CInstantSendManager::ProcessPendingInstantSendLocks() | ||
| { | ||
| decltype(pendingInstantSendLocks) pend; | ||
| std::vector<std::pair<uint256, instantsend::PendingISLockFromPeer>> pend; | ||
| instantsend::PendingState ret; | ||
|
|
||
| if (!IsInstantSendEnabled()) { | ||
|
|
@@ -189,14 +189,15 @@ instantsend::PendingState CInstantSendManager::ProcessPendingInstantSendLocks() | |
| // The keys of the removed values are temporaily stored here to avoid invalidating an iterator | ||
| std::vector<uint256> removed; | ||
| removed.reserve(maxCount); | ||
| pend.reserve(maxCount); | ||
|
|
||
| for (const auto& [islockHash, nodeid_islptr_pair] : pendingInstantSendLocks) { | ||
| // Check if we've reached max count | ||
| if (pend.size() >= maxCount) { | ||
| ret.m_pending_work = true; | ||
| break; | ||
| } | ||
| pend.emplace(islockHash, std::move(nodeid_islptr_pair)); | ||
| pend.emplace_back(islockHash, std::move(nodeid_islptr_pair)); | ||
| removed.emplace_back(islockHash); | ||
| } | ||
|
|
||
|
|
@@ -222,24 +223,25 @@ instantsend::PendingState CInstantSendManager::ProcessPendingInstantSendLocks() | |
| if (!badISLocks.empty()) { | ||
| LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- doing verification on old active set\n", __func__); | ||
|
|
||
| // filter out valid IS locks from "pend" | ||
| for (auto it = pend.begin(); it != pend.end();) { | ||
| if (!badISLocks.count(it->first)) { | ||
| it = pend.erase(it); | ||
| } else { | ||
| ++it; | ||
| // filter out valid IS locks from "pend" - keep only bad ones | ||
| std::vector<std::pair<uint256, instantsend::PendingISLockFromPeer>> filteredPend; | ||
| filteredPend.reserve(badISLocks.size()); | ||
|
Collaborator
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. nit: expected amount of elements - 0; it's a fail-over mechanism for 2nd lookup |
||
| for (auto& p : pend) { | ||
| if (badISLocks.contains(p.first)) { | ||
| filteredPend.push_back(std::move(p)); | ||
| } | ||
| } | ||
|
|
||
| // Now check against the previous active set and perform banning if this fails | ||
| ProcessPendingInstantSendLocks(llmq_params, dkgInterval, /*ban=*/true, pend, ret.m_peer_activity); | ||
| ProcessPendingInstantSendLocks(llmq_params, dkgInterval, /*ban=*/true, filteredPend, ret.m_peer_activity); | ||
| } | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| Uint256HashSet CInstantSendManager::ProcessPendingInstantSendLocks( | ||
| const Consensus::LLMQParams& llmq_params, int signOffset, bool ban, | ||
| const Uint256HashMap<std::pair<NodeId, instantsend::InstantSendLockPtr>>& pend, | ||
| const std::vector<std::pair<uint256, instantsend::PendingISLockFromPeer>>& pend, | ||
| std::vector<std::pair<NodeId, MessageProcessingResult>>& peer_activity) | ||
| { | ||
| CBLSBatchVerifier<NodeId, uint256> batchVerifier(false, true, 8); | ||
|
|
@@ -249,8 +251,8 @@ Uint256HashSet CInstantSendManager::ProcessPendingInstantSendLocks( | |
| size_t alreadyVerified = 0; | ||
| for (const auto& p : pend) { | ||
| const auto& hash = p.first; | ||
| auto nodeId = p.second.first; | ||
| const auto& islock = p.second.second; | ||
| auto nodeId = p.second.node_id; | ||
| const auto& islock = p.second.islock; | ||
|
|
||
| if (batchVerifier.badSources.count(nodeId)) { | ||
| continue; | ||
|
|
@@ -321,8 +323,8 @@ Uint256HashSet CInstantSendManager::ProcessPendingInstantSendLocks( | |
| } | ||
| for (const auto& p : pend) { | ||
| const auto& hash = p.first; | ||
| auto nodeId = p.second.first; | ||
| const auto& islock = p.second.second; | ||
| auto nodeId = p.second.node_id; | ||
| const auto& islock = p.second.islock; | ||
|
|
||
| if (batchVerifier.badMessages.count(hash)) { | ||
| LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s: invalid sig in islock, peer=%d\n", | ||
|
|
@@ -399,7 +401,7 @@ MessageProcessingResult CInstantSendManager::ProcessInstantSendLock(NodeId from, | |
| } else { | ||
| // put it in a separate pending map and try again later | ||
| LOCK(cs_pendingLocks); | ||
| pendingNoTxInstantSendLocks.try_emplace(hash, std::make_pair(from, islock)); | ||
| pendingNoTxInstantSendLocks.try_emplace(hash, instantsend::PendingISLockFromPeer{from, islock}); | ||
| } | ||
|
|
||
| // This will also add children TXs to pendingRetryTxs | ||
|
|
@@ -442,11 +444,11 @@ void CInstantSendManager::TransactionAddedToMempool(const CTransactionRef& tx) | |
| LOCK(cs_pendingLocks); | ||
| auto it = pendingNoTxInstantSendLocks.begin(); | ||
| while (it != pendingNoTxInstantSendLocks.end()) { | ||
| if (it->second.second->txid == tx->GetHash()) { | ||
| if (it->second.islock->txid == tx->GetHash()) { | ||
| // we received an islock earlier | ||
| LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s\n", __func__, | ||
| tx->GetHash().ToString(), it->first.ToString()); | ||
| islock = it->second.second; | ||
| islock = it->second.islock; | ||
| pendingInstantSendLocks.try_emplace(it->first, it->second); | ||
| pendingNoTxInstantSendLocks.erase(it); | ||
| break; | ||
|
|
@@ -539,7 +541,7 @@ void CInstantSendManager::AddNonLockedTx(const CTransactionRef& tx, const CBlock | |
| LOCK(cs_pendingLocks); | ||
| auto it = pendingNoTxInstantSendLocks.begin(); | ||
| while (it != pendingNoTxInstantSendLocks.end()) { | ||
| if (it->second.second->txid == tx->GetHash()) { | ||
| if (it->second.islock->txid == tx->GetHash()) { | ||
| // we received an islock earlier, let's put it back into pending and verify/lock | ||
| LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s\n", __func__, | ||
| tx->GetHash().ToString(), it->first.ToString()); | ||
|
|
@@ -626,7 +628,7 @@ void CInstantSendManager::TryEmplacePendingLock(const uint256& hash, const NodeI | |
| if (db.KnownInstantSendLock(hash)) return; | ||
| LOCK(cs_pendingLocks); | ||
| if (!pendingInstantSendLocks.count(hash)) { | ||
| pendingInstantSendLocks.emplace(hash, std::make_pair(id, islock)); | ||
| pendingInstantSendLocks.emplace(hash, instantsend::PendingISLockFromPeer{id, islock}); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -848,11 +850,11 @@ bool CInstantSendManager::GetInstantSendLockByHash(const uint256& hash, instants | |
| LOCK(cs_pendingLocks); | ||
| auto it = pendingInstantSendLocks.find(hash); | ||
| if (it != pendingInstantSendLocks.end()) { | ||
| islock = it->second.second; | ||
| islock = it->second.islock; | ||
| } else { | ||
| auto itNoTx = pendingNoTxInstantSendLocks.find(hash); | ||
| if (itNoTx != pendingNoTxInstantSendLocks.end()) { | ||
| islock = itNoTx->second.second; | ||
| islock = itNoTx->second.islock; | ||
| } else { | ||
| return false; | ||
| } | ||
|
|
@@ -889,7 +891,7 @@ bool CInstantSendManager::IsWaitingForTx(const uint256& txHash) const | |
| LOCK(cs_pendingLocks); | ||
| auto it = pendingNoTxInstantSendLocks.begin(); | ||
| while (it != pendingNoTxInstantSendLocks.end()) { | ||
| if (it->second.second->txid == txHash) { | ||
| if (it->second.islock->txid == txHash) { | ||
| LogPrint(BCLog::INSTANTSEND, "CInstantSendManager::%s -- txid=%s, islock=%s\n", __func__, txHash.ToString(), | ||
| it->first.ToString()); | ||
| return true; | ||
|
|
||
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.
nit: use camel_naming_for_local_variables