I'm trying to figure out how a node maintains its list of anchor peers. I know that they are important when a node restarts. However, when does a node add and remove other nodes to its anchor peer list? And does this list interact with the list of white and grey peers? Because in the function connections_maker, a node does some computations and depending on these it tries to connect to a peer of this anchor list.
Leaving aside exclusive peers, when a node starts for the very first time, it connects to the seed peer(s) to get an initial peer list. It then attempts to maintain at least 2 anchor peers (if it successfully handshakes with an attempted peer and doesn't already have enough anchor peers, it can be added to the anchor list).
If an anchor node goes away, it is removed from the peer list and another white peer is attempted to be added as a new anchor. The node also broadcasts its updated peer list.
All other peers are either in the gray or white peer lists. The gray list contains a list of peers that the node has not attempted to connect to and the white list contains a list of peers the node has successfully performed a handshake with.
Whenever a new peer list is broadcast (so from one of the connected peers), the white and gray peers received get merged into the receiving nodes peer list. The node then broadcasts this list with it's connected peers.
Essentially, each node needs to maintain some connected nodes, some nodes known to be online and some nodes not yet attempted to connect to.
connections_maker is called periodically to keep these lists healthy.
Lastly, the nodes peer lists are persisted to
~/.bitmonero/p2pstate.bin. This is saved periodically and on shutdown. Upon startup, it is loaded to initialize the peer lists, which puts less reliance on the seed nodes (e.g. if you connect to enough peers from the saved peers, there is no need to use the seed nodes, they become fallbacks).