-
Notifications
You must be signed in to change notification settings - Fork 7
net: be more aggresive wrt removing from known peers DB #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
114d784
to
9fb290d
Compare
// 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)? { |
There was a problem hiding this comment.
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
let known_peers: Vec<_> = { | ||
let rotxn = env.read_txn()?; | ||
let mut txn = env.write_txn()?; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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
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.