CWalletTx::fTimeReceivedIsTxTime
is no longer used and can be removed. This additionally allows the removal of the upgraded_txs
loop in LoadWallet
.
CWalletTx::fTimeReceivedIsTxTime
#32768
CWalletTx::fTimeReceivedIsTxTime
is no longer used and can be removed. This additionally allows the removal of the upgraded_txs
loop in LoadWallet
.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32768.
See the guideline for information on the review process.
Type | Reviewers |
---|---|
ACK | maflcko, rkrux, Eunovo, davidgumberg, w0xlt, PeterWrighten |
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
fTimeReceivedIsTxTime has been unused unused since 0.3.24
2225@@ -2227,7 +2226,6 @@ void CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
2226 CHECK_NONFATAL(wtx.vOrderForm.empty());
2227 wtx.mapValue = std::move(mapValue);
2228 wtx.vOrderForm = std::move(orderForm);
2229- wtx.fTimeReceivedIsTxTime = true;
276+ bool dummy_bool = false; //!< Used to be fFromMe, and fSpent
277+ uint32_t dummy_int = 0; // Used to be fTimeReceivedIsTxTime
278 uint256 serializedHash = TxStateSerializedBlockHash(m_state);
279 int serializedIndex = TxStateSerializedIndex(m_state);
280- s << TX_WITH_WITNESS(tx) << serializedHash << dummy_vector1 << serializedIndex << dummy_vector2 << mapValueCopy << vOrderForm << fTimeReceivedIsTxTime << nTimeReceived << dummy_bool << dummy_bool;
281+ s << TX_WITH_WITNESS(tx) << serializedHash << dummy_vector1 << serializedIndex << dummy_vector2 << mapValueCopy << vOrderForm << dummy_int << nTimeReceived << dummy_bool << dummy_bool;
1029@@ -1030,27 +1030,6 @@ static DBErrors LoadTxRecords(CWallet* pwallet, DatabaseBatch& batch, std::vecto
1030 if (wtx.GetHash() != hash)
1031 return false;
1032
1033- // Undo serialize changes in 31600
v0.3.16
is not present in the tags, might have been buggy for which this undoing was needed.
1187@@ -1189,9 +1188,6 @@ DBErrors WalletBatch::LoadWallet(CWallet* pwallet)
1188 if (result != DBErrors::LOAD_OK)
1189 return result;
1190
1191- for (const Txid& hash : upgraded_txs)
1192- WriteTx(pwallet->mapWallet.at(hash));
1193-
fTimeReceivedIsTxTime
is not really used in the wallet codebase at present, so I see no point in writing this upgraded transaction back.
ACK https://github.com/bitcoin/bitcoin/pull/32768/commits/9eb2c82e7c911a066781d67e6846cf6bbbaba6e9
fTimeReceivedIsTxTime
has had no functional impact since it was removed in https://github.com/bitcoin/bitcoin/commit/471426fb3b2c2fa37640c03819c4f7be69ba8301#diff-286fedc8ff8f47bca92c7024d2c75272aa5bcfd733379eac1555e6036528d6b1
ACK https://github.com/bitcoin/bitcoin/commit/9eb2c82e7c911a066781d67e6846cf6bbbaba6e9
The fTimeReceivedIsTxTime
once indicated whether a transactions “time” was the time the wallet heard about the transaction, or the time that the transaction was included in a block.
It was set to true for transactions created by the wallet, where presumably we care more about what time we made the transaction then what time we heard about it in a block, but for other transaction’s the time that we “receive” the transaction may be much later (e.g. IBD) than the time it was included in a block, so we don’t want the transaction’s “time” to be nTimeReceived
.:
https://github.com/bitcoin/bitcoin/blob/4405b78d6059e536c36974088a8ed4d9f0f29898/main.cpp#L263-L279 1
This field was mistakenly an unsigned int
rather than a char
/bool
:
https://github.com/bitcoin/bitcoin/blob/4405b78d6059e536c36974088a8ed4d9f0f29898/main.h#L678
A later commit (e4ff4e6898d378b1a3e83791034a7af455fde3ab), that AFAICT predates the practice of using dummy types for deprecated fields in serialization, attempted to “fix” this inefficiency of using 4 bytes to represent a bool. Since the commit was adding an nVersion
field to the serialized transaction data anyways, and nVersion
is 4 bytes, it reused the fTimeReceivedIsTxTime
field as the nVersion
field, and changed fTimeReceivedIsTxTime
to a bool and moved it to the end of tx serialization:
0diff --git a/main.h b/main.h
1index 7d1145b5ff..dda5f730c7 100644
2
3- READWRITE(fTimeReceivedIsTxTime);
4+ READWRITE(nVersion);
5+ if (fRead && nVersion < 100)
6+ const_cast<CWalletTx*>(this)->fTimeReceivedIsTxTime = nVersion;
7 READWRITE(nTimeReceived);
8 READWRITE(fFromMe);
9 READWRITE(fSpent);
10+ if (nVersion >= 31404)
11+ {
12+ READWRITE(fTimeReceivedIsTxTime);
13+ READWRITE(fUnused);
14+ READWRITE(strFromAccount);
15+ }
16 )
This broke transaction times for wallets that were upgraded and then loaded into an older bitcoin client, since these wallets would have giant version numbers like 31404
in the fTimeReceivedIsTxTime
for every transaction, and fTimeReceivedIsTxTime
would always be true.
A later commit (https://github.com/bitcoin/bitcoin/commit/865c3a23832e36d50cb873d38c976032b027b5d3) reverted the above change to fix this upgrade-then-downgrade bug, but it had to include a special case for fixing transactions that had very large fTimeReceivedIsTxTime
that matched the version numbers that were affected by this bug
And Bitcoin Core retains this special-case handling today, even though, for a long time, even before the introduction of smart time in #1393, GetTxTime()
has not used fTimeReceivedIsTxTime
(471426fb3b2c2fa37640c0381):
This snippet is from the initial git commit: 4405b78d6059e536c36 ↩︎