-
Notifications
You must be signed in to change notification settings - Fork 8.9k
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
[LEDGER] Improve readability of HandleChaincodeDeploy #1080
[LEDGER] Improve readability of HandleChaincodeDeploy #1080
Conversation
core/ledger/kvledger/txmgmt/privacyenabledstate/common_storage_db.go
Outdated
Show resolved
Hide resolved
core/ledger/kvledger/txmgmt/privacyenabledstate/common_storage_db.go
Outdated
Show resolved
Hide resolved
core/ledger/kvledger/txmgmt/privacyenabledstate/common_storage_db.go
Outdated
Show resolved
Hide resolved
d4ef0f9
to
231f5e6
Compare
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.
@cendhu - left you a comment (https://github.com/hyperledger/fabric/pull/1080/files#r409108625)
231f5e6
to
21fa654
Compare
Signed-off-by: senthil <cendhu@gmail.com>
21fa654
to
bc514a3
Compare
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.
Merging this one. However, I would like to see two improvements. That can be done in a separate PR
- Move the constants related to new function, just above the function.
- Though, not introduced in the PR but just noticed that array element access without checking lengths. A wrong input could cause panic. I recall that you mentioned that you had added that check but not included finally. But, it would be good to check for safety against a bad input.
This change adds index checks before `dirDepths[collectionIndexDirDepth]` and `dirDepths[collectionNameDepth]` to avoid indexing beyond the end of the array. We *could* just check for the `collectionIndexDirDepth` and avoid the other two, but that would be more brittle in case the constants defined a few lines earlier were reordered. We could also just calculate `len(dirsDepth)` once as a small perf improvement. This is related to the [suggestion](hyperledger#1080 (review)) from @manish-sethi in hyperledger#1080.
This change adds index checks before `dirDepths[collectionIndexDirDepth]` and `dirDepths[collectionNameDepth]` to avoid indexing beyond the end of the array. We *could* just check for the `collectionIndexDirDepth` and avoid the other two, but that would be more brittle in case the constants defined a few lines earlier were reordered. We could also just calculate `len(dirsDepth)` once as a small perf improvement. This is related to the [suggestion](hyperledger#1080 (review)) from @manish-sethi in hyperledger#1080.
Type of change
Description
The following are good examples of avoid disinformation, i.e., context should be explicit in the code itself mentioned in the coding guidelines.
if directoryPathArray[3] == "indexes" {
if directoryPathArray[3] == "collections" && directoryPathArray[5] == "indexes" {
collectionName := directoryPathArray[4]
What is 3, 4, and 5? Hence, we replace the above lines with the following
and followed the most important concept first and the low-level details in the bottom. as per the formatting rules specified in the above coding guidelines. The following may not be a perfect one. However, we try to avoid large code refactoring and restrict ourselves to the ledger package.
Additional details
These changes were initially part of #966 but we decided to push a separate PR (this one) for the readability related changes.
Related issues
FAB-17739