diff --git a/agent/app.py b/agent/app.py index a199941..c794639 100644 --- a/agent/app.py +++ b/agent/app.py @@ -44,7 +44,7 @@ def get_gw_stat_by_lock(lock_name, gw_rpc: GodwokenRpc, block_hash, lock_type_hash = gw_config.get_lock_type_hash(lock_name) res = gw_rpc.gw_get_block_committed_info(block_hash) if res is None or res is None: - return (0, 0) + raise Exception(f"Block hash: {block_hash} isn't committed.") tx = res["transaction_hash"] res = ckb_rpc.get_transaction(tx) inputs = res["transaction"]["inputs"] @@ -105,12 +105,16 @@ def update_metrics(tip_number, ping, last_block_hash: str, """ def reset_metrics(): with TaskLock: + global BlockNumber global CommitTransacionCount global DepositDict global WithdrawalDict - CommitTransacionCount = {} - DepositDict = {} - WithdrawalDict = {} + if BlockNumber is not None: + last_block_num = BlockNumber - 1 + CommitTransacionCount.pop(last_block_num, None) + DepositDict.pop(last_block_num, None) + WithdrawalDict.pop(last_block_num, None) + logging.info(f"Reset metrics for block: {last_block_num}") """ General metrics job. @@ -142,7 +146,6 @@ def __init__(self): elif net_env == "mainnet_v1": self.gw_config = mainnet_v1_config() else: - logging.info("use devnet") rollup_result_path = os.environ["ROLLUP_RESULT_PATH"] scripts_result_path = os.environ["SCRIPTS_RESULT_PATH"] self.gw_config = devnet_config(rollup_result_path, @@ -153,25 +156,27 @@ def __init__(self): ) self.gw_config = testnet_config() - """ - Always try to get new tip. - """ def run(self): global BlockNumber while True: sleep(1) - logging.info("Start running") - try: - tip_number = self.gw_rpc.get_tip_number() - except: - logging.exception("Cannot get tip number") - continue + logging.debug("Start running") + if BlockNumber is None: + try: + tip_number = self.gw_rpc.get_tip_number() + except: + logging.exception("Cannot get tip number") + continue + else: + tip_number = BlockNumber try: ping = self.gw_rpc.ping() block = self.gw_rpc.get_block_by_number(hex(tip_number)) + if block is None: + continue last_block_hash = block['hash'] last_block_ts = convert_int(block['raw']['timestamp']) tx_cnt = len(block['transactions']) @@ -188,7 +193,6 @@ def run(self): except: logging.exception("get block info failed") continue - logging.info("Loading deposit stats") try: deposit = get_gw_stat_by_lock( "deposit_lock", self.gw_rpc, @@ -197,7 +201,6 @@ def run(self): except: logging.exception("Failed to get deposit stats") continue - logging.info("Loading withdrawal stats") try: withdrawal = get_gw_stat_by_lock( "withdrawal_lock", self.gw_rpc, @@ -207,7 +210,7 @@ def run(self): logging.exception("Failed to get withdrawal stats") continue update_metrics( - tip_number, + tip_number+1, ping, last_block_hash, last_block_ts, @@ -231,7 +234,6 @@ def run(self): global CustodianStats while True: sleep(10) - logging.info("Loading custodian stats") try: CustodianStats = get_custodian( self.ckb_indexer_url, self.gw_config, diff --git a/agent/ckb_indexer.py b/agent/ckb_indexer.py index 03eaaa3..67f54e9 100644 --- a/agent/ckb_indexer.py +++ b/agent/ckb_indexer.py @@ -148,7 +148,6 @@ def get_custodian_stats(self, gw_config: GwConfig, else: ckb_cell_count += 1 - logging.info(f"loaded {cnt} page of custodian cells") cursor = result["last_cursor"] if cursor == "0x": break diff --git a/agent/godwoken_rpc.py b/agent/godwoken_rpc.py index be172d0..93403bf 100644 --- a/agent/godwoken_rpc.py +++ b/agent/godwoken_rpc.py @@ -107,7 +107,6 @@ def get_block(self, block_hash): def get_tip_number(self): tip_block_hash = self.get_tip_block_hash() - print(f'tip block hash: {tip_block_hash}') tip = self.get_block(tip_block_hash) tip_number = tip['block']['raw']['number'] return convert_int(tip_number) diff --git a/agent/json_rpc.py b/agent/json_rpc.py index 4e3e3f3..454d0c9 100644 --- a/agent/json_rpc.py +++ b/agent/json_rpc.py @@ -20,11 +20,11 @@ def submit(self, method: str, params: List): } try: r = requests.post(url="%s" % (self.url), json=payload, headers=headers) - logging.info(f"Access {self.url} {method} status: {r.status_code}") + logging.debug(f"Access {self.url} {method} status: {r.status_code}") r.raise_for_status() return r.json()["result"] except Exception as e: - logging.error(f"Submit request to {self.url}, method: {method}, params: {params}", exc_info = e) + logging.warn(f"Submit request to {self.url}, method: {method}, params: {params}", exc_info = e) raise RPCException from None