Skip to content

Commit

Permalink
receipt transfer: move interval to dynamic config
Browse files Browse the repository at this point in the history
  • Loading branch information
kkowalski-reef committed Jan 8, 2025
1 parent d3bc46d commit 8d2da9b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions validator/app/src/compute_horde_validator/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ def wrapped(*args, **kwargs):
"Whether receipt transfer between miners and validators should be enabled",
bool,
),
"DYNAMIC_RECEIPT_TRANSFER_INTERVAL": (
2,
"Seconds between consecutive receipt polling",
int,
),
}
DYNAMIC_CONFIG_CACHE_TIMEOUT = 300

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ def add_arguments(self, parser):
help="Only for debug: IP port of miner to fetch receipts from",
)
parser.add_argument(
"--interval",
type=float,
help="If provided, runs in daemon mode and polls for changes every `interval` seconds.",
"--daemon",
action="store_true",
default=False,
help="Run indefinitely. (otherwise performs a single transfer)",
)

@async_to_sync
async def handle(
self,
interval: float | None,
daemon: bool,
debug_miner_hotkey: str | None,
debug_miner_ip: str | None,
debug_miner_port: int | None,
Expand Down Expand Up @@ -144,16 +145,16 @@ async def miners():
- less timeouts due to CPU time being stolen by CPU heavy tasks
"""

if interval is None:
await self.run_once(cutoff, miners)
else:
if daemon:
while True:
try:
await self.run_in_loop(interval, cutoff, miners)
await self.run_in_loop(cutoff, miners)
except TransferIsDisabled:
# Sleep instead of exiting in case the transfer gets dynamically re-enabled.
logger.info("Transfer is currently disabled. Sleeping for a minute.")
await asyncio.sleep(60)
else:
await self.run_once(cutoff, miners)

async def run_once(
self, cutoff: datetime, miners: Callable[[], Awaitable[list[MinerInfo]]]
Expand All @@ -170,7 +171,7 @@ async def run_once(
)

async def run_in_loop(
self, interval: float, cutoff: datetime, miners: Callable[[], Awaitable[list[MinerInfo]]]
self, cutoff: datetime, miners: Callable[[], Awaitable[list[MinerInfo]]]
) -> None:
"""
Do a full catch-up + listen for changes in latest 2 pages indefinitely
Expand Down Expand Up @@ -200,7 +201,6 @@ async def run_in_loop(
),
# Keep up with latest pages continuously in parallel
self.keep_up(
interval=interval,
miners=miners,
session=session,
semaphore=asyncio.Semaphore(50),
Expand Down Expand Up @@ -247,7 +247,6 @@ async def catch_up(

async def keep_up(
self,
interval: float,
miners: Callable[[], Awaitable[list[MinerInfo]]],
session: aiohttp.ClientSession,
semaphore: asyncio.Semaphore,
Expand All @@ -257,6 +256,7 @@ async def keep_up(
"""
while True:
await self._throw_if_disabled()
interval: int = await aget_config("DYNAMIC_RECEIPT_TRANSFER_INTERVAL")

start_time = time.monotonic()
current_page = LocalFilesystemPagedReceiptStore.current_page()
Expand Down
2 changes: 1 addition & 1 deletion validator/envs/runner/data/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ services:
init: true
restart: unless-stopped
env_file: ./.env
command: python manage.py transfer_receipts --interval 2
command: python manage.py transfer_receipts --daemon
depends_on:
- redis
- db
Expand Down

0 comments on commit 8d2da9b

Please sign in to comment.