Page MenuHomePhabricator

addrman: Remove CAddrMan::Clear() function
ClosedPublic

Authored by Fabien on Tue, Apr 29, 09:33.

Details

Reviewers
PiRK
Group Reviewers
Restricted Project
Commits
rABC017ae519e82f: 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

Diff Detail

Event Timeline

Fabien requested review of this revision.Tue, Apr 29, 09:33

Tail of the build log:

wallet_txn_clone.py --mineblock            | ✓ Passed  | 3 s
wallet_txn_doublespend.py                  | ✓ Passed  | 1 s
wallet_txn_doublespend.py --mineblock      | ✓ Passed  | 3 s
wallet_watchonly.py                        | ✓ Passed  | 1 s
wallet_watchonly.py --usecli               | ✓ Passed  | 1 s
chronik_avalanche.py                       | ○ Skipped | 0 s
chronik_block.py                           | ○ Skipped | 0 s
chronik_block_header.py                    | ○ Skipped | 0 s
chronik_block_info.py                      | ○ Skipped | 0 s
chronik_block_txs.py                       | ○ Skipped | 0 s
chronik_blockchain_info.py                 | ○ Skipped | 0 s
chronik_blocks.py                          | ○ Skipped | 0 s
chronik_chronik_info.py                    | ○ Skipped | 0 s
chronik_cors.py                            | ○ Skipped | 0 s
chronik_disable_token_index.py             | ○ Skipped | 0 s
chronik_disallow_prune.py                  | ○ Skipped | 0 s
chronik_electrum_basic.py                  | ○ Skipped | 0 s
chronik_electrum_blockchain.py             | ○ Skipped | 0 s
chronik_lokad_id_group.py                  | ○ Skipped | 0 s
chronik_mempool_conflicts.py               | ○ Skipped | 0 s
chronik_mempool_disconnectpool.py          | ○ Skipped | 0 s
chronik_pause.py                           | ○ Skipped | 0 s
chronik_plugin_groups.py                   | ○ Skipped | 0 s
chronik_plugins.py                         | ○ Skipped | 0 s
chronik_plugins_setup.py                   | ○ Skipped | 0 s
chronik_raw_tx.py                          | ○ Skipped | 0 s
chronik_resync.py                          | ○ Skipped | 0 s
chronik_script_confirmed_txs.py            | ○ Skipped | 0 s
chronik_script_history.py                  | ○ Skipped | 0 s
chronik_script_unconfirmed_txs.py          | ○ Skipped | 0 s
chronik_script_utxos.py                    | ○ Skipped | 0 s
chronik_scripthash.py                      | ○ Skipped | 0 s
chronik_serve.py                           | ○ Skipped | 0 s
chronik_spent_by.py                        | ○ Skipped | 0 s
chronik_token_alp.py                       | ○ Skipped | 0 s
chronik_token_broadcast_txs.py             | ○ Skipped | 0 s
chronik_token_burn.py                      | ○ Skipped | 0 s
chronik_token_id_group.py                  | ○ Skipped | 0 s
chronik_token_parse_failure.py             | ○ Skipped | 0 s
chronik_token_script_group.py              | ○ Skipped | 0 s
chronik_token_slp_fungible.py              | ○ Skipped | 0 s
chronik_token_slp_mint_vault.py            | ○ Skipped | 0 s
chronik_token_slp_nft1.py                  | ○ Skipped | 0 s
chronik_tx.py                              | ○ Skipped | 0 s
chronik_tx_removal_order.py                | ○ Skipped | 0 s
chronik_ws.py                              | ○ Skipped | 0 s
chronik_ws_ordering.py                     | ○ Skipped | 0 s
chronik_ws_ping.py                         | ○ Skipped | 0 s
chronik_ws_script.py                       | ○ Skipped | 0 s
feature_bind_port_discover.py              | ○ Skipped | 0 s
feature_bind_port_externalip.py            | ○ Skipped | 0 s
interface_usdt_net.py                      | ○ Skipped | 0 s
interface_usdt_utxocache.py                | ○ Skipped | 0 s
interface_usdt_validation.py               | ○ Skipped | 0 s

ALL                                        | ✓ Passed  | 1200 s (accumulated) 
Runtime: 101 s

ninja: build stopped: cannot make progress due to previous errors.
Build build-diff failed with exit code 1
Fabien planned changes to this revision.Tue, Apr 29, 09:59

Restore addrman deterministicness in net_tests

This revision is now accepted and ready to land.Tue, Apr 29, 12:18
This revision was automatically updated to reflect the committed changes.