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

Fix Bandwith Limiter Panic #11988

Merged
merged 2 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions beacon-chain/sync/initial-sync/blocks_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ func timeToWait(wanted, rem, capacity int64, timeTillEmpty time.Duration) time.D
if rem >= wanted {
return 0
}
// Handle edge case where capacity is equal to the remaining amount
// of blocks. This also handles the impossible case in where remaining blocks
// exceed the limiter's capacity.
if capacity <= rem {
return 0
}
blocksNeeded := wanted - rem
currentNumBlks := capacity - rem
expectedTime := int64(timeTillEmpty) * blocksNeeded / currentNumBlks
Expand Down
8 changes: 8 additions & 0 deletions beacon-chain/sync/initial-sync/blocks_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,14 @@ func TestTimeToWait(t *testing.T) {
timeTillEmpty: 200 * time.Second,
want: 0 * time.Second,
},
{
name: "Limiter has full capacity remaining",
wanted: 350,
rem: 320,
capacity: 320,
timeTillEmpty: 0 * time.Second,
want: 0 * time.Second,
},
{
name: "Limiter has reached full capacity",
wanted: 64,
Expand Down