Skip to content

Commit 722f540

Browse files
rkapkajames-prysm
authored andcommitted
practical review :)
1 parent 05dd30d commit 722f540

3 files changed

Lines changed: 782 additions & 778 deletions

File tree

beacon-chain/rpc/eth/beacon/handlers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestPublishBlockV2(t *testing.T) {
136136
v1alpha1Server := mock2.NewMockBeaconNodeValidatorServer(ctrl)
137137
v1alpha1Server.EXPECT().ProposeBeaconBlock(gomock.Any(), mock.MatchedBy(func(req *eth.GenericSignedBeaconBlock) bool {
138138
block, ok := req.Block.(*eth.GenericSignedBeaconBlock_Deneb)
139-
converted, err := shared.DenebBlockFromConsensus(block.Deneb.Block.Block)
139+
converted, err := shared.BeaconBlockDenebFromConsensus(block.Deneb.Block.Block)
140140
require.NoError(t, err)
141141
var signedblock *shared.SignedBeaconBlockContentsDeneb
142142
err = json.Unmarshal([]byte(denebBlockContents), &signedblock)
@@ -375,7 +375,7 @@ func TestPublishBlindedBlockV2(t *testing.T) {
375375
v1alpha1Server := mock2.NewMockBeaconNodeValidatorServer(ctrl)
376376
v1alpha1Server.EXPECT().ProposeBeaconBlock(gomock.Any(), mock.MatchedBy(func(req *eth.GenericSignedBeaconBlock) bool {
377377
block, ok := req.Block.(*eth.GenericSignedBeaconBlock_BlindedDeneb)
378-
converted, err := shared.BlindedDenebBlockFromConsensus(block.BlindedDeneb.Block.Block)
378+
converted, err := shared.BlindedBeaconBlockDenebFromConsensus(block.BlindedDeneb.Block.Block)
379379
require.NoError(t, err)
380380
var signedblock *shared.SignedBlindedBeaconBlockContentsDeneb
381381
err = json.Unmarshal([]byte(blindedDenebBlockContents), &signedblock)

beacon-chain/rpc/eth/shared/request.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ func IsOptimistic(
143143
return true, nil
144144
}
145145

146-
// DecodeHexWithLength takes a string and a length and validates the hex while returning an error
146+
// DecodeHexWithLength takes a string and a length in bytes,
147+
// and validates whether the string is a hex and has the correct length.
147148
func DecodeHexWithLength(s string, length int) ([]byte, error) {
148149
bytes, err := hexutil.Decode(s)
149150
if err != nil {
@@ -155,23 +156,25 @@ func DecodeHexWithLength(s string, length int) ([]byte, error) {
155156
return bytes, nil
156157
}
157158

158-
// DecodeHexWithMaxLength takes a string and a max byte length and validates the hex while returning an error
159-
func DecodeHexWithMaxLength(s string, length int) ([]byte, error) {
159+
// DecodeHexWithMaxLength takes a string and a length in bytes,
160+
// and validates whether the string is a hex and has the correct length.
161+
func DecodeHexWithMaxLength(s string, maxLength int) ([]byte, error) {
160162
bytes, err := hexutil.Decode(s)
161163
if err != nil {
162164
return nil, errors.Wrap(err, fmt.Sprintf("%s is not a valid hex", s))
163165
}
164-
err = VerifyMaxLength(s, len(bytes), length)
166+
err = VerifyMaxLength(bytes, maxLength)
165167
if err != nil {
166-
return nil, err
168+
return nil, errors.Wrap(err, fmt.Sprintf("%s has too many bytes", s))
167169
}
168170
return bytes, nil
169171
}
170172

171-
// VerifyMaxLength takes in two lengths and returns an error
172-
func VerifyMaxLength(name string, length int, max int) error {
173-
if length > max {
174-
return fmt.Errorf("%s length of %d bytes exceeds max of %d", name, length, max)
173+
// VerifyMaxLength takes a slice and a maximum length and validates the length.
174+
func VerifyMaxLength[T any](v []T, max int) error {
175+
l := len(v)
176+
if l > max {
177+
return fmt.Errorf("length of %d exceeds max of %d", l, max)
175178
}
176179
return nil
177180
}

0 commit comments

Comments
 (0)