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

More accurate header size calculation #1629

Merged
merged 9 commits into from Jun 7, 2023

Conversation

hyunsooda
Copy link
Contributor

Proposed changes

  • Added size property to header RPC output.
  • Fixed header size summation
  • Fixed output path of go generate command

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

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.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

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

hqjang-pepper
hqjang-pepper previously approved these changes Oct 5, 2022
@blukat29 blukat29 changed the title [Type] Added missing property addition More accurate header size calculation Nov 23, 2022
@blukat29
Copy link
Contributor

@hyunsooda Let's clarify Size() function as it was already too long.

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

@hyunsooda
Copy link
Contributor Author

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

blukat29
blukat29 previously approved these changes Jan 3, 2023
@blukat29
Copy link
Contributor

blukat29 commented Jan 3, 2023

@hyunsooda The TestHeaderSizeCalc at least tests the Size function with and without BaseFee. Just to make sure there's no coding error, nil pointer mistake, etc. It's no harm having a small unit test.

blockchain/types/block.go Outdated Show resolved Hide resolved
blukat29
blukat29 previously approved these changes Jan 16, 2023
@hyunsooda
Copy link
Contributor Author

hyunsooda commented Mar 14, 2023

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

blockchain/types/block.go Outdated Show resolved Hide resolved
blockchain/types/block_test.go Outdated Show resolved Hide resolved
node/cn/filters/api.go Outdated Show resolved Hide resolved
blockchain/types/block.go Show resolved Hide resolved
@hyunsooda
Copy link
Contributor Author

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.

Copy link
Contributor

@blukat29 blukat29 left a 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

@hyunsooda
Copy link
Contributor Author

@blukat29, I'm sorry. Signed now.

@jaydenhur, The licence checker seems stuck. How it can be refreshed?

@hyunsooda hyunsooda closed this Jun 7, 2023
@hyunsooda hyunsooda reopened this Jun 7, 2023
@hyunsooda hyunsooda merged commit 7ce8287 into klaytn:dev Jun 7, 2023
11 checks passed
@aidan-kwon aidan-kwon mentioned this pull request Aug 3, 2023
20 tasks
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.

None yet

6 participants