Skip to content

Commit

Permalink
refactor: using slices.Contains to simplify the code (#13544)
Browse files Browse the repository at this point in the history
This is a [new function](https://pkg.go.dev/[email protected]#Contains)
added in the go1.21 standard library, which can make the code more
concise and easy to read.

Signed-off-by: damuzhi0810 <[email protected]>
  • Loading branch information
damuzhi0810 authored Jan 24, 2025
1 parent 989e5d5 commit 907c9ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
9 changes: 0 additions & 9 deletions erigon-lib/chain/networkname/network_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,3 @@ var All = []string{
Chiado,
Test,
}

func IsKnownNetwork(s string) bool {
for _, n := range All {
if n == s {
return true
}
}
return false
}
3 changes: 2 additions & 1 deletion erigon-lib/downloader/downloadercfg/downloadercfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -240,7 +241,7 @@ func New(ctx context.Context, dirs datadir.Dirs, version string, verbosity lg.Le
// LoadSnapshotsHashes checks local preverified.toml. If file exists, used local hashes.
// If there are no such file, try to fetch hashes from the web and create local file.
func LoadSnapshotsHashes(ctx context.Context, dirs datadir.Dirs, chainName string) (*snapcfg.Cfg, error) {
if !networkname.IsKnownNetwork(chainName) {
if !slices.Contains(networkname.All, chainName) {
log.Root().Warn("No snapshot hashes for chain", "chain", chainName)
return snapcfg.NewNonSeededCfg(chainName), nil
}
Expand Down

0 comments on commit 907c9ae

Please sign in to comment.