@ -43,7 +43,7 @@ public:
@@ -43,7 +43,7 @@ public:
return false ;
}
coin = it - > second ;
if ( coin . IsSpent ( ) & & insecure_randb ool( ) = = 0 ) {
if ( coin . IsSpent ( ) & & InsecureRandB ool( ) = = 0 ) {
// Randomly return false in case of an empty entry.
return false ;
}
@ -64,7 +64,7 @@ public:
@@ -64,7 +64,7 @@ public:
if ( it - > second . flags & CCoinsCacheEntry : : DIRTY ) {
// Same optimization used in CCoinsViewDB is to only write dirty entries.
map_ [ it - > first ] = it - > second . coin ;
if ( it - > second . coin . IsSpent ( ) & & insecure_randr ange( 3 ) = = 0 ) {
if ( it - > second . coin . IsSpent ( ) & & InsecureRandR ange( 3 ) = = 0 ) {
// Randomly delete empty entries on write.
map_ . erase ( it - > first ) ;
}
@ -139,31 +139,31 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
@@ -139,31 +139,31 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
std : : vector < uint256 > txids ;
txids . resize ( NUM_SIMULATION_ITERATIONS / 8 ) ;
for ( unsigned int i = 0 ; i < txids . size ( ) ; i + + ) {
txids [ i ] = insecure_r and256( ) ;
txids [ i ] = InsecureR and256( ) ;
}
for ( unsigned int i = 0 ; i < NUM_SIMULATION_ITERATIONS ; i + + ) {
// Do a random modification.
{
uint256 txid = txids [ insecure_randr ange( txids . size ( ) ) ] ; // txid we're going to modify in this iteration.
uint256 txid = txids [ InsecureRandR ange( txids . size ( ) ) ] ; // txid we're going to modify in this iteration.
Coin & coin = result [ COutPoint ( txid , 0 ) ] ;
const Coin & entry = ( insecure_randr ange( 500 ) = = 0 ) ? AccessByTxid ( * stack . back ( ) , txid ) : stack . back ( ) - > AccessCoin ( COutPoint ( txid , 0 ) ) ;
const Coin & entry = ( InsecureRandR ange( 500 ) = = 0 ) ? AccessByTxid ( * stack . back ( ) , txid ) : stack . back ( ) - > AccessCoin ( COutPoint ( txid , 0 ) ) ;
BOOST_CHECK ( coin = = entry ) ;
if ( insecure_randr ange( 5 ) = = 0 | | coin . IsSpent ( ) ) {
if ( InsecureRandR ange( 5 ) = = 0 | | coin . IsSpent ( ) ) {
Coin newcoin ;
newcoin . out . nValue = insecure_rand ( ) ;
newcoin . out . nValue = InsecureRand32 ( ) ;
newcoin . nHeight = 1 ;
if ( insecure_randr ange( 16 ) = = 0 & & coin . IsSpent ( ) ) {
newcoin . out . scriptPubKey . assign ( 1 + insecure_randb its( 6 ) , OP_RETURN ) ;
if ( InsecureRandR ange( 16 ) = = 0 & & coin . IsSpent ( ) ) {
newcoin . out . scriptPubKey . assign ( 1 + InsecureRandB its( 6 ) , OP_RETURN ) ;
BOOST_CHECK ( newcoin . out . scriptPubKey . IsUnspendable ( ) ) ;
added_an_unspendable_entry = true ;
} else {
newcoin . out . scriptPubKey . assign ( insecure_randb its( 6 ) , 0 ) ; // Random sizes so we can test memory usage accounting
newcoin . out . scriptPubKey . assign ( InsecureRandB its( 6 ) , 0 ) ; // Random sizes so we can test memory usage accounting
( coin . IsSpent ( ) ? added_an_entry : updated_an_entry ) = true ;
coin = newcoin ;
}
stack . back ( ) - > AddCoin ( COutPoint ( txid , 0 ) , std : : move ( newcoin ) , ! coin . IsSpent ( ) | | insecure_rand ( ) & 1 ) ;
stack . back ( ) - > AddCoin ( COutPoint ( txid , 0 ) , std : : move ( newcoin ) , ! coin . IsSpent ( ) | | InsecureRand32 ( ) & 1 ) ;
} else {
removed_an_entry = true ;
coin . Clear ( ) ;
@ -172,15 +172,15 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
@@ -172,15 +172,15 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
}
// One every 10 iterations, remove a random entry from the cache
if ( insecure_randr ange( 10 ) = = 0 ) {
COutPoint out ( txids [ insecure_rand ( ) % txids . size ( ) ] , 0 ) ;
int cacheid = insecure_rand ( ) % stack . size ( ) ;
if ( InsecureRandR ange( 10 ) = = 0 ) {
COutPoint out ( txids [ InsecureRand32 ( ) % txids . size ( ) ] , 0 ) ;
int cacheid = InsecureRand32 ( ) % stack . size ( ) ;
stack [ cacheid ] - > Uncache ( out ) ;
uncached_an_entry | = ! stack [ cacheid ] - > HaveCoinInCache ( out ) ;
}
// Once every 1000 iterations and at the end, verify the full cache.
if ( insecure_randr ange( 1000 ) = = 1 | | i = = NUM_SIMULATION_ITERATIONS - 1 ) {
if ( InsecureRandR ange( 1000 ) = = 1 | | i = = NUM_SIMULATION_ITERATIONS - 1 ) {
for ( auto it = result . begin ( ) ; it ! = result . end ( ) ; it + + ) {
bool have = stack . back ( ) - > HaveCoin ( it - > first ) ;
const Coin & coin = stack . back ( ) - > AccessCoin ( it - > first ) ;
@ -198,22 +198,22 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
@@ -198,22 +198,22 @@ BOOST_AUTO_TEST_CASE(coins_cache_simulation_test)
}
}
if ( insecure_randr ange( 100 ) = = 0 ) {
if ( InsecureRandR ange( 100 ) = = 0 ) {
// Every 100 iterations, flush an intermediate cache
if ( stack . size ( ) > 1 & & insecure_randb ool( ) = = 0 ) {
unsigned int flushIndex = insecure_randr ange( stack . size ( ) - 1 ) ;
if ( stack . size ( ) > 1 & & InsecureRandB ool( ) = = 0 ) {
unsigned int flushIndex = InsecureRandR ange( stack . size ( ) - 1 ) ;
stack [ flushIndex ] - > Flush ( ) ;
}
}
if ( insecure_randr ange( 100 ) = = 0 ) {
if ( InsecureRandR ange( 100 ) = = 0 ) {
// Every 100 iterations, change the cache stack.
if ( stack . size ( ) > 0 & & insecure_randb ool( ) = = 0 ) {
if ( stack . size ( ) > 0 & & InsecureRandB ool( ) = = 0 ) {
//Remove the top cache
stack . back ( ) - > Flush ( ) ;
delete stack . back ( ) ;
stack . pop_back ( ) ;
}
if ( stack . size ( ) = = 0 | | ( stack . size ( ) < 4 & & insecure_randb ool( ) ) ) {
if ( stack . size ( ) = = 0 | | ( stack . size ( ) < 4 & & InsecureRandB ool( ) ) ) {
//Add a new cache
CCoinsView * tip = & base ;
if ( stack . size ( ) > 0 ) {
@ -253,7 +253,7 @@ UtxoData utxoData;
@@ -253,7 +253,7 @@ UtxoData utxoData;
UtxoData : : iterator FindRandomFrom ( const std : : set < COutPoint > & utxoSet ) {
assert ( utxoSet . size ( ) ) ;
auto utxoSetIt = utxoSet . lower_bound ( COutPoint ( insecure_r and256( ) , 0 ) ) ;
auto utxoSetIt = utxoSet . lower_bound ( COutPoint ( InsecureR and256( ) , 0 ) ) ;
if ( utxoSetIt = = utxoSet . end ( ) ) {
utxoSetIt = utxoSet . begin ( ) ;
}
@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
@@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
std : : set < COutPoint > utxoset ;
for ( unsigned int i = 0 ; i < NUM_SIMULATION_ITERATIONS ; i + + ) {
uint32_t randiter = insecure_rand ( ) ;
uint32_t randiter = InsecureRand32 ( ) ;
// 19/20 txs add a new transaction
if ( randiter % 20 < 19 ) {
@ -294,14 +294,14 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
@@ -294,14 +294,14 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
tx . vin . resize ( 1 ) ;
tx . vout . resize ( 1 ) ;
tx . vout [ 0 ] . nValue = i ; //Keep txs unique unless intended to duplicate
tx . vout [ 0 ] . scriptPubKey . assign ( insecure_rand ( ) & 0x3F , 0 ) ; // Random sizes so we can test memory usage accounting
unsigned int height = insecure_rand ( ) ;
tx . vout [ 0 ] . scriptPubKey . assign ( InsecureRand32 ( ) & 0x3F , 0 ) ; // Random sizes so we can test memory usage accounting
unsigned int height = InsecureRand32 ( ) ;
Coin old_coin ;
// 2/20 times create a new coinbase
if ( randiter % 20 < 2 | | coinbase_coins . size ( ) < 10 ) {
// 1/10 of those times create a duplicate coinbase
if ( insecure_randr ange( 10 ) = = 0 & & coinbase_coins . size ( ) ) {
if ( InsecureRandR ange( 10 ) = = 0 & & coinbase_coins . size ( ) ) {
auto utxod = FindRandomFrom ( coinbase_coins ) ;
// Reuse the exact same coinbase
tx = std : : get < 0 > ( utxod - > second ) ;
@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
@@ -411,7 +411,7 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
}
// Once every 1000 iterations and at the end, verify the full cache.
if ( insecure_randr ange( 1000 ) = = 1 | | i = = NUM_SIMULATION_ITERATIONS - 1 ) {
if ( InsecureRandR ange( 1000 ) = = 1 | | i = = NUM_SIMULATION_ITERATIONS - 1 ) {
for ( auto it = result . begin ( ) ; it ! = result . end ( ) ; it + + ) {
bool have = stack . back ( ) - > HaveCoin ( it - > first ) ;
const Coin & coin = stack . back ( ) - > AccessCoin ( it - > first ) ;
@ -421,31 +421,31 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
@@ -421,31 +421,31 @@ BOOST_AUTO_TEST_CASE(updatecoins_simulation_test)
}
// One every 10 iterations, remove a random entry from the cache
if ( utxoset . size ( ) > 1 & & insecure_randr ange( 30 ) = = 0 ) {
stack [ insecure_rand ( ) % stack . size ( ) ] - > Uncache ( FindRandomFrom ( utxoset ) - > first ) ;
if ( utxoset . size ( ) > 1 & & InsecureRandR ange( 30 ) = = 0 ) {
stack [ InsecureRand32 ( ) % stack . size ( ) ] - > Uncache ( FindRandomFrom ( utxoset ) - > first ) ;
}
if ( disconnected_coins . size ( ) > 1 & & insecure_randr ange( 30 ) = = 0 ) {
stack [ insecure_rand ( ) % stack . size ( ) ] - > Uncache ( FindRandomFrom ( disconnected_coins ) - > first ) ;
if ( disconnected_coins . size ( ) > 1 & & InsecureRandR ange( 30 ) = = 0 ) {
stack [ InsecureRand32 ( ) % stack . size ( ) ] - > Uncache ( FindRandomFrom ( disconnected_coins ) - > first ) ;
}
if ( duplicate_coins . size ( ) > 1 & & insecure_randr ange( 30 ) = = 0 ) {
stack [ insecure_rand ( ) % stack . size ( ) ] - > Uncache ( FindRandomFrom ( duplicate_coins ) - > first ) ;
if ( duplicate_coins . size ( ) > 1 & & InsecureRandR ange( 30 ) = = 0 ) {
stack [ InsecureRand32 ( ) % stack . size ( ) ] - > Uncache ( FindRandomFrom ( duplicate_coins ) - > first ) ;
}
if ( insecure_randr ange( 100 ) = = 0 ) {
if ( InsecureRandR ange( 100 ) = = 0 ) {
// Every 100 iterations, flush an intermediate cache
if ( stack . size ( ) > 1 & & insecure_randb ool( ) = = 0 ) {
unsigned int flushIndex = insecure_randr ange( stack . size ( ) - 1 ) ;
if ( stack . size ( ) > 1 & & InsecureRandB ool( ) = = 0 ) {
unsigned int flushIndex = InsecureRandR ange( stack . size ( ) - 1 ) ;
stack [ flushIndex ] - > Flush ( ) ;
}
}
if ( insecure_randr ange( 100 ) = = 0 ) {
if ( InsecureRandR ange( 100 ) = = 0 ) {
// Every 100 iterations, change the cache stack.
if ( stack . size ( ) > 0 & & insecure_randb ool( ) = = 0 ) {
if ( stack . size ( ) > 0 & & InsecureRandB ool( ) = = 0 ) {
stack . back ( ) - > Flush ( ) ;
delete stack . back ( ) ;
stack . pop_back ( ) ;
}
if ( stack . size ( ) = = 0 | | ( stack . size ( ) < 4 & & insecure_randb ool( ) ) ) {
if ( stack . size ( ) = = 0 | | ( stack . size ( ) < 4 & & InsecureRandB ool( ) ) ) {
CCoinsView * tip = & base ;
if ( stack . size ( ) > 0 ) {
tip = stack . back ( ) ;