@@ -669,33 +669,6 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
669
669
return &m_blockfile_info.at (n);
670
670
}
671
671
672
- bool BlockManager::UndoWriteToDisk (const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const
673
- {
674
- // Open history file to append
675
- AutoFile fileout{OpenUndoFile (pos)};
676
- if (fileout.IsNull ()) {
677
- LogError (" %s: OpenUndoFile failed\n " , __func__);
678
- return false ;
679
- }
680
-
681
- // Write index header
682
- unsigned int nSize = GetSerializeSize (blockundo);
683
- fileout << GetParams ().MessageStart () << nSize;
684
-
685
- // Write undo data
686
- long fileOutPos = fileout.tell ();
687
- pos.nPos = (unsigned int )fileOutPos;
688
- fileout << blockundo;
689
-
690
- // calculate & write checksum
691
- HashWriter hasher{};
692
- hasher << hashBlock;
693
- hasher << blockundo;
694
- fileout << hasher.GetHash ();
695
-
696
- return true ;
697
- }
698
-
699
672
bool BlockManager::UndoReadFromDisk (CBlockUndo& blockundo, const CBlockIndex& index) const
700
673
{
701
674
const FlatFilePos pos{WITH_LOCK (::cs_main, return index.GetUndoPos ())};
@@ -992,33 +965,52 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
992
965
993
966
// Write undo information to disk
994
967
if (block.GetUndoPos ().IsNull ()) {
995
- FlatFilePos _pos ;
996
- if (!FindUndoPos (state, block.nFile , _pos , ::GetSerializeSize (blockundo) + 40 )) {
968
+ FlatFilePos pos ;
969
+ if (!FindUndoPos (state, block.nFile , pos , ::GetSerializeSize (blockundo) + 40 )) {
997
970
LogError (" %s: FindUndoPos failed\n " , __func__);
998
971
return false ;
999
972
}
1000
- if (!UndoWriteToDisk (blockundo, _pos, block.pprev ->GetBlockHash ())) {
973
+ // Open history file to append
974
+ AutoFile fileout{OpenUndoFile (pos)};
975
+ if (fileout.IsNull ()) {
976
+ LogError (" %s: OpenUndoFile failed\n " , __func__);
1001
977
return FatalError (m_opts.notifications , state, _ (" Failed to write undo data." ));
1002
978
}
979
+
980
+ // Write index header
981
+ unsigned int nSize = GetSerializeSize (blockundo);
982
+ fileout << GetParams ().MessageStart () << nSize;
983
+
984
+ // Write undo data
985
+ long fileOutPos = fileout.tell ();
986
+ pos.nPos = (unsigned int )fileOutPos;
987
+ fileout << blockundo;
988
+
989
+ // Calculate & write checksum
990
+ HashWriter hasher{};
991
+ hasher << block.pprev ->GetBlockHash ();
992
+ hasher << blockundo;
993
+ fileout << hasher.GetHash ();
994
+
1003
995
// rev files are written in block height order, whereas blk files are written as blocks come in (often out of order)
1004
996
// we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
1005
997
// in the block file info as below; note that this does not catch the case where the undo writes are keeping up
1006
998
// with the block writes (usually when a synced up node is getting newly mined blocks) -- this case is caught in
1007
999
// the FindNextBlockPos function
1008
- if (_pos .nFile < cursor.file_num && static_cast <uint32_t >(block.nHeight ) == m_blockfile_info[_pos .nFile ].nHeightLast ) {
1000
+ if (pos .nFile < cursor.file_num && static_cast <uint32_t >(block.nHeight ) == m_blockfile_info[pos .nFile ].nHeightLast ) {
1009
1001
// Do not propagate the return code, a failed flush here should not
1010
1002
// be an indication for a failed write. If it were propagated here,
1011
1003
// the caller would assume the undo data not to be written, when in
1012
1004
// fact it is. Note though, that a failed flush might leave the data
1013
1005
// file untrimmed.
1014
- if (!FlushUndoFile (_pos .nFile , true )) {
1015
- LogPrintLevel (BCLog::BLOCKSTORAGE, BCLog::Level::Warning, " Failed to flush undo file %05i\n " , _pos .nFile );
1006
+ if (!FlushUndoFile (pos .nFile , true )) {
1007
+ LogPrintLevel (BCLog::BLOCKSTORAGE, BCLog::Level::Warning, " Failed to flush undo file %05i\n " , pos .nFile );
1016
1008
}
1017
- } else if (_pos .nFile == cursor.file_num && block.nHeight > cursor.undo_height ) {
1009
+ } else if (pos .nFile == cursor.file_num && block.nHeight > cursor.undo_height ) {
1018
1010
cursor.undo_height = block.nHeight ;
1019
1011
}
1020
1012
// update nUndoPos in block index
1021
- block.nUndoPos = _pos .nPos ;
1013
+ block.nUndoPos = pos .nPos ;
1022
1014
block.nStatus |= BLOCK_HAVE_UNDO;
1023
1015
m_dirty_blockindex.insert (&block);
1024
1016
}
0 commit comments