Skip to content

Commit

Permalink
feat(lib/state): no need to check salt with nil (#12056)
Browse files Browse the repository at this point in the history
`salt *uint32` is the return argument, so it is always nil inside the
function before returning, no need to check it.

Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa authored Sep 21, 2024
1 parent 23b46fa commit b6e0822
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions erigon-lib/state/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,25 @@ func getStateIndicesSalt(baseDir string) (salt *uint32, err error) {
if saltExists && !saltStateExists {
_ = os.Rename(filepath.Join(baseDir, "salt.txt"), filepath.Join(baseDir, "salt-state.txt"))
}

fpath := filepath.Join(baseDir, "salt-state.txt")
fexists, err := dir.FileExist(fpath)
if err != nil {
return nil, err
}

// Initialize salt if it doesn't exist
if !fexists {
if salt == nil {
saltV := rand2.Uint32()
salt = &saltV
}
saltV := rand2.Uint32()
salt = &saltV
saltBytes := make([]byte, 4)
binary.BigEndian.PutUint32(saltBytes, *salt)
if err := dir.WriteFileWithFsync(fpath, saltBytes, os.ModePerm); err != nil {
return nil, err
}
return salt, nil // Return the newly created salt directly
}

saltBytes, err := os.ReadFile(fpath)
if err != nil {
return nil, err
Expand Down

0 comments on commit b6e0822

Please sign in to comment.