Skip to content

Commit

Permalink
nilness linter (#13146)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudeepdino008 authored Dec 19, 2024
1 parent f8c1103 commit 65cbcfd
Show file tree
Hide file tree
Showing 37 changed files with 51 additions and 118 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ linters-settings:
- fieldalignment
- shadow
- unsafeptr
enable:
- nilness
goconst:
min-len: 2
min-occurrences: 2
Expand Down
4 changes: 0 additions & 4 deletions cl/antiquary/beacon_states_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ func (i *beaconStatesCollector) addGenesisState(ctx context.Context, state *stat
i.buf.Reset()
i.compressor.Reset(i.buf)

var err error
slot := state.Slot()
epoch := slot / i.beaconCfg.SlotsPerEpoch
// Setup state events handlers
Expand All @@ -121,9 +120,6 @@ func (i *beaconStatesCollector) addGenesisState(ctx context.Context, state *stat
events.AddValidator(uint64(index), v)
return true
})
if err != nil {
return err
}
roundedSlotToDump := slot - (slot % clparams.SlotsPerDump)

if err := antiquateField(ctx, roundedSlotToDump, state.RawBalances(), i.buf, i.compressor, i.balancesDumpsCollector); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cl/beacon/handler/block_production.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func (a *ApiHandler) getBuilderPayload(
ethHeader.SetVersion(baseState.Version())
}
// check kzg commitments
if header != nil && baseState.Version() >= clparams.DenebVersion {
if baseState.Version() >= clparams.DenebVersion {
if header.Data.Message.BlobKzgCommitments.Len() >= cltypes.MaxBlobsCommittmentsPerBlock {
return nil, fmt.Errorf("too many blob kzg commitments: %d", header.Data.Message.BlobKzgCommitments.Len())
}
Expand Down
4 changes: 0 additions & 4 deletions cl/beacon/handler/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,6 @@ func (a *ApiHandler) getFinalityCheckpoints(w http.ResponseWriter, r *http.Reque
}

finalizedCheckpoint, currentJustifiedCheckpoint, previousJustifiedCheckpoint, ok := a.forkchoiceStore.GetFinalityCheckpoints(blockRoot)
if err != nil {
return nil, beaconhttp.NewEndpointError(http.StatusBadRequest, err)
}

snRoTx := a.caplinStateSnapshots.View()
defer snRoTx.Close()

Expand Down
4 changes: 1 addition & 3 deletions cl/beacon/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type LayeredBeaconHandler struct {
func ListenAndServe(beaconHandler *LayeredBeaconHandler, routerCfg beacon_router_configuration.RouterConfiguration) error {
listener, err := net.Listen(routerCfg.Protocol, routerCfg.Address)
if err != nil {
log.Warn("[Beacon API] Failed to start listening", "addr", routerCfg.Address, "err", err)
return err
}
defer listener.Close()
Expand Down Expand Up @@ -72,9 +73,6 @@ func ListenAndServe(beaconHandler *LayeredBeaconHandler, routerCfg beacon_router
IdleTimeout: routerCfg.IdleTimeout,
WriteTimeout: routerCfg.WriteTimeout,
}
if err != nil {
log.Warn("[Beacon API] Failed to start listening", "addr", routerCfg.Address, "err", err)
}

if err := server.Serve(listener); err != nil {
log.Warn("[Beacon API] failed to start serving", "addr", routerCfg.Address, "err", err)
Expand Down
2 changes: 1 addition & 1 deletion cl/persistence/beacon_indicies/indicies.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func PruneSignedHeaders(tx kv.RwTx, from uint64) error {
return err
}
for k, _, err := cursor.Seek(base_encoding.Encode64ToBytes4(from)); err == nil && k != nil; k, _, err = cursor.Prev() {
if err != nil {
if err != nil { //nolint:govet
return err
}
if err := cursor.DeleteCurrent(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cl/persistence/blob_storage/blob_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func VerifyAgainstIdentifiersAndInsertIntoTheBlobStore(ctx context.Context, stor
}
if verifySignatureFn != nil {
// verify the signature of the sidecar head, we leave this step up to the caller to define
if verifySignatureFn(sidecar.SignedBlockHeader); err != nil {
if err := verifySignatureFn(sidecar.SignedBlockHeader); err != nil {
return 0, 0, err
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,6 @@ func (r *HistoricalStatesReader) readPendingEpochs(tx kv.Tx, slot uint64) (*soli
}
return true
})
if err != nil {
return nil, nil, err
}
}
return currentEpochAttestations, previousEpochAttestations, nil
}
Expand Down Expand Up @@ -789,9 +786,6 @@ func (r *HistoricalStatesReader) ReadParticipations(tx kv.Tx, kvGetter state_acc

currentIdxs := solid.NewParticipationBitList(int(validatorLength), int(r.cfg.ValidatorRegistryLimit))
previousIdxs := solid.NewParticipationBitList(int(validatorLength), int(r.cfg.ValidatorRegistryLimit))
if err != nil {
return nil, nil, err
}

// Read the previous idxs
for i := beginSlot; i <= slot; i++ {
Expand Down Expand Up @@ -864,9 +858,6 @@ func (r *HistoricalStatesReader) ReadParticipations(tx kv.Tx, kvGetter state_acc
}
return true
})
if err != nil {
return nil, nil, err
}
}
return currentIdxs, previousIdxs, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cl/persistence/state/state_accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func ReadValidatorsTable(tx kv.Tx, out *StaticValidatorTable) error {
}
out.validatorTable = append(out.validatorTable, staticValidator)
}
if err != nil {
if err != nil { //nolint:govet
return err
}
slot, err := GetStateProcessingProgress(tx)
Expand Down
3 changes: 0 additions & 3 deletions cl/phase1/core/state/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ func (b *CachingBeaconState) _initializeValidatorsPhase0() error {
if err != nil {
return err
}
if err != nil {
return err
}
attestation := &solid.Attestation{
AggregationBits: pa.AggregationBits,
Data: attestationData,
Expand Down
3 changes: 0 additions & 3 deletions cl/phase1/core/state/cache_accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ func (b *CachingBeaconState) BaseReward(index uint64) (uint64, error) {
// It grabs values from cache as needed
func (b *CachingBeaconState) SyncRewards() (proposerReward, participantReward uint64, err error) {
activeBalance := b.GetTotalActiveBalance()
if err != nil {
return 0, 0, err
}
totalActiveIncrements := activeBalance / b.BeaconConfig().EffectiveBalanceIncrement
baseRewardPerInc := b.BaseRewardPerIncrement()
totalBaseRewards := baseRewardPerInc * totalActiveIncrements
Expand Down
12 changes: 5 additions & 7 deletions cl/phase1/execution_client/execution_client_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,13 @@ func (cc *ExecutionClientRpc) ForkChoiceUpdate(ctx context.Context, finalized li

err := cc.client.CallContext(ctx, forkChoiceResp, rpc_helper.ForkChoiceUpdatedV1, args...)
if err != nil {
if err.Error() == errContextExceeded {
// ignore timeouts
return nil, nil
}
return nil, fmt.Errorf("execution Client RPC failed to retrieve ForkChoiceUpdate response, err: %w", err)
}
// Ignore timeouts
if err != nil && err.Error() == errContextExceeded {
return nil, nil
}
if err != nil {
return nil, err
}

if forkChoiceResp.PayloadId == nil {
return []byte{}, checkPayloadStatus(forkChoiceResp.PayloadStatus)
}
Expand Down
7 changes: 0 additions & 7 deletions cl/phase1/forkchoice/on_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@ func (f *ForkChoiceStore) verifyAttestationWithCheckpointState(
}
if !fromBlock {
indexedAttestation := state.GetIndexedAttestation(attestation, attestationIndicies)
if err != nil {
return nil, err
}

valid, err := targetState.isValidIndexedAttestation(indexedAttestation)
if err != nil {
return nil, err
Expand All @@ -142,9 +138,6 @@ func (f *ForkChoiceStore) verifyAttestationWithState(
}
if !fromBlock {
indexedAttestation := state.GetIndexedAttestation(attestation, attestationIndicies)
if err != nil {
return nil, err
}
valid, err := state.IsValidIndexedAttestation(s, indexedAttestation)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cl/phase1/network/gossip_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (g *GossipManager) onRecv(ctx context.Context, data *sentinel.GossipData, l
if errors.Is(err, services.ErrIgnore) || errors.Is(err, synced_data.ErrNotSynced) {
return nil
}
if err != nil {
if err != nil { //nolint:govet
g.sentinel.BanPeer(ctx, data.Peer)
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,6 @@ func verifySyncCommitteeMessageSignature(s *state.CachingBeaconState, msg *cltyp
if err != nil {
return nil, nil, nil, err
}
signingRoot, err := utils.Sha256(msg.BeaconBlockRoot[:], domain), nil
if err != nil {
return nil, nil, nil, err
}
signingRoot := utils.Sha256(msg.BeaconBlockRoot[:], domain)
return msg.Signature[:], signingRoot[:], publicKey[:], nil
}
3 changes: 0 additions & 3 deletions cl/phase1/network/services/sync_contribution_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,6 @@ func verifySyncContributionProofAggregatedSignature(s *state.CachingBeaconState,
}

msg := utils.Sha256(contribution.BeaconBlockRoot[:], domain)
if err != nil {
return nil, nil, nil, err
}
// only use the ones pertaining to the aggregation bits
subCommitteePubsKeys := make([][]byte, 0, len(subCommitteeKeys))
for i, key := range subCommitteeKeys {
Expand Down
4 changes: 0 additions & 4 deletions cl/validator/attestation_producer/attestation_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ func (ap *attestationProducer) ProduceAndCacheAttestationData(tx kv.Tx, baseStat
log.Warn("Failed to process slots", "slot", slot, "err", err)
return solid.AttestationData{}, err
}
if err != nil {
return solid.AttestationData{}, err
}

}

targetCheckpoint, err := ap.computeTargetCheckpoint(tx, baseState, baseStateBlockRoot, slot)
Expand Down
2 changes: 1 addition & 1 deletion cmd/caplin/caplin1/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func RunCaplinService(ctx context.Context, engine execution_client.ExecutionEngi
}
genesisState = state.New(beaconConfig)

if genesisState.DecodeSSZ(stateBytes, int(beaconConfig.GetCurrentStateVersion(beaconConfig.GenesisEpoch))); err != nil {
if err := genesisState.DecodeSSZ(stateBytes, int(beaconConfig.GetCurrentStateVersion(beaconConfig.GenesisEpoch))); err != nil {
return fmt.Errorf("could not decode genesis state: %s", err)
}
} else {
Expand Down
4 changes: 0 additions & 4 deletions cmd/caplin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ func runCaplinNode(cliCtx *cli.Context) error {
ctx, cn := context.WithCancel(cliCtx.Context)
defer cn()

if err != nil {
log.Error("[Checkpoint Sync] Failed", "reason", err)
return err
}
var executionEngine execution_client2.ExecutionEngine
if cfg.RunEngineAPI {
cc, err := execution_client2.NewExecutionClientRPC(cfg.JwtSecret, cfg.EngineAPIAddr, cfg.EngineAPIPort)
Expand Down
2 changes: 1 addition & 1 deletion cmd/integration/commands/state_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func requestDomains(chainDb, stateDb kv.RwDB, ctx context.Context, readDomain st
defer agg.Close()

r := state.NewReaderV3(domains)
if err != nil && startTxNum != 0 {
if startTxNum != 0 {
return fmt.Errorf("failed to seek commitment to txn %d: %w", startTxNum, err)
}
latestTx := domains.TxNum()
Expand Down
2 changes: 1 addition & 1 deletion cmd/snapshots/cmp/cmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func cmp(cliCtx *cli.Context) error {
return errors.New("no first session established")
}

if session1 == nil {
if session2 == nil {
return errors.New("no second session established")
}

Expand Down
14 changes: 7 additions & 7 deletions cmd/snapshots/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ func copy(cliCtx *cli.Context) error {
pos++
}

switch dst.LType {
switch dst.LType { //nolint:govet
case sync.TorrentFs:
return errors.New("can't copy to torrent - need intermediate local fs")

case sync.RemoteFs:
if rcCli == nil {
if rcCli == nil { //nolint:govet
rcCli, err = downloader.NewRCloneClient(logger)

if err != nil {
Expand All @@ -144,7 +144,7 @@ func copy(cliCtx *cli.Context) error {

switch src.LType {
case sync.TorrentFs:
config := sync.NewTorrentClientConfigFromCobra(cliCtx, dst.Chain)
config := sync.NewTorrentClientConfigFromCobra(cliCtx, dst.Chain) //nolint:govet
torrentCli, err = sync.NewTorrentClient(cliCtx.Context, config)
if err != nil {
return fmt.Errorf("can't create torrent: %w", err)
Expand Down Expand Up @@ -186,7 +186,7 @@ func copy(cliCtx *cli.Context) error {
version := cliCtx.Int(VersionFlag.Name)

if version != 0 {
dst.Version = snaptype.Version(version)
dst.Version = snaptype.Version(version) //nolint:govet
}

if cliCtx.Args().Len() > pos {
Expand All @@ -205,7 +205,7 @@ func copy(cliCtx *cli.Context) error {

switch src.LType {
case sync.LocalFs:
switch dst.LType {
switch dst.LType { //nolint:govet
case sync.LocalFs:
return localToLocal(src, dst, firstBlock, lastBlock, snapTypes, torrents, hashes, manifest)
case sync.RemoteFs:
Expand All @@ -215,7 +215,7 @@ func copy(cliCtx *cli.Context) error {
}

case sync.RemoteFs:
switch dst.LType {
switch dst.LType { //nolint:govet
case sync.LocalFs:
return remoteToLocal(cliCtx.Context, rcCli, src, dst, firstBlock, lastBlock, snapTypes, torrents, hashes, manifest)
case sync.RemoteFs:
Expand All @@ -225,7 +225,7 @@ func copy(cliCtx *cli.Context) error {
}

case sync.TorrentFs:
switch dst.LType {
switch dst.LType { //nolint:govet
case sync.LocalFs:
return torrentToLocal(torrentCli, src, dst, firstBlock, lastBlock, snapTypes, torrents, hashes, manifest)
case sync.RemoteFs:
Expand Down
8 changes: 3 additions & 5 deletions cmd/snapshots/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ func manifest(cliCtx *cli.Context, command string) error {

switch src.LType {
case sync.RemoteFs:
if rcCli == nil {
rcCli, err = downloader.NewRCloneClient(logger)
rcCli, err = downloader.NewRCloneClient(logger)

if err != nil {
return err
}
if err != nil {
return err
}

if err = sync.CheckRemote(rcCli, src.Src); err != nil {
Expand Down
16 changes: 5 additions & 11 deletions cmd/snapshots/torrents/torrents.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,6 @@ func torrents(cliCtx *cli.Context, command string) error {
if src, err = sync.ParseLocator(cliCtx.Args().Get(pos)); err != nil {
return err
}

if err != nil {
return err
}
}

pos++
Expand Down Expand Up @@ -144,12 +140,10 @@ func torrents(cliCtx *cli.Context, command string) error {

switch src.LType {
case sync.RemoteFs:
if rcCli == nil {
rcCli, err = downloader.NewRCloneClient(logger)
rcCli, err = downloader.NewRCloneClient(logger)

if err != nil {
return err
}
if err != nil {
return err
}

if err = sync.CheckRemote(rcCli, src.Src); err != nil {
Expand Down Expand Up @@ -178,7 +172,7 @@ func torrents(cliCtx *cli.Context, command string) error {
}

if rcCli != nil {
if src != nil && src.LType == sync.RemoteFs {
if src.LType == sync.RemoteFs {
ctx := cliCtx.Context // avoiding sonar dup complaint
srcSession, err = rcCli.NewSession(ctx, filepath.Join(tempDir, "src"), src.Src+":"+src.Root, nil)

Expand All @@ -188,7 +182,7 @@ func torrents(cliCtx *cli.Context, command string) error {
}
}

if src != nil && srcSession == nil {
if srcSession == nil {
return errors.New("no src session established")
}

Expand Down
8 changes: 3 additions & 5 deletions cmd/snapshots/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,10 @@ func verify(cliCtx *cli.Context) error {
}

case sync.RemoteFs:
if rcCli == nil {
rcCli, err = downloader.NewRCloneClient(logger)
rcCli, err = downloader.NewRCloneClient(logger)

if err != nil {
return err
}
if err != nil {
return err
}

if err = sync.CheckRemote(rcCli, src.Src); err != nil {
Expand Down
Loading

0 comments on commit 65cbcfd

Please sign in to comment.