Skip to content

Conversation

@torkelrogstad
Copy link
Contributor

Prior to this commit we end up trying to reconnect to peers every time
we start up. Be more aggressive in removing bad peers from the DB list
of known peers.

Also make sure to re-add the seed node every time we start up, if we
have an empty list of known peers.

Separate the two distinct problems:

1. We're unable to connect to mainchain
2. Mainchain doesn't support the functionality we need
Prior to this commit we end up trying to reconnect to peers every time
we start up. Be more aggressive in removing bad peers from the DB list
of known peers.

Also make sure to re-add the seed node every time we start up, if we
have an empty list of known peers.
// might end up with this peer misbehaving, causing us to
// disconnect and delete it from the database. always try
// and stick it back in, if it's missing!
if net.known_peers.is_empty(&txn)? {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why start a new db txn? This could happen in the same db txn that creates/opens the DB

#[allow(clippy::let_and_return)]
let known_peers: Vec<_> = {
let rotxn = env.read_txn()?;
let mut txn = env.write_txn()?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Prefer rotxn/rwtxn to clearly indicate DB locks, and to disambiguate w.r.t. network/block txs

#[instrument(skip_all, fields(addr))]
pub fn remove_active_peer(
&self,
env: &heed::Env,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a RwTxn

let () = self
.ctxt
.net
.remove_active_peer(&self.ctxt.env, addr)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If remove_active_peer also removes from known peers, then this seems wrong. A disconnected peer should still be in known peers

let () = self
.ctxt
.net
.remove_active_peer(&self.ctxt.env, addr)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A peer connection error could have many causes, not sure if it is correct to remove from known peers here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants