Skip to content

Commit

Permalink
port changes from common-finality exporter to avail-finality
Browse files Browse the repository at this point in the history
  • Loading branch information
xxbbxb committed Jul 19, 2024
1 parent 36e53ee commit 1302e66
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
13 changes: 5 additions & 8 deletions exporters/avail/finality_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import threading
import logging
import traceback
import random
from functions import SUBSTRATE_INTERFACE, get_chain_info, get_keys, ss58_convert
from _thread import interrupt_main
from collections import deque
Expand Down Expand Up @@ -87,6 +88,8 @@ def get_votes(url, substrate_interface):
while True:
try:
d = substrate_interface.rpc_request(method='grandpa_roundState')
if url in q_outaged:
q_outaged.remove(url)
d = d['result']['best']
if d['round'] != rd and len(r) != 0:
q_votes_raw.append(r)
Expand All @@ -97,8 +100,6 @@ def get_votes(url, substrate_interface):
r[rd]['prevotes'] = d['prevotes']['missing']
r[rd]['precommits'] = d['precommits']['missing']

if url in q_outaged:
q_outaged.remove(url)
except Exception:
if url not in q_outaged:
q_outaged.append(url)
Expand Down Expand Up @@ -176,6 +177,7 @@ def construct_metrics(active_validators, grandpa_keys, votes_threshold, current_


def main():
substrate_interface = SUBSTRATE_INTERFACE(random.choice(rpc_endpoints), chain)
while True:
try:
for i in q_outaged:
Expand Down Expand Up @@ -212,19 +214,14 @@ def main():
rpc_count = len(rpc_endpoints)
thread_count = 3

substrate_interface = SUBSTRATE_INTERFACE(rpc_endpoints[0])

q_metrics = deque([])
q_votes_raw = deque([], maxlen=rpc_count * thread_count * 15)
q_rounds_processed = deque([], maxlen=100)
q_outaged = deque([], maxlen=30)

for url in rpc_endpoints:
for i in range(thread_count):
if url == rpc_endpoints[0]:
th = threading.Thread(target=get_votes, args=(url, substrate_interface))
else:
th = threading.Thread(target=get_votes, args=(url, SUBSTRATE_INTERFACE(url)))
th = threading.Thread(target=get_votes, args=(url, SUBSTRATE_INTERFACE(url)))
th.daemon = True
th.start()
time.sleep(0.2)
Expand Down
6 changes: 5 additions & 1 deletion exporters/avail/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def request(self, module: str, function: str, params: str = None):
r = None

def rpc_request(self, method: str, params: str = None):
return self.substrate.rpc_request(method=method, params=params)
try:
return self.substrate.rpc_request(method=method, params=params)
except Exception as e:
self.substrate.connect_websocket()
logging.critical('The substrate api request failed with error ' + str(e))


def get_era_points(data):
Expand Down
2 changes: 1 addition & 1 deletion exporters/common/finality_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_votes(url, substrate_interface):
q_outaged.append(url)
time.sleep(1)
substrate_interface.connect_websocket()

pass

def construct_metrics(active_validators, grandpa_keys, votes_threshold, current_session):
data = q_votes_raw.copy()
Expand Down
1 change: 1 addition & 0 deletions exporters/github_release/projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ projects:
Moonbeam: https://api.github.com/repos/PureStake/moonbeam/releases/latest
Acala: https://api.github.com/repos/AcalaNetwork/Acala/releases/latest
Astar: https://api.github.com/repos/PlasmNetwork/Astar/releases/latest
Avail: https://api.github.com/repos/availproject/avail/releases/latest

0 comments on commit 1302e66

Please sign in to comment.