@@ -848,7 +848,7 @@ fs::path BlockManager::GetBlockPosFilename(const FlatFilePos& pos) const
848848 return BlockFileSeq ().FileName (pos);
849849}
850850
851- bool BlockManager::FindBlockPos (FlatFilePos& pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime)
851+ FlatFilePos BlockManager::FindNextBlockPos ( unsigned int nAddSize, unsigned int nHeight, uint64_t nTime)
852852{
853853 LOCK (cs_LastBlockFile);
854854
@@ -897,6 +897,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
897897 m_blockfile_info.resize (nFile + 1 );
898898 }
899899 }
900+ FlatFilePos pos;
900901 pos.nFile = nFile;
901902 pos.nPos = m_blockfile_info[nFile].nSize ;
902903
@@ -927,14 +928,14 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
927928 size_t bytes_allocated = BlockFileSeq ().Allocate (pos, nAddSize, out_of_space);
928929 if (out_of_space) {
929930 m_opts.notifications .fatalError (_ (" Disk space is too low!" ));
930- return false ;
931+ return {} ;
931932 }
932933 if (bytes_allocated != 0 && IsPruneMode ()) {
933934 m_check_for_pruning = true ;
934935 }
935936
936937 m_dirty_fileinfo.insert (nFile);
937- return true ;
938+ return pos ;
938939}
939940
940941void BlockManager::UpdateBlockInfo (const CBlock& block, unsigned int nHeight, const FlatFilePos& pos)
@@ -1031,7 +1032,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
10311032 // we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
10321033 // in the block file info as below; note that this does not catch the case where the undo writes are keeping up
10331034 // with the block writes (usually when a synced up node is getting newly mined blocks) -- this case is caught in
1034- // the FindBlockPos function
1035+ // the FindNextBlockPos function
10351036 if (_pos.nFile < cursor.file_num && static_cast <uint32_t >(block.nHeight ) == m_blockfile_info[_pos.nFile ].nHeightLast ) {
10361037 // Do not propagate the return code, a failed flush here should not
10371038 // be an indication for a failed write. If it were propagated here,
@@ -1150,12 +1151,12 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
11501151FlatFilePos BlockManager::SaveBlockToDisk (const CBlock& block, int nHeight)
11511152{
11521153 unsigned int nBlockSize = ::GetSerializeSize (TX_WITH_WITNESS (block));
1153- FlatFilePos blockPos;
11541154 // Account for the 4 magic message start bytes + the 4 length bytes (8 bytes total,
11551155 // defined as BLOCK_SERIALIZATION_HEADER_SIZE)
11561156 nBlockSize += static_cast <unsigned int >(BLOCK_SERIALIZATION_HEADER_SIZE);
1157- if (!FindBlockPos (blockPos, nBlockSize, nHeight, block.GetBlockTime ())) {
1158- LogError (" %s: FindBlockPos failed\n " , __func__);
1157+ FlatFilePos blockPos{FindNextBlockPos (nBlockSize, nHeight, block.GetBlockTime ())};
1158+ if (blockPos.IsNull ()) {
1159+ LogError (" %s: FindNextBlockPos failed\n " , __func__);
11591160 return FlatFilePos ();
11601161 }
11611162 if (!WriteBlockToDisk (block, blockPos)) {
0 commit comments