Merge cdcc74bbcc into merged_master (Elements PR #1270)

This commit is contained in:
James Dorfman 2024-09-23 16:51:13 +00:00
commit 61b0543ba7
20 changed files with 508 additions and 127 deletions

View file

@ -261,15 +261,7 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
{
int trim_below_height = 0;
if (fTrimHeaders) {
int max_height = 0;
if (!m_block_tree_db->WalkBlockIndexGutsForMaxHeight(&max_height)) {
LogPrintf("LoadBlockIndex: Failed to WalkBlockIndexGutsForMaxHeight.\n");
return false;
}
int must_keep_headers = (consensus_params.total_valid_epochs + 2) * consensus_params.dynamic_epoch_length;
int extra_headers_buffer = consensus_params.dynamic_epoch_length * 2; // XXX arbitrary
trim_below_height = max_height - must_keep_headers - extra_headers_buffer;
trim_below_height = std::numeric_limits<int>::max();
}
if (!m_block_tree_db->LoadBlockIndexGuts(consensus_params, [this](const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main) { return this->InsertBlockIndex(hash); }, trim_below_height)) {
return false;
@ -310,6 +302,9 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
}
}
if (pindexBestHeader) {
ForceUntrimHeader(pindexBestHeader);
}
return true;
}
@ -769,23 +764,6 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus
return true;
}
bool ReadBlockHeaderFromDisk(CBlockHeader& header, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
{
// Not very efficient: read a block and throw away all but the header.
CBlock tmp;
if (!ReadBlockFromDisk(tmp, pindex, consensusParams)) {
return false;
}
const FlatFilePos block_pos{WITH_LOCK(cs_main, return pindex->GetBlockPos())};
header = tmp.GetBlockHeader();
if (tmp.GetHash() != pindex->GetBlockHash()) {
return error("ReadBlockheaderFromDisk(CBlockHeader&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
pindex->ToString(), block_pos.ToString());
}
return true;
}
bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start)
{
FlatFilePos hpos = pos;