-
Notifications
You must be signed in to change notification settings - Fork 382
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
feat: Introduce --namespace-version
CLI flag
#1585
Conversation
--namespace-version
CLI flag
--namespace-version
CLI flag--namespace-version
CLI flag
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.
Sorry for the delay in reviewing @amityadav0 but thanks for working on this!
Co-authored-by: Rootul P <rootulp@gmail.com>
Thanks for the review @rootulp. I have updated the PR. |
Codecov Report
@@ Coverage Diff @@
## main #1585 +/- ##
==========================================
- Coverage 49.17% 49.04% -0.13%
==========================================
Files 84 85 +1
Lines 4948 4963 +15
==========================================
+ Hits 2433 2434 +1
- Misses 2277 2290 +13
- Partials 238 239 +1 see 5 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Thanks for updating the PR! This overall LGTM. I had two optional suggestions that I applied on top of this PR. I made the changes myself b/c I forgot to include them in the previous round of PR feedback and I didn't want to block the PR on addressing them. |
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.
Left a few minor blocking questions/change, thanks @amityadav0 !!
x/blob/client/cli/payforblob.go
Outdated
@@ -57,10 +60,24 @@ func CmdPayForBlob() *cobra.Command { | |||
} | |||
|
|||
flags.AddTxFlagsToCmd(cmd) | |||
cmd.PersistentFlags().String(FlagNamespaceVersion, "0", "Specify the namespace version (default is 0)") |
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.
we shouldn't write defaults, since they're filled in for us by cobra
cmd.PersistentFlags().String(FlagNamespaceVersion, "0", "Specify the namespace version (default is 0)") | |
cmd.PersistentFlags().String(FlagNamespaceVersion, "0", "Specify the namespace version") |
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.
@evan-forbes where are they filled in? After this suggestion the help doc looks like:
$ ./build/celestia-appd tx blob PayForBlobs --help
...
--namespace-version uint8 Specify the namespace version
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.
hmmm I'm not sure that's a good question. the rest get filled in for example https://github.com/celestiaorg/cosmos-sdk/blob/f19e20459b8bcf195167ad256de5a6ca6edc41f5/server/start.go#L159-L161
--address string Listen address (default "tcp://0.0.0.0:26658")
--home string The application home directory (default "/home/evan/.celestia-app")
Co-authored-by: Evan Forbes <42654277+evan-forbes@users.noreply.github.com>
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.
2 small nits based on the last change to uint8
flag
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
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.
Missed this first time around! sorry about that @amityadav0 thanks again for your patience
x/blob/client/cli/payforblob.go
Outdated
func getNamespace(namespaceID []byte, namespaceVersion uint8) (appns.Namespace, error) { | ||
switch namespaceVersion { | ||
case appns.NamespaceVersionZero: | ||
return appns.New(namespaceVersion, append(appns.NamespaceVersionZeroPrefix, namespaceID...)) |
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.
we should never append directly to a global, as it could cause tons of bugs
we need to first make an empty slice of appropriate capacity, and then append
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.
I don't think we are appending to global value. Append function will return a value here which is passed to appns.New()
z = append(x, y)
This line won't change x or y.
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.
the issue is that as a rule of thumb, we should never do
z = append(x, y)
only ever
z = append(z, x, y)
this can, and has, caused quite a few really tricky bugs in the past
https://www.calhoun.io/why-are-slices-sometimes-altered-when-passed-by-value-in-go/
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.
Got it. Will read this in depth and update the PR. Thanks for the answer.
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.
My takeaway after reading that article is that
z = append(x, y)
is safe because the length or capacity of x will not be impacted by the above statement. After execution the global x
remains unmodified. My understanding is that the copy is only necessary if a function is invoked on the global x
that modifies elements of the original slice. If append
is dangerous in this usage, I would expect there to be a linter to warn us about incorrect usage but I couldn't find one on https://golangci-lint.run/usage/linters/
@evan-forbes how do we enforce that append
isn't misused? Additionally are there examples of just the append
causing bugs:
we should never append directly to a global, as it could cause tons of bugs
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.
I think we have some linter, but otherwise this is just good practice imo since it always fixes the issue and eliminates the reader having to think "is this an issue". Also, I still think its an issue but don't have the brain capacity at the moment to figure it out lol 😆
examples celestiaorg/celestia-core#336, celestiaorg/celestia-core#250, celestiaorg/nmt#30, there was also one in node that fixed during the barcelona onsite but I couldn't find it in a cursory search
all were caused by
z = append(x, y)
so now we should never ever ever do that no matter what because evan is too scarred
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.
I have updated the code. Have created a copy of global and then used append on that copy
x/blob/client/cli/payforblob.go
Outdated
namespaceVersionZeroPrefix := appns.NamespaceVersionZeroPrefix | ||
return appns.New(namespaceVersion, append(namespaceVersionZeroPrefix, namespaceID...)) |
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.
this doesn't actually avoid the issue, since slices can be treated similar to pointers. Its true that we're passing by value here, but we're passing a pointer by value, which unfortunatley still won't solve our problem
in order to avoid the underlying issue, we need to make an explicit copy of the slice
similar to
ns := make([]byte, 0, appconsts.NamespaceSize)
ns = append(ns, append(prefix, namespaceID)...)
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.
I guess now I get it.
with above example prefix may still be changed
nsp := make([]byte, 0, appns.NamespaceVersionZeroPrefixSize)
nsp = append(nsp, appns.NamespaceVersionZeroPrefix...)
return appns.New(namespaceVersion, append(nsp, namespaceID...))
I have updated the code to this
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.
made super minor change to push this over the line
thanks again @amityadav0 !! apologies this took so long
x/blob/client/cli/payforblob.go
Outdated
func getNamespace(namespaceID []byte, namespaceVersion uint8) (appns.Namespace, error) { | ||
switch namespaceVersion { | ||
case appns.NamespaceVersionZero: | ||
nsp := make([]byte, 0, appns.NamespaceSize) |
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.
[nit]
nsp := make([]byte, 0, appns.NamespaceSize) | |
nsp := make([]byte, 0, appns.NamespaceIDSize) |
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.
why not namespace size here? aren't we using the full 33?
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.
The ID is 32 bytes. The version is 1 byte. The total namespace is 33 bytes.
Since this variable is just the ID, only 32 bytes are necessary.
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.
merged to clear out his PR, but we should still fix this imo if need be,
I'm confused a bit
so we should not be appending the version at all here since its added when we call Bytes()? therefore we're adding it twice?
Overview
Introduce --namespace-version CLI flag
--namespace-version
CLI flag #1528I have introduced namespace flag. Currently this supports namespace version zero only.
I think data structure for storing namespace versions can be updated. Maybe a map with version details.
For example:
instead of constants
Then it would be possible to switch versions easily from cli. same for share version.
Please let me know if this makes sense or am I missing something.