Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions src/bench/rpc_blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ static void BlockToJsonVerbose(benchmark::Bench& bench)
stream >> block;

CBlockIndex blockindex;
const uint256 blockHash = block.GetHash();
blockindex.phashBlock = &blockHash;
blockindex.m_hash_block = block.GetHash();
blockindex.nBits = 403014710;

bench.run([&] {
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 @@ -230,9 +230,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 @@ -1347,10 +1347,10 @@ static UniValue getchaintips(const JSONRPCRequest& request)
std::set<const CBlockIndex*> setOrphans;
std::set<const CBlockIndex*> setPrevs;

for (const std::pair<const uint256, CBlockIndex*>& item : chainman.BlockIndex()) {
if (!chainman.ActiveChain().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 @@ -1368,7 +1368,7 @@ static UniValue getchaintips(const JSONRPCRequest& request)
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 - chainman.ActiveChain().FindFork(block)->nHeight;
obj.pushKV("branchlen", branchLen);
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 @@ void test_one_input(const std::vector<uint8_t>& buffer)
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 @@ void test_one_input(const std::vector<uint8_t>& buffer)
}

CBlockIndex block_index{block_header};
block_index.phashBlock = &zero;
(void)block_index.GetBlockHash();
(void)block_index.ToString();
}
5 changes: 2 additions & 3 deletions src/test/miner_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
while (::ChainActive().Tip()->nHeight < 209999) {
CBlockIndex* prev = ::ChainActive().Tip();
CBlockIndex* next = new CBlockIndex();
next->phashBlock = new uint256(InsecureRand256());
next->m_hash_block = uint256(InsecureRand256());
::ChainstateActive().CoinsTip().SetBestBlock(next->GetBlockHash());
next->pprev = prev;
next->nHeight = prev->nHeight + 1;
Expand All @@ -389,7 +389,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
while (::ChainActive().Tip()->nHeight < 210000) {
CBlockIndex* prev = ::ChainActive().Tip();
CBlockIndex* next = new CBlockIndex();
next->phashBlock = new uint256(InsecureRand256());
next->m_hash_block = uint256(InsecureRand256());
::ChainstateActive().CoinsTip().SetBestBlock(next->GetBlockHash());
next->pprev = prev;
next->nHeight = prev->nHeight + 1;
Expand Down Expand Up @@ -421,7 +421,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
CBlockIndex* del = ::ChainActive().Tip();
::ChainActive().SetTip(del->pprev);
::ChainstateActive().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
Loading