Skip to content

Commit c3c1843

Browse files
committed
refactor: Use typesafe Wtxid in compact block encoding message, instead of ambiguous uint256.
Wtxid/Txid types introduced in #28107
1 parent d1e9a02 commit c3c1843

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

src/blockencodings.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ void CBlockHeaderAndShortTxIDs::FillShortTxIDSelector() const {
4040
shorttxidk1 = shorttxidhash.GetUint64(1);
4141
}
4242

43-
uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const {
43+
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, txhash) & 0xffffffffffffL;
45+
return SipHashUint256(shorttxidk0, shorttxidk1, wtxid) & 0xffffffffffffL;
4646
}
4747

4848

4949

50-
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn) {
50+
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<Wtxid, CTransactionRef>>& extra_txn) {
5151
if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
5252
return READ_STATUS_INVALID;
5353
if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_WEIGHT / MIN_SERIALIZABLE_TRANSACTION_WEIGHT)

src/blockencodings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class CBlockHeaderAndShortTxIDs {
111111

112112
CBlockHeaderAndShortTxIDs(const CBlock& block);
113113

114-
uint64_t GetShortID(const uint256& txhash) const;
114+
uint64_t GetShortID(const Wtxid& wtxid) const;
115115

116116
size_t BlockTxCount() const { return shorttxids.size() + prefilledtxn.size(); }
117117

@@ -142,7 +142,7 @@ class PartiallyDownloadedBlock {
142142
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
143143

144144
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
145-
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn);
145+
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<Wtxid, CTransactionRef>>& extra_txn);
146146
bool IsTxAvailable(size_t index) const;
147147
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing);
148148
};

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ class PeerManagerImpl final : public PeerManager
10061006
/** Orphan/conflicted/etc transactions that are kept for compact block reconstruction.
10071007
* The last -blockreconstructionextratxn/DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN of
10081008
* these are kept in a ring buffer */
1009-
std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex);
1009+
std::vector<std::pair<Wtxid, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex);
10101010
/** Offset into vExtraTxnForCompact to insert the next tx */
10111011
size_t vExtraTxnForCompactIt GUARDED_BY(g_msgproc_mutex) = 0;
10121012

src/test/blockencodings_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <boost/test/unit_test.hpp>
1616

17-
std::vector<std::pair<uint256, CTransactionRef>> extra_txn;
17+
std::vector<std::pair<Wtxid, CTransactionRef>> extra_txn;
1818

1919
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegTestingSetup)
2020

@@ -126,7 +126,7 @@ class TestHeaderAndShortIDs {
126126
explicit TestHeaderAndShortIDs(const CBlock& block) :
127127
TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs{block}) {}
128128

129-
uint64_t GetShortID(const uint256& txhash) const {
129+
uint64_t GetShortID(const Wtxid& txhash) const {
130130
DataStream stream{};
131131
stream << *this;
132132
CBlockHeaderAndShortTxIDs base;
@@ -155,8 +155,8 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
155155
shortIDs.prefilledtxn.resize(1);
156156
shortIDs.prefilledtxn[0] = {1, block.vtx[1]};
157157
shortIDs.shorttxids.resize(2);
158-
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetHash());
159-
shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetHash());
158+
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetWitnessHash());
159+
shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetWitnessHash());
160160

161161
DataStream stream{};
162162
stream << shortIDs;
@@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
226226
shortIDs.prefilledtxn[0] = {0, block.vtx[0]};
227227
shortIDs.prefilledtxn[1] = {1, block.vtx[2]}; // id == 1 as it is 1 after index 1
228228
shortIDs.shorttxids.resize(1);
229-
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetHash());
229+
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetWitnessHash());
230230

231231
DataStream stream{};
232232
stream << shortIDs;

src/test/fuzz/partially_downloaded_block.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
6060
// The coinbase is always available
6161
available.insert(0);
6262

63-
std::vector<std::pair<uint256, CTransactionRef>> extra_txn;
63+
std::vector<std::pair<Wtxid, CTransactionRef>> extra_txn;
6464
for (size_t i = 1; i < block->vtx.size(); ++i) {
6565
auto tx{block->vtx[i]};
6666

0 commit comments

Comments
 (0)