@@ -30,14 +30,18 @@ class CMasternodeSync;
3030class CSporkManager ;
3131class PeerManager ;
3232
33+ namespace instantsend {
34+ class InstantSendSigner ;
35+ } // namespace instantsend
36+
3337namespace llmq
3438{
3539class CChainLocksHandler ;
3640class CQuorumManager ;
3741class CSigningManager ;
3842class CSigSharesManager ;
3943
40- class CInstantSendManager : public CRecoveredSigsListener
44+ class CInstantSendManager
4145{
4246private:
4347 instantsend::CInstantSendDb db;
@@ -46,35 +50,15 @@ class CInstantSendManager : public CRecoveredSigsListener
4650 CChainState& m_chainstate;
4751 CQuorumManager& qman;
4852 CSigningManager& sigman;
49- CSigSharesManager& shareman;
5053 CSporkManager& spork_manager;
5154 CTxMemPool& mempool;
5255 const CMasternodeSync& m_mn_sync;
5356
54- const bool m_is_masternode ;
57+ std::unique_ptr<instantsend::InstantSendSigner> m_signer{ nullptr } ;
5558
5659 std::thread workThread;
5760 CThreadInterrupt workInterrupt;
5861
59- mutable Mutex cs_inputReqests;
60-
61- /* *
62- * Request ids of inputs that we signed. Used to determine if a recovered signature belongs to an
63- * in-progress input lock.
64- */
65- std::unordered_set<uint256, StaticSaltedHasher> inputRequestIds GUARDED_BY (cs_inputReqests);
66-
67- mutable Mutex cs_creating;
68-
69- /* *
70- * These are the islocks that are currently in the middle of being created. Entries are created when we observed
71- * recovered signatures for all inputs of a TX. At the same time, we initiate signing of our sigshare for the islock.
72- * When the recovered sig for the islock later arrives, we can finish the islock and propagate it.
73- */
74- std::unordered_map<uint256, CInstantSendLock, StaticSaltedHasher> creatingInstantSendLocks GUARDED_BY (cs_creating);
75- // maps from txid to the in-progress islock
76- std::unordered_map<uint256, CInstantSendLock*, StaticSaltedHasher> txToCreatingInstantSendLocks GUARDED_BY (cs_creating);
77-
7862 mutable Mutex cs_pendingLocks;
7963 // Incoming and not verified yet
8064 std::unordered_map<uint256, std::pair<NodeId, CInstantSendLockPtr>, StaticSaltedHasher> pendingInstantSendLocks GUARDED_BY (cs_pendingLocks);
@@ -111,69 +95,52 @@ class CInstantSendManager : public CRecoveredSigsListener
11195 void InterruptWorkerThread () { workInterrupt (); };
11296
11397private:
114- void ProcessTx (const CTransaction& tx, bool fRetroactive , const Consensus::Params& params)
115- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests);
116- bool CheckCanLock (const CTransaction& tx, bool printDebug, const Consensus::Params& params) const ;
117- bool CheckCanLock (const COutPoint& outpoint, bool printDebug, const uint256& txHash,
118- const Consensus::Params& params) const ;
119-
120- void HandleNewInputLockRecoveredSig (const CRecoveredSig& recoveredSig, const uint256& txid)
121- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating);
122- void HandleNewInstantSendLockRecoveredSig (const CRecoveredSig& recoveredSig)
123- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_pendingLocks);
124-
125- bool TrySignInputLocks (const CTransaction& tx, bool allowResigning, Consensus::LLMQType llmqType,
126- const Consensus::Params& params) EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests);
127- void TrySignInstantSendLock (const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(!cs_creating);
128-
12998 PeerMsgRet ProcessMessageInstantSendLock (const CNode& pfrom, PeerManager& peerman, const CInstantSendLockPtr& islock);
13099 bool ProcessPendingInstantSendLocks (PeerManager& peerman)
131- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, ! cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
100+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
132101
133102 std::unordered_set<uint256, StaticSaltedHasher> ProcessPendingInstantSendLocks (
134103 const Consensus::LLMQParams& llmq_params, PeerManager& peerman, int signOffset,
135104 const std::unordered_map<uint256, std::pair<NodeId, CInstantSendLockPtr>, StaticSaltedHasher>& pend, bool ban)
136- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, ! cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
105+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
137106 void ProcessInstantSendLock (NodeId from, PeerManager& peerman, const uint256& hash, const CInstantSendLockPtr& islock)
138- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, ! cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
107+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
139108
140109 void AddNonLockedTx (const CTransactionRef& tx, const CBlockIndex* pindexMined)
141110 EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks);
142111 void RemoveNonLockedTx (const uint256& txid, bool retryChildren)
143112 EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
144113 void RemoveConflictedTx (const CTransaction& tx)
145- EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests, !cs_nonLocked, !cs_pendingRetry);
146- void TruncateRecoveredSigsForInputs (const CInstantSendLock& islock)
147- EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests);
114+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
115+ void TruncateRecoveredSigsForInputs (const CInstantSendLock& islock);
148116
149117 void RemoveMempoolConflictsForLock (PeerManager& peerman, const uint256& hash, const CInstantSendLock& islock)
150- EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests, ! cs_nonLocked, !cs_pendingRetry);
118+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
151119 void ResolveBlockConflicts (const uint256& islockHash, const CInstantSendLock& islock)
152- EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests, !cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
153- void ProcessPendingRetryLockTxs ()
154- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, !cs_nonLocked, !cs_pendingRetry);
120+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
155121
156122 void WorkThreadMain (PeerManager& peerman)
157- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, !cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
123+ NO_THREAD_SAFETY_ANALYSIS;
124+ // Needed as compiler cannot differentiate between negative capability against member and against
125+ // member accessed through reference.
126+ // TODO: Remove this, it's terrible.
127+ // EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
158128
159129 void HandleFullyConfirmedBlock (const CBlockIndex* pindex)
160- EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests, ! cs_nonLocked, !cs_pendingRetry);
130+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
161131
162132public:
163133 bool IsLocked (const uint256& txHash) const ;
164134 bool IsWaitingForTx (const uint256& txHash) const EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
165135 CInstantSendLockPtr GetConflictingLock (const CTransaction& tx) const ;
166136
167- [[nodiscard]] MessageProcessingResult HandleNewRecoveredSig (const CRecoveredSig& recoveredSig) override
168- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, !cs_pendingLocks);
169-
170137 PeerMsgRet ProcessMessage (const CNode& pfrom, PeerManager& peerman, std::string_view msg_type, CDataStream& vRecv);
171138
172139 void TransactionAddedToMempool (PeerManager& peerman, const CTransactionRef& tx)
173- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, ! cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
140+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
174141 void TransactionRemovedFromMempool (const CTransactionRef& tx);
175142 void BlockConnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex)
176- EXCLUSIVE_LOCKS_REQUIRED(!cs_creating, !cs_inputReqests, ! cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
143+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingLocks, !cs_pendingRetry);
177144 void BlockDisconnected (const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexDisconnected);
178145
179146 bool AlreadyHave (const CInv& inv) const EXCLUSIVE_LOCKS_REQUIRED(!cs_pendingLocks);
@@ -182,9 +149,9 @@ class CInstantSendManager : public CRecoveredSigsListener
182149 CInstantSendLockPtr GetInstantSendLockByTxid (const uint256& txid) const ;
183150
184151 void NotifyChainLock (const CBlockIndex* pindexChainLock)
185- EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests, ! cs_nonLocked, !cs_pendingRetry);
152+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
186153 void UpdatedBlockTip (const CBlockIndex* pindexNew)
187- EXCLUSIVE_LOCKS_REQUIRED(!cs_inputReqests, ! cs_nonLocked, !cs_pendingRetry);
154+ EXCLUSIVE_LOCKS_REQUIRED(!cs_nonLocked, !cs_pendingRetry);
188155
189156 void RemoveConflictingLock (const uint256& islockHash, const CInstantSendLock& islock);
190157
@@ -196,8 +163,9 @@ class CInstantSendManager : public CRecoveredSigsListener
196163 * transactions in mempool, but should sign txes included in a block. This
197164 * allows ChainLocks to continue even while this spork is disabled.
198165 */
199- bool IsInstantSendMempoolSigningEnabled () const ;
200166 bool RejectConflictingBlocks () const ;
167+
168+ friend class ::instantsend::InstantSendSigner;
201169};
202170} // namespace llmq
203171
0 commit comments