Skip to content

Commit bda2f5b

Browse files
brakmicfanquake
authored andcommitted
cli: fix Fatal LevelDB error when specifying -blockfilterindex=basic twice
Github-Pull: bitcoin#17687 Rebased-From: 034561f
1 parent d14ab7c commit bda2f5b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

src/blockfilter.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <mutex>
66
#include <sstream>
7+
#include <set>
78

89
#include <blockfilter.h>
910
#include <crypto/siphash.h>
@@ -221,15 +222,14 @@ bool BlockFilterTypeByName(const std::string& name, BlockFilterType& filter_type
221222
return false;
222223
}
223224

224-
const std::vector<BlockFilterType>& AllBlockFilterTypes()
225+
const std::set<BlockFilterType>& AllBlockFilterTypes()
225226
{
226-
static std::vector<BlockFilterType> types;
227+
static std::set<BlockFilterType> types;
227228

228229
static std::once_flag flag;
229230
std::call_once(flag, []() {
230-
types.reserve(g_filter_types.size());
231231
for (auto entry : g_filter_types) {
232-
types.push_back(entry.first);
232+
types.insert(entry.first);
233233
}
234234
});
235235

src/blockfilter.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <stdint.h>
99
#include <string>
10+
#include <set>
1011
#include <unordered_set>
1112
#include <vector>
1213

@@ -97,7 +98,7 @@ const std::string& BlockFilterTypeName(BlockFilterType filter_type);
9798
bool BlockFilterTypeByName(const std::string& name, BlockFilterType& filter_type);
9899

99100
/** Get a list of known filter types. */
100-
const std::vector<BlockFilterType>& AllBlockFilterTypes();
101+
const std::set<BlockFilterType>& AllBlockFilterTypes();
101102

102103
/** Get a comma-separated list of known filter type names. */
103104
const std::string& ListBlockFilterTypes();

src/init.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
#include <stdint.h>
5959
#include <stdio.h>
60+
#include <set>
6061

6162
#ifndef WIN32
6263
#include <attributes.h>
@@ -865,7 +866,7 @@ int nUserMaxConnections;
865866
int nFD;
866867
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED);
867868
int64_t peer_connect_timeout;
868-
std::vector<BlockFilterType> g_enabled_filter_types;
869+
std::set<BlockFilterType> g_enabled_filter_types;
869870

870871
} // namespace
871872

@@ -953,13 +954,12 @@ bool AppInitParameterInteraction()
953954
g_enabled_filter_types = AllBlockFilterTypes();
954955
} else if (blockfilterindex_value != "0") {
955956
const std::vector<std::string> names = gArgs.GetArgs("-blockfilterindex");
956-
g_enabled_filter_types.reserve(names.size());
957957
for (const auto& name : names) {
958958
BlockFilterType filter_type;
959959
if (!BlockFilterTypeByName(name, filter_type)) {
960960
return InitError(strprintf(_("Unknown -blockfilterindex value %s.").translated, name));
961961
}
962-
g_enabled_filter_types.push_back(filter_type);
962+
g_enabled_filter_types.insert(filter_type);
963963
}
964964
}
965965

0 commit comments

Comments
 (0)