mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
refactor: Add a bunch of GUARDED_BY(*) in llmq code (#4121)
This commit is contained in:
parent
81067b435f
commit
bf7b6adef2
@ -205,8 +205,8 @@ private:
|
|||||||
CDKGSessionManager& dkgManager;
|
CDKGSessionManager& dkgManager;
|
||||||
|
|
||||||
mutable CCriticalSection quorumsCacheCs;
|
mutable CCriticalSection quorumsCacheCs;
|
||||||
mutable std::map<Consensus::LLMQType, unordered_lru_cache<uint256, CQuorumPtr, StaticSaltedHasher>> mapQuorumsCache;
|
mutable std::map<Consensus::LLMQType, unordered_lru_cache<uint256, CQuorumPtr, StaticSaltedHasher>> mapQuorumsCache GUARDED_BY(quorumsCacheCs);
|
||||||
mutable std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CQuorumCPtr>, StaticSaltedHasher>> scanQuorumsCache;
|
mutable std::map<Consensus::LLMQType, unordered_lru_cache<uint256, std::vector<CQuorumCPtr>, StaticSaltedHasher>> scanQuorumsCache GUARDED_BY(quorumsCacheCs);
|
||||||
|
|
||||||
mutable ctpl::thread_pool workerPool;
|
mutable ctpl::thread_pool workerPool;
|
||||||
mutable CThreadInterrupt quorumThreadInterrupt;
|
mutable CThreadInterrupt quorumThreadInterrupt;
|
||||||
|
@ -29,10 +29,10 @@ private:
|
|||||||
|
|
||||||
// TODO cleanup
|
// TODO cleanup
|
||||||
CCriticalSection minableCommitmentsCs;
|
CCriticalSection minableCommitmentsCs;
|
||||||
std::map<std::pair<Consensus::LLMQType, uint256>, uint256> minableCommitmentsByQuorum;
|
std::map<std::pair<Consensus::LLMQType, uint256>, uint256> minableCommitmentsByQuorum GUARDED_BY(minableCommitmentsCs);
|
||||||
std::map<uint256, CFinalCommitment> minableCommitments;
|
std::map<uint256, CFinalCommitment> minableCommitments GUARDED_BY(minableCommitmentsCs);
|
||||||
|
|
||||||
std::map<Consensus::LLMQType, unordered_lru_cache<uint256, bool, StaticSaltedHasher>> mapHasMinedCommitmentCache;
|
std::map<Consensus::LLMQType, unordered_lru_cache<uint256, bool, StaticSaltedHasher>> mapHasMinedCommitmentCache GUARDED_BY(minableCommitmentsCs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CQuorumBlockProcessor(CEvoDB& _evoDb);
|
explicit CQuorumBlockProcessor(CEvoDB& _evoDb);
|
||||||
|
@ -57,29 +57,29 @@ private:
|
|||||||
CScheduler* scheduler;
|
CScheduler* scheduler;
|
||||||
boost::thread* scheduler_thread;
|
boost::thread* scheduler_thread;
|
||||||
CCriticalSection cs;
|
CCriticalSection cs;
|
||||||
bool tryLockChainTipScheduled{false};
|
bool tryLockChainTipScheduled GUARDED_BY(cs) {false};
|
||||||
bool isEnabled{false};
|
bool isEnabled GUARDED_BY(cs) {false};
|
||||||
bool isEnforced{false};
|
bool isEnforced GUARDED_BY(cs) {false};
|
||||||
|
|
||||||
uint256 bestChainLockHash;
|
uint256 bestChainLockHash GUARDED_BY(cs);
|
||||||
CChainLockSig bestChainLock;
|
CChainLockSig bestChainLock GUARDED_BY(cs);
|
||||||
|
|
||||||
CChainLockSig bestChainLockWithKnownBlock;
|
CChainLockSig bestChainLockWithKnownBlock GUARDED_BY(cs);
|
||||||
const CBlockIndex* bestChainLockBlockIndex{nullptr};
|
const CBlockIndex* bestChainLockBlockIndex GUARDED_BY(cs) {nullptr};
|
||||||
const CBlockIndex* lastNotifyChainLockBlockIndex{nullptr};
|
const CBlockIndex* lastNotifyChainLockBlockIndex GUARDED_BY(cs) {nullptr};
|
||||||
|
|
||||||
int32_t lastSignedHeight{-1};
|
int32_t lastSignedHeight GUARDED_BY(cs) {-1};
|
||||||
uint256 lastSignedRequestId;
|
uint256 lastSignedRequestId GUARDED_BY(cs);
|
||||||
uint256 lastSignedMsgHash;
|
uint256 lastSignedMsgHash GUARDED_BY(cs);
|
||||||
|
|
||||||
// We keep track of txids from recently received blocks so that we can check if all TXs got islocked
|
// We keep track of txids from recently received blocks so that we can check if all TXs got islocked
|
||||||
typedef std::unordered_map<uint256, std::shared_ptr<std::unordered_set<uint256, StaticSaltedHasher>>> BlockTxs;
|
typedef std::unordered_map<uint256, std::shared_ptr<std::unordered_set<uint256, StaticSaltedHasher>>> BlockTxs;
|
||||||
BlockTxs blockTxs;
|
BlockTxs blockTxs GUARDED_BY(cs);
|
||||||
std::unordered_map<uint256, int64_t> txFirstSeenTime;
|
std::unordered_map<uint256, int64_t> txFirstSeenTime GUARDED_BY(cs);
|
||||||
|
|
||||||
std::map<uint256, int64_t> seenChainLocks;
|
std::map<uint256, int64_t> seenChainLocks GUARDED_BY(cs);
|
||||||
|
|
||||||
int64_t lastCleanupTime{0};
|
int64_t lastCleanupTime GUARDED_BY(cs) {0};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CChainLocksHandler();
|
explicit CChainLocksHandler();
|
||||||
|
@ -90,7 +90,7 @@ class CDKGDebugManager
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CCriticalSection cs;
|
CCriticalSection cs;
|
||||||
CDKGDebugStatus localStatus;
|
CDKGDebugStatus localStatus GUARDED_BY(cs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDKGDebugManager();
|
CDKGDebugManager();
|
||||||
|
@ -270,16 +270,16 @@ private:
|
|||||||
// conflicting messages as otherwise an attacker might be able to broadcast conflicting (valid+invalid) messages
|
// conflicting messages as otherwise an attacker might be able to broadcast conflicting (valid+invalid) messages
|
||||||
// and thus split the quorum. Such members are later removed from the quorum.
|
// and thus split the quorum. Such members are later removed from the quorum.
|
||||||
mutable CCriticalSection invCs;
|
mutable CCriticalSection invCs;
|
||||||
std::map<uint256, CDKGContribution> contributions;
|
std::map<uint256, CDKGContribution> contributions GUARDED_BY(invCs);
|
||||||
std::map<uint256, CDKGComplaint> complaints;
|
std::map<uint256, CDKGComplaint> complaints GUARDED_BY(invCs);
|
||||||
std::map<uint256, CDKGJustification> justifications;
|
std::map<uint256, CDKGJustification> justifications GUARDED_BY(invCs);
|
||||||
std::map<uint256, CDKGPrematureCommitment> prematureCommitments;
|
std::map<uint256, CDKGPrematureCommitment> prematureCommitments GUARDED_BY(invCs);
|
||||||
|
|
||||||
mutable CCriticalSection cs_pending;
|
mutable CCriticalSection cs_pending;
|
||||||
std::vector<size_t> pendingContributionVerifications;
|
std::vector<size_t> pendingContributionVerifications GUARDED_BY(cs_pending);
|
||||||
|
|
||||||
// filled by ReceivePrematureCommitment and used by FinalizeCommitments
|
// filled by ReceivePrematureCommitment and used by FinalizeCommitments
|
||||||
std::set<uint256> validCommitments;
|
std::set<uint256> validCommitments GUARDED_BY(invCs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDKGSession(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CDKGSessionManager& _dkgManager) :
|
CDKGSession(const Consensus::LLMQParams& _params, CBLSWorker& _blsWorker, CDKGSessionManager& _dkgManager) :
|
||||||
|
@ -44,11 +44,11 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mutable CCriticalSection cs;
|
mutable CCriticalSection cs;
|
||||||
int invType;
|
const int invType;
|
||||||
size_t maxMessagesPerNode;
|
size_t maxMessagesPerNode GUARDED_BY(cs);
|
||||||
std::list<BinaryMessage> pendingMessages;
|
std::list<BinaryMessage> pendingMessages GUARDED_BY(cs);
|
||||||
std::map<NodeId, size_t> messagesPerNode;
|
std::map<NodeId, size_t> messagesPerNode GUARDED_BY(cs);
|
||||||
std::set<uint256> seenMessages;
|
std::set<uint256> seenMessages GUARDED_BY(cs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType);
|
explicit CDKGPendingMessages(size_t _maxMessagesPerNode, int _invType);
|
||||||
@ -110,17 +110,18 @@ private:
|
|||||||
CBLSWorker& blsWorker;
|
CBLSWorker& blsWorker;
|
||||||
CDKGSessionManager& dkgManager;
|
CDKGSessionManager& dkgManager;
|
||||||
|
|
||||||
QuorumPhase phase{QuorumPhase_Idle};
|
QuorumPhase phase GUARDED_BY(cs) {QuorumPhase_Idle};
|
||||||
int currentHeight{-1};
|
int currentHeight GUARDED_BY(cs) {-1};
|
||||||
int quorumHeight{-1};
|
int quorumHeight GUARDED_BY(cs) {-1};
|
||||||
uint256 quorumHash;
|
uint256 quorumHash GUARDED_BY(cs);
|
||||||
|
|
||||||
std::shared_ptr<CDKGSession> curSession;
|
std::shared_ptr<CDKGSession> curSession;
|
||||||
std::thread phaseHandlerThread;
|
std::thread phaseHandlerThread;
|
||||||
|
|
||||||
CDKGPendingMessages pendingContributions;
|
CDKGPendingMessages pendingContributions GUARDED_BY(cs);
|
||||||
CDKGPendingMessages pendingComplaints;
|
CDKGPendingMessages pendingComplaints GUARDED_BY(cs);
|
||||||
CDKGPendingMessages pendingJustifications;
|
CDKGPendingMessages pendingJustifications GUARDED_BY(cs);
|
||||||
CDKGPendingMessages pendingPrematureCommitments;
|
CDKGPendingMessages pendingPrematureCommitments GUARDED_BY(cs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDKGSessionHandler(const Consensus::LLMQParams& _params, CBLSWorker& blsWorker, CDKGSessionManager& _dkgManager);
|
CDKGSessionHandler(const Consensus::LLMQParams& _params, CBLSWorker& blsWorker, CDKGSessionManager& _dkgManager);
|
||||||
|
@ -43,7 +43,7 @@ private:
|
|||||||
BLSVerificationVectorPtr vvec;
|
BLSVerificationVectorPtr vvec;
|
||||||
CBLSSecretKey skContribution;
|
CBLSSecretKey skContribution;
|
||||||
};
|
};
|
||||||
std::map<ContributionsCacheKey, ContributionsCacheEntry> contributionsCache;
|
std::map<ContributionsCacheKey, ContributionsCacheEntry> contributionsCache GUARDED_BY(contributionsCacheCs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDKGSessionManager(CDBWrapper& _llmqDb, CBLSWorker& _blsWorker);
|
CDKGSessionManager(CDBWrapper& _llmqDb, CBLSWorker& _blsWorker);
|
||||||
|
@ -90,19 +90,19 @@ private:
|
|||||||
* Request ids of inputs that we signed. Used to determine if a recovered signature belongs to an
|
* Request ids of inputs that we signed. Used to determine if a recovered signature belongs to an
|
||||||
* in-progress input lock.
|
* in-progress input lock.
|
||||||
*/
|
*/
|
||||||
std::unordered_set<uint256, StaticSaltedHasher> inputRequestIds;
|
std::unordered_set<uint256, StaticSaltedHasher> inputRequestIds GUARDED_BY(cs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These are the islocks that are currently in the middle of being created. Entries are created when we observed
|
* These are the islocks that are currently in the middle of being created. Entries are created when we observed
|
||||||
* recovered signatures for all inputs of a TX. At the same time, we initiate signing of our sigshare for the islock.
|
* recovered signatures for all inputs of a TX. At the same time, we initiate signing of our sigshare for the islock.
|
||||||
* When the recovered sig for the islock later arrives, we can finish the islock and propagate it.
|
* When the recovered sig for the islock later arrives, we can finish the islock and propagate it.
|
||||||
*/
|
*/
|
||||||
std::unordered_map<uint256, CInstantSendLock, StaticSaltedHasher> creatingInstantSendLocks;
|
std::unordered_map<uint256, CInstantSendLock, StaticSaltedHasher> creatingInstantSendLocks GUARDED_BY(cs);
|
||||||
// maps from txid to the in-progress islock
|
// maps from txid to the in-progress islock
|
||||||
std::unordered_map<uint256, CInstantSendLock*, StaticSaltedHasher> txToCreatingInstantSendLocks;
|
std::unordered_map<uint256, CInstantSendLock*, StaticSaltedHasher> txToCreatingInstantSendLocks GUARDED_BY(cs);
|
||||||
|
|
||||||
// Incoming and not verified yet
|
// Incoming and not verified yet
|
||||||
std::unordered_map<uint256, std::pair<NodeId, CInstantSendLockPtr>, StaticSaltedHasher> pendingInstantSendLocks;
|
std::unordered_map<uint256, std::pair<NodeId, CInstantSendLockPtr>, StaticSaltedHasher> pendingInstantSendLocks GUARDED_BY(cs);
|
||||||
|
|
||||||
// TXs which are neither IS locked nor ChainLocked. We use this to determine for which TXs we need to retry IS locking
|
// TXs which are neither IS locked nor ChainLocked. We use this to determine for which TXs we need to retry IS locking
|
||||||
// of child TXs
|
// of child TXs
|
||||||
@ -111,10 +111,10 @@ private:
|
|||||||
CTransactionRef tx;
|
CTransactionRef tx;
|
||||||
std::unordered_set<uint256, StaticSaltedHasher> children;
|
std::unordered_set<uint256, StaticSaltedHasher> children;
|
||||||
};
|
};
|
||||||
std::unordered_map<uint256, NonLockedTxInfo, StaticSaltedHasher> nonLockedTxs;
|
std::unordered_map<uint256, NonLockedTxInfo, StaticSaltedHasher> nonLockedTxs GUARDED_BY(cs);
|
||||||
std::unordered_map<COutPoint, uint256, SaltedOutpointHasher> nonLockedTxsByOutpoints;
|
std::unordered_map<COutPoint, uint256, SaltedOutpointHasher> nonLockedTxsByOutpoints GUARDED_BY(cs);
|
||||||
|
|
||||||
std::unordered_set<uint256, StaticSaltedHasher> pendingRetryTxs;
|
std::unordered_set<uint256, StaticSaltedHasher> pendingRetryTxs GUARDED_BY(cs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CInstantSendManager(CDBWrapper& _llmqDb);
|
explicit CInstantSendManager(CDBWrapper& _llmqDb);
|
||||||
|
@ -81,9 +81,9 @@ private:
|
|||||||
CDBWrapper& db;
|
CDBWrapper& db;
|
||||||
|
|
||||||
CCriticalSection cs;
|
CCriticalSection cs;
|
||||||
unordered_lru_cache<std::pair<Consensus::LLMQType, uint256>, bool, StaticSaltedHasher, 30000> hasSigForIdCache;
|
unordered_lru_cache<std::pair<Consensus::LLMQType, uint256>, bool, StaticSaltedHasher, 30000> hasSigForIdCache GUARDED_BY(cs);
|
||||||
unordered_lru_cache<uint256, bool, StaticSaltedHasher, 30000> hasSigForSessionCache;
|
unordered_lru_cache<uint256, bool, StaticSaltedHasher, 30000> hasSigForSessionCache GUARDED_BY(cs);
|
||||||
unordered_lru_cache<uint256, bool, StaticSaltedHasher, 30000> hasSigForHashCache;
|
unordered_lru_cache<uint256, bool, StaticSaltedHasher, 30000> hasSigForHashCache GUARDED_BY(cs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CRecoveredSigsDb(CDBWrapper& _db);
|
explicit CRecoveredSigsDb(CDBWrapper& _db);
|
||||||
@ -138,15 +138,14 @@ private:
|
|||||||
CRecoveredSigsDb db;
|
CRecoveredSigsDb db;
|
||||||
|
|
||||||
// Incoming and not verified yet
|
// Incoming and not verified yet
|
||||||
std::unordered_map<NodeId, std::list<std::shared_ptr<const CRecoveredSig>>> pendingRecoveredSigs;
|
std::unordered_map<NodeId, std::list<std::shared_ptr<const CRecoveredSig>>> pendingRecoveredSigs GUARDED_BY(cs);
|
||||||
std::unordered_map<uint256, std::shared_ptr<const CRecoveredSig>, StaticSaltedHasher> pendingReconstructedRecoveredSigs;
|
std::unordered_map<uint256, std::shared_ptr<const CRecoveredSig>, StaticSaltedHasher> pendingReconstructedRecoveredSigs GUARDED_BY(cs);
|
||||||
|
|
||||||
// must be protected by cs
|
FastRandomContext rnd GUARDED_BY(cs);
|
||||||
FastRandomContext rnd;
|
|
||||||
|
|
||||||
int64_t lastCleanupTime{0};
|
int64_t lastCleanupTime{0};
|
||||||
|
|
||||||
std::vector<CRecoveredSigsListener*> recoveredSigsListeners;
|
std::vector<CRecoveredSigsListener*> recoveredSigsListeners GUARDED_BY(cs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CSigningManager(CDBWrapper& llmqDb, bool fMemory);
|
CSigningManager(CDBWrapper& llmqDb, bool fMemory);
|
||||||
|
@ -368,20 +368,19 @@ private:
|
|||||||
std::thread workThread;
|
std::thread workThread;
|
||||||
CThreadInterrupt workInterrupt;
|
CThreadInterrupt workInterrupt;
|
||||||
|
|
||||||
SigShareMap<CSigShare> sigShares;
|
SigShareMap<CSigShare> sigShares GUARDED_BY(cs);
|
||||||
std::unordered_map<uint256, CSignedSession, StaticSaltedHasher> signedSessions;
|
std::unordered_map<uint256, CSignedSession, StaticSaltedHasher> signedSessions GUARDED_BY(cs);
|
||||||
|
|
||||||
// stores time of last receivedSigShare. Used to detect timeouts
|
// stores time of last receivedSigShare. Used to detect timeouts
|
||||||
std::unordered_map<uint256, int64_t, StaticSaltedHasher> timeSeenForSessions;
|
std::unordered_map<uint256, int64_t, StaticSaltedHasher> timeSeenForSessions GUARDED_BY(cs);
|
||||||
|
|
||||||
std::unordered_map<NodeId, CSigSharesNodeState> nodeStates;
|
std::unordered_map<NodeId, CSigSharesNodeState> nodeStates GUARDED_BY(cs);
|
||||||
SigShareMap<std::pair<NodeId, int64_t>> sigSharesRequested;
|
SigShareMap<std::pair<NodeId, int64_t>> sigSharesRequested GUARDED_BY(cs);
|
||||||
SigShareMap<bool> sigSharesQueuedToAnnounce;
|
SigShareMap<bool> sigSharesQueuedToAnnounce GUARDED_BY(cs);
|
||||||
|
|
||||||
std::vector<std::tuple<const CQuorumCPtr, uint256, uint256>> pendingSigns;
|
std::vector<std::tuple<const CQuorumCPtr, uint256, uint256>> pendingSigns GUARDED_BY(cs);
|
||||||
|
|
||||||
// must be protected by cs
|
FastRandomContext rnd GUARDED_BY(cs);
|
||||||
FastRandomContext rnd;
|
|
||||||
|
|
||||||
int64_t lastCleanupTime{0};
|
int64_t lastCleanupTime{0};
|
||||||
std::atomic<uint32_t> recoveredSigsCounter{0};
|
std::atomic<uint32_t> recoveredSigsCounter{0};
|
||||||
|
Loading…
Reference in New Issue
Block a user