refactor: Remove useless CBlock::GetBlockHeader
There is no need for a function to convert a CBlock to a CBlockHeader, as it's a child class of it.
This commit is contained in:
1 parent
4568652222
commit
ca0243e3a6
7 files changed
+8
-21
No files matched your search
+1
-1
@@ -29,7 +29,7 @@ std::vector<bool> BytesToBits(const std::vector<unsigned char>& bytes)
|
|||||||
|
|
||||||
CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std::set<Txid>* txids)
|
CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter* filter, const std::set<Txid>* txids)
|
||||||
{
|
{
|
||||||
header = block.GetBlockHeader();
|
header = static_cast<const CBlockHeader&>(block);
|
||||||
|
|
||||||
std::vector<bool> vMatch;
|
std::vector<bool> vMatch;
|
||||||
std::vector<Txid> vHashes;
|
std::vector<Txid> vHashes;
|
||||||
|
|||||||
@@ -4666,7 +4666,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));
|
mapBlockSource.emplace(hash, std::make_pair(pfrom.GetId(), true));
|
||||||
|
|
||||||
// Check claimed work on this block against our anti-dos thresholds.
|
// Check claimed work on this block against our anti-dos thresholds.
|
||||||
if (prev_block && prev_block->nChainWork + GetBlockProof(pblock->GetBlockHeader()) >= GetAntiDoSWorkThreshold()) {
|
if (prev_block && prev_block->nChainWork + GetBlockProof(*pblock) >= GetAntiDoSWorkThreshold()) {
|
||||||
min_pow_checked = true;
|
min_pow_checked = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,18 +101,6 @@ public:
|
|||||||
m_checked_merkle_root = false;
|
m_checked_merkle_root = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBlockHeader GetBlockHeader() const
|
|
||||||
{
|
|
||||||
CBlockHeader block;
|
|
||||||
block.nVersion = nVersion;
|
|
||||||
block.hashPrevBlock = hashPrevBlock;
|
|
||||||
block.hashMerkleRoot = hashMerkleRoot;
|
|
||||||
block.nTime = nTime;
|
|
||||||
block.nBits = nBits;
|
|
||||||
block.nNonce = nNonce;
|
|
||||||
return block;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ToString() const;
|
std::string ToString() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -102,10 +102,9 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
|
|||||||
chain.resize(length);
|
chain.resize(length);
|
||||||
for (auto& block : chain) {
|
for (auto& block : chain) {
|
||||||
block = std::make_shared<CBlock>(CreateBlock(pindex, no_txns, coinbase_script_pub_key));
|
block = std::make_shared<CBlock>(CreateBlock(pindex, no_txns, coinbase_script_pub_key));
|
||||||
CBlockHeader header = block->GetBlockHeader();
|
|
||||||
|
|
||||||
BlockValidationState state;
|
BlockValidationState state;
|
||||||
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({{header}}, true, state, &pindex)) {
|
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({{*block}}, true, state, &pindex)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ FUZZ_TARGET(block_header)
|
|||||||
mut_block_header.SetNull();
|
mut_block_header.SetNull();
|
||||||
assert(mut_block_header.IsNull());
|
assert(mut_block_header.IsNull());
|
||||||
CBlock block{*block_header};
|
CBlock block{*block_header};
|
||||||
assert(block.GetBlockHeader().GetHash() == block_header->GetHash());
|
assert(block.GetHash() == block_header->GetHash());
|
||||||
(void)block.ToString();
|
(void)block.ToString();
|
||||||
block.SetNull();
|
block.SetNull();
|
||||||
assert(block.GetBlockHeader().GetHash() == mut_block_header.GetHash());
|
assert(block.GetHash() == mut_block_header.GetHash());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
std::optional<CBlockLocator> block_locator = ConsumeDeserializable<CBlockLocator>(fuzzed_data_provider);
|
std::optional<CBlockLocator> block_locator = ConsumeDeserializable<CBlockLocator>(fuzzed_data_provider);
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ void initialize_chain()
|
|||||||
auto& chainman{*setup->m_node.chainman};
|
auto& chainman{*setup->m_node.chainman};
|
||||||
for (const auto& block : chain) {
|
for (const auto& block : chain) {
|
||||||
BlockValidationState dummy;
|
BlockValidationState dummy;
|
||||||
bool processed{chainman.ProcessNewBlockHeaders({{block->GetBlockHeader()}}, true, dummy)};
|
bool processed{chainman.ProcessNewBlockHeaders({{*block}}, true, dummy)};
|
||||||
Assert(processed);
|
Assert(processed);
|
||||||
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
|
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
|
||||||
Assert(index);
|
Assert(index);
|
||||||
@@ -171,7 +171,7 @@ void utxo_snapshot_fuzz(FuzzBufferType buffer)
|
|||||||
if constexpr (!INVALID) {
|
if constexpr (!INVALID) {
|
||||||
for (const auto& block : *g_chain) {
|
for (const auto& block : *g_chain) {
|
||||||
BlockValidationState dummy;
|
BlockValidationState dummy;
|
||||||
bool processed{chainman.ProcessNewBlockHeaders({{block->GetBlockHeader()}}, true, dummy)};
|
bool processed{chainman.ProcessNewBlockHeaders({{*block}}, true, dummy)};
|
||||||
Assert(processed);
|
Assert(processed);
|
||||||
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
|
const auto* index{WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block->GetHash()))};
|
||||||
Assert(index);
|
Assert(index);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock>
|
|||||||
// submit block header, so that miner can get the block height from the
|
// submit block header, so that miner can get the block height from the
|
||||||
// global state and the node has the topology of the chain
|
// global state and the node has the topology of the chain
|
||||||
BlockValidationState ignored;
|
BlockValidationState ignored;
|
||||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({{pblock->GetBlockHeader()}}, true, ignored));
|
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({{*pblock}}, true, ignored));
|
||||||
|
|
||||||
return pblock;
|
return pblock;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user