From 03d63c5b90188f2ba428e37d95cb1335538987eb Mon Sep 17 00:00:00 2001 From: pharr117 Date: Tue, 19 Mar 2024 18:12:22 -0400 Subject: [PATCH] Update failed blocks tool to take into account the chain id --- tools/dump-failed-block-heights/main.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tools/dump-failed-block-heights/main.py b/tools/dump-failed-block-heights/main.py index 032d30a..d021843 100644 --- a/tools/dump-failed-block-heights/main.py +++ b/tools/dump-failed-block-heights/main.py @@ -2,6 +2,7 @@ import os import json import traceback +import argparse def get_env(): ret = { @@ -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])