Replace Empty Slice Literals with Nil Slices (#13093)

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
terencechain
2023-10-23 09:36:11 -07:00
committed by GitHub
parent 9c938d354d
commit 76fec1799e
15 changed files with 20 additions and 20 deletions

View File

@@ -769,7 +769,7 @@ func TestFinalizedDeposits_ReturnsTrieCorrectly(t *testing.T) {
} }
} }
ctrs := []*ethpb.DepositContainer{} var ctrs []*ethpb.DepositContainer
for i := 0; i < 2000; i++ { for i := 0; i < 2000; i++ {
ctrs = append(ctrs, generateCtr(uint64(10+(i/2)), int64(i))) ctrs = append(ctrs, generateCtr(uint64(10+(i/2)), int64(i)))
} }

View File

@@ -622,9 +622,9 @@ func (s *Service) ReconstructFullBellatrixBlockBatch(
if len(blindedBlocks) == 0 { if len(blindedBlocks) == 0 {
return []interfaces.SignedBeaconBlock{}, nil return []interfaces.SignedBeaconBlock{}, nil
} }
executionHashes := []common.Hash{} var executionHashes []common.Hash
validExecPayloads := []int{} var validExecPayloads []int
zeroExecPayloads := []int{} var zeroExecPayloads []int
for i, b := range blindedBlocks { for i, b := range blindedBlocks {
if err := blocks.BeaconBlockIsNil(b); err != nil { if err := blocks.BeaconBlockIsNil(b); err != nil {
return nil, errors.Wrap(err, "cannot reconstruct bellatrix block from nil data") return nil, errors.Wrap(err, "cannot reconstruct bellatrix block from nil data")

View File

@@ -461,7 +461,7 @@ func convertToUdpMultiAddr(node *enode.Node) ([]ma.Multiaddr, error) {
} }
func peerIdsFromMultiAddrs(addrs []ma.Multiaddr) []peer.ID { func peerIdsFromMultiAddrs(addrs []ma.Multiaddr) []peer.ID {
peers := []peer.ID{} var peers []peer.ID
for _, a := range addrs { for _, a := range addrs {
info, err := peer.AddrInfoFromP2pAddr(a) info, err := peer.AddrInfoFromP2pAddr(a)
if err != nil { if err != nil {

View File

@@ -118,7 +118,7 @@ func (s *Store) SetTrustedPeers(peers []peer.ID) {
// GetTrustedPeers gets our desired trusted peer ids. // GetTrustedPeers gets our desired trusted peer ids.
// Important: it is assumed that store mutex is locked when calling this method. // Important: it is assumed that store mutex is locked when calling this method.
func (s *Store) GetTrustedPeers() []peer.ID { func (s *Store) GetTrustedPeers() []peer.ID {
peers := []peer.ID{} var peers []peer.ID
for p := range s.trustedPeers { for p := range s.trustedPeers {
peers = append(peers, p) peers = append(peers, p)
} }

View File

@@ -788,7 +788,7 @@ func TestPrunePeers_TrustedPeers(t *testing.T) {
createPeer(t, p, nil, network.DirInbound, peerdata.PeerConnectionState(ethpb.ConnectionState_CONNECTED)) createPeer(t, p, nil, network.DirInbound, peerdata.PeerConnectionState(ethpb.ConnectionState_CONNECTED))
} }
trustedPeers := []peer.ID{} var trustedPeers []peer.ID
// Set up bad scores for inbound peers. // Set up bad scores for inbound peers.
inboundPeers := p.InboundConnected() inboundPeers := p.InboundConnected()
for i, pid := range inboundPeers { for i, pid := range inboundPeers {

View File

@@ -86,7 +86,7 @@ func (s *Server) AddTrustedPeer(w http.ResponseWriter, r *http.Request) {
s.PeersFetcher.Peers().Add(nil, info.ID, info.Addrs[0], direction) s.PeersFetcher.Peers().Add(nil, info.ID, info.Addrs[0], direction)
} }
peers := []peer.ID{} var peers []peer.ID
peers = append(peers, info.ID) peers = append(peers, info.ID)
s.PeersFetcher.Peers().SetTrustedPeers(peers) s.PeersFetcher.Peers().SetTrustedPeers(peers)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
@@ -112,7 +112,7 @@ func (s *Server) RemoveTrustedPeer(w http.ResponseWriter, r *http.Request) {
return return
} }
peers := []peer.ID{} var peers []peer.ID
peers = append(peers, peerId) peers = append(peers, peerId)
s.PeersFetcher.Peers().DeleteTrustedPeers(peers) s.PeersFetcher.Peers().DeleteTrustedPeers(peers)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View File

@@ -5,7 +5,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var Commands = []*cli.Command{} var Commands []*cli.Command
func init() { func init() {
Commands = append(Commands, checkpoint.Commands...) Commands = append(Commands, checkpoint.Commands...)

View File

@@ -47,7 +47,7 @@ func walletCreate(c *cli.Context) error {
// ConstructCLIManagerOpts prompts the user for wallet creation input. // ConstructCLIManagerOpts prompts the user for wallet creation input.
func ConstructCLIManagerOpts(cliCtx *cli.Context, keymanagerKind keymanager.Kind) ([]accounts.Option, error) { func ConstructCLIManagerOpts(cliCtx *cli.Context, keymanagerKind keymanager.Kind) ([]accounts.Option, error) {
cliOpts := []accounts.Option{} var cliOpts []accounts.Option
// Get wallet dir and check that no wallet exists at the location. // Get wallet dir and check that no wallet exists at the location.
walletDir, err := userprompt.InputDirectory(cliCtx, userprompt.WalletDirPromptText, flags.WalletDirFlag) walletDir, err := userprompt.InputDirectory(cliCtx, userprompt.WalletDirPromptText, flags.WalletDirFlag)
if err != nil { if err != nil {

View File

@@ -70,4 +70,4 @@ var deprecatedFlags = []cli.Flag{
// deprecatedBeaconFlags contains flags that are still used by other components // deprecatedBeaconFlags contains flags that are still used by other components
// and therefore cannot be added to deprecatedFlags // and therefore cannot be added to deprecatedFlags
var deprecatedBeaconFlags = []cli.Flag{} var deprecatedBeaconFlags []cli.Flag

View File

@@ -94,7 +94,7 @@ func TestPublicKey_Aggregate(t *testing.T) {
} }
func TestPublicKey_Aggregation_NoCorruption(t *testing.T) { func TestPublicKey_Aggregation_NoCorruption(t *testing.T) {
pubkeys := []common.PublicKey{} var pubkeys []common.PublicKey
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
priv, err := blst.RandKey() priv, err := blst.RandKey()
require.NoError(t, err) require.NoError(t, err)
@@ -102,7 +102,7 @@ func TestPublicKey_Aggregation_NoCorruption(t *testing.T) {
pubkeys = append(pubkeys, pubkey) pubkeys = append(pubkeys, pubkey)
} }
compressedKeys := [][]byte{} var compressedKeys [][]byte
// Fill up the cache // Fill up the cache
for _, pkey := range pubkeys { for _, pkey := range pubkeys {
_, err := blst.PublicKeyFromBytes(pkey.Marshal()) _, err := blst.PublicKeyFromBytes(pkey.Marshal())

View File

@@ -20,7 +20,7 @@ var versionToString = map[int]string{
// stringToVersion and allVersions are populated in init() // stringToVersion and allVersions are populated in init()
var stringToVersion = map[string]int{} var stringToVersion = map[string]int{}
var allVersions = []int{} var allVersions []int
// ErrUnrecognizedVersionName means a string does not match the list of canonical version names. // ErrUnrecognizedVersionName means a string does not match the list of canonical version names.
var ErrUnrecognizedVersionName = errors.New("version name doesn't map to a known value in the enum") var ErrUnrecognizedVersionName = errors.New("version name doesn't map to a known value in the enum")

View File

@@ -153,7 +153,7 @@ func processesDepositsInBlocks(ec *e2etypes.EvaluationContext, conns ...*grpc.Cl
observed[k] = v + d.Data.Amount observed[k] = v + d.Data.Amount
} }
} }
mismatches := []string{} var mismatches []string
for k, ev := range expected { for k, ev := range expected {
ov := observed[k] ov := observed[k]
if ev != ov { if ev != ov {
@@ -361,7 +361,7 @@ func proposeVoluntaryExit(ec *e2etypes.EvaluationContext, conns ...*grpc.ClientC
if err != nil { if err != nil {
return errors.Wrap(err, "could not get state") return errors.Wrap(err, "could not get state")
} }
execIndices := []int{} var execIndices []int
err = st.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error { err = st.ReadFromEveryValidator(func(idx int, val state.ReadOnlyValidator) error {
if val.WithdrawalCredentials()[0] == params.BeaconConfig().ETH1AddressWithdrawalPrefixByte { if val.WithdrawalCredentials()[0] == params.BeaconConfig().ETH1AddressWithdrawalPrefixByte {
execIndices = append(execIndices, idx) execIndices = append(execIndices, idx)

View File

@@ -244,7 +244,7 @@ func (p *Builder) isBuilderCall(req *http.Request) bool {
} }
func (p *Builder) registerValidators(w http.ResponseWriter, req *http.Request) { func (p *Builder) registerValidators(w http.ResponseWriter, req *http.Request) {
registrations := []shared.SignedValidatorRegistration{} var registrations []shared.SignedValidatorRegistration
if err := json.NewDecoder(req.Body).Decode(&registrations); err != nil { if err := json.NewDecoder(req.Body).Decode(&registrations); err != nil {
http.Error(w, "invalid request", http.StatusBadRequest) http.Error(w, "invalid request", http.StatusBadRequest)
return return

View File

@@ -60,7 +60,7 @@ func (c *waitForActivationClient) Recv() (*ethpb.ValidatorActivationResponse, er
// Contains all keys in targetPubKeys but not in retrievedPubKeys // Contains all keys in targetPubKeys but not in retrievedPubKeys
var missingPubKeys [][]byte var missingPubKeys [][]byte
statuses := []*ethpb.ValidatorActivationResponse_Status{} var statuses []*ethpb.ValidatorActivationResponse_Status
for index, publicKey := range c.ValidatorActivationRequest.PublicKeys { for index, publicKey := range c.ValidatorActivationRequest.PublicKeys {
stringPubKey := hexutil.Encode(publicKey) stringPubKey := hexutil.Encode(publicKey)

View File

@@ -55,7 +55,7 @@ func (c *beaconApiValidatorClient) getValidatorsStatusResponse(ctx context.Conte
stringRetrievedPubKeys := make(map[string]struct{}) stringRetrievedPubKeys := make(map[string]struct{})
// Contains all keys in targetPubKeys but not in retrievedPubKeys // Contains all keys in targetPubKeys but not in retrievedPubKeys
missingPubKeys := [][]byte{} var missingPubKeys [][]byte
totalLen := len(inPubKeys) + len(inIndexes) totalLen := len(inPubKeys) + len(inIndexes)