@@ -55,7 +55,7 @@ class CCoinsViewTest : public CCoinsView
55
55
56
56
bool BatchWrite (CCoinsMap& mapCoins, const uint256& hashBlock, bool erase = true ) override
57
57
{
58
- for (CCoinsMap::iterator it = mapCoins.begin (); it != mapCoins.end (); ) {
58
+ for (CCoinsMap::iterator it = mapCoins.begin (); it != mapCoins.end (); it = erase ? mapCoins. erase (it) : ++it ) {
59
59
if (it->second .flags & CCoinsCacheEntry::DIRTY) {
60
60
// Same optimization used in CCoinsViewDB is to only write dirty entries.
61
61
map_[it->first ] = it->second .coin ;
@@ -64,7 +64,6 @@ class CCoinsViewTest : public CCoinsView
64
64
map_.erase (it->first );
65
65
}
66
66
}
67
- mapCoins.erase (it++);
68
67
}
69
68
if (!hashBlock.IsNull ())
70
69
hashBestBlock_ = hashBlock;
@@ -126,6 +125,7 @@ void SimulationTest(CCoinsView* base, bool fake_best_block)
126
125
bool found_an_entry = false ;
127
126
bool missed_an_entry = false ;
128
127
bool uncached_an_entry = false ;
128
+ bool flushed_without_erase = false ;
129
129
130
130
// A simple map to track what we expect the cache stack to represent.
131
131
std::map<COutPoint, Coin> result;
@@ -228,15 +228,19 @@ void SimulationTest(CCoinsView* base, bool fake_best_block)
228
228
if (stack.size () > 1 && InsecureRandBool () == 0 ) {
229
229
unsigned int flushIndex = InsecureRandRange (stack.size () - 1 );
230
230
if (fake_best_block) stack[flushIndex]->SetBestBlock (InsecureRand256 ());
231
- BOOST_CHECK (stack[flushIndex]->Flush ());
231
+ bool should_erase = InsecureRandRange (4 ) < 3 ;
232
+ BOOST_CHECK (should_erase ? stack[flushIndex]->Flush () : stack[flushIndex]->Sync ());
233
+ flushed_without_erase |= !should_erase;
232
234
}
233
235
}
234
236
if (InsecureRandRange (100 ) == 0 ) {
235
237
// Every 100 iterations, change the cache stack.
236
238
if (stack.size () > 0 && InsecureRandBool () == 0 ) {
237
239
// Remove the top cache
238
240
if (fake_best_block) stack.back ()->SetBestBlock (InsecureRand256 ());
239
- BOOST_CHECK (stack.back ()->Flush ());
241
+ bool should_erase = InsecureRandRange (4 ) < 3 ;
242
+ BOOST_CHECK (should_erase ? stack.back ()->Flush () : stack.back ()->Sync ());
243
+ flushed_without_erase |= !should_erase;
240
244
delete stack.back ();
241
245
stack.pop_back ();
242
246
}
@@ -272,6 +276,7 @@ void SimulationTest(CCoinsView* base, bool fake_best_block)
272
276
BOOST_CHECK (found_an_entry);
273
277
BOOST_CHECK (missed_an_entry);
274
278
BOOST_CHECK (uncached_an_entry);
279
+ BOOST_CHECK (flushed_without_erase);
275
280
}
276
281
277
282
// Run the above simulation for multiple base types.
0 commit comments