Skip to content

Commit c8c6d29

Browse files
committed
refactor: use Uint256HashMap all over codebase
1 parent 3aaf330 commit c8c6d29

File tree

11 files changed

+24
-24
lines changed

11 files changed

+24
-24
lines changed

src/chainlock/chainlock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class CChainLocksHandler final : public chainlock::ChainLockSignerParent
5959
const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs){nullptr};
6060
const CBlockIndex* lastNotifyChainLockBlockIndex GUARDED_BY(cs){nullptr};
6161

62-
std::unordered_map<uint256, std::chrono::seconds, StaticSaltedHasher> txFirstSeenTime GUARDED_BY(cs);
62+
Uint256HashMap<std::chrono::seconds> txFirstSeenTime GUARDED_BY(cs);
6363

6464
std::map<uint256, std::chrono::seconds> seenChainLocks GUARDED_BY(cs);
6565

src/evo/deterministicmns.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,8 @@ class CDeterministicMNManager
627627

628628
CEvoDB& m_evoDb;
629629

630-
std::unordered_map<uint256, CDeterministicMNList, StaticSaltedHasher> mnListsCache GUARDED_BY(cs);
631-
std::unordered_map<uint256, CDeterministicMNListDiff, StaticSaltedHasher> mnListDiffsCache GUARDED_BY(cs);
630+
Uint256HashMap<CDeterministicMNList> mnListsCache GUARDED_BY(cs);
631+
Uint256HashMap<CDeterministicMNListDiff> mnListDiffsCache GUARDED_BY(cs);
632632
const CBlockIndex* tipIndex GUARDED_BY(cs) {nullptr};
633633
const CBlockIndex* m_initial_snapshot_index GUARDED_BY(cs) {nullptr};
634634

src/instantsend/db.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void CInstantSendDb::WriteInstantSendLockArchived(CDBBatch& batch, const uint256
116116
batch.Write(std::make_tuple(DB_ARCHIVED_BY_HASH, hash), true);
117117
}
118118

