-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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
p2p/msgrate: return capacity as integer #22943
Conversation
This seems the wrong approach. I think we just need to put a cap on the returned / consumed value. |
But the capacity is really an integer. All uses of this method need to convert it to integer anyway, why not convert to integer at the source? |
I mean sure, you can convert the returned values to int, but that won't fix the CI issue :) |
It does actually fix the CI issue, and it's because Capacity will no longer return negative values. |
BTW, I'm talking about this issue: https://ci.appveyor.com/project/ethereum/go-ethereum/builds/39347915/job/ji6ellrc88eshfis#L1667
|
Thought it returned something that overflown. Which part managed to go into negative? |
I tried to reproduce this failure locally, but it doesn't repro for me unfortunately. It would be ideal to have a test in p2p/msgrate, but I don't really understand the code. This is why I decided to fix it by adding |
func TestTracker(t *testing.T){
tracker := NewTracker(nil, 1)
tracker.Update(1, 1, 10000)
cap := tracker.Capacity(1, 10000000)
if int32(cap) < 0{
t.Fatalf("Negative: %v", int32(cap))
}
} |
Yeah, so it's essentially an int32 overflow. Guess we could add some upper limits somehow (e.g. maybe clamp to max int32, that should be enough for anything really and would solve the problem). |
I tried this test, but it doesn't fail for me. |
Updated to make the test fail without the previous fix, and added another fix to clamp the result to max positive int32 as well. |
@karalabe PTAL |
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!
…m#22943) * p2p/msgrate: return capacity as integer * eth/protocols/snap: remove conversions * p2p/msgrate: add overflow test * p2p/msgrate: make the capacity overflow test actually overflow * p2p/msgrate: clamp capacity to max int32 * p2p/msgrate: fix min/max confusion
Trying to fix the windows build failure.