Skip to content

Commit 200d84d

Browse files
committed
refactor: use std::string for index names
1 parent 97f5b20 commit 200d84d

8 files changed

+14
-16
lines changed

src/index/base.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include <validation.h> // For g_chainman
1919
#include <warnings.h>
2020

21+
#include <string>
22+
#include <utility>
23+
2124
using node::ReadBlockFromDisk;
2225

2326
constexpr uint8_t DB_BEST_BLOCK{'B'};
@@ -62,8 +65,8 @@ void BaseIndex::DB::WriteBestBlock(CDBBatch& batch, const CBlockLocator& locator
6265
batch.Write(DB_BEST_BLOCK, locator);
6366
}
6467

65-
BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain)
66-
: m_chain{std::move(chain)} {}
68+
BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name)
69+
: m_chain{std::move(chain)}, m_name{std::move(name)} {}
6770

6871
BaseIndex::~BaseIndex()
6972
{

src/index/base.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <threadinterrupt.h>
1111
#include <validationinterface.h>
1212

13+
#include <string>
14+
1315
class CBlock;
1416
class CBlockIndex;
1517
class Chainstate;
@@ -95,6 +97,7 @@ class BaseIndex : public CValidationInterface
9597
protected:
9698
std::unique_ptr<interfaces::Chain> m_chain;
9799
Chainstate* m_chainstate{nullptr};
100+
const std::string m_name;
98101

99102
void BlockConnected(const std::shared_ptr<const CBlock>& block, const CBlockIndex* pindex) override;
100103

@@ -117,13 +120,13 @@ class BaseIndex : public CValidationInterface
117120
virtual DB& GetDB() const = 0;
118121

119122
/// Get the name of the index for display in logs.
120-
virtual const char* GetName() const = 0;
123+
const std::string& GetName() const LIFETIMEBOUND { return m_name; }
121124

122125
/// Update the internal best block index as well as the prune lock.
123126
void SetBestBlockIndex(const CBlockIndex* block);
124127

125128
public:
126-
BaseIndex(std::unique_ptr<interfaces::Chain> chain);
129+
BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name);
127130
/// Destructor interrupts sync thread if running and blocks until it exits.
128131
virtual ~BaseIndex();
129132

src/index/blockfilterindex.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ static std::map<BlockFilterType, BlockFilterIndex> g_filter_indexes;
9797

9898
BlockFilterIndex::BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, BlockFilterType filter_type,
9999
size_t n_cache_size, bool f_memory, bool f_wipe)
100-
: BaseIndex(std::move(chain)), m_filter_type(filter_type)
100+
: BaseIndex(std::move(chain), BlockFilterTypeName(filter_type) + " block filter index")
101+
, m_filter_type(filter_type)
101102
{
102103
const std::string& filter_name = BlockFilterTypeName(filter_type);
103104
if (filter_name.empty()) throw std::invalid_argument("unknown filter_type");
104105

105106
fs::path path = gArgs.GetDataDirNet() / "indexes" / "blockfilter" / fs::u8path(filter_name);
106107
fs::create_directories(path);
107108

108-
m_name = filter_name + " block filter index";
109109
m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
110110
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr", FLTR_FILE_CHUNK_SIZE);
111111
}

src/index/blockfilterindex.h

-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class BlockFilterIndex final : public BaseIndex
2626
{
2727
private:
2828
BlockFilterType m_filter_type;
29-
std::string m_name;
3029
std::unique_ptr<BaseIndex::DB> m_db;
3130

3231
FlatFilePos m_next_filter_pos;
@@ -52,8 +51,6 @@ class BlockFilterIndex final : public BaseIndex
5251

5352
BaseIndex::DB& GetDB() const LIFETIMEBOUND override { return *m_db; }
5453

55-
const char* GetName() const LIFETIMEBOUND override { return m_name.c_str(); }
56-
5754
public:
5855
/** Constructs the index, which becomes available to be queried. */
5956
explicit BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain, BlockFilterType filter_type,

src/index/coinstatsindex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ struct DBHashKey {
105105
std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
106106

107107
CoinStatsIndex::CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)
108-
: BaseIndex(std::move(chain))
108+
: BaseIndex(std::move(chain), "coinstatsindex")
109109
{
110110
fs::path path{gArgs.GetDataDirNet() / "indexes" / "coinstats"};
111111
fs::create_directories(path);

src/index/coinstatsindex.h

-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct CCoinsStats;
2020
class CoinStatsIndex final : public BaseIndex
2121
{
2222
private:
23-
std::string m_name;
2423
std::unique_ptr<BaseIndex::DB> m_db;
2524

2625
MuHash3072 m_muhash;
@@ -52,8 +51,6 @@ class CoinStatsIndex final : public BaseIndex
5251

5352
BaseIndex::DB& GetDB() const override { return *m_db; }
5453

55-
const char* GetName() const override { return "coinstatsindex"; }
56-
5754
public:
5855
// Constructs the index, which becomes available to be queried.
5956
explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);

src/index/txindex.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ bool TxIndex::DB::WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_
4949
}
5050

5151
TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory, bool f_wipe)
52-
: BaseIndex(std::move(chain)), m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
52+
: BaseIndex(std::move(chain), "txindex"), m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe))
5353
{}
5454

5555
TxIndex::~TxIndex() = default;

src/index/txindex.h

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class TxIndex final : public BaseIndex
2727

2828
BaseIndex::DB& GetDB() const override;
2929

30-
const char* GetName() const override { return "txindex"; }
31-
3230
public:
3331
/// Constructs the index, which becomes available to be queried.
3432
explicit TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);

0 commit comments

Comments
 (0)