diff options
author | Andrew Chow <achow101-github@achow101.com> | 2022-06-16 14:11:12 -0400 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2022-06-16 14:11:19 -0400 |
commit | b0c830634907076480528f1829e212eeb0e764e3 (patch) | |
tree | f4bdee7043ea7829f428ac90e63fddc74a5db121 /src/wallet/spend.cpp | |
parent | 0ea92cad5274f3939f09d6890da31a21b8481282 (diff) | |
parent | 7832e9438f5c66b88f60676d14e1e11d669eb109 (diff) | |
download | bitcoin-b0c830634907076480528f1829e212eeb0e764e3.tar.xz |
Merge bitcoin/bitcoin#24649: wallet: do not count wallet utxos as external
7832e9438f5c66b88f60676d14e1e11d669eb109 test: fundrawtransaction preset input weight calculation (S3RK)
c3981e379fa088aa7aa03b2f505342a5b3bc3436 wallet: do not count wallet utxos as external (S3RK)
Pull request description:
Correctly differentiating between external vs non-external utxos in coin control produces more accurate weight and fee estimations.
Weight for external utxos is estimated based on the maximum signature size, while for the wallet utxos we expect minimal signature due to signature grinding.
ACKs for top commit:
achow101:
re-ACK 7832e9438f5c66b88f60676d14e1e11d669eb109
Xekyo:
re-ACK 7832e9438f5c66b88f60676d14e1e11d669eb109
furszy:
ACK 7832e943
Tree-SHA512: bb5635b0bd85fa9a76922a53ad3fa062286424c06a695a0e87407c665713e80a33555b644fbb13bcc1ab503dcd7f53aacbdc368d69ac0ecff8005603623ac94f
Diffstat (limited to 'src/wallet/spend.cpp')
-rw-r--r-- | src/wallet/spend.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp index 6f79ae4e9b..ce99aeefe5 100644 --- a/src/wallet/spend.cpp +++ b/src/wallet/spend.cpp @@ -1023,14 +1023,28 @@ bool FundTransaction(CWallet& wallet, CMutableTransaction& tx, CAmount& nFeeRet, coinControl.fAllowOtherInputs = true; - for (const CTxIn& txin : tx.vin) { - coinControl.Select(txin.prevout); - } - // Acquire the locks to prevent races to the new locked unspents between the // CreateTransaction call and LockCoin calls (when lockUnspents is true). LOCK(wallet.cs_wallet); + // Fetch specified UTXOs from the UTXO set to get the scriptPubKeys and values of the outputs being selected + // and to match with the given solving_data. Only used for non-wallet outputs. + std::map<COutPoint, Coin> coins; + for (const CTxIn& txin : tx.vin) { + coins[txin.prevout]; // Create empty map entry keyed by prevout. + } + wallet.chain().findCoins(coins); + + for (const CTxIn& txin : tx.vin) { + // if it's not in the wallet and corresponding UTXO is found than select as external output + const auto& outPoint = txin.prevout; + if (wallet.mapWallet.find(outPoint.hash) == wallet.mapWallet.end() && !coins[outPoint].out.IsNull()) { + coinControl.SelectExternal(outPoint, coins[outPoint].out); + } else { + coinControl.Select(outPoint); + } + } + FeeCalculation fee_calc_out; std::optional<CreatedTransactionResult> txr = CreateTransaction(wallet, vecSend, nChangePosInOut, error, coinControl, fee_calc_out, false); if (!txr) return false; |