@@ -43,7 +43,7 @@ class CCoinsViewTest : public CCoinsView
43
43
return false ;
44
44
}
45
45
coin = it->second ;
46
- if (coin.IsSpent () && insecure_randbool () == 0 ) {
46
+ if (coin.IsSpent () && InsecureRandBool () == 0 ) {
47
47
// Randomly return false in case of an empty entry.
48
48
return false ;
49
49
}
@@ -64,7 +64,7 @@ class CCoinsViewTest : public CCoinsView
64
64
if (it->second .flags & CCoinsCacheEntry::DIRTY) {
65
65
// Same optimization used in CCoinsViewDB is to only write dirty entries.
66
66
map_[it->first ] = it->second .coin ;
67
- if (it->second .coin .IsSpent () && insecure_randrange (3 ) == 0 ) {
67
+ if (it->second .coin .IsSpent () && InsecureRandRange (3 ) == 0 ) {
68
68
// Randomly delete empty entries on write.
69
69
map_.erase (it->first );
70
70
}
@@ -139,31 +139,31 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
139
139
std::vector<uint256> txids;
140
140
txids.resize (NUM_SIMULATION_ITERATIONS / 8 );
141
141
for (unsigned int i = 0 ; i < txids.size (); i++) {
142
- txids[i] = insecure_rand256 ();
142
+ txids[i] = InsecureRand256 ();
143
143
}
144
144
145
145
for (unsigned int i = 0 ; i < NUM_SIMULATION_ITERATIONS; i++) {
146
146
// Do a random modification.
147
147
{
148
- uint256 txid = txids[insecure_randrange (txids.size ())]; // txid we're going to modify in this iteration.
148
+ uint256 txid = txids[InsecureRandRange (txids.size ())]; // txid we're going to modify in this iteration.
149
149
Coin& coin = result[COutPoint (txid, 0 )];
150
- const Coin& entry = (insecure_randrange (500 ) == 0 ) ? AccessByTxid (*stack.back (), txid) : stack.back ()->AccessCoin (COutPoint (txid, 0 ));
150
+ const Coin& entry = (InsecureRandRange (500 ) == 0 ) ? AccessByTxid (*stack.back (), txid) : stack.back ()->AccessCoin (COutPoint (txid, 0 ));
151
151
BOOST_CHECK (coin == entry);
152
152
153
- if (insecure_randrange (5 ) == 0 || coin.IsSpent ()) {
153
+ if (InsecureRandRange (5 ) == 0 || coin.IsSpent ()) {
154
154
Coin newcoin;
155
- newcoin.out .nValue = insecure_rand ();
155
+ newcoin.out .nValue = InsecureRand32 ();
156
156
newcoin.nHeight = 1 ;
157
- if (insecure_randrange (16 ) == 0 && coin.IsSpent ()) {
158
- newcoin.out .scriptPubKey .assign (1 + insecure_randbits (6 ), OP_RETURN);
157
+ if (InsecureRandRange (16 ) == 0 && coin.IsSpent ()) {
158
+ newcoin.out .scriptPubKey .assign (1 + InsecureRandBits (6 ), OP_RETURN);
159
159
BOOST_CHECK (newcoin.out .scriptPubKey .IsUnspendable ());
160
160
added_an_unspendable_entry = true ;
161
161
} else {
162
- newcoin.out .scriptPubKey .assign (insecure_randbits (6 ), 0 ); // Random sizes so we can test memory usage accounting
162
+ newcoin.out .scriptPubKey .assign (InsecureRandBits (6 ), 0 ); // Random sizes so we can test memory usage accounting
163
163
(coin.IsSpent () ? added_an_entry : updated_an_entry) = true ;
164
164
coin = newcoin;
165
165
}
166
- stack.back ()->AddCoin (COutPoint (txid, 0 ), std::move (newcoin), !coin.IsSpent () || insecure_rand () & 1 );
166
+ stack.back ()->AddCoin (COutPoint (txid, 0 ), std::move (newcoin), !coin.IsSpent () || InsecureRand32 () & 1 );
167
167
} else {
168
168
removed_an_entry = true ;
169
169
coin.Clear ();
@@ -172,15 +172,15 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
172
172
}
173
173
174
174
// One every 10 iterations, remove a random entry from the cache
175
- if (insecure_randrange (10 ) == 0 ) {
176
- COutPoint out (txids[insecure_rand () % txids.size ()], 0 );
177
- int cacheid = insecure_rand () % stack.size ();
175
+ if (InsecureRandRange (10 ) == 0 ) {
176
+ COutPoint out (txids[InsecureRand32 () % txids.size ()], 0 );
177
+ int cacheid = InsecureRand32 () % stack.size ();
178
178
stack[cacheid]->Uncache (out);
179
179
uncached_an_entry |= !stack[cacheid]->HaveCoinInCache (out);
180
180
}
181
181
182
182
// Once every 1000 iterations and at the end, verify the full cache.
183
- if (insecure_randrange (1000 ) == 1 || i == NUM_SIMULATION_ITERATIONS - 1 ) {
183
+ if (InsecureRandRange (1000 ) == 1 || i == NUM_SIMULATION_ITERATIONS - 1 ) {
184
184
for (auto it = result.begin (); it != result.end (); it++) {
185
185
bool have = stack.back ()->HaveCoin (it->first );
186
186
const Coin& coin = stack.back ()->AccessCoin (it->first );
@@ -198,22 +198,22 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
198
198
}
199
199
}
200
200
201
- if (insecure_randrange (100 ) == 0 ) {
201
+ if (InsecureRandRange (100 ) == 0 ) {
202
202
// Every 100 iterations, flush an intermediate cache
203
- if (stack.size () > 1 && insecure_randbool () == 0 ) {
204
- unsigned int flushIndex = insecure_randrange (stack.size () - 1 );
203
+ if (stack.size () > 1 && InsecureRandBool () == 0 ) {
204
+ unsigned int flushIndex = InsecureRandRange (stack.size () - 1 );
205
205
stack[flushIndex]->Flush ();
206
206
}
207
207
}
208
- if (insecure_randrange (100 ) == 0 ) {
208
+ if (InsecureRandRange (100 ) == 0 ) {
209
209
// Every 100 iterations, change the cache stack.
210
- if (stack.size () > 0 && insecure_randbool () == 0 ) {
210
+ if (stack.size () > 0 && InsecureRandBool () == 0 ) {
211
211
// Remove the top cache
212
212
stack.back ()->Flush ();
213
213
delete stack.back ();
214
214
stack.pop_back ();
215
215
}
216
- if (stack.size () == 0 || (stack.size () < 4 && insecure_randbool ())) {
216
+ if (stack.size () == 0 || (stack.size () < 4 && InsecureRandBool ())) {
217
217
// Add a new cache
218
218
CCoinsView* tip = &base;
219
219
if (stack.size () > 0 ) {
@@ -253,7 +253,7 @@ UtxoData utxoData;
253
253
254
254
UtxoData::iterator FindRandomFrom (const std::set<COutPoint> &utxoSet) {
255
255
assert (utxoSet.size ());
256
- auto utxoSetIt = utxoSet.lower_bound (COutPoint (insecure_rand256 (), 0 ));
256
+ auto utxoSetIt = utxoSet.lower_bound (COutPoint (InsecureRand256 (), 0 ));
257
257
if (utxoSetIt == utxoSet.end ()) {
258
258
utxoSetIt = utxoSet.begin ();
259
259
}
@@ -286,22 +286,22 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
286
286
std::set<COutPoint> utxoset;
287
287
288
288
for (unsigned int i = 0 ; i < NUM_SIMULATION_ITERATIONS; i++) {
289
- uint32_t randiter = insecure_rand ();
289
+ uint32_t randiter = InsecureRand32 ();
290
290
291
291
// 19/20 txs add a new transaction
292
292
if (randiter % 20 < 19 ) {
293
293
CMutableTransaction tx;
294
294
tx.vin .resize (1 );
295
295
tx.vout .resize (1 );
296
296
tx.vout [0 ].nValue = i; // Keep txs unique unless intended to duplicate
297
- tx.vout [0 ].scriptPubKey .assign (insecure_rand () & 0x3F , 0 ); // Random sizes so we can test memory usage accounting
298
- unsigned int height = insecure_rand ();
297
+ tx.vout [0 ].scriptPubKey .assign (InsecureRand32 () & 0x3F , 0 ); // Random sizes so we can test memory usage accounting
298
+ unsigned int height = InsecureRand32 ();
299
299
Coin old_coin;
300
300
301
301
// 2/20 times create a new coinbase
302
302
if (randiter % 20 < 2 || coinbase_coins.size () < 10 ) {
303
303
// 1/10 of those times create a duplicate coinbase
304
- if (insecure_randrange (10 ) == 0 && coinbase_coins.size ()) {
304
+ if (InsecureRandRange (10 ) == 0 && coinbase_coins.size ()) {
305
305
auto utxod = FindRandomFrom (coinbase_coins);
306
306
// Reuse the exact same coinbase
307
307
tx = std::get<0 >(utxod->second );
@@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
411
411
}
412
412
413
413
// Once every 1000 iterations and at the end, verify the full cache.
414
- if (insecure_randrange (1000 ) == 1 || i == NUM_SIMULATION_ITERATIONS - 1 ) {
414
+ if (InsecureRandRange (1000 ) == 1 || i == NUM_SIMULATION_ITERATIONS - 1 ) {
415
415
for (auto it = result.begin (); it != result.end (); it++) {
416
416
bool have = stack.back ()->HaveCoin (it->first );
417
417
const Coin& coin = stack.back ()->AccessCoin (it->first );
@@ -421,31 +421,31 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
421
421
}
422
422
423
423
// One every 10 iterations, remove a random entry from the cache
424
- if (utxoset.size () > 1 && insecure_randrange (30 ) == 0 ) {
425
- stack[insecure_rand () % stack.size ()]->Uncache (FindRandomFrom (utxoset)->first );
424
+ if (utxoset.size () > 1 && InsecureRandRange (30 ) == 0 ) {
425
+ stack[InsecureRand32 () % stack.size ()]->Uncache (FindRandomFrom (utxoset)->first );
426
426
}
427
- if (disconnected_coins.size () > 1 && insecure_randrange (30 ) == 0 ) {
428
- stack[insecure_rand () % stack.size ()]->Uncache (FindRandomFrom (disconnected_coins)->first );
427
+ if (disconnected_coins.size () > 1 && InsecureRandRange (30 ) == 0 ) {
428
+ stack[InsecureRand32 () % stack.size ()]->Uncache (FindRandomFrom (disconnected_coins)->first );
429
429
}
430
- if (duplicate_coins.size () > 1 && insecure_randrange (30 ) == 0 ) {
431
- stack[insecure_rand () % stack.size ()]->Uncache (FindRandomFrom (duplicate_coins)->first );
430
+ if (duplicate_coins.size () > 1 && InsecureRandRange (30 ) == 0 ) {
431
+ stack[InsecureRand32 () % stack.size ()]->Uncache (FindRandomFrom (duplicate_coins)->first );
432
432
}
433
433
434
- if (insecure_randrange (100 ) == 0 ) {
434
+ if (InsecureRandRange (100 ) == 0 ) {
435
435
// Every 100 iterations, flush an intermediate cache
436
- if (stack.size () > 1 && insecure_randbool () == 0 ) {
437
- unsigned int flushIndex = insecure_randrange (stack.size () - 1 );
436
+ if (stack.size () > 1 && InsecureRandBool () == 0 ) {
437
+ unsigned int flushIndex = InsecureRandRange (stack.size () - 1 );
438
438
stack[flushIndex]->Flush ();
439
439
}
440
440
}
441
- if (insecure_randrange (100 ) == 0 ) {
441
+ if (InsecureRandRange (100 ) == 0 ) {
442
442
// Every 100 iterations, change the cache stack.
443
- if (stack.size () > 0 && insecure_randbool () == 0 ) {
443
+ if (stack.size () > 0 && InsecureRandBool () == 0 ) {
444
444
stack.back ()->Flush ();
445
445
delete stack.back ();
446
446
stack.pop_back ();
447
447
}
448
- if (stack.size () == 0 || (stack.size () < 4 && insecure_randbool ())) {
448
+ if (stack.size () == 0 || (stack.size () < 4 && InsecureRandBool ())) {
449
449
CCoinsView* tip = &base;
450
450
if (stack.size () > 0 ) {
451
451
tip = stack.back ();
0 commit comments