Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure thorbuilder doesnt colide on the same process #14

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions environments/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@ func NewLocalEnv() environments.Actions {
func (l *Local) LoadConfig(cfg *network.Network) (string, error) {
l.networkCfg = cfg
l.id = l.networkCfg.Environment + l.networkCfg.ID
baseTmpDir := filepath.Join(os.TempDir(), l.id)

// ensure paths exist, use temp dirs if not defined
// ensure paths exist, use ExecArtifact base dirs if not defined
for _, n := range l.networkCfg.Nodes {
if n.GetConfigDir() == "" {
n.SetConfigDir(filepath.Join(baseTmpDir, n.GetID(), "config"))
// check if the exec artifact path exists
if !fileExists(n.GetExecArtifact()) {
return "", fmt.Errorf("exec does not exist at path: %s", n.GetExecArtifact())
}

if n.GetDataDir() == "" {
n.SetDataDir(filepath.Join(baseTmpDir, n.GetID(), "data"))
if n.GetConfigDir() == "" {
n.SetConfigDir(filepath.Join(filepath.Dir(n.GetExecArtifact()), n.GetID(), "config"))
}

// check if the exec artifact path exists
if !fileExists(n.GetExecArtifact()) {
return "", fmt.Errorf("exec does not exist at path: %s", n.GetExecArtifact())
if n.GetDataDir() == "" {
n.SetDataDir(filepath.Join(filepath.Dir(n.GetExecArtifact()), n.GetID(), "data"))
}
}

Expand Down
1 change: 1 addition & 0 deletions environments/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func TestSixNodes(t *testing.T) {
}

func TestSixNodesGalactica(t *testing.T) {
t.Skip()
var sixNodesGalacticaNetwork *network.Network
require.NotPanics(t, func() { sixNodesGalacticaNetwork = preset.LocalSixNodesGalacticaNetwork() })

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

replace github.com/syndtr/goleveldb => github.com/vechain/goleveldb v1.0.1-0.20220809091043-51eb019c8655

replace github.com/ethereum/go-ethereum => github.com/vechain/go-ethereum v1.8.15-0.20241126085506-c74017ec91b2
replace github.com/ethereum/go-ethereum => github.com/vechain/go-ethereum v1.8.15-0.20250203151135-b4d97bda6bc9

require (
github.com/docker/docker v26.1.5+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/vechain/go-ecvrf v0.0.0-20220525125849-96fa0442e765 h1:jvr+TSivjObZmOKVdqlgeLtRhaDG27gE39PMuE2IJ24=
github.com/vechain/go-ecvrf v0.0.0-20220525125849-96fa0442e765/go.mod h1:cwnTMgAVzMb30xMKnGI1LdU1NjMiPllYb7i3ibj/fzE=
github.com/vechain/go-ethereum v1.8.15-0.20241126085506-c74017ec91b2 h1:ch3DqXvl1ApfJut768bf5Vlhqtw+bxAWTyPDYXQkQZk=
github.com/vechain/go-ethereum v1.8.15-0.20241126085506-c74017ec91b2/go.mod h1:yPUCNmntAh1PritrMfSi7noK+9vVPStZX3wgh3ieaY0=
github.com/vechain/go-ethereum v1.8.15-0.20250203151135-b4d97bda6bc9 h1:dkF3gD0LQPAD3ajR5XEtddDN0ffLZwflgRt6YKe5Deg=
github.com/vechain/go-ethereum v1.8.15-0.20250203151135-b4d97bda6bc9/go.mod h1:yPUCNmntAh1PritrMfSi7noK+9vVPStZX3wgh3ieaY0=
github.com/vechain/goleveldb v1.0.1-0.20220809091043-51eb019c8655 h1:CbHcWpCi7wOYfpoErRABh3Slyq9vO0Ay/EHN5GuJSXQ=
github.com/vechain/goleveldb v1.0.1-0.20220809091043-51eb019c8655/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
github.com/vechain/thor/v2 v2.1.6 h1:VCs/2lgz2KdWygTpETKaHg/Kd7s3lR9o+coA4mSZV3g=
Expand Down
2 changes: 2 additions & 0 deletions network/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ type Node interface {
GetGenesis() *genesis.CustomGenesis
SetGenesis(genesis *genesis.CustomGenesis)
GetAPIAddr() string
SetAPIAddr(addr string)
GetAPICORS() string
GetP2PListenPort() int
SetP2PListenPort(port int)
GetVerbosity() int
GetHTTPAddr() string
GetFakeExecution() bool
Expand Down
6 changes: 6 additions & 0 deletions network/node/node_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@ func (b *BaseNode) GetP2PListenPort() int {
return b.P2PListenPort
}

func (b *BaseNode) SetP2PListenPort(port int) {
b.P2PListenPort = port
}
func (b *BaseNode) GetAPIAddr() string {
return b.APIAddr
}
func (b *BaseNode) SetAPIAddr(addr string) {
b.APIAddr = addr
}

func (b *BaseNode) GetAPICORS() string {
return b.APICORS
Expand Down
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
13 changes: 12 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,9 @@ 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 := generateRandomSuffix(4)

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

return thorBinaryPath, nil
}

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