You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.8 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "sort"
  5. "time"
  6. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  7. )
  8. func Start(testnet *e2e.Testnet) error {
  9. // Sort nodes by starting order
  10. nodeQueue := testnet.Nodes
  11. sort.SliceStable(nodeQueue, func(i, j int) bool {
  12. return nodeQueue[i].StartAt < nodeQueue[j].StartAt
  13. })
  14. // Start initial nodes (StartAt: 0)
  15. logger.Info("Starting initial network nodes...")
  16. for len(nodeQueue) > 0 && nodeQueue[0].StartAt == 0 {
  17. node := nodeQueue[0]
  18. nodeQueue = nodeQueue[1:]
  19. if err := execCompose(testnet.Dir, "up", "-d", node.Name); err != nil {
  20. return err
  21. }
  22. if _, err := waitForNode(node, 0, 15*time.Second); err != nil {
  23. return err
  24. }
  25. logger.Info(fmt.Sprintf("Node %v up on http://127.0.0.1:%v", node.Name, node.ProxyPort))
  26. }
  27. // Wait for initial height
  28. logger.Info(fmt.Sprintf("Waiting for initial height %v...", testnet.InitialHeight))
  29. block, blockID, err := waitForHeight(testnet, testnet.InitialHeight)
  30. if err != nil {
  31. return err
  32. }
  33. // Update any state sync nodes with a trusted height and hash
  34. for _, node := range nodeQueue {
  35. if node.StateSync {
  36. err = UpdateConfigStateSync(node, block.Height, blockID.Hash.Bytes())
  37. if err != nil {
  38. return err
  39. }
  40. }
  41. }
  42. // Start up remaining nodes
  43. for _, node := range nodeQueue {
  44. logger.Info(fmt.Sprintf("Starting node %v at height %v...", node.Name, node.StartAt))
  45. if _, _, err := waitForHeight(testnet, node.StartAt); err != nil {
  46. return err
  47. }
  48. if err := execCompose(testnet.Dir, "up", "-d", node.Name); err != nil {
  49. return err
  50. }
  51. status, err := waitForNode(node, node.StartAt, 1*time.Minute)
  52. if err != nil {
  53. return err
  54. }
  55. logger.Info(fmt.Sprintf("Node %v up on http://127.0.0.1:%v at height %v",
  56. node.Name, node.ProxyPort, status.SyncInfo.LatestBlockHeight))
  57. }
  58. return nil
  59. }