net: dedup and RAII-fy the creation of a copy of CConnman::vNodes
Summary:
The following pattern was duplicated in CConnman:
cpp lock create a copy of vNodes, add a reference to each one unlock ... use the copy ... lock release each node from the copy unlock
Put that code in a RAII helper that reduces it to:
cpp create snapshot "snap" ... use the copy ... // release happens when "snap" goes out of scope
This is a partial backport of core#21943
https://github.com/bitcoin/bitcoin/pull/21943/commits/75e8bf55f5a014faada7712a9640dc35e8c86f15
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, roqqit
Reviewed By: roqqit
Differential Revision: https://reviews.bitcoinabc.org/D17106