Skip to content

Commit d9ff862

Browse files
committed
CreateTransaction calls KeepDestination on ReserveDestination before success
1 parent 6c1e45c commit d9ff862

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/wallet/feebumper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,6 @@ Result CreateRateBumpTransaction(CWallet* wallet, const uint256& txid, const CCo
281281
return Result::WALLET_ERROR;
282282
}
283283

284-
// If change key hasn't been ReturnKey'ed by this point, we take it out of keypool
285-
reservedest.KeepDestination();
286-
287284
// Write back new fee if successful
288285
new_fee = fee_ret;
289286

src/wallet/wallet.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,9 +2674,6 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
26742674

26752675
if (nChangePosInOut != -1) {
26762676
tx.vout.insert(tx.vout.begin() + nChangePosInOut, tx_new->vout[nChangePosInOut]);
2677-
// We don't have the normal Create/Commit cycle, and don't want to risk
2678-
// reusing change, so just remove the key from the keypool here.
2679-
reservedest.KeepDestination();
26802677
}
26812678

26822679
// 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
30703067
}
30713068
}
30723069

3073-
if (nChangePosInOut == -1) reservedest.ReturnDestination(); // Return any reserved address if we don't have change
3074-
30753070
// Shuffle selected coins and fill in final vin
30763071
txNew.vin.clear();
30773072
std::vector<CInputCoin> selected_coins(setCoins.begin(), setCoins.end());
@@ -3134,6 +3129,10 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
31343129
}
31353130
}
31363131

3132+
// Before we return success, we assume any change key will be used to prevent
3133+
// accidental re-use.
3134+
reservedest.KeepDestination();
3135+
31373136
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",
31383137
nFeeRet, nBytes, nFeeNeeded, feeCalc.returnedTarget, feeCalc.desiredTarget, StringForFeeReason(feeCalc.reason), feeCalc.est.decay,
31393138
feeCalc.est.pass.start, feeCalc.est.pass.end,

0 commit comments

Comments
 (0)