Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115762
D17707.id52782.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
D17707.id52782.diff
View Options
diff --git a/src/index/base.h b/src/index/base.h
--- a/src/index/base.h
+++ b/src/index/base.h
@@ -10,6 +10,8 @@
#include <threadinterrupt.h>
#include <validationinterface.h>
+#include <string>
+
class CBlock;
class CBlockIndex;
class Chainstate;
@@ -89,6 +91,7 @@
protected:
std::unique_ptr<interfaces::Chain> m_chain;
Chainstate *m_chainstate{nullptr};
+ const std::string m_name;
void BlockConnected(const std::shared_ptr<const CBlock> &block,
const CBlockIndex *pindex) override;
@@ -117,13 +120,13 @@
virtual DB &GetDB() const = 0;
/// Get the name of the index for display in logs.
- virtual const char *GetName() const = 0;
+ const std::string &GetName() const LIFETIMEBOUND { return m_name; }
/// Update the internal best block index as well as the prune lock.
void SetBestBlockIndex(const CBlockIndex *block);
public:
- BaseIndex(std::unique_ptr<interfaces::Chain> chain);
+ BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name);
/// Destructor interrupts sync thread if running and blocks until it exits.
virtual ~BaseIndex();
diff --git a/src/index/base.cpp b/src/index/base.cpp
--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -21,6 +21,8 @@
#include <warnings.h>
#include <functional>
+#include <string>
+#include <utility>
constexpr uint8_t DB_BEST_BLOCK{'B'};
@@ -62,8 +64,8 @@
batch.Write(DB_BEST_BLOCK, locator);
}
-BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain)
- : m_chain{std::move(chain)} {}
+BaseIndex::BaseIndex(std::unique_ptr<interfaces::Chain> chain, std::string name)
+ : m_chain{std::move(chain)}, m_name{std::move(name)} {}
BaseIndex::~BaseIndex() {
Interrupt();
diff --git a/src/index/blockfilterindex.h b/src/index/blockfilterindex.h
--- a/src/index/blockfilterindex.h
+++ b/src/index/blockfilterindex.h
@@ -27,7 +27,6 @@
class BlockFilterIndex final : public BaseIndex {
private:
BlockFilterType m_filter_type;
- std::string m_name;
std::unique_ptr<BaseIndex::DB> m_db;
FlatFilePos m_next_filter_pos;
@@ -57,9 +56,6 @@
const CBlockIndex *new_tip) override;
BaseIndex::DB &GetDB() const override { return *m_db; }
-
- const char *GetName() const override { return m_name.c_str(); }
-
public:
/** Constructs the index, which becomes available to be queried. */
explicit BlockFilterIndex(std::unique_ptr<interfaces::Chain> chain,
diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp
--- a/src/index/blockfilterindex.cpp
+++ b/src/index/blockfilterindex.cpp
@@ -106,7 +106,9 @@
BlockFilterType filter_type,
size_t n_cache_size, bool f_memory,
bool f_wipe)
- : BaseIndex(std::move(chain)), m_filter_type(filter_type) {
+ : BaseIndex(std::move(chain),
+ BlockFilterTypeName(filter_type) + " block filter index"),
+ m_filter_type(filter_type) {
const std::string &filter_name = BlockFilterTypeName(filter_type);
if (filter_name.empty()) {
throw std::invalid_argument("unknown filter_type");
@@ -116,7 +118,6 @@
gArgs.GetDataDirNet() / "indexes" / "blockfilter" / filter_name;
fs::create_directories(path);
- m_name = filter_name + " block filter index";
m_db = std::make_unique<BaseIndex::DB>(path / "db", n_cache_size, f_memory,
f_wipe);
m_filter_fileseq = std::make_unique<FlatFileSeq>(std::move(path), "fltr",
diff --git a/src/index/coinstatsindex.h b/src/index/coinstatsindex.h
--- a/src/index/coinstatsindex.h
+++ b/src/index/coinstatsindex.h
@@ -20,7 +20,6 @@
*/
class CoinStatsIndex final : public BaseIndex {
private:
- std::string m_name;
std::unique_ptr<BaseIndex::DB> m_db;
MuHash3072 m_muhash;
@@ -53,8 +52,6 @@
BaseIndex::DB &GetDB() const override { return *m_db; }
- const char *GetName() const override { return "coinstatsindex"; }
-
public:
// Constructs the index, which becomes available to be queried.
explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain,
diff --git a/src/index/coinstatsindex.cpp b/src/index/coinstatsindex.cpp
--- a/src/index/coinstatsindex.cpp
+++ b/src/index/coinstatsindex.cpp
@@ -103,7 +103,7 @@
CoinStatsIndex::CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain,
size_t n_cache_size, bool f_memory, bool f_wipe)
- : BaseIndex(std::move(chain)) {
+ : BaseIndex(std::move(chain), "coinstatsindex") {
fs::path path{gArgs.GetDataDirNet() / "indexes" / "coinstats"};
fs::create_directories(path);
diff --git a/src/index/txindex.h b/src/index/txindex.h
--- a/src/index/txindex.h
+++ b/src/index/txindex.h
@@ -33,8 +33,6 @@
BaseIndex::DB &GetDB() const override;
- const char *GetName() const override { return "txindex"; }
-
public:
/// Constructs the index, which becomes available to be queried.
explicit TxIndex(std::unique_ptr<interfaces::Chain> chain,
diff --git a/src/index/txindex.cpp b/src/index/txindex.cpp
--- a/src/index/txindex.cpp
+++ b/src/index/txindex.cpp
@@ -48,7 +48,7 @@
TxIndex::TxIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size,
bool f_memory, bool f_wipe)
- : BaseIndex(std::move(chain)),
+ : BaseIndex(std::move(chain), "txindex"),
m_db(std::make_unique<TxIndex::DB>(n_cache_size, f_memory, f_wipe)) {}
TxIndex::~TxIndex() {}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 11:59 (40 m, 25 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187749
Default Alt Text
D17707.id52782.diff (5 KB)
Attached To
D17707: refactor: use std::string for index names
Event Timeline
Log In to Comment