Skip to content

Commit

Permalink
remove try
Browse files Browse the repository at this point in the history
  • Loading branch information
likesToEatFish committed Sep 29, 2024
1 parent 48d336d commit d492d08
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 125 deletions.
2 changes: 0 additions & 2 deletions ignite/cmd/testnet_multi_node.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ignitecmd

import (
// "fmt"
"math/rand"
"strconv"
"time"
Expand Down Expand Up @@ -113,7 +112,6 @@ func testnetMultiNode(cmd *cobra.Command, session *cliui.Session) error {

time.Sleep(7 * time.Second)

// c.TestnetStartMultiNode(cmd.Context(), args)
m := cmdmodel.NewModel(c.Name(), cmd.Context(), args)
_, err = tea.NewProgram(m).Run()
return err
Expand Down
6 changes: 0 additions & 6 deletions ignite/pkg/chaincmd/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ func (c ChainCmd) StartCommand(options ...string) step.Option {
command := append([]string{
commandStart,
}, options...)
fmt.Println(command)
return c.daemonCommand(command)
}

Expand Down Expand Up @@ -644,11 +643,6 @@ func (c ChainCmd) daemonCommand(command []string) step.Option {
return step.Exec(c.appCmd, c.attachHome(command)...)
}

// daemonCommand returns the daemon command from the given command (including the home flag).
func (c ChainCmd) daemonCommandIncludedHomeFlag(command []string) step.Option {
return step.Exec(c.appCmd, command...)
}

// cliCommand returns the cli command from the provided command.
func (c ChainCmd) cliCommand(command []string) step.Option {
return step.Exec(c.appCmd, c.attachHome(command)...)
Expand Down
26 changes: 0 additions & 26 deletions ignite/pkg/chaincmd/in-place-testnet.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package chaincmd

import (
"fmt"

"github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step"
)

Expand Down Expand Up @@ -85,15 +83,6 @@ func MultiNodeWithValidatorsStakeAmount(satkeAmounts string) MultiNodeOption {
}
}

func MultiNodeWithHome(home string) MultiNodeOption {
return func(s []string) []string {
if len(home) > 0 {
return append(s, optionHome, home)
}
return s
}
}

// TestnetMultiNodeCommand return command to start testnet multinode.
func (c ChainCmd) TestnetMultiNodeCommand(options ...MultiNodeOption) step.Option {
command := []string{
Expand All @@ -104,21 +93,6 @@ func (c ChainCmd) TestnetMultiNodeCommand(options ...MultiNodeOption) step.Optio
for _, apply := range options {
command = apply(command)
}
fmt.Println(command)

return c.daemonCommand(command)
}

// TestnetMultiNodeCommand return command to start testnet multinode.
func (c ChainCmd) TestnetStartMultiNodeCommand(options ...MultiNodeOption) step.Option {
command := []string{
commandStart,
}

// Apply the options provided by the user
for _, apply := range options {
command = apply(command)
}

return c.daemonCommandIncludedHomeFlag(command)
}
13 changes: 0 additions & 13 deletions ignite/pkg/chaincmd/runner/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,6 @@ func (r Runner) MultiNode(ctx context.Context, options ...chaincmd.MultiNodeOpti
)
}

func (r Runner) StartMultiNode(ctx context.Context, options ...chaincmd.MultiNodeOption) error {
runOptions := runOptions{
wrappedStdErrMaxLen: 50000,
stdout: os.Stdout,
stderr: os.Stderr,
}
return r.run(
ctx,
runOptions,
r.chainCmd.TestnetStartMultiNodeCommand(options...),
)
}

// Gentx generates a genesis tx carrying a self delegation.
func (r Runner) Gentx(
ctx context.Context,
Expand Down
56 changes: 0 additions & 56 deletions ignite/services/chain/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"context"
"os"
"path/filepath"
"strconv"
"sync"
// "time"

"github.com/nqd/flat"
"github.com/pelletier/go-toml"
Expand Down Expand Up @@ -61,59 +58,6 @@ func (c Chain) MultiNode(ctx context.Context, runner chaincmdrunner.Runner, args
return err
}

func (c Chain) StartMultiNode(ctx context.Context, runner chaincmdrunner.Runner, args MultiNodeArgs) error {
numVal, err := strconv.Atoi(args.NumValidator)
if err != nil {
return err
}

// Kênh để nhận lỗi từ các goroutines
errCh := make(chan error, numVal)
var wg sync.WaitGroup

// Tạo context có thể hủy bỏ
ctx, cancel := context.WithCancel(ctx)
defer cancel()

// Tạo các goroutines để chạy các node
for i := 0; i < numVal; i++ {
wg.Add(1)
go func(i int) {
defer wg.Done()
home := filepath.Join(args.OutputDir, args.NodeDirPrefix+strconv.Itoa(i))

// Kiểm tra nếu context bị hủy
select {
case <-ctx.Done():
return // Kết thúc goroutine nếu context bị hủy
default:
// Chạy node
errRunNode := runner.StartMultiNode(ctx, chaincmd.MultiNodeWithHome(home))

// Nếu có lỗi, gửi lỗi vào kênh và hủy toàn bộ goroutines
if errRunNode != nil {
errCh <- errRunNode
cancel() // Hủy tất cả goroutines khác
}
}
}(i)
}

// Chờ tất cả các goroutines hoàn thành
wg.Wait()

// Đóng kênh sau khi tất cả các goroutine hoàn tất
close(errCh)

// Kiểm tra lỗi từ các goroutines
if len(errCh) > 0 {
// Lấy lỗi đầu tiên nếu có lỗi
return <-errCh
}

return nil
}

// Start wraps the "appd start" command to begin running a chain from the daemon.
func (c Chain) Start(ctx context.Context, runner chaincmdrunner.Runner, cfg *chainconfig.Config) error {
validator, err := chainconfig.FirstValidator(cfg)
Expand Down
22 changes: 0 additions & 22 deletions ignite/services/chain/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,3 @@ func (c Chain) TestnetMultiNode(ctx context.Context, args MultiNodeArgs) error {
}
return nil
}

func (c Chain) TestnetStartMultiNode(ctx context.Context, args MultiNodeArgs) error {
commands, err := c.Commands(ctx)
if err != nil {
return err
}

// make sure that config.yml exists
if c.options.ConfigFile != "" {
if _, err := os.Stat(c.options.ConfigFile); err != nil {
return err
}
} else if _, err := chainconfig.LocateDefault(c.app.Path); err != nil {
return err
}

err = c.StartMultiNode(ctx, commands, args)
if err != nil {
return err
}
return nil
}

0 comments on commit d492d08

Please sign in to comment.