@@ -722,29 +722,30 @@ static bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos, const CMessa
722
722
723
723
bool BlockManager::WriteUndoDataForBlock (const CBlockUndo& blockundo, BlockValidationState& state, CBlockIndex* pindex, const CChainParams& chainparams)
724
724
{
725
+ auto & block{*pindex};
725
726
AssertLockHeld (::cs_main);
726
727
// Write undo information to disk
727
- if (pindex-> GetUndoPos ().IsNull ()) {
728
+ if (block. GetUndoPos ().IsNull ()) {
728
729
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 )) {
730
731
return error (" ConnectBlock(): FindUndoPos failed" );
731
732
}
732
- if (!UndoWriteToDisk (blockundo, _pos, pindex-> pprev ->GetBlockHash (), GetParams ().MessageStart ())) {
733
+ if (!UndoWriteToDisk (blockundo, _pos, block. pprev ->GetBlockHash (), GetParams ().MessageStart ())) {
733
734
return AbortNode (state, " Failed to write undo data" );
734
735
}
735
736
// rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
736
737
// we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
737
738
// in the block file info as below; note that this does not catch the case where the undo writes are keeping up
738
739
// with the block writes (usually when a synced up node is getting newly mined blocks) -- this case is caught in
739
740
// 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 ) {
741
742
FlushUndoFile (_pos.nFile , true );
742
743
}
743
744
744
745
// 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 );
748
749
}
749
750
750
751
return true ;
0 commit comments