-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(submit loop): add more logging around skew calculation #1000
Conversation
WalkthroughThis update enhances error handling, state management, and overall code clarity across the codebase. Key improvements include encapsulating block height management through dedicated methods, refining logging in concurrent operations, and updating tests for better alignment with these changes. Collectively, these modifications aim to bolster maintainability and robustness while improving the visibility of errors during execution. Changes
Sequence Diagram(s)sequenceDiagram
participant M as Manager
participant S as State
participant L as Logger
participant E as ErrorGroup
M->>E: Start
E->>M: Goroutines for SubmitLoop, ProduceBlockLoop, etc.
M->>S: SetHeight(0)
S-->>M: Height set
E->>L: Log errors if any
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (3)
utils/atomic/funcs.go (1)
1-5
: Consider moving tosdk-utils
.The TODO comment suggests moving this code to
sdk-utils
. Ensure this is tracked properly.utils/atomic/funcs_test.go (1)
1-10
: Consider moving tosdk-utils
.The TODO comment in the implementation file suggests moving this code to
sdk-utils
. Ensure this is tracked properly.utils/errors/err_group.go (1)
1-6
: Consider moving tosdk-utils
.The TODO comment suggests moving this code to
sdk-utils
. Ensure this is tracked properly.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
go.sum
is excluded by!**/*.sum
Files selected for processing (16)
- block/executor_test.go (1 hunks)
- block/manager.go (2 hunks)
- block/manager_test.go (2 hunks)
- block/produce.go (1 hunks)
- block/state.go (1 hunks)
- block/submit.go (8 hunks)
- block/submit_loop_test.go (1 hunks)
- go.mod (1 hunks)
- store/store_test.go (1 hunks)
- test/loadtime/cmd/report/main.go (1 hunks)
- testutil/types.go (1 hunks)
- types/serialization.go (2 hunks)
- types/serialization_test.go (1 hunks)
- utils/atomic/funcs.go (1 hunks)
- utils/atomic/funcs_test.go (1 hunks)
- utils/errors/err_group.go (1 hunks)
Files skipped from review due to trivial changes (2)
- block/produce.go
- block/submit_loop_test.go
Additional comments not posted (25)
utils/atomic/funcs.go (1)
11-12
: Ensure correctness of the subtraction logic.The function
Uint64Sub
uses atomic operations to subtract a value from an atomic uint64. The use ofx.Add(^(y - 1))
is a bitwise trick to perform subtraction. Ensure this approach is well-documented and tested thoroughly to avoid potential issues.utils/atomic/funcs_test.go (1)
12-35
: Ensure comprehensive test coverage.The test function
TestUint64Sub
uses property-based testing to validate theUint64Sub
function. Ensure that the test cases cover a wide range of scenarios, including edge cases, to thoroughly validate the functionality.utils/errors/err_group.go (1)
12-23
: Ensure proper error handling and logging.The function
ErrGroupGoLog
enhances error logging within anerrgroup
. Ensure that the error messages are informative and that the logging mechanism is efficient and does not introduce significant overhead.test/loadtime/cmd/report/main.go (1)
56-56
: LGTM! But verify the usage ofstate.Height()
.The change enhances encapsulation by using a method to access the block height.
However, ensure that the
state.Height()
method is correctly implemented and used throughout the codebase.Verification successful
LGTM! The
state.Height()
method is correctly implemented and used throughout the codebase.The change enhances encapsulation by using a method to access the block height. The method is consistently used to retrieve the height of the highest block saved in the store.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `state.Height()` method. # Test: Search for the method usage. Expect: Correct and consistent usage. rg --type go -A 5 $'state.Height()'Length of output: 1706
Script:
#!/bin/bash # Find the definition of the `Height` method in Go files. ast-grep --lang go --pattern 'func (state $_) Height() $_' --json # Check the context of `state.Height` usage in `da/celestia/celestia.go`. rg --type go -A 10 -B 10 'state.Height' da/celestia/celestia.goLength of output: 585
Script:
#!/bin/bash # Search for the definition of the `Height` field in Go files. rg --type go 'Height' -A 5 -B 5Length of output: 329168
types/serialization_test.go (1)
157-157
: LGTM! But verify the usage ofSetHeight
.The change enhances encapsulation by using a setter method to set the block height.
However, ensure that the
SetHeight
method is correctly implemented and used throughout the codebase.Verification successful
LGTM! But verify the usage of
SetHeight
.The change enhances encapsulation by using a setter method to set the block height.
- The
SetHeight
method is correctly implemented intypes/state.go
.- It is used consistently across various files in the codebase.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `SetHeight` method. # Test: Search for the method usage. Expect: Correct and consistent usage. rg --type go -A 5 $'SetHeight'Length of output: 3546
store/store_test.go (2)
101-101
: LGTM! But verify the usage ofSetHeight
.The change enhances encapsulation by using a setter method to set the block height.
However, ensure that the
SetHeight
method is correctly implemented and used throughout the codebase.Verification successful
LGTM! The
SetHeight
method is correctly implemented and used throughout the codebase.The method is utilized consistently across various files, ensuring proper encapsulation and state management.
types/serialization.go
types/state.go
testutil/mocks.go
testutil/types.go
store/store_test.go
rpc/client/client_test.go
block/state.go
block/executor_test.go
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `SetHeight` method. # Test: Search for the method usage. Expect: Correct and consistent usage. rg --type go -A 5 $'SetHeight'Length of output: 3546
109-109
: LGTM! But verify the usage ofHeight
.The change enhances encapsulation by using a method to access the block height.
However, ensure that the
Height
method is correctly implemented and used throughout the codebase.Verification successful
Verification Successful:
Height
Method Implementation and UsageThe
Height
method is correctly implemented intypes/state.go
and is used consistently throughout the codebase.
- Implementation: The method returns the value of
s.LastBlockHeight.Load()
, ensuring thread-safe access to the block height.- Usage: Verified across various files and contexts, confirming appropriate and consistent usage.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `Height` method. # Test: Search for the method usage. Expect: Correct and consistent usage. rg --type go -A 5 $'Height()'Length of output: 216904
Script:
#!/bin/bash # Description: Find the implementation and usage of the `Height` method. # Search for the implementation of the `Height` method in Go files. ast-grep --lang go --pattern 'func (s *$_) Height() $_' -A 5Length of output: 434
block/state.go (1)
69-69
: Encapsulate block height management.The direct assignment of
LastBlockHeight
has been replaced with a call toSetHeight
, which likely encapsulates additional logic. This change improves maintainability and consistency in managing the block height.block/manager.go (5)
168-168
: Improve error handling and logging.The introduction of
uerrors.ErrGroupGoLog
enhances error handling and logging within theSubmitLoop
function, centralizing error management.
171-172
: Enhance logging forProduceBlockLoop
.The use of
uerrors.ErrGroupGoLog
for theProduceBlockLoop
function ensures that errors are properly logged, improving maintainability.
176-176
: Centralize error handling forRetrieveLoop
.The
uerrors.ErrGroupGoLog
function centralizes error handling for theRetrieveLoop
, enhancing the robustness of the code.
179-179
: Improve error logging forSyncToTargetHeightLoop
.The
uerrors.ErrGroupGoLog
function improves error logging for theSyncToTargetHeightLoop
, ensuring better visibility of errors.
185-186
: Suppress and log errors from the error group.The errors from the error group are suppressed and logged elsewhere, streamlining the logging process and reducing clutter.
testutil/types.go (1)
232-232
: Encapsulate state height management.The direct assignment of
lastBlockHeight
has been replaced with a call toSetHeight
, which likely encapsulates additional logic. This change improves maintainability and consistency in managing the state height.block/executor_test.go (1)
145-145
: Encapsulate height-setting logic.The change from
state.LastBlockHeight.Store(0)
tostate.SetHeight(0)
encapsulates the height-setting logic, improving maintainability and clarity.Verify that the
SetHeight
method correctly handles the height-setting logic.Verification successful
Encapsulate height-setting logic.
The change from
state.LastBlockHeight.Store(0)
tostate.SetHeight(0)
encapsulates the height-setting logic, improving maintainability and clarity. TheSetHeight
method correctly handles the height-setting logic by storing the height ins.LastBlockHeight
.
types/state.go
:
- Line 48:
func (s *State) SetHeight(height uint64) {
- Line 49:
s.LastBlockHeight.Store(height)
- Line 50:
}
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of the `SetHeight` method in the `State` struct. # Test: Search for the `SetHeight` method implementation. Expect: Correct handling of the height-setting logic. ast-grep --lang go --pattern $'func (s *State) SetHeight(height uint64) { $$$ }'Length of output: 215
block/submit.go (6)
80-80
: Enhance logging for bytes produced.The addition of the logger statement improves traceability of the bytes produced.
112-117
: Improve error handling and diagnostics.The refined error handling logic ensures that internal errors during batch creation and submission are logged and diagnosed clearly.
120-121
: Ensure thread safety with atomic operations.The use of
uatomic.Uint64Sub
for managing the pending bytes ensures thread safety in concurrent environments.
144-154
: Add validation for height checks.The added checks ensure that
startHeight
is not greater thanendHeightInclusive
, preventing potential logical errors in batch creation.
162-162
: Log batch creation details.The logger statement enhances visibility into the batch creation process, indicating the start and end heights.
157-157
: Ensure correct batch size calculations.The logic for creating a batch ensures that the batch size does not exceed the maximum size, preventing potential errors.
types/serialization.go (2)
282-282
: Encapsulate height-setting logic.The change from
s.LastBlockHeight.Store(uint64(other.LastBlockHeight))
tos.SetHeight(uint64(other.LastBlockHeight))
encapsulates the height-setting logic, improving maintainability and clarity.
264-264
: Encapsulate height retrieval logic.The change from
s.LastBlockHeight.Load()
tos.Height()
encapsulates the height retrieval logic, improving maintainability and clarity.Verify that the
Height
method correctly handles the height retrieval logic.Verification successful
Encapsulate height retrieval logic.
The change from
s.LastBlockHeight.Load()
tos.Height()
encapsulates the height retrieval logic, improving maintainability and clarity. TheHeight
method correctly returns the height of the highest block saved in the store by callings.LastBlockHeight.Load()
.
types/state.go
:
func (s *State) Height() uint64 { return s.LastBlockHeight.Load() }
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of the `Height` method in the `State` struct. # Test: Search for the `Height` method implementation. Expect: Correct handling of the height retrieval logic. ast-grep --lang go --pattern $'func (s *State) Height() int64 { $$$ }'Length of output: 73
Script:
#!/bin/bash # Search for the definition of the `Height` method in the codebase. rg 'func (s *State) Height() int64' -A 10 # Search for the definition of the `State` struct to understand its structure. rg 'type State struct' -A 20Length of output: 5743
Script:
#!/bin/bash # Search for methods in the types/state.go file that interact with the LastBlockHeight field. rg 'LastBlockHeight' types/state.go -A 10Length of output: 845
go.mod (1)
275-275
: Dependency Addition ApprovedThe addition of
pgregory.net/rapid v1.1.0
as an indirect dependency is approved. This library is useful for property-based testing in Go.block/manager_test.go (1)
92-92
: Improved State Management in TestsThe changes in
TestInitialState
to usesampleState.Height()
instead ofLoad()
improve clarity and maintainability by standardizing the method of obtaining the last block height.Also applies to: 106-106
Had to fix test logger |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- block/submit_loop_test.go (2 hunks)
- utils/atomic/funcs_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- block/submit_loop_test.go
- utils/atomic/funcs_test.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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- utils/atomic/funcs.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- utils/atomic/funcs.go
(cherry picked from commit 0bbe5be)
Adds more visibility to try to fix #999 in a followup PR.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Chores