The code to read banlist.dat should be removed eventually. The major release (22.x) can be used to translate a banlist.dat into a banlist.json. Thus, it is now possible to remove the reading code.
Ignore banlist.dat #22570
pull MarcoFalke wants to merge 3 commits into bitcoin:master from MarcoFalke:2107-noSerSubnet changing 8 files +550 −587-
MarcoFalke commented at 5:27 PM on July 28, 2021: member
- MarcoFalke added the label P2P on Jul 28, 2021
-
in src/addrdb.cpp:203 in fab2cd8287 outdated
198 | @@ -199,11 +199,13 @@ bool CBanDB::Write(const banmap_t& banSet) 199 | 200 | bool CBanDB::Read(banmap_t& banSet, bool& dirty) 201 | { 202 | - // If the JSON banlist does not exist, then try to read the non-upgraded banlist.dat. 203 | + if (fs::exists(m_banlist_dat)) { 204 | + LogPrintf("banlist.dat ignored because it can only be read by " PACKAGE_NAME " version 22.x. Remove %s to silence this warning.", m_banlist_dat);
fanquake commented at 12:16 AM on July 29, 2021:All calls to LogPrintf() and LogPrint() should be terminated with \n
MarcoFalke commented at 6:35 AM on July 29, 2021:Thanks, fixed.
DrahtBot commented at 3:39 AM on July 29, 2021: member<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
MarcoFalke force-pushed on Jul 29, 2021in doc/files.md:116 in fa718eab70 outdated
112 | @@ -114,6 +113,7 @@ These subdirectories and files are no longer used by Bitcoin Core: 113 | 114 | Path | Description | Repository notes 115 | ---------------|-------------|----------------- 116 | +`banlist.dat` | Stores the addresses/subnets of banned nodes; replaced by `banlist.json` in 23.0 | [PR #22570](https://github.com/bitcoin/bitcoin/pull/22570)
vasild commented at 7:09 AM on July 29, 2021:I think this should read 22.0 instead of 23.0 because already in 22.0 we ignore
banlist.datifbanlist.jsonis present during read and only write tobanlist.json.`banlist.dat` | Stores the addresses/subnets of banned nodes; superseded by `banlist.json` in 22.0 and completely ignored in 23.0 | [PR [#20966](/bitcoin-bitcoin/20966/)](https://github.com/bitcoin/bitcoin/pull/20966), [PR [#22570](/bitcoin-bitcoin/22570/)](https://github.com/bitcoin/bitcoin/pull/22570)in src/addrdb.cpp:200 in fa718eab70 outdated
198 | @@ -199,11 +199,13 @@ bool CBanDB::Write(const banmap_t& banSet) 199 | 200 | bool CBanDB::Read(banmap_t& banSet, bool& dirty)
vasild commented at 7:59 AM on July 29, 2021:The
dirtyargument can be removed.There is just one caller of this method and if this method returns
false, then the caller would ignore the value set inRead()and would set the dirty flag totrueregardless. The only reason for thedirtyflag was ifRead()returnstrueand would setdirtytotrue. This was done to force json creation if onlybanlist.datexisted and was read successfully.
MarcoFalke commented at 10:16 AM on July 29, 2021:The
dirtyargument is used to not write the json file again if it was read successfully and nothing needed to be swept. Happy to drop it, as it simplifies and writing the json once per startup shouldn't cost too much.
vasild commented at 10:28 AM on July 29, 2021:Yes, since
Read()does not do any sweeping its return value is enough to tell whether the read was successful or not. Or, in other words - with this PR it is not possibleRead()to returntrueand set its second argument (dirty) totrue.Something like this should work (not tested):
diff --git i/src/addrdb.cpp w/src/addrdb.cpp index fbffd5c959..c3e224ee83 100644 --- i/src/addrdb.cpp +++ w/src/addrdb.cpp @@ -194,25 +194,22 @@ bool CBanDB::Write(const banmap_t& banSet) for (const auto& err : errors) { error("%s", err); } return false; } -bool CBanDB::Read(banmap_t& banSet, bool& dirty) +bool CBanDB::Read(banmap_t& banSet) { 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)) { - dirty = true; return false; } - dirty = false; - std::map<std::string, util::SettingsValue> settings; std::vector<std::string> errors; if (!util::ReadSettings(m_banlist_json, settings, errors)) { for (const auto& err : errors) { LogPrintf("Cannot load banlist %s: %s\n", m_banlist_json.string(), err); diff --git i/src/addrdb.h w/src/addrdb.h index 0213a14af5..1e0ccb1f60 100644 --- i/src/addrdb.h +++ w/src/addrdb.h @@ -92,17 +92,15 @@ public: bool Write(const banmap_t& banSet); /** * Read the banlist from disk. * [@param](/bitcoin-bitcoin/contributor/param/)[out] banSet The loaded list. Set if `true` is returned, otherwise it is left * in an undefined state. - * [@param](/bitcoin-bitcoin/contributor/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](/bitcoin-bitcoin/contributor/return/) true on success */ - bool Read(banmap_t& banSet, bool& dirty); + bool Read(banmap_t& banSet); }; /** * Dump the anchor IP address database (anchors.dat) * * Anchors are last known outgoing block-relay-only peers that are diff --git i/src/banman.cpp w/src/banman.cpp index d2437e6733..c64a48a05a 100644 --- i/src/banman.cpp +++ w/src/banman.cpp @@ -15,13 +15,13 @@ BanMan::BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time) : m_client_interface(client_interface), m_ban_db(std::move(ban_file)), m_default_ban_time(default_ban_time) { 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(), GetTimeMillis() - n_start); } else { LogPrintf("Recreating the banlist database\n");
MarcoFalke commented at 10:44 AM on July 29, 2021:Thanks, will pick the patch. It is almost correct š„²:
==4031966== Conditional jump or move depends on uninitialised value(s) ==4031966== at 0x46011B: BanMan::DumpBanlist() (banman.cpp:44) ==4031966== by 0x45E962: BanMan::BanMan(boost::filesystem::path, CClientUIInterface*, long) (banman.cpp:32) ==4031966== by 0x15C119: make_unique<BanMan, boost::filesystem::path, CClientUIInterface *, long> (unique_ptr.h:962) ==4031966== by 0x15C119: AppInitMain(NodeContext&, interfaces::BlockAndHeaderTipInfo*) (init.cpp:1164) ==4031966== by 0x141388: AppInit (bitcoind.cpp:226) ==4031966== by 0x141388: main (bitcoind.cpp:269) ==4031966==
vasild commented at 10:53 AM on July 29, 2021:Oh, why did you had to run valgrind on this? It was perfectly safe before that...
in src/addrdb.cpp:203 in fa718eab70 outdated
198 | @@ -199,11 +199,13 @@ bool CBanDB::Write(const banmap_t& banSet) 199 | 200 | bool CBanDB::Read(banmap_t& banSet, bool& dirty) 201 | { 202 | - // If the JSON banlist does not exist, then try to read the non-upgraded banlist.dat. 203 | + if (fs::exists(m_banlist_dat)) { 204 | + 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);
vasild commented at 8:02 AM on July 29, 2021:nit:
LogPrintf("%s ignored because it can only be read by " PACKAGE_NAME " version 22.x or older. Remove %s to silence this warning.\n", m_banlist_dat, m_banlist_dat);Or maybe remove
CBanDB::m_banlist_datand hardcode the string"banlist.dat"here since it is only used here.
MarcoFalke commented at 10:13 AM on July 29, 2021:I need the full path for
fs::exists(m_banlist_dat), so I am going to keep as is for now.practicalswift commented at 8:41 AM on July 29, 2021: contributorConcept ACK
in src/netaddress.h:123 in fa718eab70 outdated
119 | @@ -120,354 +120,354 @@ static constexpr uint16_t I2P_SAM31_PORT{0}; 120 | */ 121 | class CNetAddr 122 | { 123 | - protected:
vasild commented at 9:48 AM on July 29, 2021:This is the whitespace fixup that was dropped as a standalone change in #22562. Here it is combined with some other changes that touch those files.
netaddress.his not fully clang-formatted. Runningclang-format -i netaddress.hproduces the following diff:<details> <summary>format diff</summary>
diff --git i/src/netaddress.h w/src/netaddress.h index 77e1c0464e..eb35ed3fac 100644 --- i/src/netaddress.h +++ w/src/netaddress.h @@ -39,14 +39,13 @@ static constexpr int ADDRV2_FORMAT = 0x20000000; * belongs to both `NET_UNROUTABLE` and `NET_IPV4`. * Keep these sequential starting from 0 and `NET_MAX` as the last entry. * We have loops like `for (int i = 0; i < NET_MAX; ++i)` that expect to iterate * over all enum values and also `GetExtNetwork()` "extends" this enum by * introducing standalone constants starting from `NET_MAX`. */ -enum Network -{ +enum Network { /// Addresses from these networks are not publicly routable on the global Internet. NET_UNROUTABLE = 0, /// IPv4 NET_IPV4, @@ -70,22 +69,20 @@ enum Network NET_MAX, }; /// Prefix of an IPv6 address when it contains an embedded IPv4 address. /// Used when (un)serializing addresses in ADDRv1 format (pre-BIP155). static const std::array<uint8_t, 12> IPV4_IN_IPV6_PREFIX{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF -}; + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}; /// Prefix of an IPv6 address when it contains an embedded TORv2 address. /// Used when (un)serializing addresses in ADDRv1 format (pre-BIP155). /// Such dummy IPv6 addresses are guaranteed to not be publicly routable as they /// fall under RFC4193's fc00::/7 subnet allocated to unique-local addresses. static const std::array<uint8_t, 6> TORV2_IN_IPV6_PREFIX{ - 0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43 -}; + 0xFD, 0x87, 0xD8, 0x7E, 0xEB, 0x43}; /// Prefix of an IPv6 address when it contains an embedded "internal" address. /// Used when (un)serializing addresses in ADDRv1 format (pre-BIP155). /// The prefix comes from 0xFD + SHA256("bitcoin")[0:5]. /// Such dummy IPv6 addresses are guaranteed to not be publicly routable as they /// fall under RFC4193's fc00::/7 subnet allocated to unique-local addresses.</details>
I guess a scripted diff that fully formats the files would be even easier to verify and more complete.
MarcoFalke commented at 10:27 AM on July 29, 2021:Thanks, taken. Couldn't get a scripted-diff working, but happy to take if you find one.
vasild commented at 10:50 AM on July 29, 2021:commit f8a3771957cb1d4d202cd7e3173edfbbeed2657e Parent: faaf9e930d94328c6be42516beab817d45d847f1 Author: Vasil Dimov <vd@FreeBSD.org> AuthorDate: Thu Jul 29 12:39:49 2021 +0200 Commit: Vasil Dimov <vd@FreeBSD.org> CommitDate: Thu Jul 29 12:39:49 2021 +0200 scripted-diff: violate guidelines -BEGIN VERIFY SCRIPT- clang-format -i src/netaddress.h src/test/fuzz/deserialize.cpp -END VERIFY SCRIPT- diff --git a/src/netaddress.h b/src/netaddress.h index c81f9fd5d8..eb35ed3fac 100644 --- a/src/netaddress.h +++ b/src/netaddress.h ... same diff as in fa81dae3db ...Verify:
$ test/lint/commit-script-check.sh origin/master..HEAD Running script for: f8a3771957cb1d4d202cd7e3173edfbbeed2657e clang-format -i src/netaddress.h src/test/fuzz/deserialize.cpp OKvasild commented at 9:49 AM on July 29, 2021: memberApproach ACK
Just to confirm that my understanding is correct: if this is merged now in
master, it will be included in 23.0 but not in 22.1, right?MarcoFalke commented at 10:08 AM on July 29, 2021: memberJust to confirm that my understanding is correct: if this is merged now in master, it will be included in 23.0 but not in 22.1, right?
Yes, the pull request is to the
masterbranch. 22.x is a different branch: https://github.com/bitcoin/bitcoin/tree/22.xMarcoFalke force-pushed on Jul 29, 2021MarcoFalke force-pushed on Jul 29, 2021vasild approvedvasild commented at 3:06 PM on July 29, 2021: memberACK fac51e94ff2781de70ad4e8d3b4868a2d148d237
Zero-1729 approvedZero-1729 commented at 7:37 PM on July 29, 2021: contributorACK fac51e94ff2781de70ad4e8d3b4868a2d148d237
vasild commented at 8:47 AM on July 30, 2021: memberfa384fdd0bIgnore banlist.dat
This also allows to remove the "dirty" argument, which can now be deduced from the return value of Read().
Remove unused CSubNet serialize code fa4e6afdaefa1eddb1a3Fix whitespace in touched files
Leaving the incorrect indentation would be frustrating because: * Some editor may fix up the whitespace when editing a file, so before commiting the whitespace changes need to be undone. * It makes it harder to use clang-format-diff on a change. Can be trivially reviewed with --word-diff-regex=. --ignore-all-space
MarcoFalke force-pushed on Jul 30, 2021Zero-1729 commented at 9:30 AM on July 30, 2021: contributorre-ACK fa1eddb1a3d1319ddc3643b6f34fe2014de32764
vasild approvedvasild commented at 10:58 AM on July 30, 2021: memberACK fa1eddb1a3d1319ddc3643b6f34fe2014de32764
jonatack commented at 11:57 AM on July 30, 2021: memberLight code review utACK fa1eddb1a3d1319ddc3643b6f34fe2014de32764
Zero-1729 approvedlaanwj commented at 10:43 AM on August 2, 2021: memberNot a big fan of the huge whitespace change in the last commit, but otherwise concept and code review ACK fa1eddb1a3d1319ddc3643b6f34fe2014de32764
laanwj merged this on Aug 2, 2021laanwj closed this on Aug 2, 2021MarcoFalke deleted the branch on Aug 2, 2021MarcoFalke commented at 2:20 PM on August 2, 2021: memberRelease notes for 23.0 added in #22603
sidhujag referenced this in commit 1273a5204d on Aug 4, 2021MarcoFalke referenced this in commit 2b06af1747 on Aug 4, 2021sidhujag referenced this in commit 6cb8e022bc on Aug 4, 2021MarcoFalke commented at 8:23 AM on August 7, 2021: memberLooks like we can re-enable the disabled assert again due to the removal of the code here: #22657
MarcoFalke referenced this in commit 2c6707be8b on Sep 6, 2021DrahtBot locked this on Aug 16, 2022
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 12:14 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me