-
Notifications
You must be signed in to change notification settings - Fork 210
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(ssz): Add type defs #1664
feat(ssz): Add type defs #1664
Conversation
Warning Rate limit exceeded@itsdevbear has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 56 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes enhance the type system and functionality for serialization in the Changes
Sequence Diagram(s)(Changes are too varied and specific to include sequence diagrams.) Poem
Tip Early access features: enabledWe are currently testing the following features in early access:
Note:
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 Configration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1664 +/- ##
===========================================
+ Coverage 22.38% 70.45% +48.07%
===========================================
Files 270 8 -262
Lines 11888 88 -11800
Branches 18 18
===========================================
- Hits 2661 62 -2599
+ Misses 9107 22 -9085
+ Partials 120 4 -116 |
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
Outside diff range comments (2)
mod/primitives/pkg/ssz/vector.go (2)
Line range hint
50-52
: Reminder: Deprecate the function.The TODO comment indicates that the
VectorCompositeFromElements
function is to be deprecated.Do you want me to deprecate the function or open a GitHub issue to track this task?
Line range hint
98-100
: Avoid usingpanic
for error handling.The
MarshalSSZToBytes
andNewFromSSZ
methods usepanic
for error handling, which is not recommended.- if !c.IsFixed() { - panic("not implemented yet") - } + if !c.IsFixed() { + return nil, errors.New("not implemented yet") + }Also applies to: 113-115
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (6)
- mod/primitives/pkg/ssz/basic.go (12 hunks)
- mod/primitives/pkg/ssz/constraints.go (1 hunks)
- mod/primitives/pkg/ssz/interfaces.go (1 hunks)
- mod/primitives/pkg/ssz/list.go (2 hunks)
- mod/primitives/pkg/ssz/types/types.go (1 hunks)
- mod/primitives/pkg/ssz/vector.go (2 hunks)
Additional comments not posted (22)
mod/primitives/pkg/ssz/types/types.go (3)
3-8
: LGTM!The
Type
definition and constants forBasic
andComposite
are clear and straightforward.
10-28
: LGTM!The
SSZType
interface is well-defined and comprehensive.
30-40
: LGTM!The
SSZEnumerable
interface is well-defined and extendsSSZType
.mod/primitives/pkg/ssz/constraints.go (2)
26-29
: LGTM!The
Basic
interface now extendstypes.SSZType
and the type constraint is clear.
33-35
: LGTM!The
Composite
interface now extendstypes.SSZType
and the type constraint is clear.mod/primitives/pkg/ssz/interfaces.go (3)
23-28
: LGTM!The
BaseMerkleizer
interface now usestypes.SSZType
and the type constraint is clear.
Line range hint
29-34
: LGTM!The
BasicMerkleizer
interface provides clear merkleization operations for basic SSZ types.
Line range hint
35-41
: LGTM!The
CompositeMerkleizer
interface provides clear merkleization operations for composite SSZ types.mod/primitives/pkg/ssz/vector.go (2)
34-39
: LGTM!The
VectorBasic
type definition and its methods are clear and well-implemented.
38-39
: LGTM!The
VectorComposite
type definition and its methods are clear and well-implemented.mod/primitives/pkg/ssz/list.go (5)
34-46
: LGTM!The new type definitions for
ListBasic
andListComposite
are clear and align with the existing code structure.
Line range hint
48-55
: LGTM!The function
ListCompositeFromElements
is straightforward. Ensure to address the TODO comment for deprecation.
Line range hint
56-60
: LGTM!The function
IsFixed
correctly follows the SSZ specification.
Line range hint
61-65
: LGTM!The function
N
correctly returns the limit of the list.
Line range hint
66-70
: LGTM!The function
ChunkCount
correctly calculates the number of chunks in the list.mod/primitives/pkg/ssz/basic.go (7)
35-43
: LGTM!The new type definitions for
Bool
,U8
,U16
,U32
,U64
, andByte
are clear and align with the existing code structure.
Line range hint
45-100
: LGTM!The functions for
Bool
are well-implemented and follow the SSZ specification.
Line range hint
101-149
: LGTM!The functions for
U8
are well-implemented and follow the SSZ specification.
Line range hint
150-198
: LGTM!The functions for
U16
are well-implemented and follow the SSZ specification.
Line range hint
199-247
: LGTM!The functions for
U32
are well-implemented and follow the SSZ specification.
Line range hint
248-296
: LGTM!The functions for
U64
are well-implemented and follow the SSZ specification.
Line range hint
297-343
: LGTM!The functions for
Byte
are well-implemented and follow the SSZ specification.
// TODO: Enable these | ||
// | ||
// ChunkCount returns the number of chunks required to store the type. | ||
// ChunkCount() uint64 | ||
// Type returns the type of the SSZ object. | ||
// Type() Type |
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.
Reminder: Enable the commented methods.
The TODO comment indicates that some methods are not yet enabled.
Do you want me to implement the commented methods or open a GitHub issue to track this task?
|
||
// VectorBasicFromElements creates a new ListComposite from elements. | ||
// TODO: Deprecate once off of Fastssz |
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.
Reminder: Deprecate the function.
The TODO comment indicates that the VectorBasicFromElements
function is to be deprecated.
Do you want me to deprecate the function or open a GitHub issue to track this task?
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 (4)
- mod/engine-primitives/pkg/engine-primitives/withdrawal.go (2 hunks)
- mod/primitives/pkg/ssz/basic.go (12 hunks)
- mod/primitives/pkg/ssz/container.go (1 hunks)
- mod/primitives/pkg/ssz/types/types.go (1 hunks)
Additional comments not posted (14)
mod/primitives/pkg/ssz/types/types.go (4)
1-21
: LGTM!The license header and package declaration are correctly defined.
23-28
: LGTM!The type
Type
and constantsBasic
andComposite
are correctly defined.
30-41
: LGTM!The
BaseSSZType
interface is well-defined and follows Go interface design principles.
53-62
: LGTM!The
SSZEnumerable
interface is well-defined and follows Go interface design principles.mod/primitives/pkg/ssz/container.go (3)
1-8
: LGTM!The package declaration and imports are correctly defined.
10-47
: LGTM!The
Container
struct and its methods are well-defined and follow Go struct and method design principles.
49-107
: LGTM!The methods for SSZ serialization are well-defined and follow Go method design principles.
mod/engine-primitives/pkg/engine-primitives/withdrawal.go (3)
Line range hint
1-26
: LGTM!The license header and package declaration are correctly defined.
Line range hint
28-86
: LGTM!The
Withdrawal
struct and its methods are well-defined and follow Go struct and method design principles.
87-90
: LGTM!The
Type
method for theWithdrawal
struct is well-defined and follows Go method design principles.mod/primitives/pkg/ssz/basic.go (4)
Line range hint
1-11
: LGTM!The license header and package declaration are correctly defined.
27-52
: LGTM!The imports and type definitions are correctly defined.
Line range hint
54-103
: LGTM!The
Bool
type and its methods are well-defined and follow Go method design principles.
Line range hint
105-343
: LGTM!The types
U8
,U16
,U32
,U64
, andByte
and their methods are well-defined and follow Go method design principles.
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: 3
Outside diff range comments (3)
testing/files/entrypoint.sh (3)
Line range hint
46-47
: Unused VariablesThe variables
GENESIS
andTMP_GENESIS
are defined but not used. Verify their usage or remove them if unnecessary.- GENESIS=$HOMEDIR/config/genesis.json - TMP_GENESIS=$HOMEDIR/config/tmp_genesis.json
Line range hint
81-81
: Unquoted VariableThe surrounding quotes unquote the variable. Remove or escape the quotes.
- BEACON_START_CMD="./build/bin/beacond start --pruning=nothing "$TRACE" \ + BEACON_START_CMD="./build/bin/beacond start --pruning=nothing \"$TRACE\" \
Line range hint
95-95
: Double Quote to Prevent Globbing and Word SplittingDouble quote the variable to prevent globbing and word splitting.
- RPC_DIAL_URL=$(resolve_path "$RPC_DIAL_URL") + RPC_DIAL_URL="$(resolve_path "$RPC_DIAL_URL")"
Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Files selected for processing (7)
- mod/primitives/pkg/ssz/container.go (1 hunks)
- mod/primitives/pkg/ssz/interfaces.go (2 hunks)
- mod/primitives/pkg/ssz/list.go (3 hunks)
- mod/primitives/pkg/ssz/types/types.go (1 hunks)
- mod/primitives/pkg/ssz/vector.go (1 hunks)
- mod/primitives/pkg/ssz/vector_test.go (5 hunks)
- testing/files/entrypoint.sh (1 hunks)
Additional context used
Shellcheck
testing/files/entrypoint.sh
[warning] 46-46: GENESIS appears unused. Verify use (or export if used externally).
(SC2034)
[warning] 47-47: TMP_GENESIS appears unused. Verify use (or export if used externally).
(SC2034)
[warning] 81-81: The surrounding quotes actually unquote this. Remove or escape them.
(SC2027)
[info] 95-95: Double quote to prevent globbing and word splitting.
(SC2086)
Additional comments not posted (51)
mod/primitives/pkg/ssz/types/types.go (4)
1-19
: License and Copyright NoticeThe license and copyright notice are correctly included and formatted.
21-28
: New Type DefinitionsThe
Type
enum and its constantsBasic
andComposite
are well-defined and clear.
30-41
: BaseSSZType InterfaceThe
BaseSSZType
interface defines essential methods for SSZ types, includingHashTreeRoot
,IsFixed
,SizeSSZ
,Type
, andMarshalSSZ
. These methods are crucial for SSZ serialization and type handling.
53-63
: New SSZEnumerable InterfaceThe
SSZEnumerable
interface extendsSSZType
and adds methodsN
andElements
for SSZ enumerable types. This extension is logical and aligns with SSZ specifications.mod/primitives/pkg/ssz/interfaces.go (7)
Line range hint
1-22
: License and Copyright NoticeThe license and copyright notice are correctly included and formatted.
23-23
: Import StatementThe import statement correctly imports the
types
package from the specified path.
Line range hint
27-31
: BaseMerkleizer InterfaceThe
BaseMerkleizer
interface defines basic merkleization operations for SSZ types. The method signatures are clear and appropriate.
Line range hint
33-43
: BasicMerkleizer InterfaceThe
BasicMerkleizer
interface extendsBaseMerkleizer
and adds methods for merkleizing basic SSZ types. The method signatures are clear and appropriate.
Line range hint
45-51
: CompositeMerkleizer InterfaceThe
CompositeMerkleizer
interface extendsBaseMerkleizer
and adds methods for merkleizing composite SSZ types. The method signatures are clear and appropriate.
53-56
: VectorMerkelizer InterfaceThe
VectorMerkelizer
interface defines methods for merkleizing vectors of SSZ types. The method signatures are clear and appropriate.
58-61
: ListMerkliezer InterfaceThe
ListMerkliezer
interface defines methods for merkleizing lists of SSZ types. The method signatures are clear and appropriate.testing/files/entrypoint.sh (2)
Line range hint
1-43
: License and Function DefinitionThe license and permission notice are correctly included and formatted. The function
resolve_path
is well-defined and handles both URLs and file paths.
65-65
: CHAIN_SPEC Variable UpdateThe
CHAIN_SPEC
variable is updated totestnet
. Ensure this change is intentional and aligns with the environment requirements.mod/primitives/pkg/ssz/container.go (13)
1-19
: License and Copyright NoticeThe license and copyright notice are correctly included and formatted.
21-28
: Import StatementsThe import statements correctly import necessary packages and modules.
30-30
: Interface Implementation AssertionThe assertion ensures that
Container
implements thetypes.SSZEnumerable
interface. This is a good practice to catch interface implementation issues at compile time.
32-35
: Container Struct DefinitionThe
Container
struct is defined with a single fieldelements
which is a slice oftypes.BaseSSZType
. This is clear and straightforward.
37-54
: NewContainer FunctionThe
NewContainer
function uses reflection to create a newContainer
from a struct. It includes checks to ensure the input is a struct and handles pointers correctly. The TODO comment indicates that struct tags need to be checked to exclude fields.
56-65
: Field Iteration and Type CheckingThe loop iterates over the fields of the struct and checks if they implement the
types.BaseSSZType
interface. If a field does not implement the interface, an error is returned. This is a robust way to ensure all fields are valid SSZ types.
67-67
: Return StatementThe function returns a new
Container
with the collected elements. This is clear and straightforward.
70-72
: N MethodThe
N
method returns the number of elements in the container. This is clear and straightforward.
74-76
: Elements MethodThe
Elements
method returns the elements of the container. This is clear and straightforward.
78-92
: MarshalSSZ MethodThe
MarshalSSZ
method marshals the container into SSZ format by iterating over the elements and calling theirMarshalSSZ
method. This is a clear and efficient implementation.
94-103
: SizeSSZ MethodThe
SizeSSZ
method returns the size of the container in bytes by summing the sizes of its elements. This is a clear and efficient implementation.
105-113
: IsFixed MethodThe
IsFixed
method returns true if all elements in the container are of fixed size. This is a clear and efficient implementation.
120-123
: Type MethodThe
Type
method returns the type of the container astypes.Composite
. This is clear and straightforward.mod/primitives/pkg/ssz/vector_test.go (3)
30-61
: LGTM!The test cases for
TestVectorSizeSSZ
cover various vector types and are correctly implemented.
Line range hint
62-93
: LGTM!The test cases for
TestVectorHashTreeRoot
cover various vector types and are correctly implemented.
Line range hint
95-149
: LGTM!The test cases for
TestVectorMarshalUnmarshal
cover various vector types and are correctly implemented.mod/primitives/pkg/ssz/vector.go (12)
35-37
: LGTM!The type definition for
Vector
with the type constraint is appropriate and ensures type safety.
50-54
: LGTM!The method
SizeSSZ
correctly calculates the size of the vector in bytes using theSizeSSZ
method of the element type.
56-59
: LGTM!The method
IsFixed
correctly determines if the vector is of fixed size using theIsFixed
method of the element type.
62-65
: LGTM!The method
Type
correctly returns the type of the vector using theType
method of the element type.
68-75
: LGTM!The method
ChunkCount
correctly calculates the number of chunks in the vector and handles both basic and composite types appropriately.
79-81
: LGTM!The method
N
correctly returns the length of the vector.
86-88
: LGTM!The method
Elements
correctly returns the elements of the vector.
96-102
: LGTM!The method
HashTreeRootWith
correctly calculates the Merkle root of the vector with a given merkleizer and handles both basic and composite types appropriately.
107-110
: LGTM!The method
HashTreeRoot
correctly calculates the Merkle root of the vector using theHashTreeRootWith
method with a new merkleizer.
117-123
: LGTM!The method
MarshalSSZTo
correctly marshals the vector into SSZ format using the appropriate serializer method based on whether the vector is fixed size.
126-128
: LGTM!The method
MarshalSSZ
correctly marshals the vector into SSZ format using theMarshalSSZTo
method.
131-137
: LGTM!The method
NewFromSSZ
correctly creates a new vector from SSZ format using the appropriate deserializer method based on whether the vector is fixed size.mod/primitives/pkg/ssz/list.go (10)
Line range hint
74-77
: LGTM!The method
IsFixed
correctly returns false, indicating that lists are not of fixed size.
79-82
: LGTM!The method
N
correctly returns the limit of the list.
Line range hint
84-89
: LGTM!The method
ChunkCount
correctly calculates the number of chunks in the list using the size of the element type.
79-80
: LGTM!The method
SizeSSZ
correctly calculates the size of the list in bytes using theSizeSSZ
method of theVector
type.
Line range hint
91-94
: LGTM!The method
HashTreeRootWith
correctly calculates the Merkle root of the list with a given merkleizer using theMerkleizeListBasic
method of the merkleizer.
96-98
: LGTM!The method
HashTreeRoot
correctly calculates the Merkle root of the list using theHashTreeRootWith
method with a new merkleizer.
99-101
: LGTM!The method
MarshalSSZTo
correctly marshals the list into SSZ format using theMarshalVectorFixed
method of the serializer.
104-106
: LGTM!The method
MarshalSSZ
correctly marshals the list into SSZ format using theMarshalSSZTo
method.
110-115
: LGTM!The method
NewFromSSZ
correctly creates a new list from SSZ format using theNewFromSSZ
method of theVector
type to deserialize the elements.
Line range hint
146-149
: LGTM!The method
IsFixed
correctly returns false, indicating that lists are not of fixed size.
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 (2)
- mod/primitives/pkg/ssz/interfaces.go (2 hunks)
- mod/primitives/pkg/ssz/vector.go (1 hunks)
Additional comments not posted (14)
mod/primitives/pkg/ssz/interfaces.go (3)
27-27
: LGTM!The update to use
types.SSZType[T]
inBaseMerkleizer
is consistent with the objective of adding type definitions.
53-56
: LGTM!The addition of the
VectorMerkleizer
interface with methods for Merkleizing vectors of basic and composite types is consistent with the objective of adding type definitions.
58-61
: LGTM!The addition of the
ListMerkleizer
interface with methods for Merkleizing lists of basic and composite types is consistent with the objective of adding type definitions.mod/primitives/pkg/ssz/vector.go (11)
52-54
: LGTM!The
SizeSSZ
function correctly calculates the size of the list in bytes.
58-63
: LGTM!The
IsFixed
function correctly determines if the vector is of fixed size.
66-67
: LGTM!The
Type
function correctly returns the type of the vector.
71-78
: LGTM!The
ChunkCount
function correctly calculates the number of chunks in the vector.
82-85
: LGTM!The
N
function correctly returns the N value as defined in the SSZ specification.
89-90
: LGTM!The
Elements
function correctly returns the elements of the vector.
99-106
: LGTM!The
HashTreeRootWith
function correctly returns the Merkle root of the vector with a given merkleizer, performing necessary type checks.
110-111
: LGTM!The
HashTreeRoot
function correctly returns the Merkle root of the vector.
119-124
: LGTM!The
MarshalSSZTo
function correctly marshals the vector into SSZ format, returning an error for non-fixed size vectors.
128-129
: LGTM!The
MarshalSSZ
function correctly marshals the vector into SSZ format.
133-138
: LGTM!The
NewFromSSZ
function correctly creates a new vector from SSZ format, panicking for non-fixed size vectors.
func VectorFromElements[B Basic[B]](elements ...B) Vector[B] { | ||
return elements | ||
} |
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.
Reminder: Deprecate the function.
The TODO comment indicates that the VectorFromElements
function is to be deprecated.
Do you want me to deprecate the function or open a GitHub issue to track this task?
Summary by CodeRabbit
New Features
U8
,U16
,U32
,U64
,Byte
) with enhanced serialization capabilities.VectorMerkleizer
andListMerkleizer
interfaces for improved Merkleization operations.Refactor
ListBasic
andListComposite
types for better type handling.Chores
CHAIN_SPEC
in the entrypoint script from "devnet" to "testnet".