Skip to content

Commit 8e3f39e

Browse files
committed
wallet: Add some tracepoints for coin selection
1 parent 15b5838 commit 8e3f39e

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/wallet/coinselection.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,17 @@ struct SelectionResult
254254
private:
255255
/** Set of inputs selected by the algorithm to use in the transaction */
256256
std::set<COutput> m_selected_inputs;
257-
/** The target the algorithm selected for. Note that this may not be equal to the recipient amount as it can include non-input fees */
258-
const CAmount m_target;
259257
/** Whether the input values for calculations should be the effective value (true) or normal value (false) */
260258
bool m_use_effective{false};
261259
/** The computed waste */
262260
std::optional<CAmount> m_waste;
263-
/** The algorithm used to produce this result */
264-
SelectionAlgorithm m_algo;
265261

266262
public:
263+
/** The target the algorithm selected for. Note that this may not be equal to the recipient amount as it can include non-input fees */
264+
const CAmount m_target;
265+
/** The algorithm used to produce this result */
266+
const SelectionAlgorithm m_algo;
267+
267268
explicit SelectionResult(const CAmount target, SelectionAlgorithm algo)
268269
: m_target(target), m_algo(algo) {}
269270

src/wallet/spend.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <util/fees.h>
1212
#include <util/moneystr.h>
1313
#include <util/rbf.h>
14+
#include <util/trace.h>
1415
#include <util/translation.h>
1516
#include <wallet/coincontrol.h>
1617
#include <wallet/fees.h>
@@ -792,6 +793,7 @@ static bool CreateTransactionInternal(
792793
error = _("Insufficient funds");
793794
return false;
794795
}
796+
TRACE5(coin_selection, selected_coins, wallet.GetName().c_str(), GetAlgorithmName(result->m_algo).c_str(), result->m_target, result->GetWaste(), result->GetSelectedValue());
795797

796798
// Always make a change output
797799
// We will reduce the fee from this change output later, and remove the output if it is too small.
@@ -982,8 +984,10 @@ bool CreateTransaction(
982984
int nChangePosIn = nChangePosInOut;
983985
Assert(!tx); // tx is an out-param. TODO change the return type from bool to tx (or nullptr)
984986
bool res = CreateTransactionInternal(wallet, vecSend, tx, nFeeRet, nChangePosInOut, error, coin_control, fee_calc_out, sign);
987+
TRACE4(coin_selection, normal_create_tx_internal, wallet.GetName().c_str(), res, nFeeRet, nChangePosInOut);
985988
// try with avoidpartialspends unless it's enabled already
986989
if (res && nFeeRet > 0 /* 0 means non-functional fee rate estimation */ && wallet.m_max_aps_fee > -1 && !coin_control.m_avoid_partial_spends) {
990+
TRACE1(coin_selection, attempting_aps_create_tx, wallet.GetName().c_str());
987991
CCoinControl tmp_cc = coin_control;
988992
tmp_cc.m_avoid_partial_spends = true;
989993
CAmount nFeeRet2;
@@ -994,6 +998,7 @@ bool CreateTransaction(
994998
// if fee of this alternative one is within the range of the max fee, we use this one
995999
const bool use_aps = nFeeRet2 <= nFeeRet + wallet.m_max_aps_fee;
9961000
wallet.WalletLogPrintf("Fee non-grouped = %lld, grouped = %lld, using %s\n", nFeeRet, nFeeRet2, use_aps ? "grouped" : "non-grouped");
1001+
TRACE5(coin_selection, aps_create_tx_internal, wallet.GetName().c_str(), use_aps, res, nFeeRet2, nChangePosInOut2);
9971002
if (use_aps) {
9981003
tx = tx2;
9991004
nFeeRet = nFeeRet2;

0 commit comments

Comments
 (0)