Skip to content

Commit 5706eda

Browse files
committed
merge bitcoin#22915: Remove confusing CAddrDB
1 parent 3f69606 commit 5706eda

File tree

12 files changed

+33
-44
lines changed

12 files changed

+33
-44
lines changed

src/addrdb.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,19 @@ bool CBanDB::Read(banmap_t& banSet)
171171
return true;
172172
}
173173

174-
CAddrDB::CAddrDB()
175-
{
176-
pathAddr = GetDataDir() / "peers.dat";
177-
}
178-
179-
bool CAddrDB::Write(const CAddrMan& addr)
174+
bool DumpPeerAddresses(const ArgsManager& args, const CAddrMan& addr)
180175
{
176+
const auto pathAddr = GetDataDir() / "peers.dat";
181177
return SerializeFileDB("peers", pathAddr, addr, CLIENT_VERSION);
182178
}
183179

184-
bool CAddrDB::Read(CAddrMan& addr)
180+
bool ReadPeerAddresses(const ArgsManager& args, CAddrMan& addr)
185181
{
182+
const auto pathAddr = GetDataDir() / "peers.dat";
186183
return DeserializeFileDB(pathAddr, addr, CLIENT_VERSION);
187184
}
188185

189-
bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)
186+
bool ReadFromStream(CAddrMan& addr, CDataStream& ssPeers)
190187
{
191188
return DeserializeDB(ssPeers, addr, false);
192189
}

src/addrdb.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@
1212

1313
#include <vector>
1414

15-
class CAddress;
15+
class ArgsManager;
1616
class CAddrMan;
17+
class CAddress;
1718
class CDataStream;
1819

19-
/** Access to the (IP) address database (peers.dat) */
20-
class CAddrDB
21-
{
22-
private:
23-
fs::path pathAddr;
24-
public:
25-
CAddrDB();
26-
bool Write(const CAddrMan& addr);
27-
bool Read(CAddrMan& addr);
28-
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
29-
};
20+
bool DumpPeerAddresses(const ArgsManager& args, const CAddrMan& addr);
21+
bool ReadPeerAddresses(const ArgsManager& args, CAddrMan& addr);
22+
/** Only used by tests. */
23+
bool ReadFromStream(CAddrMan& addr, CDataStream& ssPeers);
3024

3125
/** Access to the banlist database (banlist.json) */
3226
class CBanDB

src/addrman.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
#include <addrman.h>
77

8+
#include <clientversion.h>
89
#include <hash.h>
910
#include <logging.h>
1011
#include <netaddress.h>
1112
#include <serialize.h>
13+
#include <streams.h>
1214

1315
#include <cmath>
1416
#include <optional>

src/addrman.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@
66
#ifndef BITCOIN_ADDRMAN_H
77
#define BITCOIN_ADDRMAN_H
88

9-
#include <clientversion.h>
10-
#include <config/bitcoin-config.h>
119
#include <fs.h>
12-
#include <hash.h>
10+
#include <logging.h>
1311
#include <netaddress.h>
1412
#include <protocol.h>
15-
#include <random.h>
16-
#include <streams.h>
1713
#include <sync.h>
1814
#include <timedata.h>
19-
#include <tinyformat.h>
20-
#include <util/system.h>
2115

22-
#include <ios>
16+
#include <cstdint>
2317
#include <optional>
2418
#include <set>
25-
#include <stdint.h>
2619
#include <unordered_map>
2720
#include <vector>
2821

src/init.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,14 +1698,13 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
16981698
// Load addresses from peers.dat
16991699
uiInterface.InitMessage(_("Loading P2P addresses…").translated);
17001700
int64_t nStart = GetTimeMillis();
1701-
CAddrDB adb;
1702-
if (adb.Read(*node.addrman)) {
1701+
if (ReadPeerAddresses(args, *node.addrman)) {
17031702
LogPrintf("Loaded %i addresses from peers.dat %dms\n", node.addrman->size(), GetTimeMillis() - nStart);
17041703
} else {
17051704
// Addrman can be in an inconsistent state after failure, reset it
17061705
node.addrman = std::make_unique<CAddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
17071706
LogPrintf("Recreating peers.dat\n");
1708-
adb.Write(*node.addrman);
1707+
DumpPeerAddresses(args, *node.addrman);
17091708
}
17101709
}
17111710

src/net.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <net.h>
1212
#include <netmessagemaker.h>
1313

