mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 06:52:36 +01:00
refactor: Use typesafe Wtxid in compact block encoding message, instead of ambiguous uint256.
Wtxid/Txid types introduced in #28107
This commit is contained in:
parent
d1e9a02126
commit
c3c18433ae
5 changed files with 12 additions and 12 deletions
|
@ -40,14 +40,14 @@ void CBlockHeaderAndShortTxIDs::FillShortTxIDSelector() const {
|
|||
shorttxidk1 = shorttxidhash.GetUint64(1);
|
||||
}
|
||||
|
||||
uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const {
|
||||
uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const Wtxid& wtxid) const {
|
||||
static_assert(SHORTTXIDS_LENGTH == 6, "shorttxids calculation assumes 6-byte shorttxids");
|
||||
return SipHashUint256(shorttxidk0, shorttxidk1, txhash) & 0xffffffffffffL;
|
||||
return SipHashUint256(shorttxidk0, shorttxidk1, wtxid) & 0xffffffffffffL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn) {
|
||||
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<Wtxid, CTransactionRef>>& extra_txn) {
|
||||
if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
|
||||
return READ_STATUS_INVALID;
|
||||
if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_WEIGHT / MIN_SERIALIZABLE_TRANSACTION_WEIGHT)
|
||||
|
|
|
@ -111,7 +111,7 @@ public:
|
|||
|
||||
CBlockHeaderAndShortTxIDs(const CBlock& block);
|
||||
|
||||
uint64_t GetShortID(const uint256& txhash) const;
|
||||
uint64_t GetShortID(const Wtxid& wtxid) const;
|
||||
|
||||
size_t BlockTxCount() const { return shorttxids.size() + prefilledtxn.size(); }
|
||||
|
||||
|
@ -142,7 +142,7 @@ public:
|
|||
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}
|
||||
|
||||
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
|
||||
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn);
|
||||
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<Wtxid, CTransactionRef>>& extra_txn);
|
||||
bool IsTxAvailable(size_t index) const;
|
||||
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing);
|
||||
};
|
||||
|
|
|
@ -1006,7 +1006,7 @@ private:
|
|||
/** Orphan/conflicted/etc transactions that are kept for compact block reconstruction.
|
||||
* The last -blockreconstructionextratxn/DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN of
|
||||
* these are kept in a ring buffer */
|
||||
std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex);
|
||||
std::vector<std::pair<Wtxid, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(g_msgproc_mutex);
|
||||
/** Offset into vExtraTxnForCompact to insert the next tx */
|
||||
size_t vExtraTxnForCompactIt GUARDED_BY(g_msgproc_mutex) = 0;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
std::vector<std::pair<uint256, CTransactionRef>> extra_txn;
|
||||
std::vector<std::pair<Wtxid, CTransactionRef>> extra_txn;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(blockencodings_tests, RegTestingSetup)
|
||||
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
explicit TestHeaderAndShortIDs(const CBlock& block) :
|
||||
TestHeaderAndShortIDs(CBlockHeaderAndShortTxIDs{block}) {}
|
||||
|
||||
uint64_t GetShortID(const uint256& txhash) const {
|
||||
uint64_t GetShortID(const Wtxid& txhash) const {
|
||||
DataStream stream{};
|
||||
stream << *this;
|
||||
CBlockHeaderAndShortTxIDs base;
|
||||
|
@ -155,8 +155,8 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest)
|
|||
shortIDs.prefilledtxn.resize(1);
|
||||
shortIDs.prefilledtxn[0] = {1, block.vtx[1]};
|
||||
shortIDs.shorttxids.resize(2);
|
||||
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetHash());
|
||||
shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetHash());
|
||||
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[0]->GetWitnessHash());
|
||||
shortIDs.shorttxids[1] = shortIDs.GetShortID(block.vtx[2]->GetWitnessHash());
|
||||
|
||||
DataStream stream{};
|
||||
stream << shortIDs;
|
||||
|
@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest)
|
|||
shortIDs.prefilledtxn[0] = {0, block.vtx[0]};
|
||||
shortIDs.prefilledtxn[1] = {1, block.vtx[2]}; // id == 1 as it is 1 after index 1
|
||||
shortIDs.shorttxids.resize(1);
|
||||
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetHash());
|
||||
shortIDs.shorttxids[0] = shortIDs.GetShortID(block.vtx[1]->GetWitnessHash());
|
||||
|
||||
DataStream stream{};
|
||||
stream << shortIDs;
|
||||
|
|
|
@ -60,7 +60,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
|
|||
// The coinbase is always available
|
||||
available.insert(0);
|
||||
|
||||
std::vector<std::pair<uint256, CTransactionRef>> extra_txn;
|
||||
std::vector<std::pair<Wtxid, CTransactionRef>> extra_txn;
|
||||
for (size_t i = 1; i < block->vtx.size(); ++i) {
|
||||
auto tx{block->vtx[i]};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue