Skip to content

Commit

Permalink
Ensure thorbuilder doesnt colide on the same process
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Feb 4, 2025
1 parent e96202e commit 49e80a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion preset/LocalSixNodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func LocalSixNodesNetworkGenesis() *genesis.CustomGenesis {
ExtraData: "Local Six Nodes Network",
Accounts: []thorgenesis.Account{
{
Address: thor.MustParseAddress("0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"),
Address: thor.MustParseAddress("0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"), // dce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65
Balance: convToHexOrDecimal256(consts.LargeBigValue),
Energy: convToHexOrDecimal256(consts.LargeBigValue),
},
Expand Down
19 changes: 18 additions & 1 deletion thorbuilder/thorbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package thorbuilder

import (
"bytes"
"crypto/rand"
"encoding/hex"
"fmt"
"log/slog"
"os"
Expand All @@ -18,7 +20,13 @@ type Builder struct {
// New creates a new Builder instance for the specified branch.
// If reusable is true, it skips cloning if the directory exists and checks for the binary.
func New(branch string, reusable bool) *Builder {
downloadPath := filepath.Join(os.TempDir(), fmt.Sprintf("thor_%s_%d", branch, os.Getpid()))
suffix, err := generateRandomSuffix(4)
if err != nil {

Check failure on line 24 in thorbuilder/thorbuilder.go

View workflow job for this annotation

GitHub Actions / Lint / golangci-lint

SA9003: empty branch (staticcheck)
// handle error appropriately
}
downloadPath := filepath.Join(os.TempDir(), fmt.Sprintf("thor_%s_%d_%s", branch, os.Getpid(), suffix))

//downloadPath := filepath.Join(os.TempDir(), fmt.Sprintf("thor_%s_%d", branch, os.Getpid()))
if reusable {
downloadPath = filepath.Join(os.TempDir(), fmt.Sprintf("thor_%s_reusable", branch))
}
Expand Down Expand Up @@ -97,3 +105,12 @@ func (b *Builder) Build() (string, error) {

return thorBinaryPath, nil
}

// generateRandomSuffix returns a random hexadecimal string.
func generateRandomSuffix(n int) (string, error) {
bytes := make([]byte, n)
if _, err := rand.Read(bytes); err != nil {
return "", err
}
return hex.EncodeToString(bytes), nil
}

0 comments on commit 49e80a7

Please sign in to comment.