Skip to content

Commit

Permalink
Patch/mccn monitoring (#159)
Browse files Browse the repository at this point in the history
* Hotfix add missing requirement

* Add SEED_LIST_URL to env, Fix node status case-sensitivity, fix get_thorchain_last_block

* Update README
  • Loading branch information
DollyVolley authored Apr 23, 2021
1 parent e219914 commit bf10072
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ For *docker-compose* open `variables-chaosnet.env` and/or
- `ALLOWED_USER_IDS` to a list of Telegram User IDs that are permitted to access the
Bot. Set it to `ALL` to make it available to everybody.
- `NETWORK_TYPE` to either `TESTNET` or `CHAOSNET`.
- `SEED_LIST_URL` to specify the endpoint for the seed list which provides the IPs of the nodes in the network.
- `BINANCE_NODE_IPS` to a list of Binance Node IPs with ports you want to monitor.
Leave it empty or remove it to not monitor any Binance Node.
- `ETHEREUM_NODE_IPS` to a list of Ethereum Node IPs with ports you want to monitor.
Expand Down
12 changes: 10 additions & 2 deletions bot/constants/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
logger = logging.getLogger()

DEBUG = bool(os.environ['DEBUG'] == 'True') if 'DEBUG' in os.environ else False
NATIVE_DEPLOYMENT = bool(os.environ.get('NATIVE_DEPLOYMENT', False) == 'True')

TELEGRAM_BOT_TOKEN = os.environ.get('TELEGRAM_BOT_TOKEN', '')

Expand Down Expand Up @@ -57,9 +56,18 @@

# Other

MONITORED_STATUSES = ["standby", "ready", "active"]
MONITORED_STATUSES = ["STANDBY", "READY", "ACTIVE"]
JOB_INTERVAL_IN_SECONDS = 5 if DEBUG else 30

# Thorchain
NETWORK_TYPES = ["TESTNET", "CHAOSNET"]
NETWORK_TYPE = os.getenv("NETWORK_TYPE").upper() \
if os.getenv("NETWORK_TYPE", "notFound").upper() in NETWORK_TYPES and not DEBUG else 'TESTNET'

SLASH_POINTS_NOTIFICATION_THRESHOLD_DEFAULT = 3
THORCHAIN_ONCHAIN_API_URL = "https://thorchain-service.b42.tech/v1/"

DEFAULT_SEED_LIST = "https://chaosnet-seed.thorchain.info/" \
if NETWORK_TYPE == "CHAOSNET" else "https://testnet-seed.thorchain.info/"

SEED_LIST_URL = os.environ.get("SEED_LIST_URL", DEFAULT_SEED_LIST)
6 changes: 1 addition & 5 deletions bot/constants/node_ips.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import os

from constants.globals import DEBUG

NETWORK_TYPES = ["TESTNET", "CHAOSNET"]
NETWORK_TYPE = os.getenv("NETWORK_TYPE").upper() \
if os.getenv("NETWORK_TYPE", "notFound").upper() in NETWORK_TYPES and not DEBUG else 'TESTNET'
from constants.globals import DEBUG, NETWORK_TYPE

if DEBUG:
BINANCE_NODE_IPS = ['localhost', '0.0.0.0']
Expand Down
2 changes: 1 addition & 1 deletion bot/jobs/thorchain_node_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def check_thornodes(context):
else:
local_node['notification_timeout_in_seconds'] = INITIAL_NOTIFICATION_TIMEOUT

if local_node['status'] in MONITORED_STATUSES and is_thornode_healthy(context, node_address):
if local_node['status'].upper() in MONITORED_STATUSES and is_thornode_healthy(context, node_address):
check_thorchain_block_height(context, node_address=node_address)
check_thorchain_catch_up_status(context, node_address=node_address)
check_thorchain_midgard_api(context, node_address=node_address)
Expand Down
8 changes: 2 additions & 6 deletions bot/service/thorchain_network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_thorchain_last_block(node_ip=None):
else:
last_block = get_request_json_thorchain(url_path=f":8080/v2/thorchain/lastblock", node_ip=node_ip)

return last_block['thorchain']
return last_block[0]['thorchain']


def get_asgard_json() -> dict:
Expand Down Expand Up @@ -124,11 +124,7 @@ def get_request_json_thorchain(url_path: str, node_ip: str = None) -> dict:
if node_ip:
return get_request_json(url=f"http://{node_ip}{url_path}{REQUEST_POSTFIX}")

seeding_node_url = \
{"TESTNET": "https://testnet-seed.thorchain.info", "CHAOSNET": "https://chaosnet-seed.thorchain.info"}[
NETWORK_TYPE]

available_node_ips = requests.get(url=seeding_node_url, timeout=CONNECTION_TIMEOUT).json()
available_node_ips = requests.get(url=SEED_LIST_URL, timeout=CONNECTION_TIMEOUT).json()

random.shuffle(available_node_ips)
for random_node_ip in available_node_ips:
Expand Down
1 change: 1 addition & 0 deletions variables-chaosnet.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TELEGRAM_BOT_TOKEN=XXX
NETWORK_TYPE=CHAOSNET
SEED_LIST_URL=
ALLOWED_USER_IDS=1234,5678,42
BINANCE_NODE_IPS=localhost,0.0.0.0
ETHEREUM_NODE_IPS=
Expand Down
3 changes: 2 additions & 1 deletion variables-testnet.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
TELEGRAM_BOT_TOKEN=XXX
NETWORK_TYPE=TESTNET
BINANCE_NODE_IPS=localhost,0.0.0.0
SEED_LIST_URL=
ALLOWED_USER_IDS=1234,5678,42
BINANCE_NODE_IPS=localhost,0.0.0.0
ETHEREUM_NODE_IPS=
BITCOIN_NODE_IPS=
BITCOIN_CASH_NODE_IPS=
Expand Down

0 comments on commit bf10072

Please sign in to comment.