-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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(tx-fetcher): only remove peer from active_peers when inflight_count <= 0 #6928
Conversation
Signed-off-by: int88 <golden-miner@qq.com>
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.
nice find! this hasn't been a problem now, since DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER
is 1. hence when a request resolves, the peer should indeed always be removed from active peers. but, the code isn't future proof for when we make the max count configurable.
please when you find a bug like this, add a test in the pr that fixes it to cover the buggy code.
thanks!
@@ -90,10 +90,10 @@ impl TransactionFetcher { | |||
fn decrement_inflight_request_count_for(&mut self, peer_id: &PeerId) { | |||
let remove = || -> bool { | |||
if let Some(inflight_count) = self.active_peers.get(peer_id) { | |||
if *inflight_count <= DEFAULT_MAX_COUNT_CONCURRENT_REQUESTS_PER_PEER { | |||
*inflight_count -= 1; |
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.
*inflight_count -= 1; | |
*inflight_count.saturating_sub(1); |
better safe than sorry
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.
i'm a proponent of using checked methods in case of unintended behavior such as this, thoughts?
will do :) |
@emhane updated :) |
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.
lgtm
fix logic error of
decrement_inflight_request_count_for
.