How upstreamdata/pyasic works
Main components
• Core Manager: At the heart of the system is the “pyasic core” which ties together network scanning, miner creation (via a factory), and control functions.
• Network Module: Represented by classes like MinerNetwork which manage asynchronous scanning of IP subnets for ASICs.
• Miner Factory: The abstraction offering methods like get_miner() (and underlying MinerFactory) that instantiates the correct miner type.
• Miner Modules: Organized under the “pyasic/miners” directory, these modules encapsulate support for various ASIC models and their vendor-specific implementations. They include subdirectories for different manufacturers (antminer, auradine, avalonminer, etc.) and backends (cgminer, bmminer, etc.).
• Communication Adapters: Modules implementing different protocols such as RPC (pyasic/rpc), SSH (pyasic/ssh), and Web (pyasic/web) that allow control commands and data gathering to be sent to the ASIC miners.
• Data & Configuration: Helper dataclasses (MinerData, MinerConfig) and associated utilities found across pyasic/config and pyasic/data that consistently represent miner status, configuration, errors, and operational metrics.
• Device & Algorithm Layers: Components within pyasic/device manage low-level interactions with the ASIC hardware and also contain mathematical/algorithmic logic (e.g., various hashing algorithm implementations).
• Settings & Logger: Global settings (pyasic/settings) to manage default credentials and timeouts plus logging facilities (pyasic/logger) to record operations.
Relationships and data flows
• User or Automated Service → Pyasic Interface:
• The library is typically invoked by a user script or service (as seen in the examples in the README) via command-line or API calls.
• Network Scanning → Miner Creation:
• The MinerNetwork class collects active ASICs on a given subnet and passes their IP addresses to the MinerFactory (via get_miner()).
• MinerFactory → Specific Miner Implementations:
• Based on IP probe responses, the factory selects the correct miner subclass (organized by type, model, and vendor) and returns a fully instantiated miner object.
• Miner Instance Operations:
• The miner object (which implements a common interface defined in BaseMiner) exposes asynchronous methods such as get_data(), get_config(), send_config(), and control functions (e.g., reboot, fault_light_on/off).
• Communication Adapters:
• Depending on the miner’s type, control commands and data are sent through appropriate channels (RPC, SSH, or HTTP/web protocols).
• Data Aggregation:
• Retrieved MinerData instances (and MinerConfig details) are used to aggregate metrics and provide a consistent interface to the client.
Important architectural patterns
• Asynchronous Programming:
• The project uses Python’s asyncio to perform non-blocking network calls and parallel data gathering from multiple ASICs.
• Factory and Abstraction:
• A factory pattern is used to create miner objects based on network discovery. All miner classes implement a common interface ensuring uniform control regardless of vendor differences.
• Modular Design and Separation of Concerns:
• Different directories clearly separate configuration, data processing, device handling, algorithms, networking, communication protocols, and documentation. This makes it straightforward to extend support for new ASIC models.
• Use of Data Classes & Helper Functions:
• Consistent data structures (via MinerData and MinerConfig) ensure that data collected from varied devices is normalized.