bittensor-pylon-client 2.2.0__tar.gz → 2.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/PKG-INFO +3 -1
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/_unstable/asynchronous/api.py +28 -1
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/_unstable/sync/api.py +28 -1
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/_unstable/translators.py +21 -1
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/abstract_async.py +92 -1
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/abstract_sync.py +92 -1
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/asynchronous/client.py +69 -0
- bittensor_pylon_client-2.3.0/pylon_client/_internal/client/config.py +77 -0
- bittensor_pylon_client-2.3.0/pylon_client/_internal/client/neuron_client.py +355 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/sync/client.py +69 -0
- bittensor_pylon_client-2.3.0/pylon_client/_internal/file_backed_neurons.py +132 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/_unstable/bodies.py +10 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/_unstable/endpoints.py +15 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/_unstable/models.py +2 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/_unstable/requests.py +32 -7
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/_unstable/responses.py +21 -1
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/models.py +15 -0
- bittensor_pylon_client-2.3.0/pylon_client/_internal/pylon_commons/settings.py +95 -0
- bittensor_pylon_client-2.3.0/pylon_client/_internal/pylon_commons/types/__init__.py +50 -0
- bittensor_pylon_client-2.2.0/pylon_client/_internal/pylon_commons/types.py → bittensor_pylon_client-2.3.0/pylon_client/_internal/pylon_commons/types/bittensor.py +1 -1
- bittensor_pylon_client-2.3.0/pylon_client/_internal/pylon_commons/types/evm.py +8 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/v1/requests.py +2 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/v1/responses.py +2 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/artanis/__init__.py +1 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/artanis/unstable.py +3 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/artanis/v1.py +1 -0
- bittensor_pylon_client-2.3.0/pylon_client/exceptions.py +5 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pyproject.toml +10 -1
- bittensor_pylon_client-2.2.0/pylon_client/_internal/client/config.py +0 -41
- bittensor_pylon_client-2.2.0/pylon_client/_internal/pylon_commons/settings.py +0 -59
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/.gitignore +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/_unstable/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/_unstable/asynchronous/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/_unstable/sync/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/v1/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/v1/asynchronous/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/v1/asynchronous/api.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/v1/sync/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/v1/sync/api.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/api/v1/translators.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/asynchronous/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/asynchronous/communicators.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/asynchronous/config.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/namespace.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/sync/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/sync/communicators.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/client/sync/config.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/docker_manager.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/_unstable/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/apiver.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/constants.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/currency.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/endpoints.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/exceptions.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/timeout.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/v1/__init__.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/v1/bodies.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/v1/endpoints.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/pylon_commons/v1/models.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/_internal/translators.py +0 -0
- {bittensor_pylon_client-2.2.0 → bittensor_pylon_client-2.3.0}/pylon_client/v1/__init__.py +0 -0
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bittensor-pylon-client
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: Bittensor Pylon client library
|
|
5
5
|
Project-URL: homepage, https://github.com/backend-developers-ltd/bittensor-pylon
|
|
6
6
|
Project-URL: repository, https://github.com/backend-developers-ltd/bittensor-pylon
|
|
7
7
|
Author-email: Reef Technologies <opensource@reef.pl>
|
|
8
8
|
Requires-Python: >=3.11
|
|
9
9
|
Requires-Dist: apscheduler
|
|
10
|
+
Requires-Dist: cryptography
|
|
10
11
|
Requires-Dist: docker
|
|
11
12
|
Requires-Dist: httpx
|
|
12
13
|
Requires-Dist: pydantic-settings>=2.0
|
|
13
14
|
Requires-Dist: pydantic>=2.0
|
|
15
|
+
Requires-Dist: pyyaml>=6
|
|
14
16
|
Requires-Dist: tenacity
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import cast
|
|
1
|
+
from typing import Any, cast
|
|
2
2
|
|
|
3
3
|
from pylon_client._internal.api.abstract_async import (
|
|
4
4
|
AbstractAsyncIdentityApi,
|
|
@@ -6,9 +6,11 @@ from pylon_client._internal.api.abstract_async import (
|
|
|
6
6
|
)
|
|
7
7
|
from pylon_client._internal.pylon_commons._unstable.requests import (
|
|
8
8
|
GetAllRevealedCommitmentsRequest,
|
|
9
|
+
GetCertificateRequest,
|
|
9
10
|
GetCommitmentRequest,
|
|
10
11
|
GetCommitmentsRequest,
|
|
11
12
|
GetDrandLastStoredRoundRequest,
|
|
13
|
+
GetEvmLogsRequest,
|
|
12
14
|
GetExtrinsicRequest,
|
|
13
15
|
GetIdentitiesRequest,
|
|
14
16
|
GetLatestBlockInfoRequest,
|
|
@@ -43,6 +45,7 @@ from pylon_client._internal.pylon_commons.types import (
|
|
|
43
45
|
RevealedCommitmentData,
|
|
44
46
|
Weight,
|
|
45
47
|
)
|
|
48
|
+
from pylon_client._internal.pylon_commons.types import evm as evm_types
|
|
46
49
|
|
|
47
50
|
|
|
48
51
|
class AsyncOpenAccessApi(AbstractAsyncOpenAccessApi):
|
|
@@ -104,6 +107,23 @@ class AsyncOpenAccessApi(AbstractAsyncOpenAccessApi):
|
|
|
104
107
|
async def _get_latest_evm_associations_request(self, netuid: NetUid) -> GetLatestEvmAssociationsRequest:
|
|
105
108
|
return GetLatestEvmAssociationsRequest(netuid=netuid)
|
|
106
109
|
|
|
110
|
+
async def _get_evm_logs_request(
|
|
111
|
+
self,
|
|
112
|
+
contract_address: evm_types.Address,
|
|
113
|
+
from_block: evm_types.BlockNumber,
|
|
114
|
+
to_block: evm_types.BlockNumber,
|
|
115
|
+
abi: list[dict[str, Any]],
|
|
116
|
+
) -> GetEvmLogsRequest:
|
|
117
|
+
return GetEvmLogsRequest(
|
|
118
|
+
contract_address=contract_address,
|
|
119
|
+
from_block=from_block,
|
|
120
|
+
to_block=to_block,
|
|
121
|
+
abi=abi,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
async def _get_certificate_request(self, netuid: NetUid, hotkey: Hotkey) -> GetCertificateRequest:
|
|
125
|
+
return GetCertificateRequest(netuid=netuid, hotkey=hotkey)
|
|
126
|
+
|
|
107
127
|
|
|
108
128
|
class AsyncIdentityApi(AbstractAsyncIdentityApi):
|
|
109
129
|
api_version = ApiVersion.UNSTABLE
|
|
@@ -248,3 +268,10 @@ class AsyncIdentityApi(AbstractAsyncIdentityApi):
|
|
|
248
268
|
|
|
249
269
|
async def _get_latest_evm_associations_request(self) -> GetLatestEvmAssociationsRequest:
|
|
250
270
|
return GetLatestEvmAssociationsRequest(netuid=self.netuid, identity_name=self.identity_name)
|
|
271
|
+
|
|
272
|
+
async def _get_certificate_request(self, hotkey: Hotkey) -> GetCertificateRequest:
|
|
273
|
+
return GetCertificateRequest(
|
|
274
|
+
netuid=self.netuid,
|
|
275
|
+
identity_name=self.identity_name,
|
|
276
|
+
hotkey=hotkey,
|
|
277
|
+
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import cast
|
|
1
|
+
from typing import Any, cast
|
|
2
2
|
|
|
3
3
|
from pylon_client._internal.api.abstract_sync import (
|
|
4
4
|
AbstractIdentityApi,
|
|
@@ -6,9 +6,11 @@ from pylon_client._internal.api.abstract_sync import (
|
|
|
6
6
|
)
|
|
7
7
|
from pylon_client._internal.pylon_commons._unstable.requests import (
|
|
8
8
|
GetAllRevealedCommitmentsRequest,
|
|
9
|
+
GetCertificateRequest,
|
|
9
10
|
GetCommitmentRequest,
|
|
10
11
|
GetCommitmentsRequest,
|
|
11
12
|
GetDrandLastStoredRoundRequest,
|
|
13
|
+
GetEvmLogsRequest,
|
|
12
14
|
GetExtrinsicRequest,
|
|
13
15
|
GetIdentitiesRequest,
|
|
14
16
|
GetLatestBlockInfoRequest,
|
|
@@ -43,6 +45,7 @@ from pylon_client._internal.pylon_commons.types import (
|
|
|
43
45
|
RevealedCommitmentData,
|
|
44
46
|
Weight,
|
|
45
47
|
)
|
|
48
|
+
from pylon_client._internal.pylon_commons.types import evm as evm_types
|
|
46
49
|
|
|
47
50
|
|
|
48
51
|
class OpenAccessApi(AbstractOpenAccessApi):
|
|
@@ -102,6 +105,23 @@ class OpenAccessApi(AbstractOpenAccessApi):
|
|
|
102
105
|
def _get_latest_evm_associations_request(self, netuid: NetUid) -> GetLatestEvmAssociationsRequest:
|
|
103
106
|
return GetLatestEvmAssociationsRequest(netuid=netuid)
|
|
104
107
|
|
|
108
|
+
def _get_evm_logs_request(
|
|
109
|
+
self,
|
|
110
|
+
contract_address: evm_types.Address,
|
|
111
|
+
from_block: evm_types.BlockNumber,
|
|
112
|
+
to_block: evm_types.BlockNumber,
|
|
113
|
+
abi: list[dict[str, Any]],
|
|
114
|
+
) -> GetEvmLogsRequest:
|
|
115
|
+
return GetEvmLogsRequest(
|
|
116
|
+
contract_address=contract_address,
|
|
117
|
+
from_block=from_block,
|
|
118
|
+
to_block=to_block,
|
|
119
|
+
abi=abi,
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
def _get_certificate_request(self, netuid: NetUid, hotkey: Hotkey) -> GetCertificateRequest:
|
|
123
|
+
return GetCertificateRequest(netuid=netuid, hotkey=hotkey)
|
|
124
|
+
|
|
105
125
|
|
|
106
126
|
class IdentityApi(AbstractIdentityApi):
|
|
107
127
|
api_version = ApiVersion.UNSTABLE
|
|
@@ -242,3 +262,10 @@ class IdentityApi(AbstractIdentityApi):
|
|
|
242
262
|
|
|
243
263
|
def _get_latest_evm_associations_request(self) -> GetLatestEvmAssociationsRequest:
|
|
244
264
|
return GetLatestEvmAssociationsRequest(netuid=self.netuid, identity_name=self.identity_name)
|
|
265
|
+
|
|
266
|
+
def _get_certificate_request(self, hotkey: Hotkey) -> GetCertificateRequest:
|
|
267
|
+
return GetCertificateRequest(
|
|
268
|
+
netuid=self.netuid,
|
|
269
|
+
identity_name=self.identity_name,
|
|
270
|
+
hotkey=hotkey,
|
|
271
|
+
)
|
|
@@ -8,9 +8,11 @@ from pylon_client._internal.pylon_commons._unstable.endpoints import Endpoint as
|
|
|
8
8
|
from pylon_client._internal.pylon_commons._unstable.requests import (
|
|
9
9
|
AuthenticatedPylonRequest,
|
|
10
10
|
GetAllRevealedCommitmentsRequest,
|
|
11
|
+
GetCertificateRequest,
|
|
11
12
|
GetCommitmentRequest,
|
|
12
13
|
GetCommitmentsRequest,
|
|
13
14
|
GetDrandLastStoredRoundRequest,
|
|
15
|
+
GetEvmLogsRequest,
|
|
14
16
|
GetExtrinsicRequest,
|
|
15
17
|
GetIdentitiesRequest,
|
|
16
18
|
GetLatestBlockInfoRequest,
|
|
@@ -68,7 +70,7 @@ class HttpTranslator(AbstractRequestTranslator[Request, HttpCommunicatorT]):
|
|
|
68
70
|
identity_name_=request.identity_name,
|
|
69
71
|
**request.model_dump(exclude={"netuid", "identity_name"}),
|
|
70
72
|
)
|
|
71
|
-
return endpoint.absolute_url(**request.model_dump())
|
|
73
|
+
return endpoint.absolute_url(is_public_=True, **request.model_dump())
|
|
72
74
|
|
|
73
75
|
def _translate_get_neurons(self, request: GetNeuronsRequest, communicator: HttpCommunicatorT) -> Request:
|
|
74
76
|
url = self._build_url(self._endpoint_cls.NEURONS, request)
|
|
@@ -265,3 +267,21 @@ class HttpTranslator(AbstractRequestTranslator[Request, HttpCommunicatorT]):
|
|
|
265
267
|
return communicator.raw_client.build_request(
|
|
266
268
|
method=self._endpoint_cls.LATEST_EVM_ASSOCIATIONS.method, url=url, headers=headers
|
|
267
269
|
)
|
|
270
|
+
|
|
271
|
+
def _translate_get_evm_logs(self, request: GetEvmLogsRequest, communicator: HttpCommunicatorT) -> Request:
|
|
272
|
+
url = self._endpoint_cls.EVM_LOGS.absolute_url(contract_address=request.contract_address)
|
|
273
|
+
headers = self._get_auth_headers(request, communicator)
|
|
274
|
+
return communicator.raw_client.build_request(
|
|
275
|
+
method=self._endpoint_cls.EVM_LOGS.method,
|
|
276
|
+
url=url,
|
|
277
|
+
headers=headers,
|
|
278
|
+
params={"from_block": request.from_block, "to_block": request.to_block},
|
|
279
|
+
json=request.model_dump(include={"abi"}),
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
def _translate_get_certificate(self, request: GetCertificateRequest, communicator: HttpCommunicatorT) -> Request:
|
|
283
|
+
url = self._build_url(self._endpoint_cls.CERTIFICATES_HOTKEY, request)
|
|
284
|
+
headers = self._get_auth_headers(request, communicator)
|
|
285
|
+
return communicator.raw_client.build_request(
|
|
286
|
+
method=self._endpoint_cls.CERTIFICATES_HOTKEY.method, url=url, headers=headers
|
|
287
|
+
)
|
|
@@ -2,14 +2,17 @@ import asyncio
|
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
3
|
from collections.abc import Awaitable, Callable
|
|
4
4
|
from functools import partial
|
|
5
|
-
from typing import TypeVar
|
|
5
|
+
from typing import Any, TypeVar
|
|
6
6
|
|
|
7
7
|
from pylon_client._internal.client.asynchronous.communicators import AbstractAsyncCommunicator
|
|
8
|
+
from pylon_client._internal.file_backed_neurons import load_file_backed_neurons
|
|
8
9
|
from pylon_client._internal.pylon_commons._unstable.requests import (
|
|
9
10
|
GetAllRevealedCommitmentsRequest,
|
|
11
|
+
GetCertificateRequest,
|
|
10
12
|
GetCommitmentRequest,
|
|
11
13
|
GetCommitmentsRequest,
|
|
12
14
|
GetDrandLastStoredRoundRequest,
|
|
15
|
+
GetEvmLogsRequest,
|
|
13
16
|
GetExtrinsicRequest,
|
|
14
17
|
GetLatestBlockInfoRequest,
|
|
15
18
|
GetLatestEvmAssociationsRequest,
|
|
@@ -33,9 +36,11 @@ from pylon_client._internal.pylon_commons._unstable.requests import (
|
|
|
33
36
|
)
|
|
34
37
|
from pylon_client._internal.pylon_commons._unstable.responses import (
|
|
35
38
|
GetAllRevealedCommitmentsResponse,
|
|
39
|
+
GetCertificateResponse,
|
|
36
40
|
GetCommitmentResponse,
|
|
37
41
|
GetCommitmentsResponse,
|
|
38
42
|
GetDrandLastStoredRoundResponse,
|
|
43
|
+
GetEvmLogsResponse,
|
|
39
44
|
GetExtrinsicResponse,
|
|
40
45
|
GetLatestBlockInfoResponse,
|
|
41
46
|
GetLatestEvmAssociationsResponse,
|
|
@@ -66,6 +71,7 @@ from pylon_client._internal.pylon_commons.types import (
|
|
|
66
71
|
NetUid,
|
|
67
72
|
Weight,
|
|
68
73
|
)
|
|
74
|
+
from pylon_client._internal.pylon_commons.types import evm as evm_types
|
|
69
75
|
|
|
70
76
|
ResponseT = TypeVar("ResponseT", bound=PylonResponse)
|
|
71
77
|
|
|
@@ -93,6 +99,16 @@ class AbstractAsyncApi(ABC):
|
|
|
93
99
|
request.api_version = self.api_version
|
|
94
100
|
return await self._communicator.request(request)
|
|
95
101
|
|
|
102
|
+
def _file_backed_neurons(self) -> GetNeuronsResponse | None:
|
|
103
|
+
"""
|
|
104
|
+
Returns neurons loaded from the configured local `neurons_file` for local development,
|
|
105
|
+
or None when no `neurons_file` is set (i.e. the call should hit the live service).
|
|
106
|
+
"""
|
|
107
|
+
neurons_file = self._communicator.config.neurons_file
|
|
108
|
+
if neurons_file:
|
|
109
|
+
return load_file_backed_neurons(neurons_file)
|
|
110
|
+
return None
|
|
111
|
+
|
|
96
112
|
|
|
97
113
|
class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
98
114
|
"""
|
|
@@ -135,6 +151,8 @@ class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
|
135
151
|
GetNeuronsResponse: containing the latest block information and a dictionary mapping hotkeys to
|
|
136
152
|
Neuron objects.
|
|
137
153
|
"""
|
|
154
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
155
|
+
return file_backed
|
|
138
156
|
return await self._send_request(await self._get_latest_neurons_request(netuid))
|
|
139
157
|
|
|
140
158
|
async def get_recent_neurons(self, netuid: NetUid) -> GetNeuronsResponse:
|
|
@@ -158,6 +176,8 @@ class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
|
158
176
|
- The requested subnet is not of one of the configured identities or is not configured
|
|
159
177
|
for caching recent data via `PYLON_RECENT_OBJECTS_NETUIDS` config variable.
|
|
160
178
|
"""
|
|
179
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
180
|
+
return file_backed
|
|
161
181
|
return await self._send_request(await self._get_recent_neurons_request(netuid))
|
|
162
182
|
|
|
163
183
|
async def get_commitments(self, netuid: NetUid) -> GetCommitmentsResponse:
|
|
@@ -245,6 +265,22 @@ class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
|
245
265
|
"""
|
|
246
266
|
return await self._send_request(await self._get_latest_validators_request(netuid))
|
|
247
267
|
|
|
268
|
+
async def get_certificate(self, netuid: NetUid, hotkey: Hotkey) -> GetCertificateResponse:
|
|
269
|
+
"""
|
|
270
|
+
Retrieves the certificate for a specific hotkey in a subnet at the latest available block.
|
|
271
|
+
|
|
272
|
+
Args:
|
|
273
|
+
netuid: The unique identifier of the subnet.
|
|
274
|
+
hotkey: The hotkey to retrieve the certificate for.
|
|
275
|
+
|
|
276
|
+
Returns:
|
|
277
|
+
GetCertificateResponse: containing the certificate's algorithm and public key.
|
|
278
|
+
|
|
279
|
+
Raises:
|
|
280
|
+
PylonNotFound: If a certificate could not be found.
|
|
281
|
+
"""
|
|
282
|
+
return await self._send_request(await self._get_certificate_request(netuid, hotkey))
|
|
283
|
+
|
|
248
284
|
async def get_latest_block_info(self) -> GetLatestBlockInfoResponse:
|
|
249
285
|
"""
|
|
250
286
|
Retrieves the latest block information from the chain.
|
|
@@ -315,6 +351,27 @@ class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
|
315
351
|
"""
|
|
316
352
|
return await self._send_request(await self._get_latest_evm_associations_request(netuid))
|
|
317
353
|
|
|
354
|
+
async def get_evm_logs(
|
|
355
|
+
self,
|
|
356
|
+
contract_address: evm_types.Address,
|
|
357
|
+
from_block: evm_types.BlockNumber,
|
|
358
|
+
to_block: evm_types.BlockNumber,
|
|
359
|
+
abi: list[dict[str, Any]],
|
|
360
|
+
) -> GetEvmLogsResponse:
|
|
361
|
+
"""
|
|
362
|
+
Retrieves decoded EVM contract logs for a given address and block range.
|
|
363
|
+
|
|
364
|
+
Args:
|
|
365
|
+
contract_address: The EVM contract address to query logs for.
|
|
366
|
+
from_block: The starting block number (inclusive).
|
|
367
|
+
to_block: The ending block number (inclusive).
|
|
368
|
+
abi: The contract ABI as a list of dicts, used to decode event logs.
|
|
369
|
+
|
|
370
|
+
Returns:
|
|
371
|
+
GetEvmLogsResponse: containing the decoded logs and the queried block range.
|
|
372
|
+
"""
|
|
373
|
+
return await self._send_request(await self._get_evm_logs_request(contract_address, from_block, to_block, abi))
|
|
374
|
+
|
|
318
375
|
# Private API
|
|
319
376
|
|
|
320
377
|
@abstractmethod
|
|
@@ -372,6 +429,18 @@ class AbstractAsyncOpenAccessApi(AbstractAsyncApi, ABC):
|
|
|
372
429
|
@abstractmethod
|
|
373
430
|
async def _get_latest_evm_associations_request(self, netuid: NetUid) -> GetLatestEvmAssociationsRequest: ...
|
|
374
431
|
|
|
432
|
+
@abstractmethod
|
|
433
|
+
async def _get_evm_logs_request(
|
|
434
|
+
self,
|
|
435
|
+
contract_address: evm_types.Address,
|
|
436
|
+
from_block: evm_types.BlockNumber,
|
|
437
|
+
to_block: evm_types.BlockNumber,
|
|
438
|
+
abi: list[dict[str, Any]],
|
|
439
|
+
) -> GetEvmLogsRequest: ...
|
|
440
|
+
|
|
441
|
+
@abstractmethod
|
|
442
|
+
async def _get_certificate_request(self, netuid: NetUid, hotkey: Hotkey) -> GetCertificateRequest: ...
|
|
443
|
+
|
|
375
444
|
|
|
376
445
|
class AbstractAsyncIdentityApi(AbstractAsyncApi, ABC):
|
|
377
446
|
"""
|
|
@@ -459,6 +528,8 @@ class AbstractAsyncIdentityApi(AbstractAsyncApi, ABC):
|
|
|
459
528
|
GetNeuronsResponse containing the latest block information and a dictionary mapping hotkeys to
|
|
460
529
|
Neuron objects.
|
|
461
530
|
"""
|
|
531
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
532
|
+
return file_backed
|
|
462
533
|
return await self._send_identity_request(self._get_latest_neurons_request)
|
|
463
534
|
|
|
464
535
|
async def get_recent_neurons(self) -> GetNeuronsResponse:
|
|
@@ -476,6 +547,8 @@ class AbstractAsyncIdentityApi(AbstractAsyncApi, ABC):
|
|
|
476
547
|
Raises:
|
|
477
548
|
PylonResponseException: When the Pylon service cache doesn't have fresh enough data.
|
|
478
549
|
"""
|
|
550
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
551
|
+
return file_backed
|
|
479
552
|
return await self._send_identity_request(self._get_recent_neurons_request)
|
|
480
553
|
|
|
481
554
|
async def put_weights(
|
|
@@ -632,6 +705,21 @@ class AbstractAsyncIdentityApi(AbstractAsyncApi, ABC):
|
|
|
632
705
|
"""
|
|
633
706
|
return await self._send_identity_request(self._get_latest_validators_request)
|
|
634
707
|
|
|
708
|
+
async def get_certificate(self, hotkey: Hotkey) -> GetCertificateResponse:
|
|
709
|
+
"""
|
|
710
|
+
Retrieves the certificate for a specific hotkey in the authenticated identity's subnet.
|
|
711
|
+
|
|
712
|
+
Args:
|
|
713
|
+
hotkey: The hotkey to retrieve the certificate for.
|
|
714
|
+
|
|
715
|
+
Returns:
|
|
716
|
+
GetCertificateResponse: containing the certificate's algorithm and public key.
|
|
717
|
+
|
|
718
|
+
Raises:
|
|
719
|
+
PylonNotFound: If a certificate could not be found.
|
|
720
|
+
"""
|
|
721
|
+
return await self._send_identity_request(partial(self._get_certificate_request, hotkey))
|
|
722
|
+
|
|
635
723
|
async def get_latest_block_info(self) -> GetLatestBlockInfoResponse:
|
|
636
724
|
"""
|
|
637
725
|
Retrieves the latest block information from the chain.
|
|
@@ -782,3 +870,6 @@ class AbstractAsyncIdentityApi(AbstractAsyncApi, ABC):
|
|
|
782
870
|
|
|
783
871
|
@abstractmethod
|
|
784
872
|
async def _get_latest_evm_associations_request(self) -> GetLatestEvmAssociationsRequest: ...
|
|
873
|
+
|
|
874
|
+
@abstractmethod
|
|
875
|
+
async def _get_certificate_request(self, hotkey: Hotkey) -> GetCertificateRequest: ...
|
|
@@ -2,14 +2,17 @@ import threading
|
|
|
2
2
|
from abc import ABC, abstractmethod
|
|
3
3
|
from collections.abc import Callable
|
|
4
4
|
from functools import partial
|
|
5
|
-
from typing import TypeVar
|
|
5
|
+
from typing import Any, TypeVar
|
|
6
6
|
|
|
7
7
|
from pylon_client._internal.client.sync.communicators import AbstractCommunicator
|
|
8
|
+
from pylon_client._internal.file_backed_neurons import load_file_backed_neurons
|
|
8
9
|
from pylon_client._internal.pylon_commons._unstable.requests import (
|
|
9
10
|
GetAllRevealedCommitmentsRequest,
|
|
11
|
+
GetCertificateRequest,
|
|
10
12
|
GetCommitmentRequest,
|
|
11
13
|
GetCommitmentsRequest,
|
|
12
14
|
GetDrandLastStoredRoundRequest,
|
|
15
|
+
GetEvmLogsRequest,
|
|
13
16
|
GetExtrinsicRequest,
|
|
14
17
|
GetLatestBlockInfoRequest,
|
|
15
18
|
GetLatestEvmAssociationsRequest,
|
|
@@ -33,9 +36,11 @@ from pylon_client._internal.pylon_commons._unstable.requests import (
|
|
|
33
36
|
)
|
|
34
37
|
from pylon_client._internal.pylon_commons._unstable.responses import (
|
|
35
38
|
GetAllRevealedCommitmentsResponse,
|
|
39
|
+
GetCertificateResponse,
|
|
36
40
|
GetCommitmentResponse,
|
|
37
41
|
GetCommitmentsResponse,
|
|
38
42
|
GetDrandLastStoredRoundResponse,
|
|
43
|
+
GetEvmLogsResponse,
|
|
39
44
|
GetExtrinsicResponse,
|
|
40
45
|
GetLatestBlockInfoResponse,
|
|
41
46
|
GetLatestEvmAssociationsResponse,
|
|
@@ -66,6 +71,7 @@ from pylon_client._internal.pylon_commons.types import (
|
|
|
66
71
|
NetUid,
|
|
67
72
|
Weight,
|
|
68
73
|
)
|
|
74
|
+
from pylon_client._internal.pylon_commons.types import evm as evm_types
|
|
69
75
|
|
|
70
76
|
ResponseT = TypeVar("ResponseT", bound=PylonResponse)
|
|
71
77
|
|
|
@@ -93,6 +99,16 @@ class AbstractApi(ABC):
|
|
|
93
99
|
request.api_version = self.api_version
|
|
94
100
|
return self._communicator.request(request)
|
|
95
101
|
|
|
102
|
+
def _file_backed_neurons(self) -> GetNeuronsResponse | None:
|
|
103
|
+
"""
|
|
104
|
+
Returns neurons loaded from the configured local `neurons_file` for local development,
|
|
105
|
+
or None when no `neurons_file` is set (i.e. the call should hit the live service).
|
|
106
|
+
"""
|
|
107
|
+
neurons_file = self._communicator.config.neurons_file
|
|
108
|
+
if neurons_file:
|
|
109
|
+
return load_file_backed_neurons(neurons_file)
|
|
110
|
+
return None
|
|
111
|
+
|
|
96
112
|
|
|
97
113
|
class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
98
114
|
"""
|
|
@@ -135,6 +151,8 @@ class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
|
135
151
|
GetNeuronsResponse: containing the latest block information and a dictionary mapping hotkeys to
|
|
136
152
|
Neuron objects.
|
|
137
153
|
"""
|
|
154
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
155
|
+
return file_backed
|
|
138
156
|
return self._send_request(self._get_latest_neurons_request(netuid))
|
|
139
157
|
|
|
140
158
|
def get_recent_neurons(self, netuid: NetUid) -> GetNeuronsResponse:
|
|
@@ -158,6 +176,8 @@ class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
|
158
176
|
- The requested subnet is not of one of the configured identities or is not configured
|
|
159
177
|
for caching recent data via `PYLON_RECENT_OBJECTS_NETUIDS` config variable.
|
|
160
178
|
"""
|
|
179
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
180
|
+
return file_backed
|
|
161
181
|
return self._send_request(self._get_recent_neurons_request(netuid))
|
|
162
182
|
|
|
163
183
|
def get_commitments(self, netuid: NetUid) -> GetCommitmentsResponse:
|
|
@@ -244,6 +264,22 @@ class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
|
244
264
|
"""
|
|
245
265
|
return self._send_request(self._get_latest_validators_request(netuid))
|
|
246
266
|
|
|
267
|
+
def get_certificate(self, netuid: NetUid, hotkey: Hotkey) -> GetCertificateResponse:
|
|
268
|
+
"""
|
|
269
|
+
Retrieves the certificate for a specific hotkey in a subnet at the latest available block.
|
|
270
|
+
|
|
271
|
+
Args:
|
|
272
|
+
netuid: The unique identifier of the subnet.
|
|
273
|
+
hotkey: The hotkey to retrieve the certificate for.
|
|
274
|
+
|
|
275
|
+
Returns:
|
|
276
|
+
GetCertificateResponse: containing the certificate's algorithm and public key.
|
|
277
|
+
|
|
278
|
+
Raises:
|
|
279
|
+
PylonNotFound: If a certificate could not be found.
|
|
280
|
+
"""
|
|
281
|
+
return self._send_request(self._get_certificate_request(netuid, hotkey))
|
|
282
|
+
|
|
247
283
|
def get_latest_block_info(self) -> GetLatestBlockInfoResponse:
|
|
248
284
|
"""
|
|
249
285
|
Retrieves the latest block information from the chain.
|
|
@@ -314,6 +350,27 @@ class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
|
314
350
|
"""
|
|
315
351
|
return self._send_request(self._get_latest_evm_associations_request(netuid))
|
|
316
352
|
|
|
353
|
+
def get_evm_logs(
|
|
354
|
+
self,
|
|
355
|
+
contract_address: evm_types.Address,
|
|
356
|
+
from_block: evm_types.BlockNumber,
|
|
357
|
+
to_block: evm_types.BlockNumber,
|
|
358
|
+
abi: list[dict[str, Any]],
|
|
359
|
+
) -> GetEvmLogsResponse:
|
|
360
|
+
"""
|
|
361
|
+
Retrieves decoded EVM contract logs for a given address and block range.
|
|
362
|
+
|
|
363
|
+
Args:
|
|
364
|
+
contract_address: The EVM contract address to query logs for.
|
|
365
|
+
from_block: The starting block number (inclusive).
|
|
366
|
+
to_block: The ending block number (inclusive).
|
|
367
|
+
abi: The contract ABI as a list of dicts, used to decode event logs.
|
|
368
|
+
|
|
369
|
+
Returns:
|
|
370
|
+
GetEvmLogsResponse: containing the decoded logs and the queried block range.
|
|
371
|
+
"""
|
|
372
|
+
return self._send_request(self._get_evm_logs_request(contract_address, from_block, to_block, abi))
|
|
373
|
+
|
|
317
374
|
# Private API
|
|
318
375
|
|
|
319
376
|
@abstractmethod
|
|
@@ -369,6 +426,18 @@ class AbstractOpenAccessApi(AbstractApi, ABC):
|
|
|
369
426
|
@abstractmethod
|
|
370
427
|
def _get_latest_evm_associations_request(self, netuid: NetUid) -> GetLatestEvmAssociationsRequest: ...
|
|
371
428
|
|
|
429
|
+
@abstractmethod
|
|
430
|
+
def _get_evm_logs_request(
|
|
431
|
+
self,
|
|
432
|
+
contract_address: evm_types.Address,
|
|
433
|
+
from_block: evm_types.BlockNumber,
|
|
434
|
+
to_block: evm_types.BlockNumber,
|
|
435
|
+
abi: list[dict[str, Any]],
|
|
436
|
+
) -> GetEvmLogsRequest: ...
|
|
437
|
+
|
|
438
|
+
@abstractmethod
|
|
439
|
+
def _get_certificate_request(self, netuid: NetUid, hotkey: Hotkey) -> GetCertificateRequest: ...
|
|
440
|
+
|
|
372
441
|
|
|
373
442
|
class AbstractIdentityApi(AbstractApi, ABC):
|
|
374
443
|
"""
|
|
@@ -454,6 +523,8 @@ class AbstractIdentityApi(AbstractApi, ABC):
|
|
|
454
523
|
GetNeuronsResponse containing the latest block information and a dictionary mapping hotkeys to
|
|
455
524
|
Neuron objects.
|
|
456
525
|
"""
|
|
526
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
527
|
+
return file_backed
|
|
457
528
|
return self._send_identity_request(self._get_latest_neurons_request)
|
|
458
529
|
|
|
459
530
|
def get_recent_neurons(self) -> GetNeuronsResponse:
|
|
@@ -471,6 +542,8 @@ class AbstractIdentityApi(AbstractApi, ABC):
|
|
|
471
542
|
Raises:
|
|
472
543
|
PylonResponseException: When the Pylon service cache doesn't have fresh enough data.
|
|
473
544
|
"""
|
|
545
|
+
if (file_backed := self._file_backed_neurons()) is not None:
|
|
546
|
+
return file_backed
|
|
474
547
|
return self._send_identity_request(self._get_recent_neurons_request)
|
|
475
548
|
|
|
476
549
|
def put_weights(
|
|
@@ -631,6 +704,21 @@ class AbstractIdentityApi(AbstractApi, ABC):
|
|
|
631
704
|
"""
|
|
632
705
|
return self._send_identity_request(self._get_latest_validators_request)
|
|
633
706
|
|
|
707
|
+
def get_certificate(self, hotkey: Hotkey) -> GetCertificateResponse:
|
|
708
|
+
"""
|
|
709
|
+
Retrieves the certificate for a specific hotkey in the authenticated identity's subnet.
|
|
710
|
+
|
|
711
|
+
Args:
|
|
712
|
+
hotkey: The hotkey to retrieve the certificate for.
|
|
713
|
+
|
|
714
|
+
Returns:
|
|
715
|
+
GetCertificateResponse: containing the certificate's algorithm and public key.
|
|
716
|
+
|
|
717
|
+
Raises:
|
|
718
|
+
PylonNotFound: If a certificate could not be found.
|
|
719
|
+
"""
|
|
720
|
+
return self._send_identity_request(partial(self._get_certificate_request, hotkey))
|
|
721
|
+
|
|
634
722
|
def get_latest_block_info(self) -> GetLatestBlockInfoResponse:
|
|
635
723
|
"""
|
|
636
724
|
Retrieves the latest block information from the chain.
|
|
@@ -777,3 +865,6 @@ class AbstractIdentityApi(AbstractApi, ABC):
|
|
|
777
865
|
|
|
778
866
|
@abstractmethod
|
|
779
867
|
def _get_latest_evm_associations_request(self) -> GetLatestEvmAssociationsRequest: ...
|
|
868
|
+
|
|
869
|
+
@abstractmethod
|
|
870
|
+
def _get_certificate_request(self, hotkey: Hotkey) -> GetCertificateRequest: ...
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import logging
|
|
2
2
|
import warnings
|
|
3
3
|
from abc import ABC
|
|
4
|
+
from collections.abc import AsyncIterator
|
|
5
|
+
from contextlib import asynccontextmanager
|
|
4
6
|
from typing import Generic, TypeVar
|
|
5
7
|
|
|
8
|
+
from httpx import AsyncClient
|
|
9
|
+
|
|
6
10
|
from pylon_client._internal.api._unstable.asynchronous.api import AsyncIdentityApi as UnstableAsyncIdentityApi
|
|
7
11
|
from pylon_client._internal.api._unstable.asynchronous.api import AsyncOpenAccessApi as UnstableAsyncOpenAccessApi
|
|
8
12
|
from pylon_client._internal.api.abstract_async import (
|
|
@@ -13,6 +17,9 @@ from pylon_client._internal.api.v1.asynchronous.api import AsyncIdentityApi, Asy
|
|
|
13
17
|
from pylon_client._internal.client.asynchronous.communicators import AbstractAsyncCommunicator, AsyncHttpCommunicator
|
|
14
18
|
from pylon_client._internal.client.asynchronous.config import AsyncConfig
|
|
15
19
|
from pylon_client._internal.client.namespace import ClientNamespace
|
|
20
|
+
from pylon_client._internal.client.neuron_client import AsyncNeuronClientManager
|
|
21
|
+
from pylon_client._internal.pylon_commons.v1.models import Neuron
|
|
22
|
+
from pylon_client.exceptions import MtlsVerificationError
|
|
16
23
|
|
|
17
24
|
CommunicatorT = TypeVar("CommunicatorT", bound=AbstractAsyncCommunicator)
|
|
18
25
|
|
|
@@ -45,6 +52,12 @@ class AbstractAsyncPylonClient(Generic[CommunicatorT], ABC):
|
|
|
45
52
|
def __init__(self, config: AsyncConfig):
|
|
46
53
|
self.config = config
|
|
47
54
|
self._communicator = self._communicator_cls(config)
|
|
55
|
+
self._neuron_client_manager = AsyncNeuronClientManager(
|
|
56
|
+
config.neuron_keepalive_expiry,
|
|
57
|
+
config.mtls_cert_path,
|
|
58
|
+
config.mtls_key_path,
|
|
59
|
+
config.neurons_file,
|
|
60
|
+
)
|
|
48
61
|
|
|
49
62
|
self.v1 = ClientNamespace(
|
|
50
63
|
open_access_cls=AsyncOpenAccessApi,
|
|
@@ -85,6 +98,61 @@ class AbstractAsyncPylonClient(Generic[CommunicatorT], ABC):
|
|
|
85
98
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
86
99
|
await self.close()
|
|
87
100
|
|
|
101
|
+
@asynccontextmanager
|
|
102
|
+
async def get_neuron_client(
|
|
103
|
+
self,
|
|
104
|
+
neuron: Neuron,
|
|
105
|
+
timeout: float = 30.0,
|
|
106
|
+
) -> AsyncIterator[AsyncClient]:
|
|
107
|
+
"""
|
|
108
|
+
Async context manager that yields a configured ``AsyncClient`` for communicating with a miner.
|
|
109
|
+
|
|
110
|
+
The client (and its underlying connection pool) is cached by ``(ip, port)`` for the
|
|
111
|
+
lifetime of this pylon client. The ``timeout`` argument only takes effect on the first
|
|
112
|
+
call for a given miner; subsequent calls reuse the cached client and its baked-in timeout.
|
|
113
|
+
|
|
114
|
+
Uses mTLS when ``mtls_cert_path``/``mtls_key_path`` are set in the client config,
|
|
115
|
+
verifying the miner's certificate against the Pylon registry. Falls back
|
|
116
|
+
to plain HTTP when cert/key are absent or ``neurons_file`` is set.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
neuron: The miner to query; host, port, and hotkey are extracted from it.
|
|
120
|
+
timeout: Seconds to wait for the raw TLS probe and for the yielded client's requests
|
|
121
|
+
(default 30.0). Only applied on the first call for a given ``(ip, port)`` pair.
|
|
122
|
+
|
|
123
|
+
Yields:
|
|
124
|
+
AsyncClient: Configured for either plain HTTP or mTLS.
|
|
125
|
+
|
|
126
|
+
Raises:
|
|
127
|
+
MtlsVerificationError: If the miner does not present a certificate, its public
|
|
128
|
+
key does not match the Pylon registry, or TLS verification fails. If raised
|
|
129
|
+
from a cached client, the cache entry is evicted so the next
|
|
130
|
+
call re-probes. Other exceptions leave the cache intact so the same client
|
|
131
|
+
is reused on the next call.
|
|
132
|
+
ConnectionRefusedError: If the raw TLS probe cannot connect to the miner.
|
|
133
|
+
TimeoutError: If the raw TLS probe times out.
|
|
134
|
+
|
|
135
|
+
Note:
|
|
136
|
+
If two tasks concurrently hold the same cached client (same neuron) and one
|
|
137
|
+
raises ``MtlsVerificationError``, the client is closed immediately via
|
|
138
|
+
``invalidate``. The other task's in-flight request on that client will fail
|
|
139
|
+
with ``RuntimeError``.
|
|
140
|
+
"""
|
|
141
|
+
ip = neuron.axon_info.ip
|
|
142
|
+
port = neuron.axon_info.port
|
|
143
|
+
neuron_client = self._neuron_client_manager.get(ip, port)
|
|
144
|
+
if neuron_client is None:
|
|
145
|
+
expected_pubkey_hex = None
|
|
146
|
+
if self._neuron_client_manager.use_mtls:
|
|
147
|
+
cert_resp = await self.v1.identity.get_certificate(neuron.hotkey)
|
|
148
|
+
expected_pubkey_hex = cert_resp.public_key
|
|
149
|
+
neuron_client = await self._neuron_client_manager.build_async(ip, port, timeout, expected_pubkey_hex)
|
|
150
|
+
try:
|
|
151
|
+
yield neuron_client
|
|
152
|
+
except MtlsVerificationError:
|
|
153
|
+
await self._neuron_client_manager.invalidate(ip, port, neuron_client)
|
|
154
|
+
raise
|
|
155
|
+
|
|
88
156
|
async def open(self) -> None:
|
|
89
157
|
"""
|
|
90
158
|
Prepares the client to work by opening the communicators.
|
|
@@ -109,6 +177,7 @@ class AbstractAsyncPylonClient(Generic[CommunicatorT], ABC):
|
|
|
109
177
|
raise ValueError("The client is already closed.")
|
|
110
178
|
logger.debug(f"Closing client for the server {self.config.address}")
|
|
111
179
|
self.is_open = False
|
|
180
|
+
await self._neuron_client_manager.aclear()
|
|
112
181
|
await self._communicator.close()
|
|
113
182
|
|
|
114
183
|
|