diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-10-22 12:29:23 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-10-22 12:29:28 +0200 |
commit | c001da306b29c46ef1e7421002c3aba3ff5ed514 (patch) | |
tree | ef3e6c3ff1338e464e1581243986f3082cbddec2 /src/primitives | |
parent | 4833d1fdf39fb4e3dc45b76960b769d641eca4b8 (diff) | |
parent | 4307849256761fe2440d82bbec892d0e8e6b4dd4 (diff) |
Merge bitcoin/bitcoin#23325: mempool: delete exists(uint256) function
4307849256761fe2440d82bbec892d0e8e6b4dd4 [mempool] delete exists(uint256) function (glozow)
d50fbd4c5b4bc72415854d582cedf94541a46983 create explicit GenTxid::{Txid, Wtxid} ctors (glozow)
Pull request description:
We use the same type for txids and wtxids, `uint256`. In places where we want the ability to pass either one, we distinguish them using `GenTxid`.
The (overloaded) `CTxMemPool::exists()` function is defined as follows:
```c
bool exists(const uint256& txid) const { return exists(GenTxid{false, txid}); }
```
It always assumes that a uint256 is a txid, which is a footgunny interface.
Querying by wtxid returns a false negative if the transaction has a witness. :bug:
Another approach would be to try both:
```c
bool exists(const uint256& txid) const { return exists(GenTxid{false, txid}) || exists(GenTxid{false, txid}); }
```
But that's slower and wrongfully placing the burden on the callee; the caller always knows whether the hash is a txid or a wtxid.
ACKs for top commit:
laanwj:
Code review ACK 4307849256761fe2440d82bbec892d0e8e6b4dd4
jnewbery:
Tested and code review ACK 4307849256761fe2440d82bbec892d0e8e6b4dd4
MarcoFalke:
review ACK 4307849256761fe2440d82bbec892d0e8e6b4dd4 👘
Tree-SHA512: 8ed167a96f3124b6c14e41073c8358658114ce121a15a4cca2db7a5ac565903a6236e34e88ac03382b8bb8b68e3999abbfc5718bc8c22476554d6b49a5298eec
Diffstat (limited to 'src/primitives')
-rw-r--r-- | src/primitives/transaction.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 46db39f8db..d7a85015ef 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -393,6 +393,8 @@ class GenTxid uint256 m_hash; public: GenTxid(bool is_wtxid, const uint256& hash) : m_is_wtxid(is_wtxid), m_hash(hash) {} + static GenTxid Txid(const uint256& hash) { return GenTxid{false, hash}; } + static GenTxid Wtxid(const uint256& hash) { return GenTxid{true, hash}; } bool IsWtxid() const { return m_is_wtxid; } const uint256& GetHash() const { return m_hash; } friend bool operator==(const GenTxid& a, const GenTxid& b) { return a.m_is_wtxid == b.m_is_wtxid && a.m_hash == b.m_hash; } |