Skip to content

Commit fa3f74a

Browse files
author
MarcoFalke
committed
Replace pindex pointer with block reference
pindex can not be nullptr, so document that, and clear it up in the next commit.
1 parent facdb8b commit fa3f74a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/node/blockstorage.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -722,29 +722,30 @@ static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessa
722722

723723
bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
724724
{
725+
auto& block{*pindex};
725726
AssertLockHeld(::cs_main);
726727
// Write undo information to disk
727-
if (pindex->GetUndoPos().IsNull()) {
728+
if (block.GetUndoPos().IsNull()) {
728729
FlatFilePos _pos;
729-
if (!FindUndoPos(state, pindex->nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) {
730+
if (!FindUndoPos(state, block.nFile, _pos, ::GetSerializeSize(blockundo, CLIENT_VERSION) + 40)) {
730731
return error("ConnectBlock(): FindUndoPos failed");
731732
}
732-
if (!UndoWriteToDisk(blockundo, _pos, pindex->pprev->GetBlockHash(), GetParams().MessageStart())) {
733+
if (!UndoWriteToDisk(blockundo, _pos, block.pprev->GetBlockHash(), GetParams().MessageStart())) {
733734
return AbortNode(state, "Failed to write undo data");
734735
}
735736
// rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
736737
// we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
737738
// in the block file info as below; note that this does not catch the case where the undo writes are keeping up
738739
// with the block writes (usually when a synced up node is getting newly mined blocks) -- this case is caught in
739740
// the FindBlockPos function
740-
if (_pos.nFile < m_last_blockfile && static_cast<uint32_t>(pindex->nHeight) == m_blockfile_info[_pos.nFile].nHeightLast) {
741+
if (_pos.nFile < m_last_blockfile && static_cast<uint32_t>(block.nHeight) == m_blockfile_info[_pos.nFile].nHeightLast) {
741742
FlushUndoFile(_pos.nFile, true);
742743
}
743744

744745
// update nUndoPos in block index
745-
pindex->nUndoPos = _pos.nPos;
746-
pindex->nStatus |= BLOCK_HAVE_UNDO;
747-
m_dirty_blockindex.insert(pindex);
746+
block.nUndoPos = _pos.nPos;
747+
block.nStatus |= BLOCK_HAVE_UNDO;
748+
m_dirty_blockindex.insert(&block);
748749
}
749750

750751
return true;

0 commit comments

Comments
 (0)