Skip to content

Commit bbd4646

Browse files
committed
blockstorage: switch from CAutoFile to AutoFile
Also bump includes per suggestions from iwyu.
1 parent c72ddf0 commit bbd4646

File tree

6 files changed

+34
-25
lines changed

6 files changed

+34
-25
lines changed

src/index/txindex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
7979
return false;
8080
}
8181

82-
CAutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
82+
AutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
8383
if (file.IsNull()) {
8484
return error("%s: OpenBlockFile failed", __func__);
8585
}

src/node/blockstorage.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,32 @@
44

55
#include <node/blockstorage.h>
66

7+
#include <arith_uint256.h>
78
#include <chain.h>
8-
#include <clientversion.h>
9+
#include <consensus/params.h>
910
#include <consensus/validation.h>
1011
#include <dbwrapper.h>
1112
#include <flatfile.h>
1213
#include <hash.h>
13-
#include <kernel/chain.h>
14+
#include <kernel/blockmanager_opts.h>
1415
#include <kernel/chainparams.h>
1516
#include <kernel/messagestartchars.h>
17+
#include <kernel/notifications_interface.h>
1618
#include <logging.h>
1719
#include <pow.h>
20+
#include <primitives/block.h>
21+
#include <primitives/transaction.h>
1822
#include <reverse_iterator.h>
23+
#include <serialize.h>
1924
#include <signet.h>
25+
#include <span.h>
2026
#include <streams.h>
2127
#include <sync.h>
28+
#include <tinyformat.h>
29+
#include <uint256.h>
2230
#include <undo.h>
2331
#include <util/batchpriority.h>
32+
#include <util/check.h>
2433
#include <util/fs.h>
2534
#include <util/signalinterrupt.h>
2635
#include <util/strencodings.h>
@@ -656,7 +665,7 @@ CBlockFileInfo* BlockManager::GetBlockFileInfo(size_t n)
656665
bool BlockManager::UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const
657666
{
658667
// Open history file to append
659-
CAutoFile fileout{OpenUndoFile(pos)};
668+
AutoFile fileout{OpenUndoFile(pos)};
660669
if (fileout.IsNull()) {
661670
return error("%s: OpenUndoFile failed", __func__);
662671
}
@@ -691,7 +700,7 @@ bool BlockManager::UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex& in
691700
}
692701

693702
// Open history file to read
694-
CAutoFile filein{OpenUndoFile(pos, true)};
703+
AutoFile filein{OpenUndoFile(pos, true)};
695704
if (filein.IsNull()) {
696705
return error("%s: OpenUndoFile failed", __func__);
697706
}
@@ -810,15 +819,15 @@ FlatFileSeq BlockManager::UndoFileSeq() const
810819
return FlatFileSeq(m_opts.blocks_dir, "rev", UNDOFILE_CHUNK_SIZE);
811820
}
812821

813-
CAutoFile BlockManager::OpenBlockFile(const FlatFilePos& pos, bool fReadOnly) const
822+
AutoFile BlockManager::OpenBlockFile(const FlatFilePos& pos, bool fReadOnly) const
814823
{
815-
return CAutoFile{BlockFileSeq().Open(pos, fReadOnly), CLIENT_VERSION};
824+
return AutoFile{BlockFileSeq().Open(pos, fReadOnly)};
816825
}
817826

818827
/** Open an undo file (rev?????.dat) */
819-
CAutoFile BlockManager::OpenUndoFile(const FlatFilePos& pos, bool fReadOnly) const
828+
AutoFile BlockManager::OpenUndoFile(const FlatFilePos& pos, bool fReadOnly) const
820829
{
821-
return CAutoFile{UndoFileSeq().Open(pos, fReadOnly), CLIENT_VERSION};
830+
return AutoFile{UndoFileSeq().Open(pos, fReadOnly)};
822831
}
823832

