Skip to content

Commit

Permalink
Update failed blocks tool to take into account the chain id
Browse files Browse the repository at this point in the history
  • Loading branch information
pharr117 committed Mar 19, 2024
1 parent 6a35041 commit 03d63c5
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tools/dump-failed-block-heights/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import json
import traceback
import argparse

def get_env():
ret = {
Expand All @@ -17,17 +18,34 @@ def get_env():

return ret

DUMP_FAILED_BLOCKS_QUERY = "SELECT height FROM failed_blocks ORDER BY height ASC;"
SELECT_CHAINS_QUERY = "SELECT id FROM chains WHERE chain_id=%s;"
DUMP_FAILED_BLOCKS_QUERY = "SELECT height FROM failed_blocks WHERE blockchain_id=%s ORDER BY height ASC;"

def get_chain_id_arg():
parser = argparse.ArgumentParser(description="Dump failed block heights")
parser.add_argument("--chain-id", type=str, default="osmosis-1", help="Chain ID to dump failed block heights from")
args = parser.parse_args()
return args.chain_id


if __name__ == "__main__":
env = get_env()
chain_id = get_chain_id_arg()
os.makedirs("./output", exist_ok=True)

conn = psycopg2.connect(f"dbname={env['db_name']} user={env['user']} host={env['host']} password={env['password']} port={env['port']}")
try:

rec = None
with conn.cursor() as cur:
cur.execute(SELECT_CHAINS_QUERY, (chain_id,))
rec = cur.fetchone()
if rec is None:
raise Exception(f"Chain ID {chain_id} not found")

heights = []
with conn.cursor() as cur:
cur.execute(DUMP_FAILED_BLOCKS_QUERY)
cur.execute(DUMP_FAILED_BLOCKS_QUERY, (rec[0],))
for record in cur.fetchall():
heights.append(record[0])

Expand Down

0 comments on commit 03d63c5

Please sign in to comment.