From d492d08ccc05f815f4e0c18c56be9fe58339ded8 Mon Sep 17 00:00:00 2001 From: Likes To Eat Fish Date: Sun, 29 Sep 2024 23:20:28 +0700 Subject: [PATCH] remove try --- ignite/cmd/testnet_multi_node.go | 2 - ignite/pkg/chaincmd/chaincmd.go | 6 --- ignite/pkg/chaincmd/in-place-testnet.go | 26 ------------ ignite/pkg/chaincmd/runner/chain.go | 13 ------ ignite/services/chain/runtime.go | 56 ------------------------- ignite/services/chain/testnet.go | 22 ---------- 6 files changed, 125 deletions(-) diff --git a/ignite/cmd/testnet_multi_node.go b/ignite/cmd/testnet_multi_node.go index 30c897bb5f..34bc89a8fa 100644 --- a/ignite/cmd/testnet_multi_node.go +++ b/ignite/cmd/testnet_multi_node.go @@ -1,7 +1,6 @@ package ignitecmd import ( - // "fmt" "math/rand" "strconv" "time" @@ -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 diff --git a/ignite/pkg/chaincmd/chaincmd.go b/ignite/pkg/chaincmd/chaincmd.go index 057f4445d0..e7c9f78ab5 100644 --- a/ignite/pkg/chaincmd/chaincmd.go +++ b/ignite/pkg/chaincmd/chaincmd.go @@ -181,7 +181,6 @@ func (c ChainCmd) StartCommand(options ...string) step.Option { command := append([]string{ commandStart, }, options...) - fmt.Println(command) return c.daemonCommand(command) } @@ -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)...) diff --git a/ignite/pkg/chaincmd/in-place-testnet.go b/ignite/pkg/chaincmd/in-place-testnet.go index f4ecf360bb..8b33093a77 100644 --- a/ignite/pkg/chaincmd/in-place-testnet.go +++ b/ignite/pkg/chaincmd/in-place-testnet.go @@ -1,8 +1,6 @@ package chaincmd import ( - "fmt" - "github.com/ignite/cli/v29/ignite/pkg/cmdrunner/step" ) @@ -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{ @@ -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) -} diff --git a/ignite/pkg/chaincmd/runner/chain.go b/ignite/pkg/chaincmd/runner/chain.go index ad7e099419..ea39c315ac 100644 --- a/ignite/pkg/chaincmd/runner/chain.go +++ b/ignite/pkg/chaincmd/runner/chain.go @@ -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, diff --git a/ignite/services/chain/runtime.go b/ignite/services/chain/runtime.go index 739347df7c..b558eb2d7b 100644 --- a/ignite/services/chain/runtime.go +++ b/ignite/services/chain/runtime.go @@ -4,9 +4,6 @@ import ( "context" "os" "path/filepath" - "strconv" - "sync" - // "time" "github.com/nqd/flat" "github.com/pelletier/go-toml" @@ -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) diff --git a/ignite/services/chain/testnet.go b/ignite/services/chain/testnet.go index 1e45abdea8..cfd9d50137 100644 --- a/ignite/services/chain/testnet.go +++ b/ignite/services/chain/testnet.go @@ -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 -}