aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2021-05-26 14:06:52 +0800
committerfanquake <fanquake@gmail.com>2021-05-26 14:24:50 +0800
commit7aa41fc58196843bc021ab06a7d3f37189b4a871 (patch)
treef2d1724f4fbe5129c7c0abb41375a8d412cdc3db /src
parent48c86eca02030827a0bbe7159e9a452d1ae1e3fc (diff)
parent881a3e2e17c5a6fdffb16a47a2eaff9029f261e5 (diff)
Merge bitcoin/bitcoin#22042: Replace size/weight estimate tuple with struct for named fields
881a3e2e17c5a6fdffb16a47a2eaff9029f261e5 Replace size/weight estimate tuple with struct for named fields (Gregory Sanders) Pull request description: For clarity of return values of size estimation functions. ACKs for top commit: MarcoFalke: review ACK 881a3e2e17c5a6fdffb16a47a2eaff9029f261e5 practicalswift: cr ACK 881a3e2e17c5a6fdffb16a47a2eaff9029f261e5 Tree-SHA512: 9aa97e3774fcaf1e5b905259418d827051325c2ad76d6c7388ad7c687c605c024a6c5d2f7e9565f4c180ad1a9f6b179557fcb8b23371ff1a4f3b81300ac1f3d1
Diffstat (limited to 'src')
-rw-r--r--src/wallet/feebumper.cpp2
-rw-r--r--src/wallet/wallet.cpp19
-rw-r--r--src/wallet/wallet.h9
3 files changed, 17 insertions, 13 deletions
diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp
index 08adf09df4..30fef50c3b 100644
--- a/src/wallet/feebumper.cpp
+++ b/src/wallet/feebumper.cpp
@@ -190,7 +190,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
if (coin_control.m_feerate) {
// The user provided a feeRate argument.
// We calculate this here to avoid compiler warning on the cs_wallet lock
- const int64_t maxTxSize = CalculateMaximumSignedTxSize(*wtx.tx, &wallet).first;
+ const int64_t maxTxSize{CalculateMaximumSignedTxSize(*wtx.tx, &wallet).vsize};
Result res = CheckFeeRate(wallet, wtx, *new_coin_control.m_feerate, maxTxSize, errors);
if (res != Result::OK) {
return res;
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index e603ce7d0b..6c97a48561 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1627,15 +1627,14 @@ bool CWallet::ImportScriptPubKeys(const std::string& label, const std::set<CScri
return true;
}
-// Returns pair of vsize and weight
-std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
+TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig)
{
std::vector<CTxOut> txouts;
for (const CTxIn& input : tx.vin) {
const auto mi = wallet->mapWallet.find(input.prevout.hash);
// Can not estimate size without knowing the input details
if (mi == wallet->mapWallet.end()) {
- return std::make_pair(-1, -1);
+ return TxSize{-1, -1};
}
assert(input.prevout.n < mi->second.tx->vout.size());
txouts.emplace_back(mi->second.tx->vout[input.prevout.n]);
@@ -1644,16 +1643,16 @@ std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx,
}
// txouts needs to be in the order of tx.vin
-std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
+TxSize CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig)
{
CMutableTransaction txNew(tx);
if (!wallet->DummySignTx(txNew, txouts, use_max_sig)) {
- return std::make_pair(-1, -1);
+ return TxSize{-1, -1};
}
CTransaction ctx(txNew);
int64_t vsize = GetVirtualTransactionSize(ctx);
int64_t weight = GetTransactionWeight(ctx);
- return std::make_pair(vsize, weight);
+ return TxSize{vsize, weight};
}
int CalculateMaximumSignedInputSize(const CTxOut& txout, const CWallet* wallet, bool use_max_sig)
@@ -2820,7 +2819,7 @@ bool CWallet::CreateTransactionInternal(
CMutableTransaction txNew;
FeeCalculation feeCalc;
- std::pair<int64_t, int64_t> tx_sizes;
+ TxSize tx_sizes;
int nBytes;
{
std::set<CInputCoin> setCoins;
@@ -2967,7 +2966,7 @@ bool CWallet::CreateTransactionInternal(
// Calculate the transaction fee
tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
- nBytes = tx_sizes.first;
+ nBytes = tx_sizes.vsize;
if (nBytes < 0) {
error = _("Signing transaction failed");
return false;
@@ -2992,7 +2991,7 @@ bool CWallet::CreateTransactionInternal(
// Because we have dropped this change, the tx size and required fee will be different, so let's recalculate those
tx_sizes = CalculateMaximumSignedTxSize(CTransaction(txNew), this, coin_control.fAllowWatchOnly);
- nBytes = tx_sizes.first;
+ nBytes = tx_sizes.vsize;
fee_needed = coin_selection_params.m_effective_feerate.GetFee(nBytes);
}
@@ -3072,7 +3071,7 @@ bool CWallet::CreateTransactionInternal(
// Limit size
if ((sign && GetTransactionWeight(*tx) > MAX_STANDARD_TX_WEIGHT) ||
- (!sign && tx_sizes.second > MAX_STANDARD_TX_WEIGHT))
+ (!sign && tx_sizes.weight > MAX_STANDARD_TX_WEIGHT))
{
error = _("Transaction too large");
return false;
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 5f48e77590..9a572bc610 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -1346,12 +1346,17 @@ public:
}
};
+struct TxSize {
+ int64_t vsize{-1};
+ int64_t weight{-1};
+};
+
/** Calculate the size of the transaction assuming all signatures are max size
* Use DummySignatureCreator, which inserts 71 byte signatures everywhere.
* NOTE: this requires that all inputs must be in mapWallet (eg the tx should
* be IsAllFromMe). */
-std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, bool use_max_sig = false) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
-std::pair<int64_t, int64_t> CalculateMaximumSignedTxSize(const CTransaction &tx, const CWallet *wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false);
+TxSize CalculateMaximumSignedTxSize(const CTransaction& tx, const CWallet* wallet, bool use_max_sig = false) EXCLUSIVE_LOCKS_REQUIRED(wallet->cs_wallet);
+TxSize CalculateMaximumSignedTxSize(const CTransaction& tx, const CWallet* wallet, const std::vector<CTxOut>& txouts, bool use_max_sig = false);
//! Add wallet name to persistent configuration so it will be loaded on startup.
bool AddWalletSetting(interfaces::Chain& chain, const std::string& wallet_name);