Merge b9968373c3d95db7abc58f2c71b8b136373a4779 into 254f6b986720c92ddf97fbb1a6a6465da8e87e29

This commit is contained in:
Kelvin Velasquez 2025-12-25 00:06:35 +00:00 committed by GitHub
commit fee1157f8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,6 +3,7 @@
import enum import enum
import time import time
import weakref
from collections.abc import Callable, Mapping from collections.abc import Callable, Mapping
from functools import partial from functools import partial
from typing import TYPE_CHECKING, Any, Optional from typing import TYPE_CHECKING, Any, Optional
@ -132,7 +133,9 @@ class Request:
self.block_hashes: list[BlockHash] = [] self.block_hashes: list[BlockHash] = []
self.get_hash_new_full_blocks: Callable[[], list[BlockHash]] | None = None self.get_hash_new_full_blocks: Callable[[], list[BlockHash]] | None = None
if block_hasher is not None: if block_hasher is not None:
self.get_hash_new_full_blocks = partial(block_hasher, self) # Use weakref to avoid circular reference: Request -> partial -> Request
# This allows immediate reclamation by refcounting without waiting for GC.
self.get_hash_new_full_blocks = partial(block_hasher, weakref.proxy(self))
self.block_hashes = self.get_hash_new_full_blocks() self.block_hashes = self.get_hash_new_full_blocks()
self.skip_reading_prefix_cache = self.get_skip_reading_prefix_cache() self.skip_reading_prefix_cache = self.get_skip_reading_prefix_cache()