-
Notifications
You must be signed in to change notification settings - Fork 320
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
chore: check if a block is empty by taking its reference #4063
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,8 +25,17 @@ func ExtendBlock(data coretypes.Data, appVersion uint64) (*rsmt2d.ExtendedDataSq | |||||||||||||||||||||||||||||||||
return da.ExtendShares(share.ToBytes(dataSquare)) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// EmptyBlock returns true if the given block data is considered empty by the | ||||||||||||||||||||||||||||||||||
// IsEmptyBlock returns true if the given block data is considered empty by the | ||||||||||||||||||||||||||||||||||
// application at a given version. | ||||||||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||||||||
// Deprecated: Use IsEmptyBlockRef for better performance with large data structures. | ||||||||||||||||||||||||||||||||||
func IsEmptyBlock(data coretypes.Data, _ uint64) bool { | ||||||||||||||||||||||||||||||||||
return len(data.Txs) == 0 | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// IsEmptyBlockRef returns true if the application considers the given block data | ||||||||||||||||||||||||||||||||||
// empty at a given version. | ||||||||||||||||||||||||||||||||||
// This method passes the block data by reference for improved performance. | ||||||||||||||||||||||||||||||||||
func IsEmptyBlockRef(data *coretypes.Data, _ uint64) bool { | ||||||||||||||||||||||||||||||||||
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: there are no references in Golang, only pointers see |
||||||||||||||||||||||||||||||||||
return len(data.Txs) == 0 | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Comment on lines
+36
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add nil pointer check and enhance documentation. While the implementation is correct, there are a few improvements that could make it more robust and informative:
Consider this enhanced implementation: // IsEmptyBlockRef returns true if the application considers the given block data
// empty at a given version.
-// This method passes the block data by reference for improved performance.
+// This method passes the block data by reference to avoid copying large data structures,
+// particularly beneficial when dealing with blocks containing many transactions.
func IsEmptyBlockRef(data *coretypes.Data, _ uint64) bool {
+ if data == nil {
+ return true
+ }
return len(data.Txs) == 0
} 📝 Committable suggestion
Suggested change
|
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.
what's the second argument for? Do we still need to keep it around? Also if we're not planning on backporting this can we just break the go API?
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.
in case at some point we want to have specific method for each version. For now, it's not used and not sure why it was added in first place
I'm backporting this to v3 to be released and used in node
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.