refactor: Use reference instead of pointer in IsBlockPruned

This makes it harder to pass nullptr and cause issues such as
dde7ac5c70
This commit is contained in:
MarcoFalke
2023-12-07 10:21:14 +01:00
parent dce1dfbc47
commit fa604eb6cf
5 changed files with 11 additions and 13 deletions

View File

@@ -394,18 +394,17 @@ static RPCHelpMan getrawtransaction()
// If request is verbosity >= 1 but no blockhash was given, then look up the blockindex
if (request.params[2].isNull()) {
LOCK(cs_main);
blockindex = chainman.m_blockman.LookupBlockIndex(hash_block);
blockindex = chainman.m_blockman.LookupBlockIndex(hash_block); // May be nullptr for mempool transactions
}
if (verbosity == 1 || !blockindex) {
if (verbosity == 1) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;
}
CBlockUndo blockUndo;
CBlock block;
const bool is_block_pruned{WITH_LOCK(cs_main, return chainman.m_blockman.IsBlockPruned(blockindex))};
if (tx->IsCoinBase() || is_block_pruned ||
if (tx->IsCoinBase() || !blockindex || WITH_LOCK(::cs_main, return chainman.m_blockman.IsBlockPruned(*blockindex)) ||
!(chainman.m_blockman.UndoReadFromDisk(blockUndo, *blockindex) && chainman.m_blockman.ReadBlockFromDisk(block, *blockindex))) {
TxToJSON(*tx, hash_block, result, chainman.ActiveChainstate());
return result;