cli: fix Fatal LevelDB error when specifying -blockfilterindex=basic twice

This commit is contained in:
Harris
2019-12-06 21:47:55 +01:00
parent cb11324a63
commit 034561f9cd
3 changed files with 9 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
#include <mutex> #include <mutex>
#include <sstream> #include <sstream>
#include <set>
#include <blockfilter.h> #include <blockfilter.h>
#include <crypto/siphash.h> #include <crypto/siphash.h>
@@ -221,15 +222,14 @@ bool BlockFilterTypeByName(const std::string& name, BlockFilterType& filter_type
return false; return false;
} }
const std::vector<BlockFilterType>& AllBlockFilterTypes() const std::set<BlockFilterType>& AllBlockFilterTypes()
{ {
static std::vector<BlockFilterType> types; static std::set<BlockFilterType> types;
static std::once_flag flag; static std::once_flag flag;
std::call_once(flag, []() { std::call_once(flag, []() {
types.reserve(g_filter_types.size());
for (auto entry : g_filter_types) { for (auto entry : g_filter_types) {
types.push_back(entry.first); types.insert(entry.first);
} }
}); });

View File

@@ -7,6 +7,7 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <set>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
@@ -97,7 +98,7 @@ const std::string& BlockFilterTypeName(BlockFilterType filter_type);
bool BlockFilterTypeByName(const std::string& name, BlockFilterType& filter_type); bool BlockFilterTypeByName(const std::string& name, BlockFilterType& filter_type);
/** Get a list of known filter types. */ /** Get a list of known filter types. */
const std::vector<BlockFilterType>& AllBlockFilterTypes(); const std::set<BlockFilterType>& AllBlockFilterTypes();
/** Get a comma-separated list of known filter type names. */ /** Get a comma-separated list of known filter type names. */
const std::string& ListBlockFilterTypes(); const std::string& ListBlockFilterTypes();

View File

@@ -58,6 +58,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <set>
#ifndef WIN32 #ifndef WIN32
#include <attributes.h> #include <attributes.h>
@@ -846,7 +847,7 @@ int nUserMaxConnections;
int nFD; int nFD;
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED); ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED);
int64_t peer_connect_timeout; int64_t peer_connect_timeout;
std::vector<BlockFilterType> g_enabled_filter_types; std::set<BlockFilterType> g_enabled_filter_types;
} // namespace } // namespace
@@ -934,13 +935,12 @@ bool AppInitParameterInteraction()
g_enabled_filter_types = AllBlockFilterTypes(); g_enabled_filter_types = AllBlockFilterTypes();
} else if (blockfilterindex_value != "0") { } else if (blockfilterindex_value != "0") {
const std::vector<std::string> names = gArgs.GetArgs("-blockfilterindex"); const std::vector<std::string> names = gArgs.GetArgs("-blockfilterindex");
g_enabled_filter_types.reserve(names.size());
for (const auto& name : names) { for (const auto& name : names) {
BlockFilterType filter_type; BlockFilterType filter_type;
if (!BlockFilterTypeByName(name, filter_type)) { if (!BlockFilterTypeByName(name, filter_type)) {
return InitError(strprintf(_("Unknown -blockfilterindex value %s.").translated, name)); return InitError(strprintf(_("Unknown -blockfilterindex value %s.").translated, name));
} }
g_enabled_filter_types.push_back(filter_type); g_enabled_filter_types.insert(filter_type);
} }
} }