@@ -38,7 +38,6 @@ class ChainStateMonitorResult(RunnerResult):
3838 network : str = None
3939 is_stale : bool = False
4040 last_updated : Optional [datetime ] = None
41- elapsed_minutes : float = 0
4241 blocks_behind : int = 0
4342 blocks_processed : Optional [List [int ]] = None
4443
@@ -684,17 +683,9 @@ async def _execute_impl(self, context: JobContext) -> List[ChainStateMonitorResu
684683 )
685684 return results
686685
687- # Calculate how old the chain state is
688- now = datetime .now ()
686+ # Get the last updated time for logging purposes only
689687 last_updated = latest_chain_state .updated_at
690688
691- # Convert last_updated to naive datetime if it has timezone info
692- if last_updated .tzinfo is not None :
693- last_updated = last_updated .replace (tzinfo = None )
694-
695- time_difference = now - last_updated
696- minutes_difference = time_difference .total_seconds () / 60
697-
698689 # Get current chain height from API
699690 try :
700691 logger .debug (
@@ -748,8 +739,8 @@ async def _execute_impl(self, context: JobContext) -> List[ChainStateMonitorResu
748739
749740 blocks_behind = current_api_block_height - db_block_height
750741
751- # Consider stale if more than 10 blocks behind
752- stale_threshold_blocks = 10
742+ # Consider stale if more than 30 blocks behind
743+ stale_threshold_blocks = 30
753744 is_stale = blocks_behind > stale_threshold_blocks
754745
755746 logger .info (
@@ -762,10 +753,10 @@ async def _execute_impl(self, context: JobContext) -> List[ChainStateMonitorResu
762753 },
763754 )
764755
765- # Process missing blocks if we're behind
756+ # Process missing blocks if we're behind and stale
766757 if blocks_behind > 0 and is_stale :
767758 logger .warning (
768- "Chain state is behind and exceeds threshold" ,
759+ "Chain state is behind and exceeds threshold, processing missing blocks " ,
769760 extra = {
770761 "task" : "chain_state_monitor" ,
771762 "blocks_behind" : blocks_behind ,
@@ -920,7 +911,6 @@ async def _execute_impl(self, context: JobContext) -> List[ChainStateMonitorResu
920911 network = network ,
921912 is_stale = is_stale ,
922913 last_updated = last_updated ,
923- elapsed_minutes = minutes_difference ,
924914 blocks_behind = blocks_behind ,
925915 blocks_processed = blocks_processed ,
926916 )
@@ -946,7 +936,6 @@ async def _execute_impl(self, context: JobContext) -> List[ChainStateMonitorResu
946936 network = network ,
947937 is_stale = is_stale ,
948938 last_updated = last_updated ,
949- elapsed_minutes = minutes_difference ,
950939 blocks_behind = blocks_behind ,
951940 )
952941 )
@@ -959,22 +948,19 @@ async def _execute_impl(self, context: JobContext) -> List[ChainStateMonitorResu
959948 extra = {"task" : "chain_state_monitor" , "error" : str (e )},
960949 exc_info = True ,
961950 )
962- # Fall back to legacy time-based staleness check if API call fails
951+ # Cannot determine staleness without API access
963952 logger .warning (
964- "Falling back to time-based staleness check " ,
953+ "Cannot determine chain state without API access " ,
965954 extra = {"task" : "chain_state_monitor" },
966955 )
967- stale_threshold_minutes = 5
968- is_stale = minutes_difference > stale_threshold_minutes
969956
970957 results .append (
971958 ChainStateMonitorResult (
972959 success = False ,
973- message = f"Error checking chain height, using time-based check instead : { str (e )} " ,
960+ message = f"Error checking chain height: { str (e )} " ,
974961 network = network ,
975- is_stale = is_stale ,
962+ is_stale = True , # Assume stale if we can't check
976963 last_updated = last_updated ,
977- elapsed_minutes = minutes_difference ,
978964 )
979965 )
980966 return results
0 commit comments