-
Notifications
You must be signed in to change notification settings - Fork 26
address: Add failed to dial addresses bucket #478
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
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
dmitry-markin
left a comment
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.
One way this can interfere with normal operation is if somebody launches the node with different peer ID on the same port, realizes the mistake, and launches the original node.
This way one can get their validator completely banned by the network.
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Squashed commit of the following: commit 45f842a Author: Alexandru Vasile <alexandru.vasile@parity.io> Date: Mon Nov 24 15:51:54 2025 +0000 address/tests: Add tests for the known bad addrs Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> commit 684bf13 Author: Alexandru Vasile <alexandru.vasile@parity.io> Date: Mon Nov 24 15:35:45 2025 +0000 manager: Rename addr failure to UNRECOVERABLE_FAILURES Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> commit b514e49 Author: Alexandru Vasile <alexandru.vasile@parity.io> Date: Mon Nov 24 15:35:03 2025 +0000 manager: Expire bad addresses Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> commit 1aa1fdc Author: Alexandru Vasile <alexandru.vasile@parity.io> Date: Fri Nov 21 08:54:36 2025 +0000 address: Make fn private Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> commit ba0ce24 Author: Alexandru Vasile <alexandru.vasile@parity.io> Date: Fri Nov 21 08:50:00 2025 +0000 address: Mark addresses as unreachable on terminal error Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> commit 2751bc7 Author: Alexandru Vasile <alexandru.vasile@parity.io> Date: Fri Nov 21 08:41:40 2025 +0000 address: Introduce unrecoverable addresses Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
| const MAX_ADDRESSES: usize = 64; | ||
|
|
||
| /// Duration for which a bad address is kept in the known bad list. | ||
| const BAD_ADDRESS_EXPIRATION: Duration = Duration::from_secs(15 * 60); // 15 Minutes |
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.
| const BAD_ADDRESS_EXPIRATION: Duration = Duration::from_secs(15 * 60); // 15 Minutes | |
| const BAD_ADDRESS_EXPIRATION: Duration = Duration::from_secs(5 * 60); // 5 Minutes |
What about 5 mins?
| // The eviction algorithm favours addresses with higher scores. | ||
| // | ||
| // This algorithm has the following implications: | ||
| // - it keeps the best addresses in the store. | ||
| // - if the store is at capacity, the worst address will be evicted. | ||
| // - an address that is not dialed yet (with score zero) will be preferred over an address | ||
| // that already failed (with negative score). |
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.
Have you deleted the comments on purpose?
| /// This will remove the address from the store and add it to the known bad addresses | ||
| /// with a timestamp. | ||
| fn unrecoverable_address(&mut self, address: Multiaddr) { | ||
| self.addresses.remove(&address); |
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 will lead to permanently banning the address even after the ban expires, better to exclude the address when getting it in addresses().
| pub fn addresses(&self, limit: usize) -> Vec<Multiaddr> { | ||
| let mut records = self.addresses.values().cloned().collect::<Vec<_>>(); | ||
| records.sort_by(|lhs, rhs| rhs.score.cmp(&lhs.score)); | ||
| records.into_iter().take(limit).map(|record| record.address).collect() |
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.
We should check the banned addresses here and unban the ones with the ban expired & exclude the ones with the active ban.
| DialError::NegotiationError(NegotiationError::PeerIdMismatch(_, _)) => | ||
| scores::UNRECOVERABLE_FAILURES, |
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.
In this case we should ban the address, but not set its score to i32::MIN to allow connecting once the ban expires. I don't think we can do this using the magic number, better to return a dedicated type, or at least (i32, bool).
This PR ensures that litep2p keeps track of addresses that failed to dial in the past, up to 64 addresses.
This ensures resources are preserved and failed addresses are no longer dialed.
Litep2p will no longer dial addresses that are marked as unrecoverable:
DialError::AddressErrorNegotiationError::PeerIdMismatch, which means the address corresponds to a different peer than the expected one