14+
#include <addrdb.h>
1415
#include <banman.h>
1516
#include <clientversion.h>
1617
#include <compat.h>
@@ -26,6 +27,7 @@
2627
#include <scheduler.h>
2728
#include <util/sock.h>
2829
#include <util/strencodings.h>
30+
#include <util/system.h>
2931
#include <util/thread.h>
3032
#include <util/time.h>
3133
#include <util/translation.h>
@@ -2324,8 +2326,7 @@ void CConnman::DumpAddresses()
23242326
{
23252327
int64_t nStart = GetTimeMillis();
23262328

2327-
CAddrDB adb;
2328-
adb.Write(addrman);
2329+
DumpPeerAddresses(::gArgs, addrman);
23292330

23302331
LogPrint(BCLog::NET, "Flushed %d addresses to peers.dat %dms\n",
23312332
addrman.size(), GetTimeMillis() - nStart);

src/net.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#ifndef BITCOIN_NET_H
77
#define BITCOIN_NET_H
88

9-
#include <addrdb.h>
109
#include <addrman.h>
1110
#include <bloom.h>
1211
#include <chainparams.h>

src/qt/bantablemodel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef BITCOIN_QT_BANTABLEMODEL_H
66
#define BITCOIN_QT_BANTABLEMODEL_H
77

8+
#include <addrdb.h>
89
#include <net.h>
910

1011
#include <memory>

src/qt/walletframe.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <qt/walletcontroller.h>
1313
#include <qt/walletmodel.h>
1414
#include <qt/walletview.h>
15+
#include <util/system.h>
1516

1617
#include <cassert>
1718

src/test/addrman_tests.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <addrdb.h>
66
#include <addrman.h>
77
#include <chainparams.h>
8+
#include <clientversion.h>
89
#include <hash.h>
910
#include <netbase.h>
1011
#include <random.h>
@@ -1001,8 +1002,7 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
10011002
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
10021003
}
10031004

1004-
1005-
BOOST_AUTO_TEST_CASE(caddrdb_read)
1005+
BOOST_AUTO_TEST_CASE(load_addrman)
10061006
{
10071007
CAddrManUncorrupted addrmanUncorrupted;
10081008

@@ -1037,17 +1037,17 @@ BOOST_AUTO_TEST_CASE(caddrdb_read)
10371037
BOOST_CHECK(addrman1.size() == 3);
10381038
BOOST_CHECK(exceptionThrown == false);
10391039

1040-
// Test that CAddrDB::Read creates an addrman with the correct number of addrs.
1040+
// Test that ReadFromStream creates an addrman with the correct number of addrs.
10411041
CDataStream ssPeers2 = AddrmanToStream(addrmanUncorrupted);
10421042

10431043
CAddrMan addrman2(/* asmap */ std::vector<bool>(), /* deterministic */ false, /* consistency_check_ratio */ 100);
10441044
BOOST_CHECK(addrman2.size() == 0);
1045-
BOOST_CHECK(CAddrDB::Read(addrman2, ssPeers2));
1045+
BOOST_CHECK(ReadFromStream(addrman2, ssPeers2));
10461046
BOOST_CHECK(addrman2.size() == 3);
10471047
}
10481048

10491049

1050-
BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
1050+
BOOST_AUTO_TEST_CASE(load_addrman_corrupted)
10511051
{
10521052
CAddrManCorrupted addrmanCorrupted;
10531053

@@ -1063,16 +1063,16 @@ BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
10631063
} catch (const std::exception&) {
10641064
exceptionThrown = true;
10651065
}
1066-
// Even through de-serialization failed addrman is not left in a clean state.
1066+
// Even though de-serialization failed addrman is not left in a clean state.
10671067
BOOST_CHECK(addrman1.size() == 1);
10681068
BOOST_CHECK(exceptionThrown);
10691069

1070-
// Test that CAddrDB::Read fails if peers.dat is corrupt
1070+
// Test that ReadFromStream fails if peers.dat is corrupt
10711071
CDataStream ssPeers2 = AddrmanToStream(addrmanCorrupted);
10721072

10731073
CAddrMan addrman2(/* asmap */ std::vector<bool>(), /* deterministic */ false, /* consistency_check_ratio */ 100);
10741074
BOOST_CHECK(addrman2.size() == 0);
1075-
BOOST_CHECK(!CAddrDB::Read(addrman2, ssPeers2));
1075+
BOOST_CHECK(!ReadFromStream(addrman2, ssPeers2));
10761076
}
10771077

10781078
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)