Skip to content

Commit fa384fd

Browse files
author
MarcoFalke
committed
Ignore banlist.dat
This also allows to remove the "dirty" argument, which can now be deduced from the return value of Read().
1 parent 4b1fb50 commit fa384fd

File tree

6 files changed

+12
-17
lines changed

6 files changed

+12
-17
lines changed

doc/files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Subdirectory | File(s) | Description
5656
`indexes/coinstats/db/` | LevelDB database | Coinstats index; *optional*, used if `-coinstatsindex=1`
5757
`wallets/` | | [Contains wallets](#multi-wallet-environment); can be specified by `-walletdir` option; if `wallets/` subdirectory does not exist, wallets reside in the [data directory](#data-directory-location)
5858
`./` | `anchors.dat` | Anchor IP address database, created on shutdown and deleted at startup. Anchors are last known outgoing block-relay-only peers that are tried to re-connect to on startup
59-
`./` | `banlist.dat` | Stores the addresses/subnets of banned nodes (deprecated). `bitcoind` or `bitcoin-qt` no longer save the banlist to this file, but read it on startup if `banlist.json` is not present.
6059
`./` | `banlist.json` | Stores the addresses/subnets of banned nodes.
6160
`./` | `bitcoin.conf` | User-defined [configuration settings](bitcoin-conf.md) for `bitcoind` or `bitcoin-qt`. File is not written to by the software and must be created manually. Path can be specified by `-conf` option
6261
`./` | `bitcoind.pid` | Stores the process ID (PID) of `bitcoind` or `bitcoin-qt` while running; created at start and deleted on shutdown; can be specified by `-pid` option
@@ -114,6 +113,7 @@ These subdirectories and files are no longer used by Bitcoin Core:
114113

115114
Path | Description | Repository notes
116115
---------------|-------------|-----------------
116+
`banlist.dat` | Stores the addresses/subnets of banned nodes; superseded by `banlist.json` in 22.0 and completely ignored in 23.0 | [PR #20966](https://github.com/bitcoin/bitcoin/pull/20966), [PR #22570](https://github.com/bitcoin/bitcoin/pull/22570)
117117
`blktree/` | Blockchain index; replaced by `blocks/index/` in [0.8.0](https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.8.0.md#improvements) | [PR #2231](https://github.com/bitcoin/bitcoin/pull/2231), [`8fdc94cc`](https://github.com/bitcoin/bitcoin/commit/8fdc94cc8f0341e96b1edb3a5b56811c0b20bd15)
118118
`coins/` | Unspent transaction output database; replaced by `chainstate/` in 0.8.0 | [PR #2231](https://github.com/bitcoin/bitcoin/pull/2231), [`8fdc94cc`](https://github.com/bitcoin/bitcoin/commit/8fdc94cc8f0341e96b1edb3a5b56811c0b20bd15)
119119
`blkindex.dat` | Blockchain index BDB database; replaced by {`chainstate/`, `blocks/index/`, `blocks/revNNNNN.dat`<sup>[\[2\]](#note2)</sup>} in 0.8.0 | [PR #1677](https://github.com/bitcoin/bitcoin/pull/1677)

src/addrdb.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,16 @@ bool CBanDB::Write(const banmap_t& banSet)
197197
return false;
198198
}
199199

200-
bool CBanDB::Read(banmap_t& banSet, bool& dirty)
200+
bool CBanDB::Read(banmap_t& banSet)
201201
{
202-
// If the JSON banlist does not exist, then try to read the non-upgraded banlist.dat.
202+
if (fs::exists(m_banlist_dat)) {
203+
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);
204+
}
205+
// If the JSON banlist does not exist, then recreate it
203206
if (!fs::exists(m_banlist_json)) {
204-
// If this succeeds then we need to flush to disk in order to create the JSON banlist.
205-
dirty = true;
206-
return DeserializeFileDB(m_banlist_dat, banSet, CLIENT_VERSION);
207+
return false;
207208
}
208209

209-
dirty = false;
210-
211210
std::map<std::string, util::SettingsValue> settings;
212211
std::vector<std::string> errors;
213212

src/addrdb.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CAddrDB
7676
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
7777
};
7878

79-
/** Access to the banlist databases (banlist.json and banlist.dat) */
79+
/** Access to the banlist database (banlist.json) */
8080
class CBanDB
8181
{
8282
private:
@@ -95,11 +95,9 @@ class CBanDB
9595
* Read the banlist from disk.
9696
* @param[out] banSet The loaded list. Set if `true` is returned, otherwise it is left
9797
* in an undefined state.
98-
* @param[out] dirty Indicates whether the loaded list needs flushing to disk. Set if
99-
* `true` is returned, otherwise it is left in an undefined state.
10098
* @return true on success
10199
*/
102-
bool Read(banmap_t& banSet, bool& dirty);
100+
bool Read(banmap_t& banSet);
103101
};
104102

105103
/**

src/banman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t
1818
if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist…").translated);
1919

2020
int64_t n_start = GetTimeMillis();
21-
if (m_ban_db.Read(m_banned, m_is_dirty)) {
21+
if (m_ban_db.Read(m_banned)) {
2222
SweepBanned(); // sweep out unused entries
2323

2424
LogPrint(BCLog::NET, "Loaded %d banned node addresses/subnets %dms\n", m_banned.size(),

src/banman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class BanMan
8888

8989
RecursiveMutex m_cs_banned;
9090
banmap_t m_banned GUARDED_BY(m_cs_banned);
91-
bool m_is_dirty GUARDED_BY(m_cs_banned);
91+
bool m_is_dirty GUARDED_BY(m_cs_banned){false};
9292
CClientUIInterface* m_client_interface = nullptr;
9393
CBanDB m_ban_db;
9494
const int64_t m_default_ban_time;

src/test/fuzz/banman.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
5252
const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool()};
5353
bool force_read_and_write_to_err{false};
5454
if (start_with_corrupted_banlist) {
55-
const std::string sfx{fuzzed_data_provider.ConsumeBool() ? ".dat" : ".json"};
56-
assert(WriteBinaryFile(banlist_file.string() + sfx,
55+
assert(WriteBinaryFile(banlist_file.string() + ".json",
5756
fuzzed_data_provider.ConsumeRandomLengthString()));
5857
} else {
5958
force_read_and_write_to_err = fuzzed_data_provider.ConsumeBool();
@@ -114,6 +113,5 @@ FUZZ_TARGET_INIT(banman, initialize_banman)
114113
(void)(banmap == banmap_read);
115114
}
116115
}
117-
fs::remove(banlist_file.string() + ".dat");
118116
fs::remove(banlist_file.string() + ".json");
119117
}

0 commit comments

Comments
 (0)