check_attestations.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. # This script is a CI test in tilt that verifies that prices are flowing through the entire system properly.
  3. # It checks that all prices being published by the pyth publisher are showing up at the price service.
  4. import base58
  5. import logging
  6. import time
  7. from pyth_utils import *
  8. logging.basicConfig(
  9. level=logging.DEBUG, format="%(asctime)s | %(module)s | %(levelname)s | %(message)s"
  10. )
  11. # Where to read the set of accounts from
  12. PYTH_TEST_ACCOUNTS_HOST = "pyth"
  13. PYTH_TEST_ACCOUNTS_PORT = 4242
  14. PRICE_SERVICE_HOST = "pyth-price-server"
  15. PRICE_SERVICE_PORT = 4200
  16. def base58_to_hex(base58_string):
  17. asc_string = base58.b58decode(base58_string)
  18. return asc_string.hex()
  19. all_prices_attested = False
  20. while not all_prices_attested:
  21. publisher_state_map = get_pyth_accounts(PYTH_TEST_ACCOUNTS_HOST, PYTH_TEST_ACCOUNTS_PORT)
  22. pyth_price_account_ids = sorted([base58_to_hex(x["price"]) for x in publisher_state_map["symbols"]])
  23. price_ids = sorted(get_json(PRICE_SERVICE_HOST, PRICE_SERVICE_PORT, "/api/price_feed_ids"))
  24. if price_ids == pyth_price_account_ids:
  25. if publisher_state_map["all_symbols_added"]:
  26. logging.info("Price ids match and all symbols added. Enabling readiness probe")
  27. all_prices_attested = True
  28. else:
  29. logging.info("Price ids match but still waiting for more symbols to come online.")
  30. else:
  31. logging.info("Price ids do not match")
  32. logging.info(f"published ids: {pyth_price_account_ids}")
  33. logging.info(f"attested ids: {price_ids}")
  34. time.sleep(10)
  35. # Let k8s know the service is up
  36. readiness()