CreateTransaction calls KeepDestination on ReserveDestination before success

This commit is contained in:
Gregory Sanders 2019-06-13 14:12:01 -04:00
parent 6c1e45c4c4
commit d9ff862f2d
2 changed files with 4 additions and 8 deletions

View file

@ -281,9 +281,6 @@ Result CreateRateBumpTransaction(CWallet* wallet, const uint256& txid, const CCo
return Result::WALLET_ERROR; return Result::WALLET_ERROR;
} }
// If change key hasn't been ReturnKey'ed by this point, we take it out of keypool
reservedest.KeepDestination();
// Write back new fee if successful // Write back new fee if successful
new_fee = fee_ret; new_fee = fee_ret;

View file

@ -2674,9 +2674,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
if (nChangePosInOut != -1) { if (nChangePosInOut != -1) {
tx.vout.insert(tx.vout.begin() + nChangePosInOut, tx_new->vout[nChangePosInOut]); tx.vout.insert(tx.vout.begin() + nChangePosInOut, tx_new->vout[nChangePosInOut]);
// We don't have the normal Create/Commit cycle, and don't want to risk
// reusing change, so just remove the key from the keypool here.
reservedest.KeepDestination();
} }
// Copy output sizes from new transaction; they may have had the fee // Copy output sizes from new transaction; they may have had the fee
@ -3070,8 +3067,6 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
} }
} }
if (nChangePosInOut == -1) reservedest.ReturnDestination(); // Return any reserved address if we don't have change
// Shuffle selected coins and fill in final vin // Shuffle selected coins and fill in final vin
txNew.vin.clear(); txNew.vin.clear();
std::vector<CInputCoin> selected_coins(setCoins.begin(), setCoins.end()); std::vector<CInputCoin> selected_coins(setCoins.begin(), setCoins.end());
@ -3134,6 +3129,10 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
} }
} }
// Before we return success, we assume any change key will be used to prevent
// accidental re-use.
reservedest.KeepDestination();
WalletLogPrintf("Fee Calculation: Fee:%d Bytes:%u Needed:%d Tgt:%d (requested %d) Reason:\"%s\" Decay %.5f: Estimation: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out) Fail: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out)\n", WalletLogPrintf("Fee Calculation: Fee:%d Bytes:%u Needed:%d Tgt:%d (requested %d) Reason:\"%s\" Decay %.5f: Estimation: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out) Fail: (%g - %g) %.2f%% %.1f/(%.1f %d mem %.1f out)\n",
nFeeRet, nBytes, nFeeNeeded, feeCalc.returnedTarget, feeCalc.desiredTarget, StringForFeeReason(feeCalc.reason), feeCalc.est.decay, nFeeRet, nBytes, nFeeNeeded, feeCalc.returnedTarget, feeCalc.desiredTarget, StringForFeeReason(feeCalc.reason), feeCalc.est.decay,
feeCalc.est.pass.start, feeCalc.est.pass.end, feeCalc.est.pass.start, feeCalc.est.pass.end,