Skip to content

cpuminer-switcher is a helper script to perform benchmarks and pool / algorithm switchs based on profitability

License

Notifications You must be signed in to change notification settings

emerzon/cmswitcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMSwitcher

CMSwitcher is a CPU mining profitability switcher that automatically benchmarks and switches between different mining algorithms based on real-time profitability calculations. It works with cpuminer-opt or cpuminer-multi.

Features

  • Automatic Benchmarking: Tests all supported algorithm combinations between miners and pools
  • Real-time Profit Switching: Monitors profitability and automatically switches to the most profitable algorithm
  • Multi-pool Support: Works with multiple mining pools simultaneously
  • Configurable Parameters: Customizable benchmark periods, profit thresholds, and session timeouts
  • Robust Error Handling: Handles network failures, miner crashes, and API issues gracefully
  • Detailed Logging: Comprehensive logging with configurable levels

Requirements

  • Python 3.7+
  • cpuminer-opt or cpuminer-multi binary
  • Internet connection for pool APIs and Bitcoin price data

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/cmswitcher.git
cd cmswitcher
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure your settings in the data/ directory:
    • config.json: General settings and thresholds
    • miners.json: Miner configurations
    • pools.json: Pool settings and credentials
    • algos.json: Algorithm name mappings

Usage

Basic Usage

python cmswitcher.py --cpuminer /path/to/cpuminer

Command Line Options

python cmswitcher.py --help

Options:
  --cpuminer PATH          Path to cpuminer binary (default: cpuminer)
  --data-dir PATH          Data directory with config files (default: ./data)
  --log-level LEVEL        Logging level: DEBUG, INFO, WARNING, ERROR (default: INFO)
  --log-file PATH          Log to file (optional)
  --benchmark-only         Run benchmarks only, don't start mining
  --force-benchmark        Force re-run all benchmarks

Examples

# Run with specific cpuminer binary
python cmswitcher.py --cpuminer "C:/miners/cpuminer-avx2.exe"

# Run with debug logging
python cmswitcher.py --cpuminer cpuminer --log-level DEBUG

# Benchmark only mode
python cmswitcher.py --cpuminer cpuminer --benchmark-only

# Force re-benchmark all algorithms
python cmswitcher.py --cpuminer cpuminer --force-benchmark

Configuration

config.json

{
    "benchmark_period": 120,              # Benchmark duration in seconds
    "complete_benchmark_min_shares": 100, # Minimum shares for valid benchmark
    "give_up_benchmark_low_profit_secs": 30, # Give up on unprofitable algos
    "min_profit": 0.05,                  # Minimum profit threshold (USD/day)
    "max_rejected_shares": 2,            # Max rejected shares during benchmark
    "session_timeout": 600,              # Mining session duration in seconds
    "blacklisted_algos": ["sha256", "scrypt"] # Algorithms to skip
}

pools.json

{
    "zergpool": {
        "wallet": "YOUR_BTC_ADDRESS",
        "password": "c=BTC",
        "mine_url": "stratum+tcp://{algo}.mine.zergpool.com",
        "api": "https://api.zergpool.com/api/status"
    }
}

miners.json

{
    "cpuminer-opt": {
        "launch_pattern": "-o {url}:{port} -u {wallet} -p {password} --api-bind={API_HOST}:{API_PORT}",
        "offline_bench": "--benchmark",
        "std_algos": ["yescrypt", "yespower", "argon2d"],
        "custom_algos": {}
    }
}

Architecture

The application is organized into modular components:

  • cmswitcher/config.py: Configuration management
  • cmswitcher/models.py: Data models (Miner, Pool, BenchmarkResult)
  • cmswitcher/api_client.py: cpuminer API communication
  • cmswitcher/pool_api.py: Pool API interaction
  • cmswitcher/benchmark.py: Benchmarking logic
  • cmswitcher/profit.py: Profitability calculations
  • cmswitcher/mining_session.py: Mining process management
  • cmswitcher/main.py: Application orchestration

How It Works

  1. Initialization: Loads configuration and discovers supported algorithms
  2. Benchmarking: Tests each algorithm to determine hashrates
  3. Profit Calculation: Fetches current pool rates and Bitcoin price
  4. Mining Loop:
    • Finds most profitable algorithm
    • Starts mining session
    • Monitors performance and profitability
    • Switches when a better option becomes available

Troubleshooting

No Internet Connection

The application will use a default Bitcoin price ($40,000) if it cannot fetch current prices.

Miner Crashes

The application automatically detects crashed miners and restarts with a different algorithm.

Low Profitability

Adjust the min_profit threshold in config.json to match your expectations.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

cpuminer-switcher is a helper script to perform benchmarks and pool / algorithm switchs based on profitability

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages