Skip to content

Commit 9b1a7c3

Browse files
committed
Merge bitcoin/bitcoin#33116: refactor: Convert uint256 to Txid
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](bitcoin/bitcoin#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 a20724d926d5844168c6a13fa8293df8c8927efe except address review nits. janb84: re ACK de0675f dergoegge: re-ACK de0675f theStack: Code-review ACK de0675f Tree-SHA512: 2413160fca7ab146a8d79d18ce3afcf7384cacc73c513d41928904aa453b4dd7a350064cee71e9c5d015da5904c7c81ac17603e50a47441ebc5b0c653235dd08
2 parents dbf8b09 + de0675f commit 9b1a7c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+323
-305
lines changed

src/blockencodings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void CBlockHeaderAndShortTxIDs::FillShortTxIDSelector() const {
4242

4343
uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const Wtxid& wtxid) const {
4444
static_assert(SHORTTXIDS_LENGTH == 6, "shorttxids calculation assumes 6-byte shorttxids");
45-
return SipHashUint256(shorttxidk0, shorttxidk1, wtxid) & 0xffffffffffffL;
45+
return SipHashUint256(shorttxidk0, shorttxidk1, wtxid.ToUint256()) & 0xffffffffffffL;
4646
}
4747

4848
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<CTransactionRef>& extra_txn) {

src/consensus/merkle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ uint256 BlockMerkleRoot(const CBlock& block, bool* mutated)
6868
std::vector<uint256> leaves;
6969
leaves.resize(block.vtx.size());
7070
for (size_t s = 0; s < block.vtx.size(); s++) {
71-
leaves[s] = block.vtx[s]->GetHash();
71+
leaves[s] = block.vtx[s]->GetHash().ToUint256();
7272
}
7373
return ComputeMerkleRoot(std::move(leaves), mutated);
7474
}
@@ -79,7 +79,7 @@ uint256 BlockWitnessMerkleRoot(const CBlock& block, bool* mutated)
7979
leaves.resize(block.vtx.size());
8080
leaves[0].SetNull(); // The witness hash of the coinbase is 0.
8181
for (size_t s = 1; s < block.vtx.size(); s++) {
82-
leaves[s] = block.vtx[s]->GetWitnessHash();
82+
leaves[s] = block.vtx[s]->GetWitnessHash().ToUint256();
8383
}
8484
return ComputeMerkleRoot(std::move(leaves), mutated);
8585
}
@@ -185,7 +185,7 @@ std::vector<uint256> TransactionMerklePath(const CBlock& block, uint32_t positio
185185
std::vector<uint256> leaves;
186186
leaves.resize(block.vtx.size());
187187
for (size_t s = 0; s < block.vtx.size(); s++) {
188-
leaves[s] = block.vtx[s]->GetHash();
188+
leaves[s] = block.vtx[s]->GetHash().ToUint256();
189189
}
190190
return ComputeMerklePath(leaves, position);
191191
}

src/headerssync.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ HeadersSyncState::HeadersSyncState(NodeId id, const Consensus::Params& consensus
4848

4949
/** Free any memory in use, and mark this object as no longer usable. This is
5050
* required to guarantee that we won't reuse this object with the same
51-
* SaltedTxidHasher for another sync. */
51+
* SaltedUint256Hasher for another sync. */
5252
void HeadersSyncState::Finalize()
5353
{
5454
Assume(m_download_state != State::FINAL);

src/headerssync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class HeadersSyncState {
224224
arith_uint256 m_current_chain_work;
225225

226226
/** m_hasher is a salted hasher for making our 1-bit commitments to headers we've seen. */
227-
const SaltedTxidHasher m_hasher;
227+
const SaltedUint256Hasher m_hasher;
228228

229229
/** A queue of commitment bits, created during the 1st phase, and verified during the 2nd. */
230230
bitdeque<> m_header_commitments;

src/index/txindex.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <index/disktxpos.h>
1010
#include <logging.h>
1111
#include <node/blockstorage.h>
12+
#include <primitives/transaction_identifier.h>
1213
#include <validation.h>
1314

1415
constexpr uint8_t DB_TXINDEX{'t'};
@@ -24,26 +25,26 @@ class TxIndex::DB : public BaseIndex::DB
2425

2526
/// Read the disk location of the transaction data with the given hash. Returns false if the
2627
/// transaction hash is not indexed.
27-
bool ReadTxPos(const uint256& txid, CDiskTxPos& pos) const;
28+
bool ReadTxPos(const Txid& txid, CDiskTxPos& pos) const;
2829

2930
/// Write a batch of transaction positions to the DB.
30-
[[nodiscard]] bool WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos);
31+
[[nodiscard]] bool WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos);
3132
};
3233

3334
TxIndex::DB::DB(size_t n_cache_size, bool f_memory, bool f_wipe) :
3435
BaseIndex::DB(gArgs.GetDataDirNet() / "indexes" / "txindex", n_cache_size, f_memory, f_wipe)
3536
{}
3637

37-
bool TxIndex::DB::ReadTxPos(const uint256 &txid, CDiskTxPos& pos) const
38+
bool TxIndex::DB::ReadTxPos(const Txid& txid, CDiskTxPos& pos) const
3839
{
39-
return Read(std::make_pair(DB_TXINDEX, txid), pos);
40+
return Read(std::make_pair(DB_TXINDEX, txid.ToUint256()), pos);
4041
}
4142

