mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
Ignore banlist.dat
This also allows to remove the "dirty" argument, which can now be deduced from the return value of Read().
This commit is contained in:
@@ -197,16 +197,15 @@ bool CBanDB::Write(const banmap_t& banSet)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CBanDB::Read(banmap_t& banSet, bool& dirty)
|
||||
bool CBanDB::Read(banmap_t& banSet)
|
||||
{
|
||||
// If the JSON banlist does not exist, then try to read the non-upgraded banlist.dat.
|
||||
if (!fs::exists(m_banlist_json)) {
|
||||
// If this succeeds then we need to flush to disk in order to create the JSON banlist.
|
||||
dirty = true;
|
||||
return DeserializeFileDB(m_banlist_dat, banSet, CLIENT_VERSION);
|
||||
if (fs::exists(m_banlist_dat)) {
|
||||
LogPrintf("banlist.dat ignored because it can only be read by " PACKAGE_NAME " version 22.x. Remove %s to silence this warning.\n", m_banlist_dat);
|
||||
}
|
||||
// If the JSON banlist does not exist, then recreate it
|
||||
if (!fs::exists(m_banlist_json)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dirty = false;
|
||||
|
||||
std::map<std::string, util::SettingsValue> settings;
|
||||
std::vector<std::string> errors;
|
||||
|
||||
@@ -76,7 +76,7 @@ public:
|
||||
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
|
||||
};
|
||||
|
||||
/** Access to the banlist databases (banlist.json and banlist.dat) */
|
||||
/** Access to the banlist database (banlist.json) */
|
||||
class CBanDB
|
||||
{
|
||||
private:
|
||||
@@ -95,11 +95,9 @@ public:
|
||||
* Read the banlist from disk.
|
||||
* @param[out] banSet The loaded list. Set if `true` is returned, otherwise it is left
|
||||
* in an undefined state.
|
||||
* @param[out] dirty Indicates whether the loaded list needs flushing to disk. Set if
|
||||
* `true` is returned, otherwise it is left in an undefined state.
|
||||
* @return true on success
|
||||
*/
|
||||
bool Read(banmap_t& banSet, bool& dirty);
|
||||
bool Read(banmap_t& banSet);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t
|
||||
if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist…").translated);
|
||||
|
||||
int64_t n_start = GetTimeMillis();
|
||||
if (m_ban_db.Read(m_banned, m_is_dirty)) {
|
||||
if (m_ban_db.Read(m_banned)) {
|
||||
SweepBanned(); // sweep out unused entries
|
||||
|
||||
LogPrint(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),
|
||||
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
|
||||
RecursiveMutex m_cs_banned;
|
||||
banmap_t m_banned GUARDED_BY(m_cs_banned);
|
||||
bool m_is_dirty GUARDED_BY(m_cs_banned);
|
||||
bool m_is_dirty GUARDED_BY(m_cs_banned){false};
|
||||
CClientUIInterface* m_client_interface = nullptr;
|
||||
CBanDB m_ban_db;
|
||||
const int64_t m_default_ban_time;
|
||||
|
||||
@@ -52,8 +52,7 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
|
||||
const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool()};
|
||||
bool force_read_and_write_to_err{false};
|
||||
if (start_with_corrupted_banlist) {
|
||||
const std::string sfx{fuzzed_data_provider.ConsumeBool() ? ".dat" : ".json"};
|
||||
assert(WriteBinaryFile(banlist_file.string() + sfx,
|
||||
assert(WriteBinaryFile(banlist_file.string() + ".json",
|
||||
fuzzed_data_provider.ConsumeRandomLengthString()));
|
||||
} else {
|
||||
force_read_and_write_to_err = fuzzed_data_provider.ConsumeBool();
|
||||
@@ -114,6 +113,5 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
|
||||
(void)(banmap == banmap_read);
|
||||
}
|
||||
}
|
||||
fs::remove(banlist_file.string() + ".dat");
|
||||
fs::remove(banlist_file.string() + ".json");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user