-
Notifications
You must be signed in to change notification settings - Fork 646
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
fix: Don't drop messages. RouteBack cache update #2841
Conversation
1e1509f
to
9caf3b0
Compare
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 in general avoid negative numbers as much as possible, especially when it is not really needed.
chain/network/src/cache.rs
Outdated
{ | ||
{ | ||
let records = entry.get_mut(); | ||
let first = records.iter().next().cloned().unwrap(); |
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.
Am I correct that you are using BTreeSet
as a heap? If so, why bother with the negative number trick and not use BinaryHeap
instead?
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.
Not exactly, because I need to insert/remove arbitrary elements from the collection.
d2a2ae7
to
2eb0d0b
Compare
} | ||
|
||
fn remove_frequent(&mut self) { | ||
let (mut size, target) = self.size_per_target.iter().next().cloned().unwrap(); |
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 the cache is empty wouldn't this line crash the node?
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.
no, this function is only called when the cache is full so it should have at least one element. There is an assertion that cache capacity should be a positive number.
2eb0d0b
to
2fedb67
Compare
With this implementation once we got to
It will be happening on each insert, so makes the cache pretty expensive compared to a regular cache that does one insert into a hashtable and one linked list insertion. One simple-ish approach is to change With that, I would also always call |
1c058cf
to
b2b3880
Compare
chain/network/src/cache.rs
Outdated
} | ||
|
||
self.size_per_target.remove(&(size, target.clone())); | ||
// Since size has negative sign, adding 1, is equivalent to subtracting 1 from the size. |
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 comment is no longer correct?
fix #2756 Increased route back cache to avoid dropping messages which are supposed to be routed back. The problem was that when some nodes are syncing several chunk request are asked, and request arrive faster than responses, effectively invalidating the cache most of the responses are dropped, since the route back hash was dropped from the cache. Note: This is a vector of attack if we rely on route-back-messages, since malicious actor can feed the cache with new information, effectively invalidating our current cache. Test plan ========= Reproduced this scenario locally, and tested with and without the cache.
This cache is resistant to malicious actors that try to poisson the cache with useless messages.
b2b3880
to
c289912
Compare
Increased route back cache to avoid dropping messages which
are supposed to be routed back. The problem was that when some
nodes are syncing several chunk request are asked, and request
arrive faster than responses, effectively invalidating the cache
most of the responses are dropped, since the route back hash was
dropped from the cache.
This PR also introduce cache strategy proposed here
Fix #2756
Test plan