-
Notifications
You must be signed in to change notification settings - Fork 20k
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
eth/downloader, core/types: take withdrawals-size into account in downloader queue #30276
Conversation
core/types/withdrawal.go
Outdated
@@ -42,6 +43,10 @@ type withdrawalMarshaling struct { | |||
Amount hexutil.Uint64 | |||
} | |||
|
|||
func (w Withdrawal) Size() common.StorageSize { | |||
return common.StorageSize(unsafe.Sizeof(w)) |
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.
Please avoid the use of package unsafe here. Since withdrawals are defined by the protocol and will never change, we can just hard-code the returned size here.
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.
var withdrawalSize = common.StorageSize(reflect.TypeOf(Withdrawal{}).Size())
func (w Withdrawal) Size() common.StorageSize {
return common.StorageSize(withdrawalSize)
}
What do think about handling it like this, similar to the code in other parts?
eth/downloader/queue.go
Outdated
for _, withdrawal := range result.Withdrawals { | ||
size += withdrawal.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.
Since withdrawals are constant size, perhaps put Size
on Withdrawals
instead, and do
size += common.StorageSize(result.Withdrawals.Size())
(yes, make the conversion to StorageSize here, not in the Size-function)
Then the change in types
boils down to
var withdrawalSize = int(reflect.TypeOf(Withdrawal{}).Size())
func (s Withdrawals) Size() int {
return withdrawalSize * len(s)
}
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
…nloader queue (ethereum#30276) Fixes a slight miscalculation in the downloader queue, which was not accurately taking block withdrawals into account when calculating the size of the items in the queue
…nloader queue (ethereum#30276) Fixes a slight miscalculation in the downloader queue, which was not accurately taking block withdrawals into account when calculating the size of the items in the queue
This PR addresses an issue where the size of the downloader queue was not accurately measured. Previously, the size of withdrawals was not included in the queue size calculation, leading to an accumulation of more items than originally intended. This simple fix ensures that withdrawals are now considered, providing an accurate measurement of the queue size.