]> Git Repo - VerusCoin.git/blobdiff - src/cheatcatcher.cpp
Fix stakeguard validation
[VerusCoin.git] / src / cheatcatcher.cpp
index ab4af2141998ecf438e3d50efd04b9de00f22e74..89c2bbe417b8507e4144623aed1822464926568c 100644 (file)
@@ -27,10 +27,10 @@ uint32_t CCheatList::Prune(uint32_t height)
     pair<multimap<const uint32_t, CTxHolder>::iterator, multimap<const uint32_t, CTxHolder>::iterator> range;
     vector<CTxHolder *> toPrune;
 
-    if (height > 0 && NetworkUpgradeActive(height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING))
+    if (height > 0 && Params().GetConsensus().NetworkUpgradeActive(height, Consensus::UPGRADE_SAPLING))
     {
         LOCK(cs_cheat);
-        for (auto it = orderedCheatCandidates.begin(); it != orderedCheatCandidates.end() && it->second.height <= height; it--)
+        for (auto it = orderedCheatCandidates.begin(); it != orderedCheatCandidates.end() && it->second.height <= height; it++)
         {
             toPrune.push_back(&it->second);
         }
@@ -126,9 +126,9 @@ bool CCheatList::IsUTXOInList(COutPoint _utxo, uint32_t height)
     return false;
 }
 
-bool CCheatList::Add(const CTxHolder &txh)
+void CCheatList::Add(const CTxHolder &txh)
 {
-    if (NetworkUpgradeActive(txh.height, Params().GetConsensus(), Consensus::UPGRADE_SAPLING))
+    if (Params().GetConsensus().NetworkUpgradeActive(txh.height, Consensus::UPGRADE_SAPLING))
     {
         LOCK(cs_cheat);
         auto it = orderedCheatCandidates.insert(pair<const uint32_t, CTxHolder>(txh.height, txh));
@@ -141,30 +141,42 @@ void CCheatList::Remove(const CTxHolder &txh)
 {
     // first narrow by source tx, then compare with tx hash
     uint32_t count;
-    pair<multimap<const uint256, CTxHolder *>::iterator, multimap<const uint256, CTxHolder *>::iterator> range;
     vector<multimap<const uint256, CTxHolder *>::iterator> utxoPrune;
     vector<multimap<const int32_t, CTxHolder>::iterator> heightPrune;
+    uint256 hash = txh.tx.GetHash();
 
     {
         LOCK(cs_cheat);
-        range = indexedCheatCandidates.equal_range(txh.utxo);
-        for (auto it = range.first; it != range.second; it++)
+        auto range = indexedCheatCandidates.equal_range(txh.utxo);
+        auto it = range.first;
+        for ( ; it != range.second; it++)
         {
-            uint256 hash = txh.tx.GetHash();
             if (hash == it->second->tx.GetHash())
+            {
+                utxoPrune.push_back(it);
+            }
+            // if we haven't yet looked at this height, look, otherwise skip
+            int dupHeight = -1;
+            for (auto iter : utxoPrune)
+            {
+                if (iter->second->height == it->second->height)
+                    dupHeight++;
+            }
+            // only remove matching entries by height once
+            if (!dupHeight)
             {
                 auto hrange = orderedCheatCandidates.equal_range(it->second->height);
                 for (auto hit = hrange.first; hit != hrange.second; hit++)
                 {
-                    if (hit->second.tx.GetHash() == hash)
+                    if (hit->second.tx.GetHash() == hash && hit->second.utxo == it->second->utxo)
                     {
                         // add and remove them together
-                        utxoPrune.push_back(it);
                         heightPrune.push_back(hit);
                     }
                 }
             }
         }
+
         for (auto it : utxoPrune)
         {
             indexedCheatCandidates.erase(it);
This page took 0.025724 seconds and 4 git commands to generate.