Skip to content

Commit c82df02

Browse files
committed
Fix cache
1 parent 8c80c7f commit c82df02

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@
2424
import asyncstdlib as a
2525
from bittensor_wallet.keypair import Keypair
2626
from bittensor_wallet.utils import SS58_FORMAT
27-
from bt_decode import (
28-
MetadataV15,
29-
PortableRegistry,
30-
decode as decode_by_type_string,
31-
AxonInfo as OldAxonInfo,
32-
PrometheusInfo as OldPrometheusInfo,
33-
)
27+
from bt_decode import MetadataV15, PortableRegistry, decode as decode_by_type_string
3428
from scalecodec.base import ScaleBytes, ScaleType, RuntimeConfigurationObject
3529
from scalecodec.types import (
3630
GenericCall,
@@ -957,7 +951,10 @@ async def get_runtime(block_hash, block_id) -> Runtime:
957951
if (
958952
(block_hash and block_hash == self.last_block_hash)
959953
or (block_id and block_id == self.block_id)
960-
) and self._metadata is not None:
954+
) and all(
955+
x is not None
956+
for x in [self._metadata, self._old_metadata_v15, self.metadata_v15]
957+
):
961958
return Runtime(
962959
self.chain,
963960
self.runtime_config,
@@ -1003,9 +1000,9 @@ async def get_runtime(block_hash, block_id) -> Runtime:
10031000
f"No runtime information for block '{block_hash}'"
10041001
)
10051002
# Check if runtime state already set to current block
1006-
if (
1007-
runtime_info.get("specVersion") == self.runtime_version
1008-
and self._metadata is not None
1003+
if runtime_info.get("specVersion") == self.runtime_version and all(
1004+
x is not None
1005+
for x in [self._metadata, self._old_metadata_v15, self.metadata_v15]
10091006
):
10101007
return Runtime(
10111008
self.chain,

async_substrate_interface/sync_substrate.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@
66

77
from bittensor_wallet.keypair import Keypair
88
from bittensor_wallet.utils import SS58_FORMAT
9-
from bt_decode import (
10-
MetadataV15,
11-
PortableRegistry,
12-
decode as decode_by_type_string,
13-
AxonInfo as OldAxonInfo,
14-
PrometheusInfo as OldPrometheusInfo,
15-
)
9+
from bt_decode import MetadataV15, PortableRegistry, decode as decode_by_type_string
1610
from scalecodec import (
1711
GenericCall,
1812
GenericExtrinsic,
@@ -701,7 +695,10 @@ def get_runtime(block_hash, block_id) -> Runtime:
701695
if (
702696
(block_hash and block_hash == self.last_block_hash)
703697
or (block_id and block_id == self.block_id)
704-
) and self._metadata is not None:
698+
) and all(
699+
x is not None
700+
for x in [self._metadata, self._old_metadata_v15, self.metadata_v15]
701+
):
705702
return Runtime(
706703
self.chain,
707704
self.runtime_config,
@@ -743,9 +740,9 @@ def get_runtime(block_hash, block_id) -> Runtime:
743740
f"No runtime information for block '{block_hash}'"
744741
)
745742
# Check if runtime state already set to current block
746-
if (
747-
runtime_info.get("specVersion") == self.runtime_version
748-
and self._metadata is not None
743+
if runtime_info.get("specVersion") == self.runtime_version and all(
744+
x is not None
745+
for x in [self._metadata, self._old_metadata_v15, self.metadata_v15]
749746
):
750747
return Runtime(
751748
self.chain,
@@ -802,7 +799,6 @@ def get_runtime(block_hash, block_id) -> Runtime:
802799
self.runtime_version
803800
)
804801
)
805-
806802
# Update metadata v15 cache
807803
self._metadata_v15_cache[self.runtime_version] = metadata_v15
808804

0 commit comments

Comments
 (0)