-
Notifications
You must be signed in to change notification settings - Fork 37.7k
refactor: Txid type safety (parent PR) #32189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Txid type safety (parent PR) #32189
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/32189. ReviewsSee the guideline for information on the review process. ConflictsReviewers, 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. |
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
232657d
to
68d7aaa
Compare
68d7aaa
to
48948fc
Compare
868816d refactor: Remove SetHexDeprecated (marcofleon) 6b63218 qt: Update SetHexDeprecated to FromHex (marcofleon) Pull request description: This is part of #32189. I'm separating this out because it's not immediately obvious that it's just a refactor. `SetHexDeprecated()` doesn't do any correctness checks on the input, while `FromHex()` does, so it's theoretically possible that there's a behavior change. Replaces `uint256::SetHexDeprecated()` calls with `Txid::FromHex()` in four locations: - `TransactionTableModel::updateTransaction` - `TransactionView::contextualMenu` - `TransactionView::abandonTx` - `TransactionView::bumpFee` The input strings in these cases aren't user input, so they should only be valid hex strings from `GetHex()` (through `TransactionRecord::getTxHash()`). These conversions should be safe without additional checks. ACKs for top commit: laanwj: Code review ACK 868816d w0xlt: Code review ACK 868816d BrandonOdiwuor: Code Review ACK 868816d TheCharlatan: ACK 868816d hebasto: ACK 868816d, I have reviewed the code and it looks OK. Tree-SHA512: 121f149dcc7358231d0327cb3212ec96486a88410174d3c74ab8cbd61bad35185bc0a9740d534492b714811f72a6736bc7ac6eeae590c0ea1365c61cc791da37
48948fc
to
acbd6fa
Compare
Convert all of `txdownloadman_impl` to the new variant except for `GetRequestsToSend`, which will be easier to switch at the same time as `txrequest`.
Switch all instances of GenTxid to GenTxid variant in `txrequest` and complete `txdownloadman_impl` by converting `GetRequestsToSend`.
-BEGIN VERIFY SCRIPT- sed -i 's/GenTxidVariant/GenTxid/g' $(git grep -l 'GenTxidVariant') -END VERIFY SCRIPT-
These remaining miscellaneous changes were discovered by commenting out the implicit conversion in `transaction_identifier`.
acbd6fa
to
edff83a
Compare
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
a60f863 scripted-diff: Replace GenTxidVariant with GenTxid (marcofleon) c8ba199 Remove old GenTxid class (marcofleon) 072a198 Convert remaining instances of GenTxid to GenTxidVariant (marcofleon) 1b52839 Convert `txrequest` to GenTxidVariant (marcofleon) bde4579 Convert `txdownloadman_impl` to GenTxidVariant (marcofleon) c876a89 Replace GenTxid with Txid/Wtxid overloads in `txmempool` (marcofleon) de858ce move-only: make GetInfo a private CTxMemPool member (stickies-v) eee473d Convert `CompareInvMempoolOrder` to GenTxidVariant (marcofleon) 243553d refactor: replace get_iter_from_wtxid with GetIter(const Wtxid&) (stickies-v) fcf92fd refactor: make CTxMemPool::GetIter strongly typed (marcofleon) 11d28f2 Implement GenTxid as a variant (marcofleon) Pull request description: Part of the [type safety refactor](#32189). This PR changes the GenTxid class to a variant, which holds both Txids and Wtxids. This provides compile-time type safety and eliminates the manual type check (bool m_is_wtxid). Variables that can be either a Txid or a Wtxid are now using the new GenTxid variant, instead of uint256. ACKs for top commit: w0xlt: ACK a60f863 dergoegge: Code review ACK a60f863 maflcko: review ACK a60f863 🎽 theStack: Code-review ACK a60f863 Tree-SHA512: da9b73b7bdffee2eb9281a409205519ac330d3336094d17681896703fbca8099608782c9c85801e388e4d90af5af8abf1f34931f57bbbe6e9674d802d6066047
🐙 This pull request conflicts with the target branch and needs rebase. |
de0675f refactor: Move `transaction_identifier.h` to primitives (marcofleon) 6f068f6 Remove implicit uint256 conversion and comparison (marcofleon) 9c24cda refactor: Convert remaining instances from uint256 to Txid (marcofleon) d2ecd68 policy, refactor: Convert uint256 to Txid (marcofleon) f6c0d1d mempool, refactor: Convert uint256 to Txid (marcofleon) aeb0f78 refactor: Convert `mini_miner` from uint256 to Txid (marcofleon) 326f244 refactor: Convert RPCs and `merkleblock` from uint256 to Txid (marcofleon) 49b3d3a Clean up `FindTxForGetData` (marcofleon) Pull request description: This is the final leg of the [type safety refactor](#32189). All of these changes are straightforward `uint256` --> `Txid` along with any necessary explicit conversions. Also, `transaction_identifier.h` is moved to primitives in the last commit, as `Txid` and `Wtxid` become fundamental types after this PR. ACKs for top commit: stickies-v: re-ACK de0675f, no changes since a20724d except address review nits. janb84: re ACK de0675f dergoegge: re-ACK de0675f theStack: Code-review ACK de0675f Tree-SHA512: 2413160fca7ab146a8d79d18ce3afcf7384cacc73c513d41928904aa453b4dd7a350064cee71e9c5d015da5904c7c81ac17603e50a47441ebc5b0c653235dd08
🚨🚨 UNDER NO CIRCUMSTANCES SHOULD THIS BE MERGED!! 🚨🚨
This is the full Txid type safety refactor. Any transaction that was using uint256 should now be either a Txid, Wtxid, or GenTxid. The implicit conversion in
transaction_identifier.h
from the transaction types to uint256 is removed and any conversions are now explicit, usingFromUint256
orToUint256()
. In general, I try to only convert a transaction to uint256 in contexts where the type information isn't preserved. Examples would be bloom filters or the txid hasher.The GenTxid class changes to a variant, which holds both Txids and Wtxids. This provides compile-time type safety and eliminates the manual type check (
bool m_is_wtxid
). Variables that can be either type now use GenTxid, instead of uint256.I'll be splitting this up into a few smaller PRs, but any feedback on the approach or questions about specifics are welcome here.