Skip to content

Avoid pruning trusted nodes when in excess of peers #4150

@0xalex88

Description

@0xalex88

Description

As discussed on discord with @AgeManning I'm trying to find a way to have a similar behavior of geth static/trusted nodes, so nodes that lighthouse always connects to. One limitation I've found is that after staring the beacon node with a set of trusted nodes they are eventually:

  • disconnected when there are too many peers
  • removed from the disconnected peers after reaching MAX_DC_PEERS and no longer trusted if they're discovered again

Version

rust 1.68.2 - lh 4.0.1

Present Behaviour

Trusted peers are disconnected with the same priority as other non trusted ones and are also removed from the peerdb, losing their trusted status

Expected Behaviour

It would be nice that a node is always trusted even after disconnecting/reconnecting and it's not pruned from the connected peers when there are too many peers

Steps to resolve

I had a look at the code and I think to not remove them from the peerdb we could change this section to:

        while self.disconnected_peers > MAX_DC_PEERS {
            if let Some(to_drop) = self
                .peers
                .iter()
                .filter(|(_, info)| info.is_disconnected())
                .filter(|(_, info)| !info.is_trusted())
                .filter_map(|(id, info)| match info.connection_status() {
                    PeerConnectionStatus::Disconnected { since } => Some((id, since)),
                    _ => None,
                })
                .min_by_key(|(_, age)| *age)
                .map(|(id, _)| *id)
            {
                debug!(self.log, "Removing old disconnected peer"; "peer_id" => %to_drop, "disconnected_size" => self.disconnected_peers.saturating_sub(1));
                self.peers.remove(&to_drop);
            }

and change this line to:

!info.has_future_duty() && !info.is_trusted() && $filter(*info)

However I'm not sure how the second part should be tested because I'm not familiar with the arbitrary test section of that function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions