Skip to content

rebased on current master #11

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bench/rpc_blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct TestBlockAndIndex {

stream >> block;

blockHash = block.GetHash();
blockindex.phashBlock = &blockHash;
CBlockIndex blockindex;
blockindex.m_hash_block = block.GetHash();
blockindex.nBits = 403014710;
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ enum BlockStatus: uint32_t {
class CBlockIndex
{
public:
//! pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
const uint256* phashBlock{nullptr};
//! hash of the block. m_hash_block.IsNull() if there is not yet a hash
uint256 m_hash_block;

//! pointer to the index of the predecessor of this block
CBlockIndex* pprev{nullptr};
Expand Down Expand Up @@ -243,9 +243,9 @@ class CBlockIndex
return block;
}

uint256 GetBlockHash() const
const uint256& GetBlockHash() const
{
return *phashBlock;
return m_hash_block;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,10 +1578,10 @@ static RPCHelpMan getchaintips()
std::set<const CBlockIndex*> setOrphans;
std::set<const CBlockIndex*> setPrevs;

for (const std::pair<const uint256, CBlockIndex*>& item : chainman.BlockIndex()) {
if (!active_chain.Contains(item.second)) {
setOrphans.insert(item.second);
setPrevs.insert(item.second->pprev);
for (CBlockIndex* pindex : chainman.BlockIndex()) {
if (!chainman.ActiveChain().Contains(pindex)) {
setOrphans.insert(pindex);
setPrevs.insert(pindex->pprev);
}
}

Expand All @@ -1599,7 +1599,7 @@ static RPCHelpMan getchaintips()
for (const CBlockIndex* block : setTips) {
UniValue obj(UniValue::VOBJ);
obj.pushKV("height", block->nHeight);
obj.pushKV("hash", block->phashBlock->GetHex());
obj.pushKV("hash", block->m_hash_block.GetHex());

const int branchLen = block->nHeight - active_chain.FindFork(block)->nHeight;
obj.pushKV("branchlen", branchLen);
Expand Down
5 changes: 3 additions & 2 deletions src/test/fuzz/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
BanMan ban_man_read{banlist_file, /* client_interface */ nullptr, /* default_ban_time */ 0};
banmap_t banmap_read;
ban_man_read.GetBanned(banmap_read);
// Temporarily disabled to allow the remainder of the fuzz test to run while a fix is being worked on:
// assert(banmap == banmap_read);
// Assert temporarily disabled to allow the remainder of the fuzz test to run while a
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you reenable this assert?

// fix is being worked on. See https://github.com/bitcoin/bitcoin/pull/22517
(void)(banmap == banmap_read);
}
}
fs::remove(banlist_file.string() + ".dat");
Expand Down
3 changes: 0 additions & 3 deletions src/test/fuzz/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ FUZZ_TARGET(chain)
return;
}

const uint256 zero{};
disk_block_index->phashBlock = &zero;
(void)disk_block_index->GetBlockHash();
(void)disk_block_index->GetBlockPos();
(void)disk_block_index->GetBlockTime();
Expand Down Expand Up @@ -59,7 +57,6 @@ FUZZ_TARGET(chain)
}

CBlockIndex block_index{block_header};
block_index.phashBlock = &zero;
(void)block_index.GetBlockHash();
(void)block_index.ToString();
}
6 changes: 3 additions & 3 deletions src/test/miner_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
while (m_node.chainman->ActiveChain().Tip()->nHeight < 209999) {
CBlockIndex* prev = m_node.chainman->ActiveChain().Tip();
CBlockIndex* next = new CBlockIndex();
next->phashBlock = new uint256(InsecureRand256());
next->m_hash_block = uint256(InsecureRand256());
m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(next->GetBlockHash());
next->pprev = prev;
next->nHeight = prev->nHeight + 1;
Expand All @@ -381,7 +381,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
while (m_node.chainman->ActiveChain().Tip()->nHeight < 210000) {
CBlockIndex* prev = m_node.chainman->ActiveChain().Tip();
CBlockIndex* next = new CBlockIndex();
next->phashBlock = new uint256(InsecureRand256());
next->m_hash_block = uint256(InsecureRand256());
m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(next->GetBlockHash());
next->pprev = prev;
next->nHeight = prev->nHeight + 1;
Expand Down Expand Up @@ -409,11 +409,11 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
m_node.mempool->clear();

// Delete the dummy blocks again.

while (m_node.chainman->ActiveChain().Tip()->nHeight > nHeight) {
CBlockIndex* del = m_node.chainman->ActiveChain().Tip();
m_node.chainman->ActiveChain().SetTip(del->pprev);
m_node.chainman->ActiveChainstate().CoinsTip().SetBestBlock(del->pprev->GetBlockHash());
delete del->phashBlock;
delete del;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/skiplist_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height, so we can quickly check the distances.
vBlocksMain[i].nHeight = i;
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : nullptr;
vBlocksMain[i].phashBlock = &vHashMain[i];
vBlocksMain[i].m_hash_block = vHashMain[i];
vBlocksMain[i].BuildSkip();
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].nHeight);
BOOST_CHECK(vBlocksMain[i].pprev == nullptr || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
Expand All @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
vHashSide[i] = ArithToUint256(i + 50000 + (arith_uint256(1) << 128)); // Add 1<<128 to the hashes, so GetLow64() still returns the height.
vBlocksSide[i].nHeight = i + 50000;
vBlocksSide[i].pprev = i ? &vBlocksSide[i - 1] : (vBlocksMain.data()+49999);
vBlocksSide[i].phashBlock = &vHashSide[i];
vBlocksSide[i].m_hash_block = vHashSide[i];
vBlocksSide[i].BuildSkip();
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);
BOOST_CHECK(vBlocksSide[i].pprev == nullptr || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
Expand Down Expand Up @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_test)
vHashMain[i] = ArithToUint256(i); // Set the hash equal to the height
vBlocksMain[i].nHeight = i;
vBlocksMain[i].pprev = i ? &vBlocksMain[i - 1] : nullptr;
vBlocksMain[i].phashBlock = &vHashMain[i];
vBlocksMain[i].m_hash_block = vHashMain[i];
vBlocksMain[i].BuildSkip();
if (i < 10) {
vBlocksMain[i].nTime = i;
Expand Down
12 changes: 10 additions & 2 deletions src/util/hasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ class SignatureCacheHasher
return u;
}
};

template <typename T>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a newline on top.

struct BlockHasher
{
// this used to call `GetCheapHash()` in uint256, which was later moved; the
// cheap hash function simply calls ReadLE64() however, so the end result is
// identical
size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
mutable T mock;
BlockHasher() : mock() {};
size_t operator()(T* const& ptr) const { return ReadLE64(ptr->GetBlockHash().begin()); }
// Helper for querying by hash
// e.g., map.find(map.hash_function()(h))
T* operator()(const uint256& hash) {
mock.m_hash_block = hash;
return &mock;
}
};

class SaltedSipHasher
Expand Down
Loading