mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
wallet: Pass FastRandomContext& to DiscourageFeeSniping
This commit is contained in:
parent
25d045a9ec
commit
77773b061c
1 changed files with 8 additions and 7 deletions
|
@ -585,7 +585,8 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, const uint256&
|
||||||
* Set a height-based locktime for new transactions (uses the height of the
|
* Set a height-based locktime for new transactions (uses the height of the
|
||||||
* current chain tip unless we are not synced with the current chain
|
* current chain tip unless we are not synced with the current chain
|
||||||
*/
|
*/
|
||||||
static void DiscourageFeeSniping(CMutableTransaction& tx, interfaces::Chain& chain, const uint256& block_hash, int block_height)
|
static void DiscourageFeeSniping(CMutableTransaction& tx, FastRandomContext& rng_fast,
|
||||||
|
interfaces::Chain& chain, const uint256& block_hash, int block_height)
|
||||||
{
|
{
|
||||||
// All inputs must be added by now
|
// All inputs must be added by now
|
||||||
assert(!tx.vin.empty());
|
assert(!tx.vin.empty());
|
||||||
|
@ -616,8 +617,8 @@ static void DiscourageFeeSniping(CMutableTransaction& tx, interfaces::Chain& cha
|
||||||
// that transactions that are delayed after signing for whatever reason,
|
// that transactions that are delayed after signing for whatever reason,
|
||||||
// e.g. high-latency mix networks and some CoinJoin implementations, have
|
// e.g. high-latency mix networks and some CoinJoin implementations, have
|
||||||
// better privacy.
|
// better privacy.
|
||||||
if (GetRandInt(10) == 0) {
|
if (rng_fast.randrange(10) == 0) {
|
||||||
tx.nLockTime = std::max(0, int(tx.nLockTime) - GetRandInt(100));
|
tx.nLockTime = std::max(0, int(tx.nLockTime) - int(rng_fast.randrange(100)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If our chain is lagging behind, we can't discourage fee sniping nor help
|
// If our chain is lagging behind, we can't discourage fee sniping nor help
|
||||||
|
@ -653,6 +654,7 @@ static bool CreateTransactionInternal(
|
||||||
{
|
{
|
||||||
AssertLockHeld(wallet.cs_wallet);
|
AssertLockHeld(wallet.cs_wallet);
|
||||||
|
|
||||||
|
FastRandomContext rng_fast;
|
||||||
CMutableTransaction txNew; // The resulting transaction that we make
|
CMutableTransaction txNew; // The resulting transaction that we make
|
||||||
|
|
||||||
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
|
CoinSelectionParams coin_selection_params; // Parameters for coin selection, init with dummy
|
||||||
|
@ -782,10 +784,9 @@ static bool CreateTransactionInternal(
|
||||||
assert(change_and_fee >= 0);
|
assert(change_and_fee >= 0);
|
||||||
CTxOut newTxOut(change_and_fee, scriptChange);
|
CTxOut newTxOut(change_and_fee, scriptChange);
|
||||||
|
|
||||||
if (nChangePosInOut == -1)
|
if (nChangePosInOut == -1) {
|
||||||
{
|
|
||||||
// Insert change txn at random position:
|
// Insert change txn at random position:
|
||||||
nChangePosInOut = GetRandInt(txNew.vout.size()+1);
|
nChangePosInOut = rng_fast.randrange(txNew.vout.size() + 1);
|
||||||
}
|
}
|
||||||
else if ((unsigned int)nChangePosInOut > txNew.vout.size())
|
else if ((unsigned int)nChangePosInOut > txNew.vout.size())
|
||||||
{
|
{
|
||||||
|
@ -811,7 +812,7 @@ static bool CreateTransactionInternal(
|
||||||
for (const auto& coin : selected_coins) {
|
for (const auto& coin : selected_coins) {
|
||||||
txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
|
txNew.vin.push_back(CTxIn(coin.outpoint, CScript(), nSequence));
|
||||||
}
|
}
|
||||||
DiscourageFeeSniping(txNew, wallet.chain(), wallet.GetLastBlockHash(), wallet.GetLastBlockHeight());
|
DiscourageFeeSniping(txNew, rng_fast, wallet.chain(), wallet.GetLastBlockHash(), wallet.GetLastBlockHeight());
|
||||||
|
|
||||||
// Calculate the transaction fee
|
// Calculate the transaction fee
|
||||||
TxSize tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), &wallet, &coin_control);
|
TxSize tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), &wallet, &coin_control);
|
||||||
|
|
Loading…
Add table
Reference in a new issue