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

refactor: introduces NamespaceVersionMaxValue const #1893

Merged
merged 4 commits into from
Jun 9, 2023

Conversation

staheri14
Copy link
Contributor

@staheri14 staheri14 commented Jun 8, 2023

Overview

Although we already have a constant NamespaceVersionSize, the comparison of the max value of the namespace version of the incoming Blobs is currently hardcoded to math.uint8. While this aligns with the current value of NamespaceVersionSize which is 1 byte, it would be safer (and also easier to debug and maintain the code) to derive the maximum value from the original constant instead of manually hardcoding it. This PR incorporates this modification.
cc: @rootulp @evan-forbes please let me know if this change also makes sense to you.

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user-facing features like CLI or documentation updates
  • Linked issues closed with keywords

@staheri14 staheri14 self-assigned this Jun 8, 2023
@staheri14 staheri14 added enhancement New feature or request chore optional label for items that follow the `chore` conventional commit labels Jun 8, 2023
@staheri14 staheri14 marked this pull request as ready for review June 8, 2023 00:25
@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2023

Codecov Report

Merging #1893 (56a8fd2) into main (376a1d4) will not change coverage.
The diff coverage is 0.00%.

@@           Coverage Diff           @@
##             main    #1893   +/-   ##
=======================================
  Coverage   21.85%   21.85%           
=======================================
  Files         117      117           
  Lines       13304    13304           
=======================================
  Hits         2907     2907           
  Misses      10107    10107           
  Partials      290      290           
Impacted Files Coverage Δ
x/blob/types/blob_tx.go 14.73% <0.00%> (ø)
x/blob/types/payforblob.go 71.42% <0.00%> (ø)

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

PR LGTM after a small change

@@ -11,7 +13,8 @@ import (
// They can not change throughout the lifetime of a network.
const (
// NamespaveVersionSize is the size of a namespace version in bytes.
NamespaceVersionSize = 1
NamespaceVersionSize = 1
NamespaceVersionMaxValue = math.MaxUint8 // this value should be set according to NamespaceVersionSize, i.e., 2^NamespaceVersionSize - 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there's a slight typo in 2^NamespaceVersionSize - 1 b/c it doesn't evaluate to math.MaxUint8. When NamespaceVersionSize is interpolated, this evaluates to 2 ^ 1 - 1. Maybe this meant to say something like ... i.e., // math.Pow(2, 8 * NamespaceVersionSize) - 1 but proposal to do this instead:

	// NamespaceVersionMaxValue is the maximum value a namespace version can be.
	// This const must be updated if NamespaceVersionSize is changed.
	NamespaceVersionMaxValue = math.MaxUint8

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, when writing that formula, I was thinking of NamespaceVersionSize in bits, instead of bytes. The correction is as you suggested 2^(8* NamespaceVersionSize)-1). Going to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 56a8fd2.

@MSevey MSevey requested a review from a team June 8, 2023 18:23
@staheri14 staheri14 requested a review from rootulp June 8, 2023 18:41
@rootulp
Copy link
Collaborator

rootulp commented Jun 8, 2023

[nit] you may change the conventional commit prefix of this PR to refactor:

@staheri14 staheri14 changed the title feat: introduces NamespaceVersionMaxValue const refactor: introduces NamespaceVersionMaxValue const Jun 8, 2023
@staheri14 staheri14 merged commit 9bf0cf1 into main Jun 9, 2023
18 checks passed
@staheri14 staheri14 deleted the max_namespace_version_value branch June 9, 2023 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore optional label for items that follow the `chore` conventional commit enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants