Skip to content

Commit

Permalink
fix: block other forks until ApeWorX/ape#2348
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Oct 28, 2024
1 parent 138d61a commit 5dc3025
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions silverback/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import atexit
import inspect
from collections import defaultdict
Expand Down Expand Up @@ -231,19 +232,25 @@ async def __create_snapshot_handler(
last_block_processed=self.state.get("system:last_block_processed", -1),
)

# To ensure we don't have too many forks at once
# HACK: Until `NetworkManager.fork` (and `ProviderContextManager`) allows concurrency

fork_lock: asyncio.Lock = asyncio.Lock()

def _with_fork_decorator(self, handler: Callable) -> Callable:
# Trigger worker-side handling using fork network by wrapping handler
fork_context = self.provider.network_manager.fork

@wraps(handler)
async def fork_handler(*args, **kwargs):
with fork_context():
result = handler(*args, **kwargs)
async with self.fork_lock:
with fork_context():
result = handler(*args, **kwargs)

if inspect.isawaitable(result):
return await result
if inspect.isawaitable(result):
return await result

return result
return result

return fork_handler

Expand Down

0 comments on commit 5dc3025

Please sign in to comment.