119-
std::unordered_map<uint256, InstantSendLockPtr, StaticSaltedHasher> CInstantSendDb::RemoveConfirmedInstantSendLocks(int nUntilHeight)
119+
Uint256HashMap<InstantSendLockPtr> CInstantSendDb::RemoveConfirmedInstantSendLocks(int nUntilHeight)
120120
{
121121
LOCK(cs_db);
122122
if (nUntilHeight <= best_confirmed_height) {
@@ -133,7 +133,7 @@ std::unordered_map<uint256, InstantSendLockPtr, StaticSaltedHasher> CInstantSend
133133
it->Seek(firstKey);
134134

135135
CDBBatch batch(*db);
136-
std::unordered_map<uint256, InstantSendLockPtr, StaticSaltedHasher> ret;
136+
Uint256HashMap<InstantSendLockPtr> ret;
137137
while (it->Valid()) {
138138
decltype(firstKey) curKey;
139139
if (!it->GetKey(curKey) || std::get<0>(curKey) != DB_MINED_BY_HEIGHT_AND_HASH) {

src/instantsend/db.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CInstantSendDb
101101
* @param nUntilHeight Removes all IS Locks confirmed up until nUntilHeight
102102
* @return returns an unordered_map of the hash of the IS Locks and a pointer object to the IS Locks for all IS Locks which were removed
103103
*/
104-
std::unordered_map<uint256, InstantSendLockPtr, StaticSaltedHasher> RemoveConfirmedInstantSendLocks(int nUntilHeight) EXCLUSIVE_LOCKS_REQUIRED(!cs_db);
104+
Uint256HashMap<InstantSendLockPtr> RemoveConfirmedInstantSendLocks(int nUntilHeight) EXCLUSIVE_LOCKS_REQUIRED(!cs_db);
105105
/**
106106
* Removes IS Locks from the archive if the tx was confirmed 100 blocks before nUntilHeight
107107
* @param nUntilHeight the height from which to base the remove of archive IS Locks

src/instantsend/instantsend.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ Uint256HashSet CInstantSendManager::ProcessPendingInstantSendLocks(
236236
std::vector<std::pair<NodeId, MessageProcessingResult>>& peer_activity)
237237
{
238238
CBLSBatchVerifier<NodeId, uint256> batchVerifier(false, true, 8);
239-
std::unordered_map<uint256, CRecoveredSig, StaticSaltedHasher> recSigs;
239+
Uint256HashMap<CRecoveredSig> recSigs;
240240

241241
size_t verifyCount = 0;
242242
size_t alreadyVerified = 0;
@@ -689,7 +689,7 @@ void CInstantSendManager::HandleFullyConfirmedBlock(const CBlockIndex* pindex)
689689

690690
void CInstantSendManager::RemoveMempoolConflictsForLock(const uint256& hash, const instantsend::InstantSendLock& islock)
691691
{
692-
std::unordered_map<uint256, CTransactionRef, StaticSaltedHasher> toDelete;
692+
Uint256HashMap<CTransactionRef> toDelete;
693693

694694
{
695695
LOCK(mempool.cs);
@@ -720,7 +720,7 @@ void CInstantSendManager::RemoveMempoolConflictsForLock(const uint256& hash, con
720720
void CInstantSendManager::ResolveBlockConflicts(const uint256& islockHash, const instantsend::InstantSendLock& islock)
721721
{
722722
// Lets first collect all non-locked TXs which conflict with the given ISLOCK
723-
std::unordered_map<const CBlockIndex*, std::unordered_map<uint256, CTransactionRef, StaticSaltedHasher>> conflicts;
723+
std::unordered_map<const CBlockIndex*, Uint256HashMap<CTransactionRef>> conflicts;
724724
{
725725
LOCK(cs_nonLocked);
726726
for (const auto& in : islock.inputs) {

src/instantsend/instantsend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CInstantSendManager final : public instantsend::InstantSendSignerParent
7979
};
8080

8181
mutable Mutex cs_nonLocked;
82-
std::unordered_map<uint256, NonLockedTxInfo, StaticSaltedHasher> nonLockedTxs GUARDED_BY(cs_nonLocked);
82+
Uint256HashMap<NonLockedTxInfo> nonLockedTxs GUARDED_BY(cs_nonLocked);
8383
std::unordered_map<COutPoint, uint256, SaltedOutpointHasher> nonLockedTxsByOutpoints GUARDED_BY(cs_nonLocked);
8484

8585
mutable Mutex cs_pendingRetry;

src/instantsend/signing.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class InstantSendSigner final : public llmq::CRecoveredSigsListener
6464
* recovered signatures for all inputs of a TX. At the same time, we initiate signing of our sigshare for the
6565
* islock. When the recovered sig for the islock later arrives, we can finish the islock and propagate it.
6666
*/
67-
std::unordered_map<uint256, InstantSendLock, StaticSaltedHasher> creatingInstantSendLocks GUARDED_BY(cs_creating);
67+
Uint256HashMap<InstantSendLock> creatingInstantSendLocks GUARDED_BY(cs_creating);
6868
// maps from txid to the in-progress islock
6969
std::unordered_map<uint256, InstantSendLock*, StaticSaltedHasher> txToCreatingInstantSendLocks GUARDED_BY(cs_creating);
7070

src/llmq/dkgsession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions(CConnman& connman) const
469469

470470
CDKGLogger logger(*this, __func__, __LINE__);
471471

472-
std::unordered_map<uint256, int, StaticSaltedHasher> protoMap;
472+
Uint256HashMap<int> protoMap;
473473
connman.ForEachNode([&](const CNode* pnode) {
474474
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
475475
if (verifiedProRegTxHash.IsNull()) {

src/llmq/signing_shares.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ CDeterministicMNCPtr CSigSharesManager::SelectMemberForRecovery(const CQuorumCPt
857857
return v[attempt % v.size()].second;
858858
}
859859

860-
void CSigSharesManager::CollectSigSharesToRequest(std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToRequest)
860+
void CSigSharesManager::CollectSigSharesToRequest(std::unordered_map<NodeId, Uint256HashMap<CSigSharesInv>>& sigSharesToRequest)
861861
{
862862
AssertLockHeld(cs);
863863

@@ -954,7 +954,7 @@ void CSigSharesManager::CollectSigSharesToRequest(std::unordered_map<NodeId, std
954954
}
955955
}
956956

957-
void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::unordered_map<uint256, CBatchedSigShares, StaticSaltedHasher>>& sigSharesToSend)
957+
void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, Uint256HashMap<CBatchedSigShares>>& sigSharesToSend)
958958
{
959959
AssertLockHeld(cs);
960960

@@ -1051,7 +1051,7 @@ void CSigSharesManager::CollectSigSharesToSendConcentrated(std::unordered_map<No
10511051

10521052
void CSigSharesManager::CollectSigSharesToAnnounce(
10531053
const CConnman& connman,
1054-
std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToAnnounce)
1054+
std::unordered_map<NodeId, Uint256HashMap<CSigSharesInv>>& sigSharesToAnnounce)
10551055
{
10561056
AssertLockHeld(cs);
10571057

@@ -1110,10 +1110,10 @@ void CSigSharesManager::CollectSigSharesToAnnounce(
11101110

11111111
bool CSigSharesManager::SendMessages(CConnman& connman)
11121112
{
1113-
std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>> sigSharesToRequest;
1114-
std::unordered_map<NodeId, std::unordered_map<uint256, CBatchedSigShares, StaticSaltedHasher>> sigShareBatchesToSend;
1113+
std::unordered_map<NodeId, Uint256HashMap<CSigSharesInv>> sigSharesToRequest;
1114+
std::unordered_map<NodeId, Uint256HashMap<CBatchedSigShares>> sigShareBatchesToSend;
11151115
std::unordered_map<NodeId, std::vector<CSigShare>> sigSharesToSend;
1116-
std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>> sigSharesToAnnounce;
1116+
std::unordered_map<NodeId, Uint256HashMap<CSigSharesInv>> sigSharesToAnnounce;
11171117
std::unordered_map<NodeId, std::vector<CSigSesAnn>> sigSessionAnnouncements;
11181118

11191119
auto addSigSesAnnIfNeeded = [&](NodeId nodeId, const uint256& signHash) EXCLUSIVE_LOCKS_REQUIRED(cs) {

src/llmq/signing_shares.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class CSigSharesNodeState
330330
CSigSharesInv knows;
331331
};
332332
// TODO limit number of sessions per node
333-
std::unordered_map<uint256, Session, StaticSaltedHasher> sessions;
333+
Uint256HashMap<Session> sessions;
334334

335335
std::unordered_map<uint32_t, Session*> sessionByRecvId;
336336

@@ -381,7 +381,7 @@ class CSigSharesManager : public CRecoveredSigsListener
381381
CThreadInterrupt workInterrupt;
382382

383383
SigShareMap<CSigShare> sigShares GUARDED_BY(cs);
384-
std::unordered_map<uint256, CSignedSession, StaticSaltedHasher> signedSessions GUARDED_BY(cs);
384+
Uint256HashMap<CSignedSession> signedSessions GUARDED_BY(cs);
385385

386386
// stores time of last receivedSigShare. Used to detect timeouts
387387
std::unordered_map<uint256, int64_t, StaticSaltedHasher> timeSeenForSessions GUARDED_BY(cs);
@@ -477,12 +477,12 @@ class CSigSharesManager : public CRecoveredSigsListener
477477
void BanNode(NodeId nodeId, PeerManager& peerman);
478478

479479
bool SendMessages(CConnman& connman);
480-
void CollectSigSharesToRequest(std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToRequest) EXCLUSIVE_LOCKS_REQUIRED(cs);
481-
void CollectSigSharesToSend(std::unordered_map<NodeId, std::unordered_map<uint256, CBatchedSigShares, StaticSaltedHasher>>& sigSharesToSend) EXCLUSIVE_LOCKS_REQUIRED(cs);
480+
void CollectSigSharesToRequest(std::unordered_map<NodeId, Uint256HashMap<CSigSharesInv>>& sigSharesToRequest) EXCLUSIVE_LOCKS_REQUIRED(cs);
481+
void CollectSigSharesToSend(std::unordered_map<NodeId, Uint256HashMap<CBatchedSigShares>>& sigSharesToSend) EXCLUSIVE_LOCKS_REQUIRED(cs);
482482
void CollectSigSharesToSendConcentrated(std::unordered_map<NodeId, std::vector<CSigShare>>& sigSharesToSend, const std::vector<CNode*>& vNodes) EXCLUSIVE_LOCKS_REQUIRED(cs);
483483
void CollectSigSharesToAnnounce(
484484
const CConnman& connman,
485-
std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToAnnounce)
485+
std::unordered_map<NodeId, Uint256HashMap<CSigSharesInv>>& sigSharesToAnnounce)
486486
EXCLUSIVE_LOCKS_REQUIRED(cs);
487487
void SignPendingSigShares(const CConnman& connman, PeerManager& peerman);
488488
void WorkThreadMain(CConnman& connman, PeerManager& peerman);

0 commit comments

Comments
 (0)