Skip to content

Commit ba244e8

Browse files
kwvgthelazier
authored andcommitted
merge bitcoin#17687: fix Fatal LevelDB error when specifying -blockfilterindex twice
1 parent 5b9feeb commit ba244e8

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

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

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

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

src/init.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383
#include <stdint.h>
8484
#include <stdio.h>
85+
#include <set>
8586

8687
#include <bls/bls.h>
8788

@@ -1210,7 +1211,7 @@ int nUserMaxConnections;
12101211
int nFD;
12111212
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED);
12121213
int64_t peer_connect_timeout;
1213-
std::vector<BlockFilterType> g_enabled_filter_types;
1214+
std::set<BlockFilterType> g_enabled_filter_types;
12141215

12151216
} // namespace
12161217

@@ -1294,13 +1295,12 @@ bool AppInitParameterInteraction()
12941295
g_enabled_filter_types = AllBlockFilterTypes();
12951296
} else if (blockfilterindex_value != "0") {
12961297
const std::vector<std::string> names = gArgs.GetArgs("-blockfilterindex");
1297-
g_enabled_filter_types.reserve(names.size());
12981298
for (const auto& name : names) {
12991299
BlockFilterType filter_type;
13001300
if (!BlockFilterTypeByName(name, filter_type)) {
13011301
return InitError(strprintf(_("Unknown -blockfilterindex value %s."), name));
13021302
}
1303-
g_enabled_filter_types.push_back(filter_type);
1303+
g_enabled_filter_types.insert(filter_type);
13041304
}
13051305
}
13061306

0 commit comments

Comments
 (0)