-
Notifications
You must be signed in to change notification settings - Fork 90
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(node-api): Use state processor to return the corrected beacon state on backend #1812
Conversation
WalkthroughThe recent changes enhance type safety and modularity in the beacon chain application's backend. Key updates include introducing a Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Backend
participant StateProcessor
User->>Backend: Request State
Backend->>StateProcessor: Process Slots
StateProcessor-->>Backend: Validator Updates
Backend-->>User: Return State Info
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 (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1812 +/- ##
==========================================
+ Coverage 25.42% 25.44% +0.02%
==========================================
Files 329 329
Lines 14337 14325 -12
Branches 19 19
==========================================
Hits 3645 3645
+ Misses 10569 10557 -12
Partials 123 123
|
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: 1
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (22)
- mod/node-api/backend/backend.go (5 hunks)
- mod/node-api/backend/block.go (1 hunks)
- mod/node-api/backend/genesis.go (1 hunks)
- mod/node-api/backend/mocks/beacon_state.mock.go (1 hunks)
- mod/node-api/backend/mocks/state_processor.mock.go (1 hunks)
- mod/node-api/backend/randao.go (1 hunks)
- mod/node-api/backend/state.go (2 hunks)
- mod/node-api/backend/types.go (3 hunks)
- mod/node-api/backend/validator.go (2 hunks)
- mod/node-api/handlers/proof/backend.go (1 hunks)
- mod/node-api/handlers/proof/block.go (2 hunks)
- mod/node-api/handlers/proof/handler.go (1 hunks)
- mod/node-api/handlers/proof/merkle/execution.go (2 hunks)
- mod/node-api/handlers/proof/merkle/proposer.go (2 hunks)
- mod/node-api/handlers/proof/types/types.go (2 hunks)
- mod/node-core/pkg/components/api.go (2 hunks)
- mod/node-core/pkg/components/chain_service.go (1 hunks)
- mod/node-core/pkg/components/state_processor.go (1 hunks)
- mod/node-core/pkg/components/storage/storage.go (1 hunks)
- mod/node-core/pkg/components/types.go (2 hunks)
- mod/node-core/pkg/components/validator_service.go (1 hunks)
- mod/state-transition/pkg/core/state/statedb.go (1 hunks)
Additional context used
GitHub Check: test-unit-bench
mod/node-core/pkg/components/types.go
[failure] 331-331:
not enough type arguments for type StateProcessor: have 15, want 16
GitHub Check: nilaway
mod/node-core/pkg/components/types.go
[failure] 331-331:
not enough type arguments for type StateProcessor: have 15, want 16
Additional comments not posted (46)
mod/node-api/backend/genesis.go (1)
32-32
: LGTM! But verify the function usage in the codebase.The change from
StateFromSlot
tostateFromSlot
is consistent with encapsulation principles. Ensure that all function calls tostateFromSlot
match the new signature.Verification successful
Verified! The function
stateFromSlot
has been consistently updated across the codebase to match the new signature. The first return value is discarded where it is not needed.
block.go
randao.go
state.go
genesis.go
validator.go
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `stateFromSlot` match the new signature. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type go -A 5 $'stateFromSlot'Length of output: 4941
mod/node-api/handlers/proof/backend.go (3)
24-25
: LGTM!The addition of the
BeaconBlockHeaderT
parameter enhances the flexibility of theBackend
interface. ExtendingBlockBackend
promotes better separation of concerns.
30-32
: LGTM!The
BlockBackend
interface clearly defines how block headers are accessed, promoting better separation of concerns between state and block management.
33-35
: LGTM!The renaming and modification of the method signature for
StateFromSlot
toStateFromSlotForProof
suggest a shift in the method's purpose, potentially to provide additional contextual information related to state retrieval.mod/node-api/backend/randao.go (2)
39-39
: LGTM!The streamlined logic for determining the epoch enhances readability and efficiency.
33-33
: LGTM! But verify the function usage in the codebase.The change from
StateFromSlot
tostateFromSlot
is consistent with encapsulation principles. Ensure that all function calls tostateFromSlot
match the new signature.Verification successful
LGTM! All function calls to
stateFromSlot
match the new signature.The change from
StateFromSlot
tostateFromSlot
has been correctly propagated throughout the codebase, and all instances follow the new signature.
mod/node-api/backend/genesis.go
mod/node-api/backend/randao.go
mod/node-api/backend/validator.go
mod/node-api/backend/block.go
mod/node-api/backend/state.go
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `stateFromSlot` match the new signature. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type go -A 5 $'stateFromSlot'Length of output: 4941
mod/node-api/handlers/proof/block.go (3)
41-41
: Verify the correctness of returning0
on error.Returning
0
on error might have unintended consequences. Ensure that this behavior is expected and handled correctly in the calling functions.
44-46
: LGTM! But verify the impact of the new methodStateFromSlotForProof
.The code changes are approved.
Ensure that the new method
StateFromSlotForProof
is correctly integrated and does not introduce any regressions.Verification successful
Verified the impact of the new method
StateFromSlotForProof
.The method
StateFromSlotForProof
is correctly implemented and integrated. It simply callsstateFromSlotRaw
and returns its result. The usage inblock.go
handles errors appropriately and integrates well with the existing code.
Implementation of
StateFromSlotForProof
instate.go
:func (b *Backend[ _, _, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, ]) StateFromSlotForProof(slot uint64) (BeaconStateT, uint64, error) { return b.stateFromSlotRaw(slot) }Usage in
block.go
:beaconState, slot, err = h.backend.StateFromSlotForProof(slot) if err != nil { return 0, beaconState, blockHeader, err }Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage and impact of the new method `StateFromSlotForProof`. # Test: Search for the method usage. Expect: Only occurrences of the new method. rg --type go -A 5 $'StateFromSlotForProof'Length of output: 1433
Script:
#!/bin/bash # Retrieve the full implementation of the StateFromSlotForProof method in state.go ast-grep --lang go --pattern $'func (b *Backend[$$$]) StateFromSlotForProof(slot uint64) (BeaconStateT, uint64, error) { $$$ }' --debug # Retrieve the usage context of the StateFromSlotForProof method in block.go rg --type go -A 10 -B 10 $'StateFromSlotForProof' mod/node-api/handlers/proof/block.goLength of output: 920
Script:
#!/bin/bash # Retrieve the full implementation of the StateFromSlotForProof method in state.go ast-grep --lang go --pattern $'func (b *Backend[$$$]) StateFromSlotForProof(slot uint64) (BeaconStateT, uint64, error) { $$$ }' # Retrieve the usage context of the StateFromSlotForProof method in block.go rg --type go -A 10 -B 10 $'StateFromSlotForProof' mod/node-api/handlers/proof/block.goLength of output: 1057
49-51
: LGTM! But verify the impact of the new methodBlockHeaderAtSlot
.The code changes are approved.
Ensure that the new method
BlockHeaderAtSlot
is correctly integrated and does not introduce any regressions.mod/node-core/pkg/components/state_processor.go (1)
43-43
: LGTM! But verify the impact of returning a pointer.The code changes are approved.
Ensure that returning a pointer does not introduce any regressions and is correctly handled in the calling functions.
Verification successful
LGTM! But verify the impact of returning a pointer.
The code changes are approved.
Ensure that returning a pointer does not introduce any regressions and is correctly handled in the calling functions.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage and impact of returning a pointer in `ProvideStateProcessor`. # Test: Search for the function usage. Expect: Only occurrences of the new return type. rg --type go -A 5 $'ProvideStateProcessor'Length of output: 1041
Script:
#!/bin/bash # Description: Check how ProvideStateProcessor is used in defaults.go and ensure the returned pointer is handled correctly. # Search for the usage of ProvideStateProcessor in defaults.go with additional context lines. rg --type go -A 10 'ProvideStateProcessor' mod/node-core/pkg/components/defaults.goLength of output: 288
Script:
#!/bin/bash # Description: Trace all occurrences of ProvideStateProcessor in the codebase and examine the surrounding context. # Search for all occurrences of ProvideStateProcessor with additional context lines. rg --type go -A 10 'ProvideStateProcessor'Length of output: 1585
Script:
#!/bin/bash # Description: Trace all occurrences of StateProcessor type in the codebase and examine the surrounding context. # Search for all occurrences of StateProcessor with additional context lines. rg --type go -A 10 'StateProcessor'Length of output: 49150
Script:
#!/bin/bash # Description: Verify the dereferencing of the StateProcessor pointer in the codebase. # Search for dereferencing of the StateProcessor pointer. rg --type go '\*StateProcessor'Length of output: 3843
mod/node-api/backend/state.go (3)
32-33
: LGTM! But verify the impact of the new methodStateFromSlotForProof
.The code changes are approved.
Ensure that the new method
StateFromSlotForProof
is correctly integrated and does not introduce any regressions.Verification successful
Ensure
StateFromSlotForProof
replacesStateFromSlot
and verify no regressions.The new method
StateFromSlotForProof
has been introduced and used in the codebase. Please verify if it completely replaces the previous methodStateFromSlot
and ensure there are no remaining references to the old method to prevent any regressions.
Verification successful:
StateFromSlotForProof
has completely replacedStateFromSlot
.The new method
StateFromSlotForProof
is correctly integrated and there are no remaining references to the old methodStateFromSlot
, ensuring no regressions.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage and impact of the new method `StateFromSlotForProof`. # Test: Search for the method usage. Expect: Only occurrences of the new method. rg --type go -A 5 $'StateFromSlotForProof'Length of output: 1433
Script:
#!/bin/bash # Description: Verify if `StateFromSlotForProof` replaces `StateFromSlot` and check for remaining references to `StateFromSlot`. # Test 1: Search for the old method `StateFromSlot` in the codebase. Expect: No occurrences. rg --type go -A 5 $'StateFromSlot'Length of output: 1425
42-42
: LGTM! But verify the impact of the updated methodStateRootAtSlot
.The code changes are approved.
Ensure that the updated method
StateRootAtSlot
is correctly integrated and does not introduce any regressions.
60-60
: LGTM! But verify the impact of the updated methodStateForkAtSlot
.The code changes are approved.
Ensure that the updated method
StateForkAtSlot
is correctly integrated and does not introduce any regressions.mod/node-api/backend/block.go (2)
30-43
: LGTM! Simplified control flow and error handling.The changes improve readability and reduce unnecessary variable declarations.
52-58
: LGTM! Simplified control flow and slot management.The changes improve readability and reduce complexity by removing unnecessary slot adjustments.
mod/node-api/handlers/proof/handler.go (2)
34-41
: LGTM! Enhanced capability to manage beacon block headers.The changes improve the handler's functionality in handling proof requests by including the
BeaconBlockHeaderT
type parameter.
Line range hint
49-64
:
LGTM! Enhanced capability to manage beacon block headers.The changes improve the handler's functionality in handling proof requests by including the
BeaconBlockHeaderT
type parameter.mod/node-api/handlers/proof/types/types.go (2)
Line range hint
16-19
:
LGTM! Simplified interface by removingSetStateRoot
.The removal of the
SetStateRoot
method simplifies the interface.
41-48
: LGTM! Reduced coupling between interfaces.The removal of the
GetLatestBlockHeader
method and theBeaconBlockHeaderT
type parameter reduces the coupling between the interfaces, potentially enhancing maintainability and extensibility.mod/node-core/pkg/components/chain_service.go (1)
47-47
: Approved: ChangeStateProcessor
to a pointer type.The change to use a pointer for
StateProcessor
enhances memory management and flexibility. Ensure all usages ofStateProcessor
handle the pointer correctly.mod/node-core/pkg/components/api.go (2)
47-47
: Approved: AddStateProcessor
field toNodeAPIBackendInput
.The addition of
StateProcessor
enhances the struct's functionality by allowing it to carry state-related information. Ensure all usages ofNodeAPIBackendInput
handle the new field correctly.Verification successful
Verified: The
StateProcessor
field inNodeAPIBackendInput
is correctly handled in theProvideNodeAPIBackend
function.The
StateProcessor
field is properly passed as an argument in thebackend.New
function, ensuring its correct usage.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `NodeAPIBackendInput` handle the new `StateProcessor` field correctly. # Test: Search for all usages of `NodeAPIBackendInput`. Expect: Correct handling of the new field. rg --type go 'NodeAPIBackendInput'Length of output: 209
Script:
#!/bin/bash # Extract the implementation of the `ProvideNodeAPIBackend` function to verify the handling of `StateProcessor`. ast-grep --lang go --pattern $'func ProvideNodeAPIBackend(in NodeAPIBackendInput) $_ { $$$ }'Length of output: 1750
76-76
: Approved: UpdateProvideNodeAPIBackend
to utilizeStateProcessor
.The update integrates the new
StateProcessor
field into the backend initialization process, enhancing its capabilities. Ensure the function correctly handles the new field.mod/node-core/pkg/components/validator_service.go (1)
43-43
: Approved: ChangeStateProcessor
to a pointer type.The change to use a pointer for
StateProcessor
enhances memory management and flexibility. Ensure all usages ofStateProcessor
handle the pointer correctly.mod/node-api/backend/mocks/state_processor.mock.go (3)
25-53
: Mock methodProcessSlots
looks good.The method correctly handles different return types for the mocked function.
55-82
: Type-safe mock call methods forProcessSlots
look good.The methods correctly shadow the
Run
andReturn
methods with type-safe versions.
84-96
: FunctionNewStateProcessor
looks good.The function correctly initializes the mock and registers the cleanup function.
mod/node-api/backend/validator.go (2)
38-38
: Ensure proper error handling withstateFromSlot
.The method now uses
stateFromSlot
and ignores the second return value. Ensure that this change aligns with the intended error handling strategy.
92-92
: Ensure proper error handling withValidatorByID
.The method calls
ValidatorByID
, which now usesstateFromSlot
. Ensure that this change aligns with the intended error handling strategy.mod/node-api/handlers/proof/merkle/execution.go (2)
42-42
: Function signature update forProveExecutionNumberInBlock
looks good.The function signature has been updated to remove the
BeaconBlockHeaderT
type from thebs
parameter. Ensure that the function correctly handles the new type parameters.
77-77
: Function signature update forProveExecutionNumberInState
looks good.The function signature has been updated to remove the
BeaconBlockHeaderT
type from thebs
parameter. Ensure that the function correctly handles the new type parameters.mod/node-api/handlers/proof/merkle/proposer.go (2)
83-83
: LGTM! But verify the function usage in the codebase.The updated function signature simplifies the type parameter list. Ensure that all function calls to
ProveProposerPubkeyInState
match the new signature.Verification successful
Verified: Function usage matches the new signature.
The function
ProveProposerPubkeyInState
is correctly used with the updated signature in the codebase.
mod/node-api/handlers/proof/merkle/proposer.go
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `ProveProposerPubkeyInState` match the new signature. # Test: Search for the function usage. Expect: Only occurrences of the new signature. rg --type go -A 5 $'ProveProposerPubkeyInState'Length of output: 1185
43-43
: LGTM! But verify the function usage in the codebase.The updated function signature simplifies the type parameter list. Ensure that all function calls to
ProveProposerInBlock
match the new signature.mod/node-core/pkg/components/storage/storage.go (1)
147-147
: LGTM!The return statement has been condensed into a single line, enhancing readability without altering functionality.
mod/node-api/backend/types.go (2)
74-76
: LGTM!The addition of the
SetSlot
method enhances the state management capabilities of theBeaconState
interface.
115-121
: LGTM!The introduction of the
StateProcessor
interface provides a modular approach to state processing, enhancing flexibility and robustness.mod/node-api/backend/backend.go (4)
67-67
: Field addition looks good.The
sp
field for state processing is a necessary addition to theBackend
struct.
Line range hint
101-120
:
Constructor update is appropriate.The
New
constructor correctly includes thesp
parameter and initializes theBackend
instance.
143-165
: Method implementation looks solid.The
stateFromSlot
method effectively retrieves and processes the state at a given slot, with proper error handling.
167-192
: Method implementation looks solid.The
stateFromSlotRaw
method correctly retrieves the state at a given slot, including handling the special case for slot 0.mod/state-transition/pkg/core/state/statedb.go (1)
126-126
: Simplified return statement looks good.The updated return statement in the
StateDB
constructor maintains functionality and improves readability.mod/node-api/backend/mocks/beacon_state.mock.go (6)
1144-1160
: LGTM! TheSetSlot
mock function is well-implemented.The function is consistent with other mock functions in the file and includes appropriate error handling.
1162-1165
: LGTM! TheBeaconState_SetSlot_Call
struct is well-defined.The struct provides a type-safe way to manage the mock's behavior for the
SetSlot
method.
1167-1171
: LGTM! TheSetSlot
helper method is consistent with other helper methods.The method is well-implemented and follows the pattern used in the file.
1173-1178
: LGTM! TheRun
method forBeaconState_SetSlot_Call
is well-implemented.The method is consistent with other
Run
methods in the file and correctly handles the argument.
1180-1183
: LGTM! TheReturn
method forBeaconState_SetSlot_Call
is well-implemented.The method is consistent with other
Return
methods in the file and correctly sets up return values.
1185-1188
: LGTM! TheRunAndReturn
method forBeaconState_SetSlot_Call
is well-implemented.The method is consistent with other
RunAndReturn
methods in the file and correctly sets up the function to run and return values.
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: ASSERTIVE
Files selected for processing (3)
- mod/node-api/backend/backend.go (5 hunks)
- mod/node-api/backend/types.go (4 hunks)
- mod/node-core/pkg/components/types.go (2 hunks)
Additional comments not posted (7)
mod/node-api/backend/types.go (2)
74-75
: Addition ofSetSlot
method toBeaconState
interface is appropriate.The method enhances the interface by providing a way to modify the slot with validation checks.
112-114
: Introduction ofStateProcessor
interface is well-defined.The interface and its method
ProcessSlots
are appropriately designed for processing slots and returning validator updates.mod/node-api/backend/backend.go (4)
66-67
: Addition ofsp
field toBackend
structure is appropriate.The field enhances the
Backend
's ability to manage state transitions more effectively.
Line range hint
101-120
: Update toNew
function to includesp
parameter is appropriate.The update ensures that each
Backend
instance is explicitly linked to a state processor, maintaining the integrity of state transitions.
143-165
: Addition ofstateFromSlot
method is well-implemented.The method includes robust error handling and ensures the state is up to date. The logic for setting the slot back after processing is correctly implemented.
167-192
: Addition ofstateFromSlotRaw
method is well-implemented.The method includes logic to handle cases where the input slot is zero, returning the latest available slot. The error handling is appropriately implemented.
mod/node-core/pkg/components/types.go (1)
331-347
: Update toStateProcessor
type alias is appropriate.The update enhances the state processor's capability by allowing it to manage a wider array of data structures.
However, verify the number of type arguments to ensure correctness.
Verification successful
The number of type arguments for
StateProcessor
is correct.The
StateProcessor
type alias includes 16 type arguments, which aligns with the expected data structures.
StateProcessor
type alias definition:
- *BeaconBlock
- *BeaconBlockBody
- *BeaconBlockHeader
- *BeaconState
- *Context
- *Deposit
- *Eth1Data
- *ExecutionPayload
- *ExecutionPayloadHeader
- *Fork
- *ForkData
- *KVStore
- *Validator
- Validators
- *Withdrawal
- WithdrawalCredentials
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the number of type arguments for `StateProcessor`. # Test: Search for the `StateProcessor` type alias definition. Expect: Correct number of type arguments. rg --type go -A 5 $'StateProcessor = core.StateProcessor'Length of output: 411
Script:
#!/bin/bash # Description: Verify the number of type arguments for `StateProcessor`. # Test: Search for the `StateProcessor` type alias definition. Expect: Correct number of type arguments. rg --type go -A 20 $'StateProcessor = core.StateProcessor'Length of output: 1268
…ate on backend (#1812) Co-authored-by: Cal Bera <[email protected]>
Next optimization to maintain a LRU cache of query contexts to avoid going to disk for repeated query contexts
Summary by CodeRabbit
New Features
StateProcessor
interface for improved state handling.stateFromSlot
andstateFromSlotRaw
.BeaconState
interface with a new method for slot management.Improvements
Backend
struct to manage state transitions more effectively.StateProcessor
type alias to support a broader array of data structures.Bug Fixes
Documentation
Tests