@@ -122,15 +122,11 @@ bool CInstantSend::ProcessTxLockRequest(const CTxLockRequest& txLockRequest, CCo
122122 }
123123 LogPrintf (" CInstantSend::ProcessTxLockRequest -- accepted, txid=%s\n " , txHash.ToString ());
124124
125- std::map<uint256, CTxLockCandidate>::iterator itLockCandidate = mapTxLockCandidates.find (txHash);
126- CTxLockCandidate& txLockCandidate = itLockCandidate->second ;
127- Vote (txLockCandidate, connman);
128- ProcessOrphanTxLockVotes (connman);
129-
130125 // Masternodes will sometimes propagate votes before the transaction is known to the client.
131126 // If this just happened - lock inputs, resolve conflicting locks, update transaction status
132127 // forcing external script notification.
133- TryToFinalizeLockCandidate (txLockCandidate);
128+ std::map<uint256, CTxLockCandidate>::iterator itLockCandidate = mapTxLockCandidates.find (txHash);
129+ TryToFinalizeLockCandidate (itLockCandidate->second );
134130
135131 return true ;
136132}
@@ -182,6 +178,18 @@ void CInstantSend::CreateEmptyTxLockCandidate(const uint256& txHash)
182178 mapTxLockCandidates.insert (std::make_pair (txHash, CTxLockCandidate (txLockRequest)));
183179}
184180
181+ void CInstantSend::Vote (const uint256& txHash, CConnman& connman)
182+ {
183+ AssertLockHeld (cs_main);
184+ LOCK (cs_instantsend);
185+
186+ std::map<uint256, CTxLockCandidate>::iterator itLockCandidate = mapTxLockCandidates.find (txHash);
187+ if (itLockCandidate == mapTxLockCandidates.end ()) return ;
188+ Vote (itLockCandidate->second , connman);
189+ // Let's see if our vote changed smth
190+ TryToFinalizeLockCandidate (itLockCandidate->second );
191+ }
192+
185193void CInstantSend::Vote (CTxLockCandidate& txLockCandidate, CConnman& connman)
186194{
187195 if (!fMasterNode ) return ;
@@ -190,6 +198,8 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
190198 LOCK2 (cs_main, cs_instantsend);
191199
192200 uint256 txHash = txLockCandidate.GetHash ();
201+ // We should never vote on a Transaction Lock Request that was not (yet) accepted by the mempool
202+ if (mapLockRequestAccepted.find (txHash) == mapLockRequestAccepted.end ()) return ;
193203 // check if we need to vote on this candidate's outpoints,
194204 // it's possible that we need to vote for several of them
195205 std::map<COutPoint, COutPointLock>::iterator itOutpointLock = txLockCandidate.mapOutPointLocks .begin ();
0 commit comments