@@ -848,7 +848,7 @@ fs::path BlockManager::GetBlockPosFilename(const FlatFilePos& pos) const
848
848
return BlockFileSeq ().FileName (pos);
849
849
}
850
850
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)
852
852
{
853
853
LOCK (cs_LastBlockFile);
854
854
@@ -897,6 +897,7 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
897
897
m_blockfile_info.resize (nFile + 1 );
898
898
}
899
899
}
900
+ FlatFilePos pos;
900
901
pos.nFile = nFile;
901
902
pos.nPos = m_blockfile_info[nFile].nSize ;
902
903
@@ -927,14 +928,14 @@ bool BlockManager::FindBlockPos(FlatFilePos& pos, unsigned int nAddSize, unsigne
927
928
size_t bytes_allocated = BlockFileSeq ().Allocate (pos, nAddSize, out_of_space);
928
929
if (out_of_space) {
929
930
m_opts.notifications .fatalError (_ (" Disk space is too low!" ));
930
- return false ;
931
+ return {} ;
931
932
}
932
933
if (bytes_allocated != 0 && IsPruneMode ()) {
933
934
m_check_for_pruning = true ;
934
935
}
935
936
936
937
m_dirty_fileinfo.insert (nFile);
937
- return true ;
938
+ return pos ;
938
939
}
939
940
940
941
void BlockManager::UpdateBlockInfo (const CBlock& block, unsigned int nHeight, const FlatFilePos& pos)
@@ -1031,7 +1032,7 @@ bool BlockManager::WriteUndoDataForBlock(const CBlockUndo& blockundo, BlockValid
1031
1032
// we want to flush the rev (undo) file once we've written the last block, which is indicated by the last height
1032
1033
// in the block file info as below; note that this does not catch the case where the undo writes are keeping up
1033
1034
// 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
1035
1036
if (_pos.nFile < cursor.file_num && static_cast <uint32_t >(block.nHeight ) == m_blockfile_info[_pos.nFile ].nHeightLast ) {
1036
1037
// Do not propagate the return code, a failed flush here should not
1037
1038
// 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
1150
1151
FlatFilePos BlockManager::SaveBlockToDisk (const CBlock& block, int nHeight)
1151
1152
{
1152
1153
unsigned int nBlockSize = ::GetSerializeSize (TX_WITH_WITNESS (block));
1153
- FlatFilePos blockPos;
1154
1154
// Account for the 4 magic message start bytes + the 4 length bytes (8 bytes total,
1155
1155
// defined as BLOCK_SERIALIZATION_HEADER_SIZE)
1156
1156
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__);
1159
1160
return FlatFilePos ();
1160
1161
}
1161
1162
if (!WriteBlockToDisk (block, blockPos)) {
0 commit comments