Skip to content

Commit

Permalink
Additional linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed May 10, 2024
1 parent 9b90d7b commit 56dfbe8
Show file tree
Hide file tree
Showing 52 changed files with 765 additions and 269 deletions.
58 changes: 19 additions & 39 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,54 +110,34 @@ linters-settings:
line-length: 132

revive:
ignore-generated-header: true
ignore-generated-header: false
severity: error
confidence: 0.1
confidence: 0.8
errorCode: 0
warningCode: 0
enable-all-rules: true
rules:
- name: atomic
- name: blank-imports
- name: comment-spacings
- name: add-constant
disabled: true
- name: cyclomatic
disabled: true
- name: cognitive-complexity
disabled: true
- name: confusing-results
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: datarace
- name: defer
- name: dot-imports
- name: duplicated-imports
- name: early-return
- name: error-strings
- name: errorf
- name: exported
- name: file-header
- name: identical-branches
- name: import-alias-naming
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: modifies-value-receiver
- name: range-val-address
- name: range-val-in-closure
- name: range
- name: receiver-naming
- name: string-of-int
- name: superfluous-else
- name: time-equal
- name: time-naming
- name: unchecked-type-assertion
- name: function-length
disabled: true
- name: line-length-limit
arguments: [132]
- name: max-public-structs
disabled: true
- name: package-comments
disabled: true
- name: struct-tag
arguments: ["json,allowempty"]
- name: unhandled-error
arguments:
- "fmt.Fprint"
- "fmt.Fprintf"
- name: unnecessary-stmt
- name: unused-parameter
- name: unused-receiver
- name: use-any
- name: useless-break
- name: var-naming
- name: waitgroup-by-value

stylecheck:
checks: [ "all", "-ST1000" ]
Expand Down
1 change: 1 addition & 0 deletions api/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package api

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f versionedblindedbeaconblock_ssz.go versionedsignedblindedbeaconblock_ssz.go versionedsignedvalidatorregistration_ssz.go
//go:generate sszgen -suffix=ssz -path . -include ../spec,../spec/phase0,../spec/altair,../spec/bellatrix,../spec/capella,../spec/deneb,v1,v1/bellatrix,v1/capella,v1/deneb -exclude-objs DataVersion -objs VersionedBlindedBeaconBlock,VersionedSignedBlindedBeaconBlock,VersionedSignedValidatorRegistration
Expand Down
3 changes: 2 additions & 1 deletion api/proposerdutiesopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ProposerDutiesOpts struct {

// Epoch is the epoch for which the data is obtained.
Epoch phase0.Epoch
// Indices is a list of validators to restrict the returned values. If no indices are supplied then no filter will be applied.
// Indices is a list of validators to restrict the returned values.
// If no indices are supplied then no filter will be applied.
Indices []phase0.ValidatorIndex
}
1 change: 1 addition & 0 deletions api/v1/bellatrix/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package bellatrix

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f blindedbeaconblockbody_ssz.go blindedbeaconblock_ssz.go signedblindedbeaconblock_ssz.go
//go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella -path . --suffix ssz -objs BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock
Expand Down
1 change: 1 addition & 0 deletions api/v1/capella/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package capella

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f blindedbeaconblockbody_ssz.go blindedbeaconblock_ssz.go signedblindedbeaconblock_ssz.go
//go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella -path . --suffix ssz -objs BlindedBeaconBlockBody,BlindedBeaconBlock,SignedBlindedBeaconBlock
Expand Down
1 change: 1 addition & 0 deletions api/v1/deneb/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package deneb

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f blindedbeaconblock_ssz.go blindedbeaconblockbody_ssz.go blockcontents_ssz.go signedblindedbeaconblock_ssz.go signedblockcontents_ssz.go
//go:generate sszgen --include ../../../spec/phase0,../../../spec/altair,../../../spec/bellatrix,../../../spec/capella,../../../spec/deneb -path . --suffix ssz -objs BlindedBeaconBlock,BlindedBeaconBlockBody,BlockContents,SignedBlindedBeaconBlock,SignedBlockContents
Expand Down
1 change: 1 addition & 0 deletions api/v1/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package v1

