Skip to content

Commit 881a3e2

Browse files
committed
Replace size/weight estimate tuple with struct for named fields
1 parent 3ad1b88 commit 881a3e2

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
190190
if (coin_control.m_feerate) {
191191
// The user provided a feeRate argument.
192192
// We calculate this here to avoid compiler warning on the cs_wallet lock
193-
const int64_t maxTxSize = CalculateMaximumSignedTxSize(*wtx.tx, &wallet).first;
193+
const int64_t maxTxSize{CalculateMaximumSignedTxSize(*wtx.tx, &wallet).vsize};
194194
Result res = CheckFeeRate(wallet, wtx, *new_coin_control.m_feerate, maxTxSize, errors);
195195
if (res != Result::OK) {
196196
return res;

src/wallet/wallet.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,15 +1627,14 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
16271627
return true;
16281628
}
16291629

1630-
// Returns pair of vsize and weight
1631-
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
1630+
TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
16321631
{
16331632
std::vector<CTxOut> txouts;
16341633
for (const CTxIn& input : tx.vin) {
16351634
const auto mi = wallet->mapWallet.find(input.prevout.hash);
16361635
// Can not estimate size without knowing the input details
16371636
if (mi == wallet->mapWallet.end()) {
1638-
return std::make_pair(-1, -1);
1637+
return TxSize{-1, -1};
16391638
}
16401639
assert(input.prevout.n < mi->second.tx->vout.size());
16411640
txouts.emplace_back(mi->second.tx->vout[input.prevout.n]);
@@ -1644,16 +1643,16 @@ std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx,
16441643
}
16451644

16461645
// txouts needs to be in the order of tx.vin
1647-
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
1646+
TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
16481647
{
16491648
CMutableTransaction txNew(tx);
16501649
if (!wallet->DummySignTx(txNew, txouts, use_max_sig)) {
1651-
return std::make_pair(-1, -1);
1650+
return TxSize{-1, -1};
16521651
}
16531652
CTransaction ctx(txNew);
16541653
int64_t vsize = GetVirtualTransactionSize(ctx);
16551654
int64_t weight = GetTransactionWeight(ctx);
1656-
return std::make_pair(vsize, weight);
1655+
return TxSize{vsize, weight};
16571656
}
16581657

16591658
int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* wallet, bool use_max_sig)
@@ -2820,7 +2819,7 @@ bool CWallet::CreateTransactionInternal(
28202819

28212820
CMutableTransaction txNew;
28222821
FeeCalculation feeCalc;
2823-
std::pair<int64_t, int64_t> tx_sizes;
2822+
TxSize tx_sizes;
28242823
int nBytes;
28252824
{
28262825
std::set<CInputCoin> setCoins;
@@ -2967,7 +2966,7 @@ bool CWallet::CreateTransactionInternal(
29672966

29682967
// Calculate the transaction fee
29692968
tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
2970-
nBytes = tx_sizes.first;
2969+
nBytes = tx_sizes.vsize;
29712970
if (nBytes < 0) {
29722971
error = _("Signing transaction failed");
29732972
return false;
@@ -2992,7 +2991,7 @@ bool CWallet::CreateTransactionInternal(
29922991

29932992
// Because we have dropped this change, the tx size and required fee will be different, so let's recalculate those
29942993
tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
2995-
nBytes = tx_sizes.first;
2994+
nBytes = tx_sizes.vsize;
29962995
fee_needed = coin_selection_params.m_effective_feerate.GetFee(nBytes);
29972996
}
29982997

@@ -3072,7 +3071,7 @@ bool CWallet::CreateTransactionInternal(
30723071

30733072
// Limit size
30743073
if ((sign && GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT) ||
3075-
(!sign && tx_sizes.second > MAX_STANDARD_TX_WEIGHT))
3074+
(!sign && tx_sizes.weight > MAX_STANDARD_TX_WEIGHT))
30763075
{
30773076
error = _("Transaction too large");
30783077
return false;

src/wallet/wallet.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,12 +1346,17 @@ class WalletRescanReserver
13461346
}
13471347
};
13481348

1349+
struct TxSize {
1350+
int64_t vsize{-1};
1351+
int64_t weight{-1};
1352+
};
1353+
13491354
/** Calculate the size of the transaction assuming all signatures are max size
13501355
* Use DummySignatureCreator, which inserts 71 byte signatures everywhere.
13511356
* NOTE: this requires that all inputs must be in mapWallet (eg the tx should
13521357
* be IsAllFromMe). */
1353-
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig = false) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
1354-
std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false);
1358+
TxSize CalculateMaximumSignedTxSize(const CTransaction& tx, const CWallet* wallet, bool use_max_sig = false) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
1359+
TxSize CalculateMaximumSignedTxSize(const CTransaction& tx, const CWallet* wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false);
13551360

13561361
//! Add wallet name to persistent configuration so it will be loaded on startup.
13571362
bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);

0 commit comments

Comments
 (0)