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.

87 lines
2.3 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. // Nodes are already sorted by name. Sort them by name then startAt,
  10. // which gives the overall order startAt, mode, name.
  11. nodeQueue := testnet.Nodes
  12. sort.SliceStable(nodeQueue, func(i, j int) bool {
  13. a, b := nodeQueue[i], nodeQueue[j]
  14. switch {
  15. case a.Mode == b.Mode:
  16. return false
  17. case a.Mode == e2e.ModeSeed:
  18. return true
  19. case a.Mode == e2e.ModeValidator && b.Mode == e2e.ModeFull:
  20. return true
  21. }
  22. return false
  23. })
  24. sort.SliceStable(nodeQueue, func(i, j int) bool {
  25. return nodeQueue[i].StartAt < nodeQueue[j].StartAt
  26. })
  27. if len(nodeQueue) == 0 {
  28. return fmt.Errorf("no nodes in testnet")
  29. }
  30. if nodeQueue[0].StartAt > 0 {
  31. return fmt.Errorf("no initial nodes in testnet")
  32. }
  33. // Start initial nodes (StartAt: 0)
  34. logger.Info("Starting initial network nodes...")
  35. for len(nodeQueue) > 0 && nodeQueue[0].StartAt == 0 {
  36. node := nodeQueue[0]
  37. nodeQueue = nodeQueue[1:]
  38. if err := execCompose(testnet.Dir, "up", "-d", node.Name); err != nil {
  39. return err
  40. }
  41. if _, err := waitForNode(node, 0, 15*time.Second); err != nil {
  42. return err
  43. }
  44. logger.Info(fmt.Sprintf("Node %v up on http://127.0.0.1:%v", node.Name, node.ProxyPort))
  45. }
  46. // Wait for initial height
  47. logger.Info(fmt.Sprintf("Waiting for initial height %v...", testnet.InitialHeight))
  48. block, blockID, err := waitForHeight(testnet, testnet.InitialHeight)
  49. if err != nil {
  50. return err
  51. }
  52. // Update any state sync nodes with a trusted height and hash
  53. for _, node := range nodeQueue {
  54. if node.StateSync || node.Mode == e2e.ModeLight {
  55. err = UpdateConfigStateSync(node, block.Height, blockID.Hash.Bytes())
  56. if err != nil {
  57. return err
  58. }
  59. }
  60. }
  61. // Start up remaining nodes
  62. for _, node := range nodeQueue {
  63. logger.Info(fmt.Sprintf("Starting node %v at height %v...", node.Name, node.StartAt))
  64. if _, _, err := waitForHeight(testnet, node.StartAt); err != nil {
  65. return err
  66. }
  67. if err := execCompose(testnet.Dir, "up", "-d", node.Name); err != nil {
  68. return err
  69. }
  70. status, err := waitForNode(node, node.StartAt, 3*time.Minute)
  71. if err != nil {
  72. return err
  73. }
  74. logger.Info(fmt.Sprintf("Node %v up on http://127.0.0.1:%v at height %v",
  75. node.Name, node.ProxyPort, status.SyncInfo.LatestBlockHeight))
  76. }
  77. return nil
  78. }