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
More accurate header size calculation #1629
Conversation
@hyunsooda Let's clarify func (h *Header) Size() common.StorageSize {
size := common.StorageSize(unsafe.Sizeof(*h))
byteSize := len(h.Extra) + len(h.Governance) + len(h.Vote)
size += common.StorageSize(byteSize)
bigBits := h.BlockScore.BitLen() + h.Number.BitLen() + h.Time.BitLen()
if h.BaseFee != nil {
bigBits += h.BaseFee.BitLen()
}
size += common.StorageSize(bigBits / 8)
return size
} And add a test case func TestHeaderSize(t *testing.T) {
preMagmaSize := genHeader().Size()
magmaSize := genMagmaHeader().Size()
assert.NotEqual(t, preMagmaSize, magmaSize)
} |
@blukat29, Refactored. A unit test was added too, but I prefer not to include the unit test for it because its test seems semantically meaningless. |
@hyunsooda The |
@ian0371, I would like to hear your opinion on this. Please let me know if I should make further changes or consider this not feasible for now so I can close it. |
I discovered that certain tests were not accurately executed due to an incorrect hardcoded value (https://github.com/klaytn/klaytn/blob/dev/blockchain/types/block_test.go#L49). Fixed together in this PR. |
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. @hyunsooda Can you check the CLA again? https://cla-assistant.io/klaytn/klaytn
@blukat29, I'm sorry. Signed now. @jaydenhur, The licence checker seems stuck. How it can be refreshed? |
Proposed changes
size
property to header RPC output.go generate
commandTypes of changes
Please put an x in the boxes related to your change.
Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.
$ make test
)Related issues
Further comments
If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...