What changed, and why it matters
This is a small code cleanup in Bitcoin Core's wallet. It replaces a hand-written list of field-by-field copies with a single statement that copies the same set of fields all at once. The behavior is unchanged; no security issue is introduced or fixed.
No security action needed. Treat as normal code-quality maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors CWallet::SyncMalleatedTxMetadata() in src/wallet/wallet.cpp. Previously the function copied nine named metadata fields one-by-one from the oldest malleated transaction variant to the others. The patch introduces a lambda returning a std::tie of the same nine members and assigns it in one expression. The set of copied fields and the explicit exclusions (nTimeReceived, nOrderPos, cached members) remain identical. This is a pure refactor with no functional change.
Changed components
src/wallet/wallet.cppCWallet::SyncMalleatedTxMetadataInspect captured patch +11 / −15
### src/wallet/wallet.cpp
@@ -770,22 +770,18 @@ void CWallet::SyncMalleatedTxMetadata(const CWalletTx& wtx)
// First tx is the oldest one (smallest nOrderPos)
const CWalletTx* copyFrom = *txs.begin();
+ // The metadata that is kept in sync between malleated variants.
+ // nTimeReceived, nOrderPos and cached members are not copied on purpose.
+ const auto metadata = [](auto& tx) {
+ return std::tie(tx.m_from, tx.m_message, tx.m_comment, tx.m_comment_to,
+ tx.m_replaces_txid, tx.m_replaced_by_txid,
+ tx.m_messages, tx.m_payment_requests, tx.nTimeSmart);
+ };
+
// Now copy data from copyFrom to rest:
- for (auto it = ++txs.begin(); it != txs.end(); ++it)
- {
- CWalletTx* copyTo = *it;
- copyTo->m_from = copyFrom->m_from;
- copyTo->m_message = copyFrom->m_message;
- copyTo->m_comment = copyFrom->m_comment;
- copyTo->m_comment_to = copyFrom->m_comment_to;
- copyTo->m_replaces_txid = copyFrom->m_replaces_txid;
- copyTo->m_replaced_by_txid = copyFrom->m_replaced_by_txid;
- copyTo->m_messages = copyFrom->m_messages;
- copyTo->m_payment_requests = copyFrom->m_payment_requests;
- // nTimeReceived not copied on purpose
- copyTo->nTimeSmart = copyFrom->nTimeSmart;
- // nOrderPos not copied on purpose
- // cached members not copied on purpose
+ for (CWalletTx* copyTo : txs) {
+ if (copyTo == copyFrom) continue;
+ metadata(*copyTo) = metadata(*copyFrom);
}
}
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.