Skip to content
Open
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
2 changes: 1 addition & 1 deletion cmd/network/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
return
}
fmt.Println("\n🕐 Waiting for POS to become active... expected at block ", config.ForkBlock+config.TransitionPeriod)
if err := utils.WaitForPOS(t.Context(), staker, config.ForkBlock+config.TransitionPeriod); err != nil {
if err := utils.WaitForPOS(context.Background(), staker, config.ForkBlock+config.TransitionPeriod); err != nil {
fmt.Println(" - Error waiting for PoS:", err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/txsimulation/contract/contract_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/ethereum/go-ethereum/common/math"
lru "github.com/hashicorp/golang-lru"
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/stack"
"github.com/vechain/hayabusa-e2e/utils"
netUtils "github.com/vechain/networkhub/utils/common"
"github.com/vechain/thor/v2/api"
"github.com/vechain/thor/v2/builtin/staker/validation"
"github.com/vechain/thor/v2/thor"
Expand Down Expand Up @@ -72,7 +72,7 @@ func (s *Service) GetActiveCount() uint32 {
}

func (s *Service) poll() {
ticker := utils.NewTicker(s.stack.Client())
ticker := netUtils.NewTicker(s.stack.Client())
for {
select {
case <-s.stack.Context().Done():
Expand Down
3 changes: 2 additions & 1 deletion cmd/txsimulation/devnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/xnodes"
"github.com/vechain/hayabusa-e2e/hayabusa"
utils2 "github.com/vechain/hayabusa-e2e/utils"
"github.com/vechain/networkhub/utils/common"
protocolbuiltin "github.com/vechain/thor/v2/builtin"
genesisthor "github.com/vechain/thor/v2/genesis"
"github.com/vechain/thor/v2/thor"
Expand Down Expand Up @@ -211,7 +212,7 @@ func setStargate(ctx context.Context, client *thorclient.Client, executors []*bi
}

// wait for the receipts
ticker := utils2.NewTicker(client)
ticker := common.NewTicker(client)
approved := make(map[thor.Address]bool)
for range 6 {
if len(approved) >= len(executors) {
Expand Down
9 changes: 3 additions & 6 deletions cmd/txsimulation/devnetcleanup/delegations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/vechain/hayabusa-e2e/cmd/txsimulation/contract"
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/stack"
"github.com/vechain/hayabusa-e2e/utils"
"github.com/vechain/networkhub/utils/common"
"github.com/vechain/thor/v2/api"
"github.com/vechain/thor/v2/thorclient/bind"
)
Expand Down Expand Up @@ -87,14 +87,11 @@ func (c *Cleanup) exitDelegations(delegations []*big.Int, method exitMethod) {
var groups [][]*big.Int
groupSize := 100
for i := 0; i < len(delegations); i += groupSize {
end := i + groupSize
if end > len(delegations) {
end = len(delegations)
}
end := min(i+groupSize, len(delegations))
groups = append(groups, delegations[i:end])
}

ticker := utils.NewTicker(c.stack.Client())
ticker := common.NewTicker(c.stack.Client())

for _, ids := range groups {
slog.Info("processing cleanup", "first", ids[0], "last", ids[len(ids)-1], "count", len(ids))
Expand Down
6 changes: 3 additions & 3 deletions cmd/txsimulation/lifecycle/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/stack"
utils2 "github.com/vechain/hayabusa-e2e/cmd/txsimulation/utils"
"github.com/vechain/hayabusa-e2e/cmd/txsimulation/xnodes"
"github.com/vechain/hayabusa-e2e/utils"
netUtils "github.com/vechain/networkhub/utils/common"
"github.com/vechain/thor/v2/api"
"github.com/vechain/thor/v2/test/datagen"
"github.com/vechain/thor/v2/thor"
Expand Down Expand Up @@ -58,7 +58,7 @@ func (e *Engine) AddLifecycle(lifecycle Lifecycle) {
}

func (e *Engine) Run() {
ticker := utils.NewTicker(e.stack.Client())
ticker := netUtils.NewTicker(e.stack.Client())
for {
select {
case <-e.stack.Context().Done():
Expand Down Expand Up @@ -127,7 +127,7 @@ func (e *Engine) Flush(status Status) error {
e.mu.Lock()
defer e.mu.Unlock()

ticker := utils.NewTicker(e.stack.Client())
ticker := netUtils.NewTicker(e.stack.Client())

processed := false
for !processed {
Expand Down
8 changes: 4 additions & 4 deletions cmd/txsimulation/networkhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ func startAgainstNetworkHub(ctx context.Context) (*lifecycle.Engine, func()) {
StakeChangeInterval: uint32(utils2.RandomBetween(5, 20)),
}
if i < 50 { // create 50 long term validators
config.StakingPeriods = 5000
config.Config.StakingPeriods = 5000
} else if i < 70 { // create 20 mid-term validators
config.StakingPeriods = uint32(utils2.RandomBetween(30, 100)) // create 20 mid term validators
config.Config.StakingPeriods = uint32(utils2.RandomBetween(30, 100)) // create 20 mid term validators
} else {
config.StakingPeriods = uint32(utils2.RandomBetween(6, 12)) // create 20 short term validators
config.Config.StakingPeriods = uint32(utils2.RandomBetween(6, 12)) // create 20 short term validators
}
config.QueueDelay = lifecycle.Delay{Blocks: 0, Epochs: 0}
config.Config.QueueDelay = lifecycle.Delay{Blocks: 0, Epochs: 0}
cycle := validators.NewValidatorLifecycle(config, contratService, delegations, stack, stack.RandomStakingPeriod())
engine.AddLifecycle(cycle)
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ require (
github.com/cqroot/prompt v0.9.4
github.com/ethereum/go-ethereum v1.8.14
github.com/stretchr/testify v1.10.0
github.com/vechain/thor/v2 v2.3.2-0.20250828095955-7ac607de33ad
github.com/vechain/thor/v2 v2.3.2-0.20250901040321-6805a7336a3e
)

require (
github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad
github.com/jedib0t/go-pretty/v6 v6.6.7
github.com/pkg/errors v0.9.1
github.com/vechain/networkhub v0.0.5-0.20250819120439-71315d6e4883
github.com/vechain/networkhub v0.0.5-0.20250901163122-aa8dc950279b
)

require (
Expand Down
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ github.com/vechain/go-ethereum v1.8.15-0.20241126085506-c74017ec91b2 h1:ch3DqXvl
github.com/vechain/go-ethereum v1.8.15-0.20241126085506-c74017ec91b2/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/networkhub v0.0.5-0.20250819120439-71315d6e4883 h1:Si2C1MlTKKx2ZsJD0/iP5zrm4i4aIhKArYCrkzYap2E=
github.com/vechain/networkhub v0.0.5-0.20250819120439-71315d6e4883/go.mod h1:aF1ovictX85iXRvN++DAKKFbK2mcHTGG8hBriuRhNUo=
github.com/vechain/thor/v2 v2.3.2-0.20250828095955-7ac607de33ad h1:LxuIj/+stmcielHmUlCPJ0pDmMyhkDdAD4two0odzGU=
github.com/vechain/thor/v2 v2.3.2-0.20250828095955-7ac607de33ad/go.mod h1:STGXqeAwg9qHV/q5QlAAA/VvWcC2eAeGAAYuYUUUosg=
github.com/vechain/networkhub v0.0.5-0.20250901134736-59d51b3d106f h1:UT15X3293U1/pzMAlix7gTkenf73C321D9x2PzbUl4Y=
github.com/vechain/networkhub v0.0.5-0.20250901134736-59d51b3d106f/go.mod h1:OuNmua7Py5+4wYRtyCo0DFbrV7L8x+bqzFC7mJGnvAE=
github.com/vechain/networkhub v0.0.5-0.20250901163122-aa8dc950279b h1:Icx2QnF1Ayb3H4pv7fhtjSkrOLsohU5juobVIpp+7UQ=
github.com/vechain/networkhub v0.0.5-0.20250901163122-aa8dc950279b/go.mod h1:OuNmua7Py5+4wYRtyCo0DFbrV7L8x+bqzFC7mJGnvAE=
github.com/vechain/thor/v2 v2.3.2-0.20250901040321-6805a7336a3e h1:aYnEwaTDcfiD1JuhSRfSRCvzLF+2njULsxRb8ydzgog=
github.com/vechain/thor/v2 v2.3.2-0.20250901040321-6805a7336a3e/go.mod h1:STGXqeAwg9qHV/q5QlAAA/VvWcC2eAeGAAYuYUUUosg=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
1 change: 0 additions & 1 deletion hayabusa/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func (c *Config) Apply(genesis *genesis.CustomGenesis) {
Balance: (*devgenesis.HexOrDecimal256)(big.NewInt(0)),
Energy: (*devgenesis.HexOrDecimal256)(big.NewInt(0)),
})
stakerIndex = len(genesis.Accounts) - 1
}

// params config - set max-block-proposers
Expand Down
119 changes: 16 additions & 103 deletions hayabusa/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ import (
"context"
"fmt"
"log/slog"
"os"
"strconv"
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/vechain/hayabusa-e2e/utils"
"github.com/vechain/networkhub/environments/local"
networkhubNetwork "github.com/vechain/networkhub/network"
"github.com/vechain/networkhub/network/node"
Expand All @@ -20,80 +17,43 @@ import (
)

type Network struct {
ctx context.Context
config *Config
network *local.Local
genesis *genesis.CustomGenesis
nodes []node.Config
usedPorts []int // to track used ports for cleanup
ctx context.Context
config *Config
network *local.Local
genesis *genesis.CustomGenesis
nodes []node.Config

mu sync.Mutex
}

func NewNetwork(config *Config, ctx context.Context) (*Network, error) {
buildMutex.Lock()
defer buildMutex.Unlock()

if err := config.Validate(); err != nil {
return nil, err
}

repo := "git@github.com:vechain/thor.git"

workingDir, ok := os.LookupEnv("THOR_WORKING_DIR")
var thorBuilder *thorbuilder.Config
if ok {
thorBuilder = &thorbuilder.Config{
BuildConfig: &thorbuilder.BuildConfig{
ExistingPath: workingDir,
DebugBuild: config.Debug,
},
}
} else {
slog.Warn("THOR_WORKING_DIR not set, using default repo/branch")
thorBuilder = &thorbuilder.Config{
DownloadConfig: &thorbuilder.DownloadConfig{
RepoUrl: repo,
Branch: "release/hayabusa",
IsReusable: true,
},
}
builder := thorbuilder.New(thorBuilder)
err := builder.Download()
if err != nil {
return nil, fmt.Errorf("failed to download thor: %w", err)
}
workingDir = builder.DownloadPath
}

nodes := make([]node.Config, 0)
genesis := Genesis(config)
usedPorts := make([]int, 0, config.Nodes*2)
for i := range config.Nodes {
node, apiPort, p2pPort := makeNode(config, i, ValidatorAccounts[i], genesis)
node := makeNode(config, i, ValidatorAccounts[i], genesis)
nodes = append(nodes, node)
usedPorts = append(usedPorts, apiPort, p2pPort)
}

network := local.NewEnv()
netConfig := &networkhubNetwork.Network{
BaseID: config.Name,
Nodes: nodes,
ThorBuilder: thorBuilder,
ThorBuilder: thorbuilder.DefaultConfig(),
}
builder := thorbuilder.New(netConfig.ThorBuilder)
builder.Download()
if _, err := network.LoadConfig(netConfig); err != nil {
return nil, fmt.Errorf("failed to load network config: %w", err)
}

return &Network{
ctx: ctx,
config: config,
network: network,
genesis: genesis,
nodes: nodes,
usedPorts: usedPorts,
ctx: ctx,
config: config,
network: network,
genesis: genesis,
nodes: nodes,
}, nil
}

Expand All @@ -106,13 +66,9 @@ func (n *Network) Genesis() *genesis.CustomGenesis {
}

func (n *Network) Stop() {
n.mu.Lock()
defer n.mu.Unlock()

if err := n.network.StopNetwork(); err != nil {
slog.Error("🛑 failed to stop network", "error", err)
}
globalPortManager.RemovePorts(n.config.Name)
}

func (n *Network) NodeConfigs() []node.Config {
Expand All @@ -130,12 +86,6 @@ func (n *Network) NodeLifecycles() map[string]node.Lifecycle {
}

func (n *Network) Start() error {
n.mu.Lock()
defer n.mu.Unlock()

buildMutex.Lock()
defer buildMutex.Unlock()

go func() {
<-n.ctx.Done()
slog.Info("context done, cleaning up network")
Expand All @@ -146,51 +96,19 @@ func (n *Network) Start() error {
return err
}

for _, nodeConfig := range n.nodes {
if err := nodeConfig.HealthCheck(0, 30*time.Second); err != nil {
return err
}
}

if err := utils.WaitForPeersConnection(n.nodes, n.ctx); err != nil {
return fmt.Errorf("failed to connect all nodes: %w", err)
}

return nil
}

func (n *Network) AttachNode(buildConfig *thorbuilder.Config, additionalArgs map[string]string) error {
n.mu.Lock()
defer n.mu.Unlock()
buildMutex.Lock()
defer buildMutex.Unlock()

builder := thorbuilder.New(buildConfig)

if err := builder.Download(); err != nil {
return fmt.Errorf("failed to download builder: %w", err)
}
path, err := builder.Build()
if err != nil {
return fmt.Errorf("failed to build node: %w", err)
}

node, apiPort, p2pPort := makeNode(n.config, len(n.nodes), ValidatorAccounts[len(n.nodes)], n.genesis)
node.SetExecArtifact(path)
node.SetAdditionalArgs(additionalArgs)
n.nodes = append(n.nodes, node)
n.usedPorts = append(n.usedPorts, apiPort, p2pPort)
if err := n.network.AttachNode(node); err != nil {
node := makeNode(n.config, len(n.nodes), ValidatorAccounts[len(n.nodes)], n.genesis)
if err := n.network.AttachNode(node, buildConfig, additionalArgs); err != nil {
return fmt.Errorf("failed to attach node: %w", err)
}
if err := node.HealthCheck(0, 30*time.Second); err != nil {
return fmt.Errorf("failed to health check attached node: %w", err)
}

return nil
}

func makeNode(config *Config, i int, signer *NodePair, customGenesis *genesis.CustomGenesis) (node.Config, int, int) {
func makeNode(config *Config, i int, signer *NodePair, customGenesis *genesis.CustomGenesis) node.Config {
verbosity := 3
if config.Verbosity > 0 {
verbosity = config.Verbosity
Expand All @@ -207,16 +125,11 @@ func makeNode(config *Config, i int, signer *NodePair, customGenesis *genesis.Cu
nodeID = fmt.Sprintf("%s-%s", config.Name, nodeID)
}

apiPort := globalPortManager.NewPort(config.Name)
p2pPort := globalPortManager.NewPort(config.Name)

return &node.BaseNode{
ID: nodeID,
Key: common.Bytes2Hex(signer.Node.D.Bytes()),
Genesis: customGenesis,
Verbosity: verbosity,
AdditionalArgs: additionalArgs,
APIAddr: fmt.Sprintf("0.0.0.0:%d", apiPort),
P2PListenPort: p2pPort,
}, apiPort, p2pPort
}
}
Loading
Loading