Skip to content
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

Merged
merged 6 commits into from
May 27, 2021

Conversation

fjl
Copy link
Contributor

@fjl fjl commented May 26, 2021

Trying to fix the windows build failure.

@karalabe
Copy link
Member

This seems the wrong approach. I think we just need to put a cap on the returned / consumed value.

@fjl
Copy link
Contributor Author

fjl commented May 26, 2021

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?

@karalabe
Copy link
Member

I mean sure, you can convert the returned values to int, but that won't fix the CI issue :)

@fjl
Copy link
Contributor Author

fjl commented May 27, 2021

It does actually fix the CI issue, and it's because Capacity will no longer return negative values.

@fjl
Copy link
Contributor Author

fjl commented May 27, 2021

BTW, I'm talking about this issue: https://ci.appveyor.com/project/ethereum/go-ethereum/builds/39347915/job/ji6ellrc88eshfis#L1667

panic: runtime error: makeslice: cap out of range
goroutine 38971 [running]:
github.com/ethereum/go-ethereum/eth/downloader.(*queue).reserveHeaders(0x1618ea00, 0x1618eb40, 0x80000000, 0x161b7200, 0x19f33ba8, 0x161b7220, 0x0, 0x424b4301, 0x4)
	C:/projects/go-ethereum/eth/downloader/queue.go:494 +0xd4
github.com/ethereum/go-ethereum/eth/downloader.(*queue).ReserveBodies(0x1618ea00, 0x1618eb40, 0x80000000, 0x0, 0x17e30000)
	C:/projects/go-ethereum/eth/downloader/queue.go:458 +0xb1
github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).fetchParts(0x17e39cc0, 0x161e8200, 0x17fcbf40, 0x161c33c0, 0x17fcbf38, 0x17fcbf68, 0x17fcbf60, 0x17fcbf58, 0x0, 0x101a06c, ...)
	C:/projects/go-ethereum/eth/downloader/downloader.go:1471 +0x1101
github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).fetchBodies(0x17e39cc0, 0x1, 0x0, 0xe0e7e9, 0x20)
	C:/projects/go-ethereum/eth/downloader/downloader.go:1279 +0x2c6
github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).syncWithPeer.func4(0xe711b0, 0x1)
	C:/projects/go-ethereum/eth/downloader/downloader.go:550 +0x6d
github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).spawnSync.func1(0x17e39cc0, 0x161e8b40, 0x17ea2850)
	C:/projects/go-ethereum/eth/downloader/downloader.go:573 +0x67
created by github.com/ethereum/go-ethereum/eth/downloader.(*Downloader).spawnSync
	C:/projects/go-ethereum/eth/downloader/downloader.go:573 +0xc0

@karalabe
Copy link
Member

Thought it returned something that overflown. Which part managed to go into negative?

@fjl
Copy link
Contributor Author

fjl commented May 27, 2021

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 math.Min(1, ...). This was also present in the original version in eth/downloader, but you removed it for some reason in p2p/msgrate.

@holiman
Copy link
Contributor

holiman commented May 27, 2021

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))
	}
}

@karalabe
Copy link
Member

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).

@fjl
Copy link
Contributor Author

fjl commented May 27, 2021

I tried this test, but it doesn't fail for me.

@fjl
Copy link
Contributor Author

fjl commented May 27, 2021

Updated to make the test fail without the previous fix, and added another fix to clamp the result to max positive int32 as well.

@fjl
Copy link
Contributor Author

fjl commented May 27, 2021

@karalabe PTAL

@fjl fjl added this to the 1.10.4 milestone May 27, 2021
Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@karalabe karalabe merged commit 4271751 into ethereum:master May 27, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants