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.

45 lines
1.1 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  6. )
  7. const interphaseWaitPeriod = 5
  8. // Wait waits for a number of blocks to be produced, and for all nodes to catch
  9. // up with it.
  10. func Wait(testnet *e2e.Testnet, blocks int64) error {
  11. block, _, err := waitForHeight(testnet, 0)
  12. if err != nil {
  13. return err
  14. }
  15. waitFor := block.Height + blocks
  16. logger.Info(fmt.Sprintf("Waiting for all nodes to reach height %v...", waitFor))
  17. _, err = waitForAllNodes(testnet, waitFor, 20*time.Second)
  18. if err != nil {
  19. return err
  20. }
  21. return nil
  22. }
  23. // WaitForAllMisbehaviors calculates the height of the last misbehavior and ensures the entire
  24. // testnet has surpassed this height before moving on to the next phase
  25. func waitForAllMisbehaviors(testnet *e2e.Testnet) error {
  26. _, _, err := waitForHeight(testnet, lastMisbehaviorHeight(testnet))
  27. return err
  28. }
  29. func lastMisbehaviorHeight(testnet *e2e.Testnet) int64 {
  30. lastHeight := testnet.InitialHeight
  31. for _, n := range testnet.Nodes {
  32. for height := range n.Misbehaviors {
  33. if height > lastHeight {
  34. lastHeight = height
  35. }
  36. }
  37. }
  38. return lastHeight + interphaseWaitPeriod
  39. }