Skip to content

Commit a94659c

Browse files
committed
wallet: replace GetTxSpendSize with CalculateMaximumSignedInputSize
1 parent b9122e9 commit a94659c

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

src/bench/coin_selection.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static void CoinSelection(benchmark::Bench& bench)
5858
// Create coins
5959
std::vector<COutput> coins;
6060
for (const auto& wtx : wtxs) {
61-
coins.emplace_back(COutPoint(wtx->GetHash(), 0), wtx->tx->vout.at(0), /*depth=*/6 * 24, GetTxSpendSize(wallet, *wtx, 0), /*spendable=*/true, /*solvable=*/true, /*safe=*/true, wtx->GetTxTime(), /*from_me=*/true, /*fees=*/ 0);
61+
const auto txout = wtx->tx->vout.at(0);
62+
coins.emplace_back(COutPoint(wtx->GetHash(), 0), txout, /*depth=*/6 * 24, CalculateMaximumSignedInputSize(txout, &wallet, false), /*spendable=*/true, /*solvable=*/true, /*safe=*/true, wtx->GetTxTime(), /*from_me=*/true, /*fees=*/ 0);
6263
}
6364

6465
const CoinEligibilityFilter filter_standard(1, 6, 0);

src/wallet/spend.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ using interfaces::FoundBlock;
2727
namespace wallet {
2828
static constexpr size_t OUTPUT_GROUP_MAX_ENTRIES{100};
2929

30-
int GetTxSpendSize(const CWallet& wallet, const CWalletTx& wtx, unsigned int out, bool use_max_sig)
31-
{
32-
return CalculateMaximumSignedInputSize(wtx.tx->vout[out], &wallet, use_max_sig);
33-
}
34-
3530
int CalculateMaximumSignedInputSize(const CTxOut& txout, const SigningProvider* provider, bool use_max_sig)
3631
{
3732
CMutableTransaction txn;
@@ -198,7 +193,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
198193
// Filter by spendable outputs only
199194
if (!spendable && only_spendable) continue;
200195

201-
int input_bytes = GetTxSpendSize(wallet, wtx, i, (coinControl && coinControl->fAllowWatchOnly));
196+
int input_bytes = CalculateMaximumSignedInputSize(output, provider.get(), coinControl && coinControl->fAllowWatchOnly);
202197
result.coins.emplace_back(outpoint, output, nDepth, input_bytes, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, feerate);
203198
result.total_amount += output.nValue;
204199

@@ -289,8 +284,9 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
289284
) {
290285
CTxDestination address;
291286
if (ExtractDestination(FindNonChangeParentOutput(wallet, *wtx.tx, output.n).scriptPubKey, address)) {
287+
const auto out = wtx.tx->vout.at(output.n);
292288
result[address].emplace_back(
293-
COutPoint(wtx.GetHash(), output.n), wtx.tx->vout.at(output.n), depth, GetTxSpendSize(wallet, wtx, output.n), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), CachedTxIsFromMe(wallet, wtx, ISMINE_ALL));
289+
COutPoint(wtx.GetHash(), output.n), out, depth, CalculateMaximumSignedInputSize(out, &wallet, false), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), CachedTxIsFromMe(wallet, wtx, ISMINE_ALL));
294290
}
295291
}
296292
}
@@ -447,7 +443,7 @@ std::optional<SelectionResult> SelectCoins(const CWallet& wallet, const std::vec
447443
if (ptr_wtx->tx->vout.size() <= outpoint.n) {
448444
return std::nullopt;
449445
}
450-
input_bytes = GetTxSpendSize(wallet, *ptr_wtx, outpoint.n, false);
446+
input_bytes = CalculateMaximumSignedInputSize(ptr_wtx->tx->vout[outpoint.n], &wallet, false);
451447
txout = ptr_wtx->tx->vout.at(outpoint.n);
452448
} else {
453449
// The input is external. We did not find the tx in mapWallet.

src/wallet/spend.h

-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ namespace wallet {
1616
/** Get the marginal bytes if spending the specified output from this transaction.
1717
* use_max_sig indicates whether to use the maximum sized, 72 byte signature when calculating the
1818
* size of the input spend. This should only be set when watch-only outputs are allowed */
19-
int GetTxSpendSize(const CWallet& wallet, const CWalletTx& wtx, unsigned int out, bool use_max_sig = false);
20-
21-
//Get the marginal bytes of spending the specified output
2219
int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* pwallet, bool use_max_sig = false);
2320
int CalculateMaximumSignedInputSize(const CTxOut& txout, const SigningProvider* pwallet, bool use_max_sig = false);
2421

src/wallet/test/coinselector_tests.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
8686
auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)), TxStateInactive{}));
8787
assert(ret.second);
8888
CWalletTx& wtx = (*ret.first).second;
89-
coins.emplace_back(COutPoint(wtx.GetHash(), nInput), wtx.tx->vout.at(nInput), nAge, GetTxSpendSize(wallet, wtx, nInput), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe, feerate);
89+
const auto txout = wtx.tx->vout.at(nInput);
90+
coins.emplace_back(COutPoint(wtx.GetHash(), nInput), txout, nAge, CalculateMaximumSignedInputSize(txout, &wallet, false), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe, feerate);
9091
}
9192

9293
/** Check if SelectionResult a is equivalent to SelectionResult b.

0 commit comments

Comments
 (0)