//nolint:revive
// Need to `go install github.com/ferranbt/fastssz/sszgen@latest` for this to work.
//go:generate rm -f signedvalidatorregistration_ssz.go validatorregistration_ssz.go
//go:generate sszgen -suffix ssz -include ../../spec/phase0,../../spec/altair,../../spec/bellatrix -path . -objs SignedValidatorRegistration,ValidatorRegistration
Expand Down
3 changes: 2 additions & 1 deletion api/validatorbalancesopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ValidatorBalancesOpts struct {
// State is the state at which the data is obtained.
// It can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized".
State string
// Indices is a list of validator indices to restrict the returned values. If no indices are supplied then no filter will be applied.
// Indices is a list of validator indices to restrict the returned values.
// If no indices are supplied then no filter will be applied.
Indices []phase0.ValidatorIndex
}
9 changes: 6 additions & 3 deletions api/validatorsopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ type ValidatorsOpts struct {
// State is the state at which the data is obtained.
// It can be a slot number or state root, or one of the special values "genesis", "head", "justified" or "finalized".
State string
// Indices is a list of validator indices to restrict the returned values. If no indices are supplied then no filter will be applied.
// Indices is a list of validator indices to restrict the returned values.
// If no indices are supplied then no filter will be applied.
Indices []phase0.ValidatorIndex
// PubKeys is a list of validator public keys to restrict the returned values. If no public keys are supplied then no filter will be applied.
// PubKeys is a list of validator public keys to restrict the returned values.
// If no public keys are supplied then no filter will be applied.
PubKeys []phase0.BLSPubKey
// ValidatorStates is a list of validator states to restric the returned values. If no validator states are supplied then no filter will be applied.
// ValidatorStates is a list of validator states to restric the returned values.
// If no validator states are supplied then no filter will be applied.
ValidatorStates []apiv1.ValidatorState
}
4 changes: 3 additions & 1 deletion api/versionedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,9 @@ func (v *VersionedProposal) payloadPresent() bool {
return false
case spec.DataVersionBellatrix:
if v.Blinded {
return v.BellatrixBlinded != nil && v.BellatrixBlinded.Body != nil && v.BellatrixBlinded.Body.ExecutionPayloadHeader != nil
return v.BellatrixBlinded != nil &&
v.BellatrixBlinded.Body != nil &&
v.BellatrixBlinded.Body.ExecutionPayloadHeader != nil
}

return v.Bellatrix != nil && v.Bellatrix.Body != nil && v.Bellatrix.Body.ExecutionPayload != nil
Expand Down
11 changes: 9 additions & 2 deletions http/aggregateattestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func (s *Service) AggregateAttestation(ctx context.Context,

// Confirm the attestation is for the requested slot.
if data.Data.Slot != opts.Slot {
return nil, errors.Join(fmt.Errorf("aggregate attestation for slot %d; expected %d", data.Data.Slot, opts.Slot), client.ErrInconsistentResult)
return nil,
errors.Join(
fmt.Errorf("aggregate attestation for slot %d; expected %d", data.Data.Slot, opts.Slot),
client.ErrInconsistentResult,
)
}

// Confirm the attestation data is correct.
Expand All @@ -64,7 +68,10 @@ func (s *Service) AggregateAttestation(ctx context.Context,
return nil, errors.Join(errors.New("failed to obtain hash tree root of aggregate attestation data"), err)
}
if !bytes.Equal(dataRoot[:], opts.AttestationDataRoot[:]) {
return nil, errors.Join(fmt.Errorf("aggregate attestation has data root %#x; expected %#x", dataRoot[:], opts.AttestationDataRoot[:]), client.ErrInconsistentResult)
return nil, errors.Join(
fmt.Errorf("aggregate attestation has data root %#x; expected %#x", dataRoot[:], opts.AttestationDataRoot[:]),
client.ErrInconsistentResult,
)
}

return &api.Response[*phase0.Attestation]{
Expand Down
10 changes: 8 additions & 2 deletions http/attestationdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ func (*Service) attestationDataFromJSON(_ context.Context,

func verifyAttestationData(opts *api.AttestationDataOpts, data *phase0.AttestationData) error {
if data.Slot != opts.Slot {
return errors.Join(fmt.Errorf("attestation data for slot %d; expected %d", data.Slot, opts.Slot), client.ErrInconsistentResult)
return errors.Join(
fmt.Errorf("attestation data for slot %d; expected %d", data.Slot, opts.Slot),
client.ErrInconsistentResult,
)
}
if data.Index != opts.CommitteeIndex {
return errors.Join(fmt.Errorf("attestation data for committee index %d; expected %d", data.Index, opts.CommitteeIndex), client.ErrInconsistentResult)
return errors.Join(
fmt.Errorf("attestation data for committee index %d; expected %d", data.Index, opts.CommitteeIndex),
client.ErrInconsistentResult,
)
}

return nil
Expand Down
34 changes: 28 additions & 6 deletions http/blindedproposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func (s *Service) BlindedProposal(ctx context.Context,

if opts.SkipRandaoVerification {
if !opts.RandaoReveal.IsInfinity() {
return nil, errors.Join(errors.New("randao reveal must be point at infinity if skip randao verification is set"), client.ErrInvalidOptions)
return nil, errors.Join(
errors.New("randao reveal must be point at infinity if skip randao verification is set"),
client.ErrInvalidOptions,
)
}
query = fmt.Sprintf("%s&skip_randao_verification", query)
}
Expand Down Expand Up @@ -84,7 +87,10 @@ func (s *Service) BlindedProposal(ctx context.Context,
return nil, err
}
if blockSlot != opts.Slot {
return nil, errors.Join(fmt.Errorf("blinded beacon block proposal for slot %d; expected %d", blockSlot, opts.Slot), client.ErrInconsistentResult)
return nil, errors.Join(
fmt.Errorf("blinded beacon block proposal for slot %d; expected %d", blockSlot, opts.Slot),
client.ErrInconsistentResult,
)
}

// Only check the RANDAO reveal if we are not connected to DVT middleware,
Expand All @@ -95,7 +101,14 @@ func (s *Service) BlindedProposal(ctx context.Context,
return nil, err
}
if !bytes.Equal(blockRandaoReveal[:], opts.RandaoReveal[:]) {
return nil, errors.Join(fmt.Errorf("blinded beacon block proposal has RANDAO reveal %#x; expected %#x", blockRandaoReveal[:], opts.RandaoReveal[:]), client.ErrInconsistentResult)
return nil, errors.Join(
fmt.Errorf(
"blinded beacon block proposal has RANDAO reveal %#x; expected %#x",
blockRandaoReveal[:],
opts.RandaoReveal[:],
),
client.ErrInconsistentResult,
)
}
}

Expand Down Expand Up @@ -143,11 +156,20 @@ func (*Service) blindedProposalFromJSON(res *httpResponse) (*api.Response[*api.V
var err error
switch res.consensusVersion {
case spec.DataVersionBellatrix:
response.Data.Bellatrix, response.Metadata, err = decodeJSONResponse(bytes.NewReader(res.body), &apiv1bellatrix.BlindedBeaconBlock{})
response.Data.Bellatrix, response.Metadata, err = decodeJSONResponse(
bytes.NewReader(res.body),
&apiv1bellatrix.BlindedBeaconBlock{},
)
case spec.DataVersionCapella:
response.Data.Capella, response.Metadata, err = decodeJSONResponse(bytes.NewReader(res.body), &apiv1capella.BlindedBeaconBlock{})
response.Data.Capella, response.Metadata, err = decodeJSONResponse(
bytes.NewReader(res.body),
&apiv1capella.BlindedBeaconBlock{},
)
case spec.DataVersionDeneb:
response.Data.Deneb, response.Metadata, err = decodeJSONResponse(bytes.NewReader(res.body), &apiv1deneb.BlindedBeaconBlock{})
response.Data.Deneb, response.Metadata, err = decodeJSONResponse(
bytes.NewReader(res.body),
&apiv1deneb.BlindedBeaconBlock{},
)
default:
return nil, fmt.Errorf("unsupported version %s", res.consensusVersion)
}
Expand Down
6 changes: 3 additions & 3 deletions http/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *Service) Domain(ctx context.Context, domainType phase0.DomainType, epoc
return phase0.Domain{}, errors.Join(errors.New("failed to obtain fork"), err)
}

return s.domain(ctx, domainType, epoch, fork)
return s.calculateDomain(ctx, domainType, epoch, fork)
}

// GenesisDomain returns the domain for the given domain type at genesis.
Expand All @@ -44,10 +44,10 @@ func (s *Service) GenesisDomain(ctx context.Context, domainType phase0.DomainTyp
return phase0.Domain{}, errors.Join(errors.New("failed to obtain fork"), err)
}

return s.domain(ctx, domainType, 0, fork)
return s.calculateDomain(ctx, domainType, 0, fork)
}

func (s *Service) domain(ctx context.Context,
func (s *Service) calculateDomain(ctx context.Context,
domainType phase0.DomainType,
epoch phase0.Epoch,
fork *phase0.Fork,
Expand Down
4 changes: 3 additions & 1 deletion http/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ type templateReplacement struct {

var endpointTemplates = []*templateReplacement{
{
pattern: regexp.MustCompile("/(blinded_blocks|blob_sidecars|blocks|headers|sync_committee)/(0x[0-9a-fA-F]{64}|[0-9]+|head|genesis|finalized)"),
pattern: regexp.MustCompile(
"/(blinded_blocks|blob_sidecars|blocks|headers|sync_committee)/(0x[0-9a-fA-F]{64}|[0-9]+|head|genesis|finalized)",
),
replacement: []byte("/$1/{block_id}"),
},
{
Expand Down
3 changes: 2 additions & 1 deletion http/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ func WithReducedMemoryUsage(reducedMemoryUsage bool) Parameter {
})
}

// WithCustomSpecSupport switches from the built in static SSZ library to a new dynamic SSZ library, which is able to handle non-mainnet presets.
// WithCustomSpecSupport switches from the built in static SSZ library to a new dynamic SSZ library, which is able to handle
// non-mainnet presets.
// Dynamic SSZ en-/decoding is much slower than the static one, so this should only be used if required.
func WithCustomSpecSupport(customSpecSupport bool) Parameter {
return parameterFunc(func(p *parameters) {
Expand Down
Loading

0 comments on commit 56dfbe8

Please sign in to comment.