From 6875ef54bd28306c7890ed6a553f8f5298bfeb3d Mon Sep 17 00:00:00 2001 From: UpstreamData Date: Wed, 7 Jun 2023 15:53:07 -0600 Subject: [PATCH] feature: add Avalonminer support in update miner factory, and add support for A1166 and A1246. --- .../btc/_types/avalonminer/A11X/A1166.py | 29 ++++++++++ .../btc/_types/avalonminer/A11X/__init__.py | 18 ++++++ .../btc/_types/avalonminer/A12X/A1246.py | 29 ++++++++++ .../btc/_types/avalonminer/A12X/__init__.py | 17 ++++++ .../miners/btc/_types/avalonminer/__init__.py | 2 + .../btc/avalonminer/cgminer/A11X/A1166.py | 23 ++++++++ .../btc/avalonminer/cgminer/A11X/A11X.py | 21 +++++++ .../btc/avalonminer/cgminer/A11X/__init__.py | 17 ++++++ .../btc/avalonminer/cgminer/A12X/A1246.py | 23 ++++++++ .../btc/avalonminer/cgminer/A12X/A12X.py | 21 +++++++ .../btc/avalonminer/cgminer/A12X/__init__.py | 17 ++++++ .../btc/avalonminer/cgminer/__init__.py | 2 + pyasic/miners/miner_factory.py | 58 +++++++++++++------ 13 files changed, 258 insertions(+), 19 deletions(-) create mode 100644 pyasic/miners/btc/_types/avalonminer/A11X/A1166.py create mode 100644 pyasic/miners/btc/_types/avalonminer/A11X/__init__.py create mode 100644 pyasic/miners/btc/_types/avalonminer/A12X/A1246.py create mode 100644 pyasic/miners/btc/_types/avalonminer/A12X/__init__.py create mode 100644 pyasic/miners/btc/avalonminer/cgminer/A11X/A1166.py create mode 100644 pyasic/miners/btc/avalonminer/cgminer/A11X/A11X.py create mode 100644 pyasic/miners/btc/avalonminer/cgminer/A11X/__init__.py create mode 100644 pyasic/miners/btc/avalonminer/cgminer/A12X/A1246.py create mode 100644 pyasic/miners/btc/avalonminer/cgminer/A12X/A12X.py create mode 100644 pyasic/miners/btc/avalonminer/cgminer/A12X/__init__.py diff --git a/pyasic/miners/btc/_types/avalonminer/A11X/A1166.py b/pyasic/miners/btc/_types/avalonminer/A11X/A1166.py new file mode 100644 index 00000000..ed418da4 --- /dev/null +++ b/pyasic/miners/btc/_types/avalonminer/A11X/A1166.py @@ -0,0 +1,29 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ +import warnings + +from pyasic.miners.makes import AvalonMiner + + +class Avalon1166Pro(AvalonMiner): # noqa - ignore ABC method implementation + def __init__(self, ip: str, api_ver: str = "0.0.0"): + super().__init__(ip, api_ver) + self.ip = ip + self.model = "Avalon 1166" + warnings.warn( + f"Unknown chip count for miner type {self.model}, please open an issue on GitHub (https://github.com/UpstreamData/pyasic)." + ) + self.fan_count = 4 diff --git a/pyasic/miners/btc/_types/avalonminer/A11X/__init__.py b/pyasic/miners/btc/_types/avalonminer/A11X/__init__.py new file mode 100644 index 00000000..897a199d --- /dev/null +++ b/pyasic/miners/btc/_types/avalonminer/A11X/__init__.py @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + + +from .A1166 import Avalon1166Pro diff --git a/pyasic/miners/btc/_types/avalonminer/A12X/A1246.py b/pyasic/miners/btc/_types/avalonminer/A12X/A1246.py new file mode 100644 index 00000000..975af0fa --- /dev/null +++ b/pyasic/miners/btc/_types/avalonminer/A12X/A1246.py @@ -0,0 +1,29 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ +import warnings + +from pyasic.miners.makes import AvalonMiner + + +class Avalon1246(AvalonMiner): # noqa - ignore ABC method implementation + def __init__(self, ip: str, api_ver: str = "0.0.0"): + super().__init__(ip, api_ver) + self.ip = ip + self.model = "Avalon 1246" + warnings.warn( + f"Unknown chip count for miner type {self.model}, please open an issue on GitHub (https://github.com/UpstreamData/pyasic)." + ) + self.fan_count = 4 diff --git a/pyasic/miners/btc/_types/avalonminer/A12X/__init__.py b/pyasic/miners/btc/_types/avalonminer/A12X/__init__.py new file mode 100644 index 00000000..f2cd434e --- /dev/null +++ b/pyasic/miners/btc/_types/avalonminer/A12X/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + +from .A1246 import Avalon1246 diff --git a/pyasic/miners/btc/_types/avalonminer/__init__.py b/pyasic/miners/btc/_types/avalonminer/__init__.py index b1eb124d..8b1e4305 100644 --- a/pyasic/miners/btc/_types/avalonminer/__init__.py +++ b/pyasic/miners/btc/_types/avalonminer/__init__.py @@ -18,3 +18,5 @@ from .A7X import * from .A8X import * from .A9X import * from .A10X import * +from .A11X import * +from .A12X import * diff --git a/pyasic/miners/btc/avalonminer/cgminer/A11X/A1166.py b/pyasic/miners/btc/avalonminer/cgminer/A11X/A1166.py new file mode 100644 index 00000000..a476486b --- /dev/null +++ b/pyasic/miners/btc/avalonminer/cgminer/A11X/A1166.py @@ -0,0 +1,23 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + +from pyasic.miners.btc._types import Avalon1166Pro # noqa + +from .A11X import CGMinerA11X + + +class CGMinerAvalon1166Pro(CGMinerA11X, Avalon1166Pro): + pass diff --git a/pyasic/miners/btc/avalonminer/cgminer/A11X/A11X.py b/pyasic/miners/btc/avalonminer/cgminer/A11X/A11X.py new file mode 100644 index 00000000..640dae96 --- /dev/null +++ b/pyasic/miners/btc/avalonminer/cgminer/A11X/A11X.py @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + +from pyasic.miners.backends import CGMinerAvalon # noqa - Ignore access to _module + + +class CGMinerA11X(CGMinerAvalon): + pass diff --git a/pyasic/miners/btc/avalonminer/cgminer/A11X/__init__.py b/pyasic/miners/btc/avalonminer/cgminer/A11X/__init__.py new file mode 100644 index 00000000..391aa0a7 --- /dev/null +++ b/pyasic/miners/btc/avalonminer/cgminer/A11X/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + +from .A1166 import CGMinerAvalon1166Pro diff --git a/pyasic/miners/btc/avalonminer/cgminer/A12X/A1246.py b/pyasic/miners/btc/avalonminer/cgminer/A12X/A1246.py new file mode 100644 index 00000000..9a425bbf --- /dev/null +++ b/pyasic/miners/btc/avalonminer/cgminer/A12X/A1246.py @@ -0,0 +1,23 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + +from pyasic.miners.btc._types import Avalon1246 + +from .A12X import CGMinerA12X + + +class CGMinerAvalon1246(CGMinerA12X, Avalon1246): + pass diff --git a/pyasic/miners/btc/avalonminer/cgminer/A12X/A12X.py b/pyasic/miners/btc/avalonminer/cgminer/A12X/A12X.py new file mode 100644 index 00000000..0748bfee --- /dev/null +++ b/pyasic/miners/btc/avalonminer/cgminer/A12X/A12X.py @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + +from pyasic.miners.backends import CGMinerAvalon # noqa - Ignore access to _module + + +class CGMinerA12X(CGMinerAvalon): + pass diff --git a/pyasic/miners/btc/avalonminer/cgminer/A12X/__init__.py b/pyasic/miners/btc/avalonminer/cgminer/A12X/__init__.py new file mode 100644 index 00000000..e590883d --- /dev/null +++ b/pyasic/miners/btc/avalonminer/cgminer/A12X/__init__.py @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------------ +# Copyright 2022 Upstream Data Inc - +# - +# Licensed under the Apache License, Version 2.0 (the "License"); - +# you may not use this file except in compliance with the License. - +# You may obtain a copy of the License at - +# - +# http://www.apache.org/licenses/LICENSE-2.0 - +# - +# Unless required by applicable law or agreed to in writing, software - +# distributed under the License is distributed on an "AS IS" BASIS, - +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - +# See the License for the specific language governing permissions and - +# limitations under the License. - +# ------------------------------------------------------------------------------ + +from .A1246 import CGMinerAvalon1246 diff --git a/pyasic/miners/btc/avalonminer/cgminer/__init__.py b/pyasic/miners/btc/avalonminer/cgminer/__init__.py index b1eb124d..8b1e4305 100644 --- a/pyasic/miners/btc/avalonminer/cgminer/__init__.py +++ b/pyasic/miners/btc/avalonminer/cgminer/__init__.py @@ -18,3 +18,5 @@ from .A7X import * from .A8X import * from .A9X import * from .A10X import * +from .A11X import * +from .A12X import * diff --git a/pyasic/miners/miner_factory.py b/pyasic/miners/miner_factory.py index eef52242..ad8bc391 100644 --- a/pyasic/miners/miner_factory.py +++ b/pyasic/miners/miner_factory.py @@ -65,7 +65,7 @@ class MinerTypes(enum.Enum): MINER_CLASSES = { MinerTypes.ANTMINER: { - # None: BMMiner, + None: BMMiner, "ANTMINER DR5": CGMinerDR5, "ANTMINER D3": CGMinerD3, "ANTMINER HS3": CGMinerHS3, @@ -97,7 +97,7 @@ MINER_CLASSES = { "ANTMINER T19": BMMinerT19, }, MinerTypes.WHATSMINER: { - # None: BTMiner, + None: BTMiner, "M20V10": BTMinerM20V10, "M20SV10": BTMinerM20SV10, "M20SV20": BTMinerM20SV20, @@ -280,7 +280,7 @@ MINER_CLASSES = { "M59VH30": BTMinerM59VH30, }, MinerTypes.AVALONMINER: { - # None: CGMinerAvalon, + None: CGMinerAvalon, "AVALONMINER 721": CGMinerAvalon721, "AVALONMINER 741": CGMinerAvalon741, "AVALONMINER 761": CGMinerAvalon761, @@ -291,21 +291,23 @@ MINER_CLASSES = { "AVALONMINER 1026": CGMinerAvalon1026, "AVALONMINER 1047": CGMinerAvalon1047, "AVALONMINER 1066": CGMinerAvalon1066, + "AVALONMINER 1166PRO": CGMinerAvalon1166Pro, + "AVALONMINER 1246": CGMinerAvalon1246, }, MinerTypes.INNOSILICON: { - # None: CGMiner, + None: CGMiner, "T3H+": CGMinerInnosiliconT3HPlus, "A10X": CGMinerA10X, }, MinerTypes.GOLDSHELL: { - # None: BFGMiner, + None: BFGMiner, "GOLDSHELL CK5": BFGMinerCK5, "GOLDSHELL HS5": BFGMinerHS5, "GOLDSHELL KD5": BFGMinerKD5, "GOLDSHELL KDMAX": BFGMinerKDMax, }, MinerTypes.BRAIINS_OS: { - # None: BOSMiner, + None: BOSMiner, "ANTMINER S9": BOSMinerS9, "ANTMINER S17": BOSMinerS17, "ANTMINER S17+": BOSMinerS17Plus, @@ -322,7 +324,7 @@ MINER_CLASSES = { "ANTMINER T19": BOSMinerT19, }, MinerTypes.VNISH: { - # None: VNish, + None: VNish, "ANTMINER L3+": VnishL3Plus, "ANTMINER S19": VNishS19, "ANTMINER S19 PRO": VNishS19Pro, @@ -333,7 +335,7 @@ MINER_CLASSES = { "ANTMINER T19": VNishT19, }, MinerTypes.HIVEON: { - # None: Hiveon, + None: Hiveon, "ANTMINER T9": HiveonT9, }, } @@ -442,16 +444,6 @@ class MinerFactory: pass return None, None - async def _get_miner_socket(self, ip: str): - commands = ["devdetails", "version"] - tasks = [asyncio.create_task(self._socket_ping(ip, cmd)) for cmd in commands] - - data = await concurrent_get_first_result( - tasks, lambda x: x is not None and self._parse_socket_type(x) is not None - ) - if data is not None: - return self._parse_socket_type(data) - @staticmethod def _parse_web_type(web_text: str, web_resp: aiohttp.ClientResponse) -> MinerTypes: if web_resp.status == 401 and 'realm="antMiner' in web_resp.headers.get( @@ -468,6 +460,18 @@ class MinerFactory: return MinerTypes.GOLDSHELL if "AnthillOS" in web_text: return MinerTypes.VNISH + if "Avalon" in web_text: + return MinerTypes.AVALONMINER + + async def _get_miner_socket(self, ip: str): + commands = ["devdetails", "version"] + tasks = [asyncio.create_task(self._socket_ping(ip, cmd)) for cmd in commands] + + data = await concurrent_get_first_result( + tasks, lambda x: x is not None and self._parse_socket_type(x) is not None + ) + if data is not None: + return self._parse_socket_type(data) @staticmethod async def _socket_ping(ip: str, cmd: str) -> Optional[str]: @@ -529,6 +533,8 @@ class MinerFactory: return MinerTypes.ANTMINER if "INTCHAINS_QOMO" in upper_data: return MinerTypes.GOLDSHELL + if "AVALON" in upper_data: + return MinerTypes.AVALONMINER async def send_web_command( self, @@ -690,7 +696,7 @@ class MinerFactory: return self._select_miner_from_classes( ip=IPv4Address(ip), miner_model=miner_model, - miner_type=MinerTypes.BRAIINS_OS, + miner_type=MinerTypes.WHATSMINER, ) except (TypeError, LookupError): pass @@ -700,6 +706,20 @@ class MinerFactory: ) async def get_miner_avalonminer(self, ip: str): + sock_json_data = await self.send_api_command(ip, "version") + try: + miner_model = sock_json_data["VERSION"][0]["PROD"] + if "-" in miner_model: + miner_model = miner_model.split("-") + + return self._select_miner_from_classes( + ip=IPv4Address(ip), + miner_model=miner_model, + miner_type=MinerTypes.AVALONMINER, + ) + except (TypeError, LookupError): + pass + return self._select_miner_from_classes( ip=ip, miner_model=None, miner_type=MinerTypes.AVALONMINER )