1- import contextlib
21import time
32from collections .abc import Callable
43from typing import Any
1211from compute_horde_validator .validator .allowance .utils import blocks , manifests
1312from compute_horde_validator .validator .allowance .utils .supertensor import (
1413 ArchiveSubtensorNotConfigured ,
15- PrecachingSuperTensor ,
1614 SuperTensor ,
1715 SuperTensorError ,
1816 supertensor ,
1917)
20- from compute_horde_validator .validator .allowance .utils .supertensor_django_cache import DjangoCache
2118from compute_horde_validator .validator .locks import Lock , Locked , LockType , get_advisory_lock
2219from compute_horde_validator .validator .models import (
2320 AllowanceBooking ,
@@ -42,7 +39,6 @@ def _run_block_scan_with_lock(
4239 * ,
4340 lock_type : LockType ,
4441 max_run_time : float ,
45- backfilling_supertensor : SuperTensor | None ,
4642 scan : Callable [[int , SuperTensor , float , float ], None ],
4743 task_name : str ,
4844 keep_running : bool ,
@@ -54,7 +50,6 @@ def _run_block_scan_with_lock(
5450 Args:
5551 lock_type: Type of lock to acquire
5652 max_run_time: Maximum runtime for the scan
57- backfilling_supertensor: Optional pre-configured SuperTensor instance
5853 scan: Function to call with (current_block, supertensor, start_time, max_run_time) to perform the actual scanning
5954 task_name: Name of the task for logging
6055 keep_running: Whether to reschedule on timeout
@@ -63,20 +58,13 @@ def _run_block_scan_with_lock(
6358 if not AllowanceMinerManifest .objects .exists ():
6459 logger .warning (f"No miner manifests found, skipping { task_name } " )
6560 return
66- current_block = supertensor ().get_current_block ()
61+ st = supertensor ()
62+ current_block = st .get_current_block ()
6763 with transaction .atomic (using = settings .DEFAULT_DB_ALIAS ):
6864 try :
6965 with Lock (lock_type , LOCK_WAIT_TIMEOUT , settings .DEFAULT_DB_ALIAS ):
7066 start_time = time .time ()
71-
72- cm : contextlib .AbstractContextManager [SuperTensor ]
73- if backfilling_supertensor is None :
74- cm = PrecachingSuperTensor (cache = DjangoCache (), enable_workers = True )
75- else :
76- cm = contextlib .nullcontext (backfilling_supertensor )
77-
78- with cm as st :
79- scan (current_block , st , start_time , max_run_time )
67+ scan (current_block , st , start_time , max_run_time )
8068
8169 except Locked :
8270 logger .debug (f"Another thread already running { task_name } " )
@@ -89,10 +77,7 @@ def _run_block_scan_with_lock(
8977@app .task (
9078 time_limit = MAX_RUN_TIME + 60 ,
9179)
92- def scan_blocks_and_calculate_allowance (
93- backfilling_supertensor : SuperTensor | None = None ,
94- keep_running : bool = True ,
95- ):
80+ def scan_blocks_and_calculate_allowance (keep_running : bool = True ):
9681 def _scan_live_blocks (
9782 current_block : int , st : SuperTensor , start_time : float , max_run_time : float
9883 ) -> None :
@@ -115,7 +100,6 @@ def _scan_live_blocks(
115100 _run_block_scan_with_lock (
116101 lock_type = LockType .ALLOWANCE_FETCHING ,
117102 max_run_time = MAX_RUN_TIME ,
118- backfilling_supertensor = backfilling_supertensor ,
119103 scan = _scan_live_blocks ,
120104 task_name = "live block scan" ,
121105 keep_running = keep_running ,
@@ -187,15 +171,11 @@ def evict_old_data():
187171@app .task (
188172 time_limit = allowance_settings .ARCHIVE_SCAN_MAX_RUN_TIME + 60 ,
189173)
190- def scan_archive_blocks_and_calculate_allowance (
191- backfilling_supertensor : SuperTensor | None = None ,
192- keep_running : bool = True ,
193- ):
174+ def scan_archive_blocks_and_calculate_allowance (keep_running : bool = True ):
194175 """
195176 Scan and calculate allowances for historical blocks in the archive range.
196177
197178 Args:
198- backfilling_supertensor: Optional pre-configured SuperTensor instance
199179 keep_running: Whether to reschedule itself if it times out or has more work
200180 """
201181
@@ -289,7 +269,6 @@ def _scan_archive_blocks(
289269 _run_block_scan_with_lock (
290270 lock_type = LockType .ALLOWANCE_ARCHIVE_FETCHING ,
291271 max_run_time = allowance_settings .ARCHIVE_SCAN_MAX_RUN_TIME ,
292- backfilling_supertensor = backfilling_supertensor ,
293272 scan = _scan_archive_blocks ,
294273 task_name = "archive block scan" ,
295274 keep_running = keep_running ,
0 commit comments