HomePhabricator

addrman: Remove CAddrMan::Clear() function

Description

addrman: Remove CAddrMan::Clear() function

Summary:
This completes backport of core#22697.

CAddrMan::Clear() exists to reset the internal state of CAddrMan. It's currently used in two places:

    on startup, if deserializing peers.dat fails, Clear() is called to reset to an empty addrman
    in tests, Clear() is called to reset the addrman for more tests

In both cases, we can simply destruct the CAddrMan and construct a new, empty addrman. That approach is safer - it's possible that Clear() could 'reset' the addrman to a state that's not equivalent to a freshly constructed addrman (one actual example of this is that Clear() does not clear the m_tried_collisions set). On the other hand, if we destruct and then construct a fresh addrman, we're guaranteed that the new object is empty.

This wasn't possible when addrman was initially implemented, since it was a global, and so it would only be destructed on shutdown. However, addrman is now owned by node.context, so we have control over its destruction/construction.

This involves reverting D11827 in order to match core and be a bit creative with the tests.

Test Plan:

ninja all check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D18014

Details

Provenance
FabienAuthored on Tue, Apr 29, 08:55
FabienPushed on Tue, Apr 29, 13:19
Reviewer
Restricted Project
Differential Revision
D18014: addrman: Remove CAddrMan::Clear() function
Parents
rABC7f65b6a8f20e: [test] Pretty print expected messages when asserting a debug log
Branches
Unknown
Tags
Unknown