Skip to content

Commit 1d5b075

Browse files
committed
Allow for use of the new archive backup endpoints specification.
1 parent 512d507 commit 1d5b075

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

bittensor/core/async_subtensor.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def __init__(
118118
fallback_endpoints: Optional[list[str]] = None,
119119
retry_forever: bool = False,
120120
_mock: bool = False,
121+
archive_endpoints: Optional[list[str]] = None,
121122
):
122123
"""
123124
Initializes an instance of the AsyncSubtensor class.
@@ -126,9 +127,13 @@ def __init__(
126127
network: The network name or type to connect to.
127128
config: Configuration object for the AsyncSubtensor instance.
128129
log_verbose: Enables or disables verbose logging.
129-
fallback_endpoints: List of fallback endpoints to use if default or provided network is not available. Defaults to `None`.
130+
fallback_endpoints: List of fallback endpoints to use if default or provided network is not available.
131+
Defaults to `None`.
130132
retry_forever: Whether to retry forever on connection errors. Defaults to `False`.
131133
_mock: Whether this is a mock instance. Mainly just for use in testing.
134+
archive_endpoints: Similar to fallback_endpoints, but specifically only archive nodes. Will be used in cases
135+
where you are requesting a block that is too old for your current (presumably lite) node. Defaults to
136+
`None`
132137
133138
Raises:
134139
Any exceptions raised during the setup, configuration, or connection process.
@@ -151,6 +156,7 @@ def __init__(
151156
fallback_endpoints=fallback_endpoints,
152157
retry_forever=retry_forever,
153158
_mock=_mock,
159+
archive_endpoints=archive_endpoints,
154160
)
155161
if self.log_verbose:
156162
logging.info(
@@ -289,18 +295,23 @@ def _get_substrate(
289295
fallback_endpoints: Optional[list[str]] = None,
290296
retry_forever: bool = False,
291297
_mock: bool = False,
298+
archive_endpoints: Optional[list[str]] = None,
292299
) -> Union[AsyncSubstrateInterface, RetryAsyncSubstrate]:
293300
"""Creates the Substrate instance based on provided arguments.
294301
295302
Arguments:
296-
fallback_endpoints: List of fallback endpoints to use if default or provided network is not available. Defaults to `None`.
303+
fallback_endpoints: List of fallback endpoints to use if default or provided network is not available.
304+
Defaults to `None`.
297305
retry_forever: Whether to retry forever on connection errors. Defaults to `False`.
298306
_mock: Whether this is a mock instance. Mainly just for use in testing.
307+
archive_endpoints: Similar to fallback_endpoints, but specifically only archive nodes. Will be used in cases
308+
where you are requesting a block that is too old for your current (presumably lite) node. Defaults to
309+
`None`
299310
300311
Returns:
301312
the instance of the SubstrateInterface or RetrySyncSubstrate class.
302313
"""
303-
if fallback_endpoints or retry_forever:
314+
if fallback_endpoints or retry_forever or archive_endpoints:
304315
return RetryAsyncSubstrate(
305316
url=self.chain_endpoint,
306317
fallback_chains=fallback_endpoints,
@@ -310,6 +321,7 @@ def _get_substrate(
310321
use_remote_preset=True,
311322
chain_name="Bittensor",
312323
_mock=_mock,
324+
archive_endpoints=archive_endpoints
313325
)
314326
return AsyncSubstrateInterface(
315327
url=self.chain_endpoint,

bittensor/core/subtensor.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ class Subtensor(SubtensorMixin):
115115
def __init__(
116116
self,
117117
network: Optional[str] = None,
118-
config: Optional["Config"] = None,
118+
config: Optional[Config] = None,
119119
log_verbose: bool = False,
120120
fallback_endpoints: Optional[list[str]] = None,
121121
retry_forever: bool = False,
122122
_mock: bool = False,
123+
archive_endpoints: Optional[list[str]] = None,
123124
):
124125
"""
125126
Initializes an instance of the Subtensor class.
@@ -128,9 +129,13 @@ def __init__(
128129
network: The network name or type to connect to.
129130
config: Configuration object for the AsyncSubtensor instance.
130131
log_verbose: Enables or disables verbose logging.
131-
fallback_endpoints: List of fallback endpoints to use if default or provided network is not available. Defaults to `None`.
132+
fallback_endpoints: List of fallback endpoints to use if default or provided network is not available.
133+
Defaults to `None`.
132134
retry_forever: Whether to retry forever on connection errors. Defaults to `False`.
133135
_mock: Whether this is a mock instance. Mainly just for use in testing.
136+
archive_endpoints: Similar to fallback_endpoints, but specifically only archive nodes. Will be used in cases
137+
where you are requesting a block that is too old for your current (presumably lite) node. Defaults to
138+
`None`
134139
135140
Raises:
136141
Any exceptions raised during the setup, configuration, or connection process.
@@ -151,6 +156,7 @@ def __init__(
151156
fallback_endpoints=fallback_endpoints,
152157
retry_forever=retry_forever,
153158
_mock=_mock,
159+
archive_endpoints=archive_endpoints,
154160
)
155161
if self.log_verbose:
156162
logging.info(
@@ -172,18 +178,23 @@ def _get_substrate(
172178
fallback_endpoints: Optional[list[str]] = None,
173179
retry_forever: bool = False,
174180
_mock: bool = False,
181+
archive_endpoints: Optional[list[str]] = None,
175182
) -> Union[SubstrateInterface, RetrySyncSubstrate]:
176183
"""Creates the Substrate instance based on provided arguments.
177184
178185
Arguments:
179-
fallback_endpoints: List of fallback chains endpoints to use if main network isn't available. Defaults to `None`.
186+
fallback_endpoints: List of fallback chains endpoints to use if main network isn't available. Defaults to
187+
`None`.
180188
retry_forever: Whether to retry forever on connection errors. Defaults to `False`.
181189
_mock: Whether this is a mock instance. Mainly just for use in testing.
190+
archive_endpoints: Similar to fallback_endpoints, but specifically only archive nodes. Will be used in cases
191+
where you are requesting a block that is too old for your current (presumably lite) node. Defaults to
192+
`None`
182193
183194
Returns:
184195
the instance of the SubstrateInterface or RetrySyncSubstrate class.
185196
"""
186-
if fallback_endpoints or retry_forever:
197+
if fallback_endpoints or retry_forever or archive_endpoints:
187198
return RetrySyncSubstrate(
188199
url=self.chain_endpoint,
189200
ss58_format=SS58_FORMAT,
@@ -193,6 +204,7 @@ def _get_substrate(
193204
fallback_chains=fallback_endpoints,
194205
retry_forever=retry_forever,
195206
_mock=_mock,
207+
archive_endpoints=archive_endpoints,
196208
)
197209
return SubstrateInterface(
198210
url=self.chain_endpoint,

0 commit comments

Comments
 (0)