Skip to content
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

feat: start DIP0024 from block 1 - fire up test chains by first block - 7/n #6325

Merged
merged 11 commits into from
Dec 10, 2024
Merged
15 changes: 9 additions & 6 deletions src/evo/creditpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,20 @@ void CCreditPoolManager::AddToCache(const uint256& block_hash, int height, const

static std::optional<CBlock> GetBlockForCreditPool(const CBlockIndex* const block_index, const Consensus::Params& consensusParams)
{
// There's no CbTx before DIP0003 activation
if (!DeploymentActiveAt(*block_index, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003)) {
Copy link
Member

Choose a reason for hiding this comment

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

block_index can be null here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it seems unrelated because it was used in ReadBlockFromDisk before without extra checks:

bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
{   
    const FlatFilePos block_pos{WITH_LOCK(cs_main, return pindex->GetBlockPos())};

Anyway, I added extra annotations just in case, see a new commit

return std::nullopt;
}

CBlock block;
if (!ReadBlockFromDisk(block, block_index, consensusParams)) {
throw std::runtime_error("failed-getcbforblock-read");
}

assert(!block.vtx.empty());

// Should not fail if V20 (DIP0027) is active but it happens for RegChain (unit tests)
if (!block.vtx[0]->IsSpecialTxVersion()) return std::nullopt;

assert(!block.vtx[0]->vExtraPayload.empty());
if (block.vtx.empty() || block.vtx[0]->vExtraPayload.empty() || !block.vtx[0]->IsSpecialTxVersion()) {
LogPrintf("%s: ERROR: empty CbTx for CreditPool at height=%d\n", __func__, block_index->nHeight);
return std::nullopt;
}

return block;
}
Expand Down