From 034561f9cd4180ea1c165cb02df6c84444a8d692 Mon Sep 17 00:00:00 2001 From: Harris Date: Fri, 6 Dec 2019 21:47:55 +0100 Subject: [PATCH] cli: fix Fatal LevelDB error when specifying -blockfilterindex=basic twice --- src/blockfilter.cpp | 8 ++++---- src/blockfilter.h | 3 ++- src/init.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/blockfilter.cpp b/src/blockfilter.cpp index 787390be31d42..5ad22d46eb925 100644 --- a/src/blockfilter.cpp +++ b/src/blockfilter.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -221,15 +222,14 @@ bool BlockFilterTypeByName(const std::string& name, BlockFilterType& filter_type return false; } -const std::vector& AllBlockFilterTypes() +const std::set& AllBlockFilterTypes() { - static std::vector types; + static std::set types; static std::once_flag flag; std::call_once(flag, []() { - types.reserve(g_filter_types.size()); for (auto entry : g_filter_types) { - types.push_back(entry.first); + types.insert(entry.first); } }); diff --git a/src/blockfilter.h b/src/blockfilter.h index 914b94fec13c9..828204b87543a 100644 --- a/src/blockfilter.h +++ b/src/blockfilter.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -97,7 +98,7 @@ const std::string& BlockFilterTypeName(BlockFilterType filter_type); bool BlockFilterTypeByName(const std::string& name, BlockFilterType& filter_type); /** Get a list of known filter types. */ -const std::vector& AllBlockFilterTypes(); +const std::set& AllBlockFilterTypes(); /** Get a comma-separated list of known filter type names. */ const std::string& ListBlockFilterTypes(); diff --git a/src/init.cpp b/src/init.cpp index e7dda59590cff..9c91c93e6595e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -58,6 +58,7 @@ #include #include +#include #ifndef WIN32 #include @@ -846,7 +847,7 @@ int nUserMaxConnections; int nFD; ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED); int64_t peer_connect_timeout; -std::vector g_enabled_filter_types; +std::set g_enabled_filter_types; } // namespace @@ -934,13 +935,12 @@ bool AppInitParameterInteraction() g_enabled_filter_types = AllBlockFilterTypes(); } else if (blockfilterindex_value != "0") { const std::vector names = gArgs.GetArgs("-blockfilterindex"); - g_enabled_filter_types.reserve(names.size()); for (const auto& name : names) { BlockFilterType filter_type; if (!BlockFilterTypeByName(name, filter_type)) { return InitError(strprintf(_("Unknown -blockfilterindex value %s.").translated, name)); } - g_enabled_filter_types.push_back(filter_type); + g_enabled_filter_types.insert(filter_type); } }