824833
fs::path BlockManager::GetBlockPosFilename(const FlatFilePos& pos) const
@@ -950,7 +959,7 @@ bool BlockManager::FindUndoPos(BlockValidationState& state, int nFile, FlatFileP
950959
bool BlockManager::WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const
951960
{
952961
// Open history file to append
953-
CAutoFile fileout{OpenBlockFile(pos)};
962+
AutoFile fileout{OpenBlockFile(pos)};
954963
if (fileout.IsNull()) {
955964
return error("WriteBlockToDisk: OpenBlockFile failed");
956965
}
@@ -1016,7 +1025,7 @@ bool BlockManager::ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos) cons
10161025
block.SetNull();
10171026

10181027
// Open history file to read
1019-
CAutoFile filein{OpenBlockFile(pos, true)};
1028+
AutoFile filein{OpenBlockFile(pos, true)};
10201029
if (filein.IsNull()) {
10211030
return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString());
10221031
}
@@ -1059,7 +1068,7 @@ bool BlockManager::ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatF
10591068
{
10601069
FlatFilePos hpos = pos;
10611070
hpos.nPos -= 8; // Seek back 8 bytes for meta header
1062-
CAutoFile filein{OpenBlockFile(hpos, true)};
1071+
AutoFile filein{OpenBlockFile(hpos, true)};
10631072
if (filein.IsNull()) {
10641073
return error("%s: OpenBlockFile failed for %s", __func__, pos.ToString());
10651074
}
@@ -1151,7 +1160,7 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
11511160
if (!fs::exists(chainman.m_blockman.GetBlockPosFilename(pos))) {
11521161
break; // No block files left to reindex
11531162
}
1154-
CAutoFile file{chainman.m_blockman.OpenBlockFile(pos, true)};
1163+
AutoFile file{chainman.m_blockman.OpenBlockFile(pos, true)};
11551164
if (file.IsNull()) {
11561165
break; // This error is logged in OpenBlockFile
11571166
}
@@ -1172,7 +1181,7 @@ void ImportBlocks(ChainstateManager& chainman, std::vector<fs::path> vImportFile
11721181

11731182
// -loadblock=
11741183
for (const fs::path& path : vImportFiles) {
1175-
CAutoFile file{fsbridge::fopen(path, "rb"), CLIENT_VERSION};
1184+
AutoFile file{fsbridge::fopen(path, "rb")};
11761185
if (!file.IsNull()) {
11771186
LogPrintf("Importing blocks file %s...\n", fs::PathToString(path));
11781187
chainman.LoadExternalBlockFile(file);

src/node/blockstorage.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,36 @@
88
#include <attributes.h>
99
#include <chain.h>
1010
#include <dbwrapper.h>
11+
#include <flatfile.h>
1112
#include <kernel/blockmanager_opts.h>
12-
#include <kernel/chain.h>
1313
#include <kernel/chainparams.h>
1414
#include <kernel/cs_main.h>
1515
#include <kernel/messagestartchars.h>
16+
#include <primitives/block.h>
17+
#include <streams.h>
1618
#include <sync.h>
19+
#include <uint256.h>
1720
#include <util/fs.h>
1821
#include <util/hasher.h>
1922

23+
#include <array>
2024
#include <atomic>
2125
#include <cstdint>
2226
#include <functional>
2327
#include <limits>
2428
#include <map>
2529
#include <memory>
30+
#include <optional>
2631
#include <set>
2732
#include <string>
2833
#include <unordered_map>
2934
#include <utility>
3035
#include <vector>
3136

3237
class BlockValidationState;
33-
class CAutoFile;
34-
class CBlock;
3538
class CBlockUndo;
36-
class CChainParams;
3739
class Chainstate;
3840
class ChainstateManager;
39-
struct CCheckpointData;
40-
struct FlatFilePos;
4141
namespace Consensus {
4242
struct Params;
4343
}
@@ -162,7 +162,7 @@ class BlockManager
162162
FlatFileSeq BlockFileSeq() const;
163163
FlatFileSeq UndoFileSeq() const;
164164

165-
CAutoFile OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false) const;
165+
AutoFile OpenUndoFile(const FlatFilePos& pos, bool fReadOnly = false) const;
166166

167167
bool WriteBlockToDisk(const CBlock& block, FlatFilePos& pos) const;
168168
bool UndoWriteToDisk(const CBlockUndo& blockundo, FlatFilePos& pos, const uint256& hashBlock) const;
@@ -350,7 +350,7 @@ class BlockManager
350350
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
351351

352352
/** Open a block file (blk?????.dat) */
353-
CAutoFile OpenBlockFile(const FlatFilePos& pos, bool fReadOnly = false) const;
353+
AutoFile OpenBlockFile(const FlatFilePos& pos, bool fReadOnly = false) const;
354354

355355
/** Translation to a filesystem path */
356356
fs::path GetBlockPosFilename(const FlatFilePos& pos) const;

src/test/fuzz/load_external_block_file.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ FUZZ_TARGET(load_external_block_file, .init = initialize_load_external_block_fil
2828
{
2929
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
3030
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
31-
CAutoFile fuzzed_block_file{fuzzed_file_provider.open(), CLIENT_VERSION};
31+
AutoFile fuzzed_block_file{fuzzed_file_provider.open()};
3232
if (fuzzed_block_file.IsNull()) {
3333
return;
3434
}

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4649,7 +4649,7 @@ bool Chainstate::LoadGenesisBlock()
46494649
}
46504650

46514651
void ChainstateManager::LoadExternalBlockFile(
4652-
CAutoFile& file_in,
4652+
AutoFile& file_in,
46534653
FlatFilePos* dbp,
46544654
std::multimap<uint256, FlatFilePos>* blocks_with_unknown_parent)
46554655
{

src/validation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ class ChainstateManager
11371137
* (only used for reindex)
11381138
* */
11391139
void LoadExternalBlockFile(
1140-
CAutoFile& file_in,
1140+
AutoFile& file_in,
11411141
FlatFilePos* dbp = nullptr,
11421142
std::multimap<uint256, FlatFilePos>* blocks_with_unknown_parent = nullptr);
11431143

0 commit comments

Comments
 (0)