Skip to content

Commit c9bafe1

Browse files
committed
Vote on IS only if it was accepted to mempool (#1826)
1 parent 068b20b commit c9bafe1

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/instantx.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
185193
void 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();

src/instantx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class CInstantSend
8686
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv, CConnman& connman);
8787

8888
bool ProcessTxLockRequest(const CTxLockRequest& txLockRequest, CConnman& connman);
89+
void Vote(const uint256& txHash, CConnman& connman);
8990

9091
bool AlreadyHave(const uint256& hash);
9192

src/net_processing.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16351635
LogPrintf("TXLOCKREQUEST -- Transaction Lock Request accepted, txid=%s, peer=%d\n",
16361636
tx.GetHash().ToString(), pfrom->id);
16371637
instantsend.AcceptLockRequest(txLockRequest);
1638+
instantsend.Vote(tx.GetHash(), connman);
16381639
}
16391640

16401641
mempool.check(pcoinsTip);

0 commit comments

Comments
 (0)