Skip to content

Commit ade38b6

Browse files
committed
Merge #20588: Remove unused and confusing CTransaction constructor
fac39c1 wallet: document that tx in CreateTransaction is purely an out-param (MarcoFalke) faac315 Remove unused and confusing CTransaction constructor (MarcoFalke) Pull request description: The constructor is confusing and dangerous (as explained in the TODO), fix that by removing it. ACKs for top commit: laanwj: Code review ACK fac39c1 promag: Code review ACK fac39c1. theStack: Code review ACK fac39c1 Tree-SHA512: e0c8cffce8d8ee0166b8e1cbfe85ed0657611e26e2af0d69fde70eceaa5d75cbde3eb489af0428fe4fc431360b4c791fb1cc21b8dee7d4c7a4f17df00836229d
2 parents b189780 + fac39c1 commit ade38b6

File tree

6 files changed

+7
-12
lines changed

6 files changed

+7
-12
lines changed

src/primitives/transaction.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ uint256 CTransaction::ComputeWitnessHash() const
7777
return SerializeHash(*this, SER_GETHASH, 0);
7878
}
7979

80-
/* For backward compatibility, the hash is initialized to 0. TODO: remove the need for this default constructor entirely. */
81-
CTransaction::CTransaction() : vin(), vout(), nVersion(CTransaction::CURRENT_VERSION), nLockTime(0), hash{}, m_witness_hash{} {}
8280
CTransaction::CTransaction(const CMutableTransaction& tx) : vin(tx.vin), vout(tx.vout), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
8381
CTransaction::CTransaction(CMutableTransaction&& tx) : vin(std::move(tx.vin)), vout(std::move(tx.vout)), nVersion(tx.nVersion), nLockTime(tx.nLockTime), hash{ComputeHash()}, m_witness_hash{ComputeWitnessHash()} {}
8482

src/primitives/transaction.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,9 @@ class CTransaction
287287
uint256 ComputeWitnessHash() const;
288288

289289
public:
290-
/** Construct a CTransaction that qualifies as IsNull() */
291-
CTransaction();
292-
293290
/** Convert a CMutableTransaction into a CTransaction. */
294-
explicit CTransaction(const CMutableTransaction &tx);
295-
CTransaction(CMutableTransaction &&tx);
291+
explicit CTransaction(const CMutableTransaction& tx);
292+
CTransaction(CMutableTransaction&& tx);
296293

297294
template <typename Stream>
298295
inline void Serialize(Stream& s) const {
@@ -393,7 +390,6 @@ struct CMutableTransaction
393390
};
394391

395392
typedef std::shared_ptr<const CTransaction> CTransactionRef;
396-
static inline CTransactionRef MakeTransactionRef() { return std::make_shared<const CTransaction>(); }
397393
template <typename Tx> static inline CTransactionRef MakeTransactionRef(Tx&& txIn) { return std::make_shared<const CTransaction>(std::forward<Tx>(txIn)); }
398394

399395
/** A generic txid reference (txid or wtxid). */

src/test/fuzz/script_sigcache.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
2929
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
3030

3131
const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider);
32-
const CTransaction tx = mutable_transaction ? CTransaction{*mutable_transaction} : CTransaction{};
32+
const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}};
3333
const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
3434
const CAmount amount = ConsumeMoney(fuzzed_data_provider);
3535
const bool store = fuzzed_data_provider.ConsumeBool();

src/test/fuzz/transaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
4242
return CTransaction(deserialize, ds);
4343
} catch (const std::ios_base::failure&) {
4444
valid_tx = false;
45-
return CTransaction();
45+
return CTransaction{CMutableTransaction{}};
4646
}
4747
}();
4848
bool valid_mutable_tx = true;

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
215215
// We cannot source new unconfirmed inputs(bip125 rule 2)
216216
new_coin_control.m_min_depth = 1;
217217

218-
CTransactionRef tx_new = MakeTransactionRef();
218+
CTransactionRef tx_new;
219219
CAmount fee_ret;
220220
int change_pos_in_out = -1; // No requested location for change
221221
bilingual_str fail_reason;

src/wallet/wallet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3113,13 +3113,14 @@ bool CWallet::CreateTransaction(
31133113
bool sign)
31143114
{
31153115
int nChangePosIn = nChangePosInOut;
3116-
CTransactionRef tx2 = tx;
3116+
Assert(!tx); // tx is an out-param. TODO change the return type from bool to tx (or nullptr)
31173117
bool res = CreateTransactionInternal(vecSend, tx, nFeeRet, nChangePosInOut, error, coin_control, fee_calc_out, sign);
31183118
// try with avoidpartialspends unless it's enabled already
31193119
if (res && nFeeRet > 0 /* 0 means non-functional fee rate estimation */ && m_max_aps_fee > -1 && !coin_control.m_avoid_partial_spends) {
31203120
CCoinControl tmp_cc = coin_control;
31213121
tmp_cc.m_avoid_partial_spends = true;
31223122
CAmount nFeeRet2;
3123+
CTransactionRef tx2;
31233124
int nChangePosInOut2 = nChangePosIn;
31243125
bilingual_str error2; // fired and forgotten; if an error occurs, we discard the results
31253126
if (CreateTransactionInternal(vecSend, tx2, nFeeRet2, nChangePosInOut2, error2, tmp_cc, fee_calc_out, sign)) {

0 commit comments

Comments
 (0)