Skip to content

Commit 0ba4d19

Browse files
committed
wallet: Provide input bytes to COutput
1 parent d51f27d commit 0ba4d19

File tree

4 files changed

+10
-18
lines changed

4 files changed

+10
-18
lines changed

src/bench/coin_selection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void CoinSelection(benchmark::Bench& bench)
5858
// Create coins
5959
std::vector<COutput> coins;
6060
for (const auto& wtx : wtxs) {
61-
coins.emplace_back(wallet, *wtx, /*iIn=*/ 0, /*depth=*/ 6 * 24, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx->GetTxTime(), /*from_me=*/ true, /*use_max_sig_in=*/ false);
61+
coins.emplace_back(wallet, *wtx, /*iIn=*/ 0, /*depth=*/ 6 * 24, GetTxSpendSize(wallet, *wtx, 0), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx->GetTxTime(), /*from_me=*/ true);
6262
}
6363

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

src/wallet/spend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void AvailableCoins(const CWallet& wallet, std::vector<COutput>& vCoins, const C
193193
bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false;
194194
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
195195

196-
vCoins.emplace_back(wallet, wtx, i, nDepth, spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me, /*use_max_sig_in=*/ (coinControl && coinControl->fAllowWatchOnly));
196+
vCoins.emplace_back(wallet, wtx, i, nDepth, GetTxSpendSize(wallet, wtx, i, /*use_max_sig=*/ (coinControl && coinControl->fAllowWatchOnly)), spendable, solvable, safeTx, wtx.GetTxTime(), tx_from_me);
197197

198198
// Checks the sum amount of all UTXO's.
199199
if (nMinimumSumAmount != MAX_MONEY) {
@@ -278,7 +278,7 @@ std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
278278
CTxDestination address;
279279
if (ExtractDestination(FindNonChangeParentOutput(wallet, *wtx.tx, output.n).scriptPubKey, address)) {
280280
result[address].emplace_back(
281-
wallet, wtx, output.n, depth, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), CachedTxIsFromMe(wallet, wtx, ISMINE_ALL), /*use_max_sig_in=*/ false);
281+
wallet, wtx, output.n, depth, GetTxSpendSize(wallet, wtx, output.n), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ false, wtx.GetTxTime(), CachedTxIsFromMe(wallet, wtx, ISMINE_ALL));
282282
}
283283
}
284284
}

src/wallet/spend.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include <wallet/wallet.h>
1212

1313
namespace wallet {
14-
/** Get the marginal bytes if spending the specified output from this transaction */
14+
/** Get the marginal bytes if spending the specified output from this transaction.
15+
* use_max_sig indicates whether to use the maximum sized, 72 byte signature when calculating the
16+
* size of the input spend. This should only be set when watch-only outputs are allowed */
1517
int GetTxSpendSize(const CWallet& wallet, const CWalletTx& wtx, unsigned int out, bool use_max_sig = false);
1618

1719
class COutput
@@ -38,9 +40,6 @@ class COutput
3840
/** Whether we know how to spend this output, ignoring the lack of keys */
3941
bool solvable;
4042

41-
/** Whether to use the maximum sized, 72 byte signature when calculating the size of the input spend. This should only be set when watch-only outputs are allowed */
42-
bool use_max_sig;
43-
4443
/**
4544
* Whether this output is considered safe to spend. Unconfirmed transactions
4645
* from outside keys and unconfirmed replacement transactions are considered
@@ -54,24 +53,17 @@ class COutput
5453
/** Whether the transaction containing this output is sent from the owning wallet */
5554
bool from_me;
5655

57-
COutput(const CWallet& wallet, const CWalletTx& wtx, int iIn, int depth, bool spendable, bool solvable, bool safe, int64_t time, bool from_me, bool use_max_sig_in)
56+
COutput(const CWallet& wallet, const CWalletTx& wtx, int iIn, int depth, int input_bytes, bool spendable, bool solvable, bool safe, int64_t time, bool from_me)
5857
: tx(&wtx),
5958
i(iIn),
6059
depth(depth),
61-
input_bytes(-1),
60+
input_bytes(input_bytes),
6261
spendable(spendable),
6362
solvable(solvable),
64-
use_max_sig(use_max_sig_in),
6563
safe(safe),
6664
time(time),
6765
from_me(from_me)
68-
{
69-
// If known and signable by the given wallet, compute input_bytes
70-
// Failure will keep this value -1
71-
if (spendable) {
72-
input_bytes = GetTxSpendSize(wallet, wtx, i, use_max_sig);
73-
}
74-
}
66+
{}
7567

7668
std::string ToString() const;
7769

src/wallet/test/coinselector_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void add_coin(std::vector<COutput>& coins, CWallet& wallet, const CAmount
8888
auto ret = wallet.mapWallet.emplace(std::piecewise_construct, std::forward_as_tuple(txid), std::forward_as_tuple(MakeTransactionRef(std::move(tx)), TxStateInactive{}));
8989
assert(ret.second);
9090
CWalletTx& wtx = (*ret.first).second;
91-
coins.emplace_back(wallet, wtx, nInput, nAge, /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe, /*use_max_sig_in=*/ false);
91+
coins.emplace_back(wallet, wtx, nInput, nAge, GetTxSpendSize(wallet, wtx, nInput), /*spendable=*/ true, /*solvable=*/ true, /*safe=*/ true, wtx.GetTxTime(), fIsFromMe);
9292
}
9393

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

0 commit comments

Comments
 (0)