diff --git a/compositions/cluster-k8s/gen-validators.toml b/compositions/cluster-k8s/gen-validators.toml index 4fb45e6f..d33d0f83 100644 --- a/compositions/cluster-k8s/gen-validators.toml +++ b/compositions/cluster-k8s/gen-validators.toml @@ -10,6 +10,10 @@ runner = "cluster:k8s" disable_metrics = false +[global.run.test_params] + validator = "80" + persistent-peers = "10" + [[groups]] id = "validators" builder = "docker:generic" diff --git a/compositions/local-docker/gen-validators.toml b/compositions/local-docker/gen-validators.toml index 04ff7533..2a603151 100644 --- a/compositions/local-docker/gen-validators.toml +++ b/compositions/local-docker/gen-validators.toml @@ -10,6 +10,10 @@ runner = "local:docker" disable_metrics = false +[global.run.test_params] + validator = "3" + persistent-peers = "3" + [[groups]] id = "validators" builder = "docker:generic" diff --git a/manifest.toml b/manifest.toml index 6f9166fa..6cc6e595 100644 --- a/manifest.toml +++ b/manifest.toml @@ -19,6 +19,9 @@ enabled = true [[testcases]] name = "init-val" instances = { min = 1, max = 100, default = 3 } + [testcases.params] + validator = { type = "int", default = 3} + persistent-peers = { type = "int", default = 3} [[testcases]] name = "node-sync" diff --git a/testkit/appkit/app.go b/testkit/appkit/app.go index 542c2dca..0253abd5 100644 --- a/testkit/appkit/app.go +++ b/testkit/appkit/app.go @@ -26,13 +26,18 @@ type ValidatorNode struct { } type AppKit struct { - m sync.Mutex - Cmd *cobra.Command + m sync.Mutex + home string + AccountAddress string + ChainId string + Cmd *cobra.Command } -func New() *AppKit { +func New(path, chainId string) *AppKit { return &AppKit{ - Cmd: appcmd.NewRootCmd(), + home: path, + ChainId: chainId, + Cmd: appcmd.NewRootCmd(), } } @@ -64,50 +69,54 @@ func (ak *AppKit) execCmd(args []string) (output string, err error) { return output, nil } -func (ak *AppKit) InitChain(moniker string, chainId string, home string) (string, error) { - return ak.execCmd([]string{"init", moniker, "--chain-id", chainId, "--home", home}) +func (ak *AppKit) GetHomePath() string { + return ak.home } -func (ak *AppKit) CreateKey(name string, krbackend string, home string) (string, error) { - _, err := ak.execCmd([]string{"keys", "add", name, "--keyring-backend", krbackend, "--home", home, "--keyring-dir", home}) +func (ak *AppKit) InitChain(moniker string) (string, error) { + return ak.execCmd([]string{"init", moniker, "--chain-id", ak.ChainId, "--home", ak.home}) +} + +func (ak *AppKit) CreateKey(name, krbackend, krpath string) (string, error) { + _, err := ak.execCmd([]string{"keys", "add", name, "--keyring-backend", krbackend, "--home", ak.home, "--keyring-dir", krpath}) if err != nil { return "", err } - return ak.execCmd([]string{"keys", "show", name, "-a", "--keyring-backend", krbackend, "--home", home, "--keyring-dir", home}) + return ak.execCmd([]string{"keys", "show", name, "-a", "--keyring-backend", krbackend, "--home", ak.home, "--keyring-dir", krpath}) } -func (ak *AppKit) AddGenAccount(addr string, amount string, home string) (string, error) { - return ak.execCmd([]string{"add-genesis-account", addr, amount, "--home", home}) +func (ak *AppKit) AddGenAccount(addr, amount string) (string, error) { + return ak.execCmd([]string{"add-genesis-account", addr, amount, "--home", ak.home}) } -func (ak *AppKit) SignGenTx(accName string, amount string, krbackend string, chainId string, home string) (string, error) { - return ak.execCmd([]string{"gentx", accName, amount, "--keyring-backend", krbackend, "--chain-id", chainId, "--home", home, "--keyring-dir", home}) +func (ak *AppKit) SignGenTx(accName, amount, krbackend, krpath string) (string, error) { + return ak.execCmd([]string{"gentx", accName, amount, "--keyring-backend", krbackend, "--chain-id", ak.ChainId, "--home", ak.home, "--keyring-dir", krpath}) } -func (ak *AppKit) CollectGenTxs(home string) (string, error) { - return ak.execCmd([]string{"collect-gentxs", "--home", home}) +func (ak *AppKit) CollectGenTxs() (string, error) { + return ak.execCmd([]string{"collect-gentxs", "--home", ak.home}) } -func (ak *AppKit) GetNodeId(home string) (string, error) { - return ak.execCmd([]string{"tendermint", "show-node-id", "--home", home}) +func (ak *AppKit) GetNodeId() (string, error) { + return ak.execCmd([]string{"tendermint", "show-node-id", "--home", ak.home}) } -func (ak *AppKit) StartNode(home, loglvl string) error { +func (ak *AppKit) StartNode(loglvl string) error { ak.Cmd.ResetFlags() ak.Cmd.SetErr(os.Stdout) - ak.Cmd.SetArgs([]string{"start", "--home", home, "--log_level", loglvl, "--log_format", "plain"}) + ak.Cmd.SetArgs([]string{"start", "--home", ak.home, "--log_level", loglvl, "--log_format", "plain"}) return svrcmd.Execute(ak.Cmd, appcmd.EnvPrefix, app.DefaultNodeHome) } -func (ak *AppKit) PayForData(accAdr string, msg int, krbackend, chainId, home string) error { +func (ak *AppKit) PayForData(accAdr string, msg int, krbackend, krpath string) error { ak.Cmd.ResetFlags() ak.Cmd.SetArgs([]string{ "tx", "payment", "payForData", fmt.Sprint(msg), "--from", accAdr, "-b", "block", "-y", "--gas", "1000000000", "--fees", "100000000000utia", - "--keyring-backend", krbackend, "--chain-id", chainId, "--home", home, "--keyring-dir", home, + "--keyring-backend", krbackend, "--chain-id", ak.ChainId, "--home", ak.home, "--keyring-dir", krpath, }) return svrcmd.Execute(ak.Cmd, appcmd.EnvPrefix, app.DefaultNodeHome) diff --git a/tests/app-sync/run_seeds.go b/tests/app-sync/run_seeds.go index 2d322f02..bf2622a9 100644 --- a/tests/app-sync/run_seeds.go +++ b/tests/app-sync/run_seeds.go @@ -53,9 +53,9 @@ func RunSeed(runenv *runtime.RunEnv, initCtx *run.InitContext) error { home := fmt.Sprintf("/.celestia-app-%d", initCtx.GroupSeq) runenv.RecordMessage(home) - cmd := appkit.New() + cmd := appkit.New(home, "tia-test") - nodeId, err := cmd.GetNodeId(home) + nodeId, err := cmd.GetNodeId() if err != nil { return err } @@ -95,7 +95,7 @@ func RunSeed(runenv *runtime.RunEnv, initCtx *run.InitContext) error { return err } - go cmd.StartNode(home, "info") + go cmd.StartNode("info") // // wait for a new block to be produced time.Sleep(1 * time.Minute) diff --git a/tests/app-sync/run_validator.go b/tests/app-sync/run_validator.go new file mode 100644 index 00000000..a4baac99 --- /dev/null +++ b/tests/app-sync/run_validator.go @@ -0,0 +1,85 @@ +package appsync + +import ( + "context" + "net" + "time" + + "github.com/celestiaorg/test-infra/testkit/appkit" + "github.com/celestiaorg/test-infra/tests/common" + + "github.com/testground/sdk-go/network" + "github.com/testground/sdk-go/run" + "github.com/testground/sdk-go/runtime" +) + +func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { + ctx, cancel := context.WithTimeout(context.Background(), time.Minute*4) + defer cancel() + + syncclient := initCtx.SyncClient + netclient := network.NewClient(syncclient, runenv) + + netclient.MustWaitNetworkInitialized(ctx) + + config := network.Config{ + Network: "default", + Enable: true, + Default: network.LinkShape{ + Bandwidth: 5 << 26, // 320Mib + }, + CallbackState: "network-configured", + RoutingPolicy: network.AllowAll, + } + + config.IPv4 = runenv.TestSubnet + + // using the assigned `GlobalSequencer` id per each of instance + // to fill in the last 2 octects of the new IP address for the instance + ipC := byte((initCtx.GlobalSeq >> 8) + 1) + ipD := byte(initCtx.GlobalSeq) + config.IPv4.IP = append(config.IPv4.IP[0:2:2], ipC, ipD) + + err := netclient.ConfigureNetwork(ctx, &config) + if err != nil { + return err + } + + appcmd, err := common.BuildValidator(ctx, runenv, initCtx) + if err != nil { + return err + } + + runenv.RecordMessage("starting........") + go appcmd.StartNode("info") + + // // wait for a new block to be produced + time.Sleep(1 * time.Minute) + + // If all 3 validators submit pfd - it will take too long to produce a new block + for i := 0; i < 10; i++ { + runenv.RecordMessage("Submitting PFD with 90k bytes random data") + err = appcmd.PayForData( + appcmd.AccountAddress, + 50000, + "test", + appcmd.GetHomePath(), + ) + if err != nil { + runenv.RecordFailure(err) + return err + } + + s, err := appkit.GetLatestsBlockSize(net.ParseIP("127.0.0.1")) + if err != nil { + runenv.RecordMessage("err in last size call, %s", err.Error()) + } + + runenv.RecordMessage("latest size on iteration %d of the block is - %d", i, s) + } + + time.Sleep(30 * time.Second) + runenv.RecordSuccess() + + return nil +} diff --git a/tests/common/doc.go b/tests/common/doc.go new file mode 100644 index 00000000..3fefe721 --- /dev/null +++ b/tests/common/doc.go @@ -0,0 +1,16 @@ +/* +Package common is a helper around redundant creation of App or Node part + +In order to eliminate the boilerplate code of creating a validators' set, +please use `common.BuildValidator`. This Func does: +- InitChain +- Add-Gen-Account +- Collect-GenTxs +- Add-Persistent-Peers +In addition, the func returns initialized cobra cmd, so you can continue +operating with the validator + +appcmd, err := common.BuildValidator(ctx, runenv, initCtx) +appcmd.PayForData(...) +*/ +package common diff --git a/tests/app-sync/run_validators.go b/tests/common/validator.go similarity index 54% rename from tests/app-sync/run_validators.go rename to tests/common/validator.go index 785be601..5a9fd6a7 100644 --- a/tests/app-sync/run_validators.go +++ b/tests/common/validator.go @@ -1,4 +1,4 @@ -package appsync +package common import ( "context" @@ -8,62 +8,32 @@ import ( "os" "path/filepath" "strings" - "time" "github.com/celestiaorg/test-infra/testkit" "github.com/celestiaorg/test-infra/testkit/appkit" - - "github.com/testground/sdk-go/network" "github.com/testground/sdk-go/run" "github.com/testground/sdk-go/runtime" ) -func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { - ctx, cancel := context.WithTimeout(context.Background(), time.Minute*4) - defer cancel() - +func BuildValidator(ctx context.Context, runenv *runtime.RunEnv, initCtx *run.InitContext) (*appkit.AppKit, error) { syncclient := initCtx.SyncClient - netclient := network.NewClient(syncclient, runenv) - - netclient.MustWaitNetworkInitialized(ctx) - - config := network.Config{ - Network: "default", - Enable: true, - Default: network.LinkShape{ - Bandwidth: 5 << 26, // 320Mib - }, - CallbackState: "network-configured", - RoutingPolicy: network.AllowAll, - } - - config.IPv4 = runenv.TestSubnet - - // using the assigned `GlobalSequencer` id per each of instance - // to fill in the last 2 octects of the new IP address for the instance - ipC := byte((initCtx.GlobalSeq >> 8) + 1) - ipD := byte(initCtx.GlobalSeq) - config.IPv4.IP = append(config.IPv4.IP[0:2:2], ipC, ipD) - - err := netclient.ConfigureNetwork(ctx, &config) - if err != nil { - return err - } home := fmt.Sprintf("/.celestia-app-%d", initCtx.GlobalSeq) runenv.RecordMessage(home) - cmd := appkit.New() + const chainId string = "tia-test" + cmd := appkit.New(home, chainId) keyringName := fmt.Sprintf("keyName-%d", initCtx.GlobalSeq) accAddr, err := cmd.CreateKey(keyringName, "test", home) if err != nil { - return err + return nil, err } + cmd.AccountAddress = accAddr _, err = syncclient.Publish(ctx, testkit.AccountAddressTopic, accAddr) if err != nil { - return err + return nil, err } // Here we assign the first instance to be the orchestrator role @@ -71,16 +41,15 @@ func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { // Orchestrator is receiving all accounts by subscription, to then // execute the `add-genesis-account` command and send back to the rest // of the validators to set the initial genesis.json - const chainId string = "tia-test" if initCtx.GlobalSeq == 1 { accAddrCh := make(chan string) _, err = syncclient.Subscribe(ctx, testkit.AccountAddressTopic, accAddrCh) if err != nil { - return err + return nil, err } var accounts []string - for i := 0; i < runenv.TestGroupInstanceCount; i++ { + for i := 0; i < runenv.IntParam("validator"); i++ { addr := <-accAddrCh runenv.RecordMessage("Received address: %s", addr) accounts = append(accounts, addr) @@ -88,31 +57,31 @@ func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { moniker := fmt.Sprintf("validator-%d", initCtx.GlobalSeq) - _, err = cmd.InitChain(moniker, chainId, home) + _, err = cmd.InitChain(moniker) if err != nil { - return err + return nil, err } for _, v := range accounts { - _, err := cmd.AddGenAccount(v, "100000000000000000utia", home) + _, err := cmd.AddGenAccount(v, "1000000000000000utia") if err != nil { - return err + return nil, err } } gen, err := os.Open(fmt.Sprintf("%s/config/genesis.json", home)) if err != nil { - return err + return nil, err } bt, err := ioutil.ReadAll(gen) if err != nil { - return err + return nil, err } _, err = syncclient.Publish(ctx, testkit.InitialGenenesisTopic, string(bt)) if err != nil { - return err + return nil, err } runenv.RecordMessage("Orchestrator has sent initial genesis with accounts") @@ -120,46 +89,46 @@ func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { initGenCh := make(chan string) sub, err := syncclient.Subscribe(ctx, testkit.InitialGenenesisTopic, initGenCh) if err != nil { - return err + return nil, err } select { case err = <-sub.Done(): if err != nil { - return err + return nil, err } case initGen := <-initGenCh: err = os.WriteFile(fmt.Sprintf("%s/config/genesis.json", home), []byte(initGen), 0777) if err != nil { - return err + return nil, err } } runenv.RecordMessage("Validator has received the initial genesis") } - _, err = cmd.SignGenTx(keyringName, "5000000000utia", "test", chainId, home) + _, err = cmd.SignGenTx(keyringName, "5000000000utia", "test", home) if err != nil { - return err + return nil, err } fs, err := os.ReadDir(fmt.Sprintf("%s/config/gentx", home)) if err != nil { - return err + return nil, err } // slice is needed because of auto-gen gentx-name for _, f := range fs { gentx, err := os.Open(fmt.Sprintf("%s/config/gentx/%s", home, f.Name())) if err != nil { - return err + return nil, err } bt, err := ioutil.ReadAll(gentx) if err != nil { - return err + return nil, err } _, err = syncclient.Publish(ctx, testkit.GenesisTxTopic, string(bt)) if err != nil { - return err + return nil, err } } @@ -167,36 +136,50 @@ func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { genTxCh := make(chan string) sub, err := syncclient.Subscribe(ctx, testkit.GenesisTxTopic, genTxCh) if err != nil { - return err + return nil, err } - for i := 0; i < runenv.TestInstanceCount; i++ { + for i := 0; i < runenv.IntParam("validator"); i++ { select { case err = <-sub.Done(): if err != nil { - return err + return nil, err } case genTx := <-genTxCh: if !strings.Contains(genTx, accAddr) { err := ioutil.WriteFile(fmt.Sprintf("%s/config/gentx/%d.json", home, i), []byte(genTx), 0777) if err != nil { - return err + return nil, err } } } } - _, err = cmd.CollectGenTxs(home) + _, err = cmd.CollectGenTxs() if err != nil { - return err + return nil, err } configPath := filepath.Join(home, "config", "config.toml") + err = appkit.ChangeRPCServerAddress(configPath, net.ParseIP("0.0.0.0")) + if err != nil { + return nil, err + } - if initCtx.GlobalSeq <= 10 { - nodeId, err := cmd.GetNodeId(home) + err = changeConfig(configPath) + if err != nil { + return nil, err + } + + ip, err := initCtx.NetClient.GetDataNetworkIP() + if err != nil { + return nil, err + } + + if initCtx.GlobalSeq <= int64(runenv.IntParam("persistent-peers")) { + nodeId, err := cmd.GetNodeId() if err != nil { - return err + return nil, err } _, err = syncclient.Publish( @@ -204,83 +187,40 @@ func RunValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { testkit.ValidatorPeerTopic, &appkit.ValidatorNode{ PubKey: nodeId, - IP: config.IPv4.IP}, + IP: ip}, ) if err != nil { - return err + return nil, err } - } else { - valCh := make(chan *appkit.ValidatorNode) - sub, err = syncclient.Subscribe(ctx, testkit.ValidatorPeerTopic, valCh) - if err != nil { - return err - } - - var persPeers []string - for i := 0; i < 10; i++ { - select { - case err = <-sub.Done(): - if err != nil { - return err - } - case val := <-valCh: - runenv.RecordMessage("Validator Received: %s, %s", val.IP, val.PubKey) - if !val.IP.Equal(config.IPv4.IP) { - persPeers = append(persPeers, fmt.Sprintf("%s@%s", val.PubKey, val.IP.To4().String())) - } - - err = appkit.AddPersistentPeers(configPath, persPeers) - if err != nil { - return err - } - } - } - } - - err = appkit.ChangeConfigParam(configPath, "p2p", "external_address", fmt.Sprintf("%s:26656", config.IPv4.IP.To4().String())) - if err != nil { - return err } - runenv.RecordMessage("starting........") - err = changeConfig(configPath) + valCh := make(chan *appkit.ValidatorNode) + sub, err = syncclient.Subscribe(ctx, testkit.ValidatorPeerTopic, valCh) if err != nil { - return err + return nil, err } - go cmd.StartNode(home, "info") - - // // wait for a new block to be produced - time.Sleep(1 * time.Minute) - - // If all 3 validators submit pfd - it will take too long to produce a new block - for i := 0; i < 10; i++ { - runenv.RecordMessage("Submitting PFD with 90k bytes random data") - err = cmd.PayForData( - accAddr, - 50000, - "test", - chainId, - home, - ) - if err != nil { - runenv.RecordFailure(err) - return err - } - go func() { - s, err := appkit.GetLatestsBlockSize(net.ParseIP("127.0.0.1")) + var persPeers []string + for i := 0; i < runenv.IntParam("validator"); i++ { + select { + case err = <-sub.Done(): if err != nil { - runenv.RecordMessage("err in last size call, %s", err.Error()) + return nil, err + } + case val := <-valCh: + runenv.RecordMessage("Validator Received: %s, %s", val.IP, val.PubKey) + if !val.IP.Equal(ip) { + persPeers = append(persPeers, fmt.Sprintf("%s@%s", val.PubKey, val.IP.To4().String())) } - runenv.RecordMessage("latest size on iteration %d of the block is - %d", i, s) - }() + err = appkit.AddPersistentPeers(configPath, persPeers) + if err != nil { + return nil, err + } + } } - time.Sleep(30 * time.Second) - runenv.RecordSuccess() - - return nil + return cmd, nil } func changeConfig(path string) error { @@ -289,7 +229,7 @@ func changeConfig(path string) error { "timeout_propose": "3s", "timeout_prevote": "1s", "timeout_precommit": "1s", - "timeout_commit": "30s", + "timeout_commit": "25s", }, "rpc": { "timeout_broadcast_tx_commit": "90s", diff --git a/tests/node-sync/run_app.go b/tests/node-sync/run_app.go index f0929daf..5ceed9e8 100644 --- a/tests/node-sync/run_app.go +++ b/tests/node-sync/run_app.go @@ -2,16 +2,10 @@ package nodesync import ( "context" - "fmt" - "io/ioutil" - "net" - "os" - "path/filepath" - "strings" "time" "github.com/celestiaorg/test-infra/testkit" - "github.com/celestiaorg/test-infra/testkit/appkit" + "github.com/celestiaorg/test-infra/tests/common" "github.com/testground/sdk-go/network" "github.com/testground/sdk-go/run" "github.com/testground/sdk-go/runtime" @@ -49,205 +43,13 @@ func RunAppValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { return err } - home := fmt.Sprintf("/.celestia-app-%d", initCtx.GlobalSeq) - runenv.RecordMessage(home) - - cmd := appkit.New() - - keyringName := fmt.Sprintf("keyName-%d", initCtx.GlobalSeq) - accAddr, err := cmd.CreateKey(keyringName, "test", home) - if err != nil { - return err - } - - _, err = syncclient.Publish(ctx, testkit.AccountAddressTopic, accAddr) - if err != nil { - return err - } - - // Here we assign the first instance to be the orchestrator role - // - // Orchestrator is receiving all accounts by subscription, to then - // execute the `add-genesis-account` command and send back to the rest - // of the validators to set the initial genesis.json - const chainId string = "tia-test" - if initCtx.GlobalSeq == 1 { - accAddrCh := make(chan string) - _, err = syncclient.Subscribe(ctx, testkit.AccountAddressTopic, accAddrCh) - if err != nil { - return err - } - - var accounts []string - for i := 0; i < runenv.IntParam("validator"); i++ { - addr := <-accAddrCh - runenv.RecordMessage("Received address: %s", addr) - accounts = append(accounts, addr) - } - - moniker := fmt.Sprintf("validator-%d", initCtx.GlobalSeq) - - _, err = cmd.InitChain(moniker, chainId, home) - if err != nil { - return err - } - - for _, v := range accounts { - _, err := cmd.AddGenAccount(v, "1000000000000000utia", home) - if err != nil { - return err - } - } - - gen, err := os.Open(fmt.Sprintf("%s/config/genesis.json", home)) - if err != nil { - return err - } - - bt, err := ioutil.ReadAll(gen) - if err != nil { - return err - } - - _, err = syncclient.Publish(ctx, testkit.InitialGenenesisTopic, string(bt)) - if err != nil { - return err - } - - runenv.RecordMessage("Orchestrator has sent initial genesis with accounts") - } else { - initGenCh := make(chan string) - sub, err := syncclient.Subscribe(ctx, testkit.InitialGenenesisTopic, initGenCh) - if err != nil { - return err - } - select { - case err = <-sub.Done(): - if err != nil { - return err - } - case initGen := <-initGenCh: - err = os.WriteFile(fmt.Sprintf("%s/config/genesis.json", home), []byte(initGen), 0777) - if err != nil { - return err - } - } - runenv.RecordMessage("Validator has received the initial genesis") - } - - _, err = cmd.SignGenTx(keyringName, "5000000000utia", "test", chainId, home) - if err != nil { - return err - } - - fs, err := os.ReadDir(fmt.Sprintf("%s/config/gentx", home)) - if err != nil { - return err - } - // slice is needed because of auto-gen gentx-name - for _, f := range fs { - gentx, err := os.Open(fmt.Sprintf("%s/config/gentx/%s", home, f.Name())) - if err != nil { - return err - } - - bt, err := ioutil.ReadAll(gentx) - if err != nil { - return err - } - - _, err = syncclient.Publish(ctx, testkit.GenesisTxTopic, string(bt)) - if err != nil { - return err - } - - } - - genTxCh := make(chan string) - sub, err := syncclient.Subscribe(ctx, testkit.GenesisTxTopic, genTxCh) - if err != nil { - return err - } - - for i := 0; i < runenv.IntParam("validator"); i++ { - select { - case err = <-sub.Done(): - if err != nil { - return err - } - case genTx := <-genTxCh: - if !strings.Contains(genTx, accAddr) { - err := ioutil.WriteFile(fmt.Sprintf("%s/config/gentx/%d.json", home, i), []byte(genTx), 0777) - if err != nil { - return err - } - } - } - } - - _, err = cmd.CollectGenTxs(home) - if err != nil { - return err - } - - configPath := filepath.Join(home, "config", "config.toml") - err = appkit.ChangeRPCServerAddress(configPath, net.ParseIP("0.0.0.0")) + appcmd, err := common.BuildValidator(ctx, runenv, initCtx) if err != nil { return err } runenv.RecordMessage("starting........") - - err = changeConfig(configPath) - if err != nil { - return err - } - - if initCtx.GlobalSeq <= int64(runenv.IntParam("persistent-peers")) { - nodeId, err := cmd.GetNodeId(home) - if err != nil { - return err - } - - _, err = syncclient.Publish( - ctx, - testkit.ValidatorPeerTopic, - &appkit.ValidatorNode{ - PubKey: nodeId, - IP: config.IPv4.IP}, - ) - if err != nil { - return err - } - } - - valCh := make(chan *appkit.ValidatorNode) - sub, err = syncclient.Subscribe(ctx, testkit.ValidatorPeerTopic, valCh) - if err != nil { - return err - } - - var persPeers []string - for i := 0; i < runenv.IntParam("validator"); i++ { - select { - case err = <-sub.Done(): - if err != nil { - return err - } - case val := <-valCh: - runenv.RecordMessage("Validator Received: %s, %s", val.IP, val.PubKey) - if !val.IP.Equal(config.IPv4.IP) { - persPeers = append(persPeers, fmt.Sprintf("%s@%s", val.PubKey, val.IP.To4().String())) - } - - err = appkit.AddPersistentPeers(configPath, persPeers) - if err != nil { - return err - } - } - } - - go cmd.StartNode(home, "info") + go appcmd.StartNode("info") // wait for a new block to be produced // RPC is also being initialized... @@ -278,29 +80,3 @@ func RunAppValidator(runenv *runtime.RunEnv, initCtx *run.InitContext) error { return nil } - -func changeConfig(path string) error { - cfg := map[string]map[string]string{ - "consensus": { - "timeout_propose": "3s", - "timeout_prevote": "1s", - "timeout_precommit": "1s", - "timeout_commit": "25s", - }, - "rpc": { - "timeout_broadcast_tx_commit": "90s", - "max_body_bytes": "1000000", - "max_header_bytes": "1048576", - }, - } - - for i, j := range cfg { - for k, v := range j { - err := appkit.ChangeConfigParam(path, i, k, v) - if err != nil { - return err - } - } - } - return nil -} diff --git a/tests/node-sync/run_light.go b/tests/node-sync/run_light.go index ec4b4180..b25ae816 100644 --- a/tests/node-sync/run_light.go +++ b/tests/node-sync/run_light.go @@ -31,7 +31,6 @@ func RunLightNode(runenv *runtime.RunEnv, initCtx *run.InitContext) error { Network: "default", Enable: true, Default: network.LinkShape{ - // Latency: 100 * time.Millisecond, Bandwidth: 5 << 26, // 320Mib }, CallbackState: "network-configured",