@@ -585,7 +585,8 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256&
585
585
* Set a height-based locktime for new transactions (uses the height of the
586
586
* current chain tip unless we are not synced with the current chain
587
587
*/
588
- static void DiscourageFeeSniping (CMutableTransaction& tx, interfaces::Chain& chain, const uint256& block_hash, int block_height)
588
+ static void DiscourageFeeSniping (CMutableTransaction& tx, FastRandomContext& rng_fast,
589
+ interfaces::Chain& chain, const uint256& block_hash, int block_height)
589
590
{
590
591
// All inputs must be added by now
591
592
assert (!tx.vin .empty ());
@@ -616,8 +617,8 @@ static void DiscourageFeeSniping(CMutableTransaction& tx, interfaces::Chain& cha
616
617
// that transactions that are delayed after signing for whatever reason,
617
618
// e.g. high-latency mix networks and some CoinJoin implementations, have
618
619
// better privacy.
619
- if (GetRandInt (10 ) == 0 ) {
620
- tx.nLockTime = std::max (0 , int (tx.nLockTime ) - GetRandInt ( 100 ));
620
+ if (rng_fast. randrange (10 ) == 0 ) {
621
+ tx.nLockTime = std::max (0 , int (tx.nLockTime ) - int (rng_fast. randrange ( 100 ) ));
621
622
}
622
623
} else {
623
624
// If our chain is lagging behind, we can't discourage fee sniping nor help
@@ -653,6 +654,7 @@ static bool CreateTransactionInternal(
653
654
{
654
655
AssertLockHeld (wallet.cs_wallet );
655
656
657
+ FastRandomContext rng_fast;
656
658
CMutableTransaction txNew; // The resulting transaction that we make
657
659
658
660
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
@@ -782,10 +784,9 @@ static bool CreateTransactionInternal(
782
784
assert (change_and_fee >= 0 );
783
785
CTxOut newTxOut (change_and_fee, scriptChange);
784
786
785
- if (nChangePosInOut == -1 )
786
- {
787
+ if (nChangePosInOut == -1 ) {
787
788
// Insert change txn at random position:
788
- nChangePosInOut = GetRandInt (txNew.vout .size ()+ 1 );
789
+ nChangePosInOut = rng_fast. randrange (txNew.vout .size () + 1 );
789
790
}
790
791
else if ((unsigned int )nChangePosInOut > txNew.vout .size ())
791
792
{
@@ -811,7 +812,7 @@ static bool CreateTransactionInternal(
811
812
for (const auto & coin : selected_coins) {
812
813
txNew.vin .push_back (CTxIn (coin.outpoint , CScript (), nSequence));
813
814
}
814
- DiscourageFeeSniping (txNew, wallet.chain (), wallet.GetLastBlockHash (), wallet.GetLastBlockHeight ());
815
+ DiscourageFeeSniping (txNew, rng_fast, wallet.chain (), wallet.GetLastBlockHash (), wallet.GetLastBlockHeight ());
815
816
816
817
// Calculate the transaction fee
817
818
TxSize tx_sizes = CalculateMaximumSignedTxSize (CTransaction (txNew), &wallet, &coin_control);
0 commit comments