|
14 | 14 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
15 | 15 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
16 | 16 | # DEALINGS IN THE SOFTWARE. |
17 | | -import copy |
18 | | -import uuid |
19 | | -import uvicorn |
20 | | -import bittensor.core.config as btcc |
21 | 17 | import bittensor.core.axon as btca |
22 | | -import bittensor.core.threadpool as btct |
23 | | -import bittensor.utils.networking as btun |
24 | | -import bittensor.utils.btlogging as btul |
25 | | -import bittensor_wallet.wallet as btw |
26 | | -from inspect import Signature |
27 | | -from fastapi import FastAPI, APIRouter |
28 | | -from typing import Optional, Callable, Tuple |
| 18 | +from typing import Callable, Tuple |
29 | 19 |
|
30 | 20 | from subvortex.core.core_bittensor.synapse import Synapse |
31 | 21 |
|
32 | 22 |
|
33 | 23 | class SubVortexAxon(btca.Axon): |
34 | 24 | def __init__( |
35 | 25 | self, |
36 | | - wallet: Optional["btw.Wallet"] = None, |
37 | | - config: Optional["btcc.Config"] = None, |
38 | | - port: Optional[int] = None, |
39 | | - ip: Optional[str] = None, |
40 | | - external_ip: Optional[str] = None, |
41 | | - external_port: Optional[int] = None, |
42 | | - max_workers: Optional[int] = None, |
| 26 | + *args, |
43 | 27 | blacklist_fn: Callable[[Synapse], Tuple[bool, str]] = None, |
| 28 | + **kwargs, |
44 | 29 | ): |
45 | | - """Creates a new bittensor.Axon object from passed arguments. |
| 30 | + super().__init__(*args, **kwargs) |
46 | 31 |
|
47 | | - Args: |
48 | | - config (:obj:`Optional[bittensor.core.config.Config]`): bittensor.Axon.config() |
49 | | - wallet (:obj:`Optional[bittensor_wallet.Wallet]`): bittensor wallet with hotkey and coldkeypub. |
50 | | - port (:type:`Optional[int]`): Binding port. |
51 | | - ip (:type:`Optional[str]`): Binding ip. |
52 | | - external_ip (:type:`Optional[str]`): The external ip of the server to broadcast to the network. |
53 | | - external_port (:type:`Optional[int]`): The external port of the server to broadcast to the network. |
54 | | - max_workers (:type:`Optional[int]`): Used to create the threadpool if not passed, specifies the number of active threads servicing requests. |
55 | | - """ |
56 | | - # Build and check config. |
57 | | - if config is None: |
58 | | - config = btca.Axon.config() |
59 | | - config = copy.deepcopy(config) |
60 | | - config.axon.ip = ip or config.axon.ip |
61 | | - config.axon.port = port or config.axon.port |
62 | | - config.axon.external_ip = external_ip or config.axon.external_ip |
63 | | - config.axon.external_port = external_port or config.axon.external_port |
64 | | - config.axon.max_workers = max_workers or config.axon.max_workers |
65 | | - btca.Axon.check_config(config) |
66 | | - self.config = config # type: ignore |
| 32 | + # Remove the initial ping endpoint |
| 33 | + self.router.delete("/ping") |
67 | 34 |
|
68 | | - # Get wallet or use default. |
69 | | - self.wallet = wallet or btw.Wallet(config=self.config) |
70 | | - |
71 | | - # Build axon objects. |
72 | | - self.uuid = str(uuid.uuid1()) |
73 | | - self.ip = self.config.axon.ip # type: ignore |
74 | | - self.port = self.config.axon.port # type: ignore |
75 | | - self.external_ip = ( |
76 | | - self.config.axon.external_ip # type: ignore |
77 | | - if self.config.axon.external_ip is not None # type: ignore |
78 | | - else btun.get_external_ip() |
79 | | - ) |
80 | | - self.external_port = ( |
81 | | - self.config.axon.external_port # type: ignore |
82 | | - if self.config.axon.external_port is not None # type: ignore |
83 | | - else self.config.axon.port # type: ignore |
84 | | - ) |
85 | | - self.full_address = str(self.config.axon.ip) + ":" + str(self.config.axon.port) # type: ignore |
86 | | - self.started = False |
87 | | - |
88 | | - # Build middleware |
89 | | - self.thread_pool = btct.PriorityThreadPoolExecutor( |
90 | | - max_workers=self.config.axon.max_workers # type: ignore |
91 | | - ) |
92 | | - self.nonces: dict[str, int] = {} |
93 | | - |
94 | | - # Request default functions. |
95 | | - self.forward_class_types: dict[str, list[Signature]] = {} |
96 | | - self.blacklist_fns: dict[str, Optional[Callable]] = {} |
97 | | - self.priority_fns: dict[str, Optional[Callable]] = {} |
98 | | - self.forward_fns: dict[str, Optional[Callable]] = {} |
99 | | - self.verify_fns: dict[str, Optional[Callable]] = {} |
100 | | - |
101 | | - # Instantiate FastAPI |
102 | | - self.app = FastAPI() |
103 | | - log_level = "trace" if btul.logging.__trace_on__ else "critical" |
104 | | - self.fast_config = uvicorn.Config( |
105 | | - self.app, host="0.0.0.0", port=self.config.axon.port, log_level=log_level |
106 | | - ) |
107 | | - self.fast_server = btca.FastAPIThreadedServer(config=self.fast_config) |
108 | | - self.router = APIRouter() |
109 | | - self.app.include_router(self.router) |
110 | | - |
111 | | - # Build ourselves as the middleware. |
112 | | - self.middleware_cls = btca.AxonMiddleware |
113 | | - self.app.add_middleware(self.middleware_cls, axon=self) |
114 | | - |
115 | | - # Attach default forward. |
| 35 | + # Attach new ping endpoint |
116 | 36 | def ping(r: Synapse) -> Synapse: |
117 | 37 | return r |
118 | 38 |
|
|
0 commit comments