Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions async_substrate_interface/async_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@

ResultHandler = Callable[[dict, Any], Awaitable[tuple[dict, bool]]]

logger = logging.getLogger("async_substrate_interface")


class AsyncExtrinsicReceipt:
"""
Expand Down Expand Up @@ -1017,7 +1019,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
if not self._metadata:
if self.runtime_version in self._metadata_cache:
# Get metadata from cache
logging.debug(
logger.debug(
"Retrieved metadata for {} from memory".format(
self.runtime_version
)
Expand All @@ -1031,7 +1033,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
metadata = self._metadata = await self.get_block_metadata(
block_hash=runtime_block_hash, decode=True
)
logging.debug(
logger.debug(
"Retrieved metadata for {} from Substrate node".format(
self.runtime_version
)
Expand All @@ -1044,7 +1046,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:

if self.runtime_version in self._metadata_v15_cache:
# Get metadata v15 from cache
logging.debug(
logger.debug(
"Retrieved metadata v15 for {} from memory".format(
self.runtime_version
)
Expand All @@ -1056,7 +1058,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
metadata_v15 = (
self._old_metadata_v15
) = await self._load_registry_at_block(block_hash=runtime_block_hash)
logging.debug(
logger.debug(
"Retrieved metadata v15 for {} from Substrate node".format(
self.runtime_version
)
Expand All @@ -1069,7 +1071,7 @@ async def get_runtime(block_hash, block_id) -> Runtime:
self.reload_type_registry(use_remote_preset=False, auto_discover=True)

if self.implements_scaleinfo:
logging.debug("Add PortableRegistry from metadata to type registry")
logger.debug("Add PortableRegistry from metadata to type registry")
self.runtime_config.add_portable_registry(metadata)

# Set active runtime version
Expand Down Expand Up @@ -1988,14 +1990,14 @@ async def _make_rpc_request(
break
if time.time() - self.ws.last_received >= self.retry_timeout:
if attempt >= self.max_retries:
logging.warning(
logger.warning(
f"Timed out waiting for RPC requests {attempt} times. Exiting."
)
raise SubstrateRequestException("Max retries reached.")
else:
self.ws.last_received = time.time()
await self.ws.connect(force=True)
logging.error(
logger.error(
f"Timed out waiting for RPC requests. "
f"Retrying attempt {attempt + 1} of {self.max_retries}"
)
Expand Down Expand Up @@ -2067,7 +2069,7 @@ async def rpc_request(
"Failed to get runtime version"
in result[payload_id][0]["error"]["message"]
):
logging.warning(
logger.warning(
"Failed to get runtime. Re-fetching from chain, and retrying."
)
await self.init_runtime()
Expand Down Expand Up @@ -2544,7 +2546,7 @@ async def _do_runtime_call_old(
params: Optional[Union[list, dict]] = None,
block_hash: Optional[str] = None,
) -> ScaleType:
logging.debug(
logger.debug(
f"Decoding old runtime call: {api}.{method} with params: {params} at block hash: {block_hash}"
)
runtime_call_def = _TYPE_REGISTRY["runtime_api"][api]["methods"][method]
Expand Down Expand Up @@ -2582,7 +2584,7 @@ async def _do_runtime_call_old(
# Get correct type
result_decoded = runtime_call_def["decoder"](bytes(result_bytes))
as_dict = _bt_decode_to_dict_or_list(result_decoded)
logging.debug("Decoded old runtime call result: ", as_dict)
logger.debug("Decoded old runtime call result: ", as_dict)
result_obj = ScaleObj(as_dict)

return result_obj
Expand Down
20 changes: 11 additions & 9 deletions async_substrate_interface/sync_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

ResultHandler = Callable[[dict, Any], tuple[dict, bool]]

logger = logging.getLogger("async_substrate_interface")


class ExtrinsicReceipt:
"""
Expand Down Expand Up @@ -768,7 +770,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
if not self._metadata:
if self.runtime_version in self._metadata_cache:
# Get metadata from cache
logging.debug(
logger.debug(
"Retrieved metadata for {} from memory".format(
self.runtime_version
)
Expand All @@ -780,7 +782,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
metadata = self._metadata = self.get_block_metadata(
block_hash=runtime_block_hash, decode=True
)
logging.debug(
logger.debug(
"Retrieved metadata for {} from Substrate node".format(
self.runtime_version
)
Expand All @@ -793,7 +795,7 @@ def get_runtime(block_hash, block_id) -> Runtime:

if self.runtime_version in self._metadata_v15_cache:
# Get metadata v15 from cache
logging.debug(
logger.debug(
"Retrieved metadata v15 for {} from memory".format(
self.runtime_version
)
Expand All @@ -805,7 +807,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
metadata_v15 = self._old_metadata_v15 = self._load_registry_at_block(
block_hash=runtime_block_hash
)
logging.debug(
logger.debug(
"Retrieved metadata v15 for {} from Substrate node".format(
self.runtime_version
)
Expand All @@ -817,7 +819,7 @@ def get_runtime(block_hash, block_id) -> Runtime:
self.reload_type_registry(use_remote_preset=False, auto_discover=True)

if self.implements_scaleinfo:
logging.debug("Add PortableRegistry from metadata to type registry")
logger.debug("Add PortableRegistry from metadata to type registry")
self.runtime_config.add_portable_registry(metadata)

# Set active runtime version
Expand Down Expand Up @@ -1690,7 +1692,7 @@ def _make_rpc_request(
response = json.loads(ws.recv(timeout=self.retry_timeout, decode=False))
except (TimeoutError, ConnectionClosed):
if attempt >= self.max_retries:
logging.warning(
logger.warning(
f"Timed out waiting for RPC requests {attempt} times. Exiting."
)
raise SubstrateRequestException("Max retries reached.")
Expand Down Expand Up @@ -1801,7 +1803,7 @@ def rpc_request(
"Failed to get runtime version"
in result[payload_id][0]["error"]["message"]
):
logging.warning(
logger.warning(
"Failed to get runtime. Re-fetching from chain, and retrying."
)
self.init_runtime()
Expand Down Expand Up @@ -2265,7 +2267,7 @@ def _do_runtime_call_old(
params: Optional[Union[list, dict]] = None,
block_hash: Optional[str] = None,
) -> ScaleType:
logging.debug(
logger.debug(
f"Decoding old runtime call: {api}.{method} with params: {params} at block hash: {block_hash}"
)
runtime_call_def = _TYPE_REGISTRY["runtime_api"][api]["methods"][method]
Expand Down Expand Up @@ -2301,7 +2303,7 @@ def _do_runtime_call_old(
# Get correct type
result_decoded = runtime_call_def["decoder"](bytes(result_bytes))
as_dict = _bt_decode_to_dict_or_list(result_decoded)
logging.debug("Decoded old runtime call result: ", as_dict)
logger.debug("Decoded old runtime call result: ", as_dict)
result_obj = ScaleObj(as_dict)

return result_obj
Expand Down
5 changes: 4 additions & 1 deletion async_substrate_interface/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from scalecodec.types import GenericCall, ScaleType


logger = logging.getLogger("async_substrate_interface")


class RuntimeCache:
blocks: dict[int, "Runtime"]
block_hashes: dict[str, "Runtime"]
Expand Down Expand Up @@ -644,7 +647,7 @@ def apply_type_registry_presets(
type_registry_preset_dict = load_type_registry_preset(
type_registry_name
)
logging.debug(
logger.debug(
f"Auto set type_registry_preset to {type_registry_name} ..."
)
self.type_registry_preset = type_registry_name
Expand Down