[addrman] Add deterministic argument to CAddrMan ctor

Removes the need for tests to update nKey and insecure_rand after constructing
a CAddrMan.
This commit is contained in:
John Newbery
2021-07-23 10:48:34 +01:00
parent ee458d84fc
commit fa9710f62c
10 changed files with 31 additions and 43 deletions

View File

@@ -21,24 +21,13 @@ private:
bool deterministic;
public:
explicit CAddrManTest(bool makeDeterministic = true,
std::vector<bool> asmap = std::vector<bool>())
std::vector<bool> asmap = std::vector<bool>())
: CAddrMan(makeDeterministic)
{
if (makeDeterministic) {
// Set addrman addr placement to be deterministic.
MakeDeterministic();
}
deterministic = makeDeterministic;
m_asmap = asmap;
}
//! Ensure that bucket placement is always the same for testing purposes.
void MakeDeterministic()
{
LOCK(cs);
nKey.SetNull();
insecure_rand = FastRandomContext(true);
}
CAddrInfo* Find(const CNetAddr& addr, int* pnId = nullptr)
{
LOCK(cs);