42-
bool TxIndex::DB::WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_pos)
43+
bool TxIndex::DB::WriteTxs(const std::vector<std::pair<Txid, CDiskTxPos>>& v_pos)
4344
{
4445
CDBBatch batch(*this);
45-
for (const auto& tuple : v_pos) {
46-
batch.Write(std::make_pair(DB_TXINDEX, tuple.first), tuple.second);
46+
for (const auto& [txid, pos] : v_pos) {
47+
batch.Write(std::make_pair(DB_TXINDEX, txid.ToUint256()), pos);
4748
}
4849
return WriteBatch(batch);
4950
}
@@ -61,7 +62,7 @@ bool TxIndex::CustomAppend(const interfaces::BlockInfo& block)
6162

6263
assert(block.data);
6364
CDiskTxPos pos({block.file_number, block.data_pos}, GetSizeOfCompactSize(block.data->vtx.size()));
64-
std::vector<std::pair<uint256, CDiskTxPos>> vPos;
65+
std::vector<std::pair<Txid, CDiskTxPos>> vPos;
6566
vPos.reserve(block.data->vtx.size());
6667
for (const auto& tx : block.data->vtx) {
6768
vPos.emplace_back(tx->GetHash(), pos);
@@ -72,7 +73,7 @@ bool TxIndex::CustomAppend(const interfaces::BlockInfo& block)
7273

7374
BaseIndex::DB& TxIndex::GetDB() const { return *m_db; }
7475

75-
bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRef& tx) const
76+
bool TxIndex::FindTx(const Txid& tx_hash, uint256& block_hash, CTransactionRef& tx) const
7677
{
7778
CDiskTxPos postx;
7879
if (!m_db->ReadTxPos(tx_hash, postx)) {

src/index/txindex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TxIndex final : public BaseIndex
4242
/// @param[out] block_hash The hash of the block the transaction is found in.
4343
/// @param[out] tx The transaction itself.
4444
/// @return true if transaction is found, false otherwise
45-
bool FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRef& tx) const;
45+
bool FindTx(const Txid& tx_hash, uint256& block_hash, CTransactionRef& tx) const;
4646
};
4747

4848
/// The global transaction index, used in GetTransaction. May be null.

src/interfaces/chain.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class Chain
211211
virtual bool isInMempool(const Txid& txid) = 0;
212212

213213
//! Check if transaction has descendants in mempool.
214-
virtual bool hasDescendantsInMempool(const uint256& txid) = 0;
214+
virtual bool hasDescendantsInMempool(const Txid& txid) = 0;
215215

216216
//! Transaction is added to memory pool, if the transaction fee is below the
217217
//! amount specified by max_tx_fee, and broadcast to all peers if relay is set to true.
@@ -222,7 +222,7 @@ class Chain
222222
std::string& err_string) = 0;
223223

224224
//! Calculate mempool ancestor and descendant counts for the given transaction.
225-
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) = 0;
225+
virtual void getTransactionAncestry(const Txid& txid, size_t& ancestors, size_t& descendants, size_t* ancestorsize = nullptr, CAmount* ancestorfees = nullptr) = 0;
226226

227227
//! For each outpoint, calculate the fee-bumping cost to spend this outpoint at the specified
228228
// feerate, including bumping its ancestors. For example, if the target feerate is 10sat/vbyte

src/interfaces/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include <common/signmessage.h>
1010
#include <consensus/amount.h>
1111
#include <interfaces/chain.h>
12+
#include <primitives/transaction_identifier.h>
1213
#include <pubkey.h>
1314
#include <script/script.h>
1415
#include <support/allocators/secure.h>
1516
#include <util/fs.h>
1617
#include <util/result.h>
17-
#include <util/transaction_identifier.h>
1818
#include <util/ui_change_type.h>
1919

2020
#include <cstdint>

src/kernel/coinstats.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void ApplyHash(T& hash_obj, const Txid& hash, const std::map<uint32_t, Co
9898
}
9999
}
100100

101-
static void ApplyStats(CCoinsStats& stats, const uint256& hash, const std::map<uint32_t, Coin>& outputs)
101+
static void ApplyStats(CCoinsStats& stats, const std::map<uint32_t, Coin>& outputs)
102102
{
103103
assert(!outputs.empty());
104104
stats.nTransactions++;
@@ -126,7 +126,7 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
126126
Coin coin;
127127
if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
128128
if (!outputs.empty() && key.hash != prevkey) {
129-
ApplyStats(stats, prevkey, outputs);
129+
ApplyStats(stats, outputs);
130130
ApplyHash(hash_obj, prevkey, outputs);
131131
outputs.clear();
132132
}
@@ -140,7 +140,7 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
140140
pcursor->Next();
141141
}
142142
if (!outputs.empty()) {
143-
ApplyStats(stats, prevkey, outputs);
143+
ApplyStats(stats, outputs);
144144
ApplyHash(hash_obj, prevkey, outputs);
145145
}
146146

src/kernel/disconnected_transactions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class DisconnectedBlockTransactions {
4141
const size_t m_max_mem_usage;
4242
std::list<CTransactionRef> queuedTx;
4343
using TxList = decltype(queuedTx);
44-
std::unordered_map<uint256, TxList::iterator, SaltedTxidHasher> iters_by_txid;
44+
std::unordered_map<Txid, TxList::iterator, SaltedTxidHasher> iters_by_txid;
4545

4646
/** Trim the earliest-added entries until we are within memory bounds. */
4747
std::vector<CTransactionRef> LimitMemoryUsage();

0 commit comments

Comments
 (0)