-
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
chore(codec): Remove usage of reflect #1825
Conversation
WalkthroughThe recent changes streamline various structures in the codebase by introducing an Changes
Sequence Diagram(s)sequenceDiagram
participant A as Caller
participant B as BeaconBlock
participant C as Deposit
participant D as Eth1Data
A->>B: Empty() // New call to create empty block
B-->>A: Returns new BeaconBlock
A->>C: Empty() // New call to create empty deposit
C-->>A: Returns new Deposit
A->>D: Empty() // New call to create empty Eth1Data
D-->>A: Returns new Eth1Data
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 #1825 +/- ##
==========================================
- Coverage 24.71% 24.70% -0.02%
==========================================
Files 327 327
Lines 14201 14194 -7
Branches 19 19
==========================================
- Hits 3510 3506 -4
+ Misses 10569 10566 -3
Partials 122 122
|
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: 2
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (17)
- mod/consensus-types/pkg/types/block.go (1 hunks)
- mod/consensus-types/pkg/types/block_test.go (2 hunks)
- mod/consensus-types/pkg/types/deposit.go (1 hunks)
- mod/consensus-types/pkg/types/eth1data.go (1 hunks)
- mod/consensus-types/pkg/types/fork.go (1 hunks)
- mod/consensus-types/pkg/types/header.go (1 hunks)
- mod/consensus-types/pkg/types/validator.go (1 hunks)
- mod/da/pkg/types/sidecars.go (1 hunks)
- mod/primitives/pkg/constraints/basic.go (1 hunks)
- mod/runtime/pkg/middleware/types.go (1 hunks)
- mod/runtime/pkg/p2p/noop.go (2 hunks)
- mod/runtime/pkg/p2p/types.go (1 hunks)
- mod/storage/pkg/beacondb/encoding/ssz_value.go (1 hunks)
- mod/storage/pkg/beacondb/kvstore.go (2 hunks)
- mod/storage/pkg/beacondb/types.go (1 hunks)
- mod/storage/pkg/deposit/store.go (2 hunks)
- mod/storage/pkg/deposit/types.go (1 hunks)
Additional comments not posted (20)
mod/storage/pkg/beacondb/types.go (1)
30-33
: LGTM! Verify the impact on implementing types.The addition of
constraints.Empty[SelfT]
promotes consistency and type safety. Ensure that all types used asSelfT
satisfy the new constraint.mod/runtime/pkg/p2p/noop.go (2)
32-35
: Approved: Enhanced type constraints forNoopGossipHandler
.The addition of
constraints.Empty[DataT]
improves type safety and ensures thatDataT
can instantiate an empty instance.
55-56
: Approved: Simplified instance creation inRequest
method.Using the
Empty
method to create a new instance ofDataT
instead of reflection simplifies the code and improves type safety.mod/primitives/pkg/constraints/basic.go (1)
45-48
: Approved: Addition ofEmpty
interface.The
Empty
interface enhances type safety and expressiveness in generic programming by enforcing that types can provide a default empty instance.mod/runtime/pkg/middleware/types.go (2)
34-39
: Approved: ImprovedBeaconBlock
interface.Renaming the type parameter to
SelfT
and adding theconstraints.Empty[SelfT]
constraint improve clarity and type safety by ensuring thatSelfT
can provide a default empty instance.
39-39
: Approved: UpdatedNewFromSSZ
method signature.Returning
SelfT
instead ofT
reinforces the self-referential nature of the interface, enhancing type safety.mod/storage/pkg/deposit/store.go (2)
46-48
: LGTM! But verify the usage of the new type parameterization.The type parameterization change improves type safety and flexibility.
However, ensure that all usages of
KVStore
are updated to match the new type parameterization.
52-54
: LGTM! But verify the usage of the new function signature.The function signature change ensures consistency with the updated type parameterization.
However, ensure that all usages of
NewStore
are updated to match the new function signature.Verification successful
Verified: All usages of
NewStore
match the new function signature.The function signature change has been correctly applied across the codebase, ensuring consistency with the updated type parameterization.
mod/storage/pkg/deposit/store.go
mod/storage/pkg/block/store.go
mod/node-core/pkg/components/block_store.go
mod/node-core/pkg/components/deposit_store.go
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `NewStore` match the new function signature. # Test: Search for the function usage. Expect: Only occurrences of the new function signature. rg --type go -A 5 $'NewStore'Length of output: 2338
mod/storage/pkg/beacondb/encoding/ssz_value.go (2)
40-43
: LGTM! But verify the usage of the updatedDecode
method.The method implementation change improves type safety and clarity by avoiding reflection.
However, ensure that all usages of the
Decode
method are updated to match the new implementation.Verification successful
Verify the usage of the updated
Decode
method.The search results did not show any external usage of the
SSZValueCodec
'sDecode
method. To ensure thorough verification, refine the search to specifically look for the usage ofSSZValueCodec
'sDecode
method across the codebase.
No external usages of the
SSZValueCodec
'sDecode
method found.The refined search did not produce any results, indicating that the
Decode
method fromSSZValueCodec
is not currently utilized elsewhere in the codebase. The verification is complete.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of the `Decode` method match the new implementation. # Test: Search for the method usage. Expect: Only occurrences of the new implementation. rg --type go -A 5 $'Decode'Length of output: 24936
Script:
#!/bin/bash # Description: Verify all usages of the `Decode` method from `SSZValueCodec` match the new implementation. # Test: Search for the method usage. Expect: Only occurrences of the new implementation. rg --type go 'SSZValueCodec\[.*\]\.Decode' -A 5Length of output: 49
29-32
: LGTM! But verify the usage of the new type parameterization.The type parameterization change ensures that any type used with
SSZValueCodec
must provide a way to instantiate an empty value.However, ensure that all usages of
SSZValueCodec
are updated to match the new type parameterization.Verification successful
Verification Successful!
The types used with
SSZValueCodec
(DepositT, ForkT, Eth1DataT, ValidatorT, BeaconBlockHeaderT) correctly implement both theEmpty
method and theconstraints.SSZMarshallable
interface.
DepositT
ForkT
Eth1DataT
ValidatorT
BeaconBlockHeaderT
All usages of
SSZValueCodec
are updated to match the new type parameterization.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `SSZValueCodec` match the new type parameterization. # Test: Search for the type usage. Expect: Only occurrences of the new type parameterization. rg --type go -A 5 $'SSZValueCodec'Length of output: 4886
Script:
#!/bin/bash # Description: Verify that the types used with SSZValueCodec implement the required interfaces and methods. # Test: Search for the definitions of the types used with SSZValueCodec. # Expect: Each type should implement constraints.SSZMarshallable and have an Empty method. # Types to check types=("DepositT" "ForkT" "Eth1DataT" "ValidatorT" "BeaconBlockHeaderT") # Search for type definitions and implementations for type in "${types[@]}"; do echo "Checking type: $type" rg --type go "type $type" -A 10 rg --type go "func (.*) Empty" -A 5 doneLength of output: 23993
Script:
#!/bin/bash # Description: Verify that the types used with SSZValueCodec implement the constraints.SSZMarshallable interface. # Test: Search for the implementations of the constraints.SSZMarshallable interface. # Expect: Each type should implement constraints.SSZMarshallable. # Types to check types=("DepositT" "ForkT" "Eth1DataT" "ValidatorT" "BeaconBlockHeaderT") # Search for interface implementations for type in "${types[@]}"; do echo "Checking type: $type" rg --type go "type $type" -A 10 rg --type go "func (.*) MarshalSSZ" -A 5 doneLength of output: 123133
mod/da/pkg/types/sidecars.go (1)
38-38
: LGTM! But verify the usage of the updatedEmpty
method.The method implementation change enhances clarity and conciseness by eliminating unnecessary variable assignment.
However, ensure that all usages of the
Empty
method are updated to match the new implementation.mod/consensus-types/pkg/types/fork.go (1)
57-60
: LGTM!The
Empty
method correctly returns a new instance ofFork
with default values.mod/consensus-types/pkg/types/eth1data.go (1)
54-57
: LGTM!The
Empty
method correctly returns a new instance ofEth1Data
with default values.mod/consensus-types/pkg/types/block_test.go (1)
142-144
: LGTM!The modification to the
TestBeaconBlockEmpty
function correctly aligns with the newEmpty
method signature and verifies that the method returns a non-nil instance ofBeaconBlock
.mod/consensus-types/pkg/types/deposit.go (1)
74-77
: LGTM! TheEmpty
method is a useful addition.The method provides a straightforward way to create an empty
Deposit
instance.mod/consensus-types/pkg/types/block.go (1)
49-50
: LGTM! The simplification of theEmpty
method improves usability.The removal of the
forkVersion
parameter reduces complexity and potential runtime errors.mod/consensus-types/pkg/types/header.go (1)
77-80
: LGTM! TheEmpty
method is a useful addition.The method provides a straightforward way to create an empty
BeaconBlockHeader
instance.mod/storage/pkg/beacondb/kvstore.go (2)
38-45
: LGTM! Enhanced type constraints improve type safety and consistency.The updated type constraints for
BeaconBlockHeaderT
,Eth1DataT
, andForkT
ensure that these types are serializable and can provide an empty instance, which enhances type safety and consistency in theKVStore
struct.Also applies to: 51-55
116-123
: LGTM! Enhanced type constraints improve type safety and consistency.The updated type constraints for
BeaconBlockHeaderT
,Eth1DataT
, andForkT
ensure that these types are serializable and can provide an empty instance, which enhances type safety and consistency in theNew
function.Also applies to: 129-133
mod/consensus-types/pkg/types/validator.go (1)
98-101
: LGTM! TheEmpty
method enhances usability.The
Empty
method provides a straightforward way to instantiate an emptyValidator
, improving the usability of theValidator
type.
constraints.Empty[SelfT] | ||
NewFromSSZ([]byte, uint32) (SelfT, error) | ||
} |
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.
Tip
Codebase Verification
Verify the constraints.Empty[SelfT]
constraint for BeaconBlock
interfaces
The following BeaconBlock
interfaces do not include the constraints.Empty[SelfT]
constraint:
mod/storage/pkg/block/types.go
mod/storage/pkg/pruner/types.go
mod/storage/pkg/manager/types.go
mod/runtime/pkg/encoding/types.go
mod/da/pkg/store/types.go
mod/da/pkg/blob/types.go
mod/execution/pkg/deposit/types.go
mod/beacon/blockchain/types.go
mod/beacon/validator/types.go
mod/beacon/block_store/types.go
Please verify if these interfaces are intended to be different or if they need to be updated to include the new constraint.
Analysis chain
LGTM! Verify the impact on implementing types.
The addition of constraints.Empty[SelfT]
promotes consistency and type safety. Ensure that all types implementing BeaconBlock
satisfy the new constraint.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify all types implementing `BeaconBlock` satisfy the new constraint.
# Test: Search for all types implementing `BeaconBlock`. Expect: All occurrences of the new constraint.
rg --type go -A 5 $'type BeaconBlock'
Length of output: 25960
type Deposit[DepositT any] interface { | ||
constraints.SSZMarshallable | ||
constraints.Empty[DepositT] | ||
GetIndex() math.U64 |
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.
Tip
Codebase Verification
Issues Found: Types using DepositT interface{}
do not satisfy the new constraint.
The addition of constraints.Empty[DepositT]
promotes consistency and type safety. However, the following types using DepositT interface{}
do not satisfy this new constraint and need to be updated:
mod/node-api/backend/mocks/deposit_store.mock.go
mod/node-api/backend/mocks/deposit.mock.go
Please update these types to ensure they satisfy the constraints.Empty[DepositT]
constraint.
Analysis chain
LGTM! Verify the impact on implementing types.
The addition of constraints.Empty[DepositT]
promotes consistency and type safety. Ensure that all types used as DepositT
satisfy the new constraint.
Verify the impact on implementing types.
Ensure that all types used as DepositT
in Deposit[DepositT any]
satisfy the new constraints.Empty[DepositT]
constraint.
Verify the impact on implementing types.
Ensure that all types used as DepositT
in Deposit[DepositT any]
satisfy the new constraints.Empty[DepositT]
constraint. Pay special attention to types using DepositT interface{}
as they might not satisfy the new constraint.
Verify the impact on implementing types.
Ensure that all types used as DepositT
in Deposit[DepositT any]
satisfy the new constraints.Empty[DepositT]
constraint. Pay special attention to types using DepositT interface{}
as they might not satisfy the new constraint.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify all types used as `DepositT` satisfy the new constraint.
# Test: Search for all types implementing `Deposit`. Expect: All occurrences of the new constraint.
rg --type go -A 5 $'type Deposit'
Length of output: 10368
Script:
#!/bin/bash
# Description: Verify all types used as `DepositT` satisfy the new constraint.
# Search for all types implementing `Deposit` and `DepositStore` and check their constraints.
rg --type go -A 5 'type Deposit' | grep -E 'Deposit\[|DepositStore\[|DepositT'
Length of output: 2767
Script:
#!/bin/bash
# Description: Verify all types used as `DepositT` satisfy the new constraint.
# Search for all types implementing `Deposit` and `DepositStore` and check their constraints.
rg --type go 'type Deposit' -A 5 | grep -E 'Deposit\[|DepositStore\[|DepositT' -B 5
Length of output: 7843
Script:
#!/bin/bash
# Description: Verify all types used as `DepositT` satisfy the new constraint.
# Search for the definition and constraints of `DepositT` in the relevant files.
rg --type go 'DepositT' -A 5 -B 5
Length of output: 104078
Summary by CodeRabbit
New Features
Empty
methods for multiple types (Deposit
,Eth1Data
,Fork
,Validator
,BeaconBlockHeader
, and more) to simplify instantiation of empty instances.Improvements
Empty
method inBeaconBlock
, enhancing usability by removing the need for version parameters.constraints.Empty
requirements, ensuring type instances can be created in a default state.Bug Fixes
Empty
method, improving clarity and reducing redundancy.