handshake-org / hs-miner

Mining infrastructure for handshake
Other
74 stars 19 forks source link

hs-miner

CUDA and OpenCL capable POW miner for Handshake.

Usage

Simply point the miner at an HS RPC server and you're off.

$ hs-miner --rpc-host localhost --rpc-port 13037 --rpc-pass my-password

CLI Usage

Another small utility is available for mining arbitrary headers. This is most useful for testing.

# Mine a single block
$ hs-mine [header-hex] [target] [backend] -n [nonce] -r [range]

API Usage

const miner = require('hs-miner');

const hdr = Buffer.alloc(256, 0x00);

console.log('Available backends: ', miner.getBackends());
console.log('Available devices: ', miner.getDevices());

if (miner.hasCUDA()) {
  console.log('Mining with cuda support!');
}

(async () => {
  const [nonce, extraNonce, match] = await miner.mineAsync(hdr, {
    backend: 'cuda',
    target: Buffer.alloc(32, 0xff),
    nonce: 123456,
    range: 2048,
    grids: 256,
    blocks: 8,
    threads: 2048
  });

  console.log('Nonce: %d', nonce);
  console.log('Extra Nonce: %s', extraNonce);
  console.log('Match: %s', match);
})();

API

Functions

Utilities

Constants

Options

Backends (so far)

Platform Support

The code has only been tested on Linux. Realistically, linux is the only thing that should matter for mining, but build support for other OSes is welcome via pull request.

Supports 64bit only right now.

Todo

Notes

When using one of the CUDA backends, only one job per device is allowed at a time. This is done because the CUDA miners generally wipe out your GPU's memory anyway.

The grids, blocks and threads parameters are backend-specific:

CUDA:

OpenCL:

For CUDA support, CUDA must be installed in either /opt/cuda or /usr/local/cuda when running the build scripts.

This can be modified with the CUDA_PREFIX environment variable:

$ CUDA_PREFIX=/path/to/cuda ./scripts/rebuild

Installation

NodeJS installation guide: https://nodejs.org/en/download/package-manager/

If you're on an OS without native NVIDIA packages, drivers can be installed from: https://www.nvidia.com/Download/Find.aspx

CUDA is available from NVIDIA's download page: https://developer.nvidia.com/cuda-downloads

Debian & Ubuntu

$ sudo apt-get install linux-headers-$(uname -r)
$ sudo apt-get install build-essential

# Install latest NVIDIA drivers
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt update
$ sudo apt install nvidia-390

# Install CUDA
# Pick out your installation: https://developer.nvidia.com/cuda-downloads
$ wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1704/x86_64/cuda-repo-ubuntu1704_9.1.85-1_amd64.deb
$ sudo dpkg -i cuda-repo-ubuntu1704_9.1.85-1_amd64.deb
$ sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1704/x86_64/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install cuda

# Install the latest node.js
$ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
$ sudo apt-get install nodejs

# Install git & python
$ sudo apt-get install git python

$ npm install hs-miner

RHEL & Fedora

Follow this installation guide for nvidia drivers: https://www.if-not-true-then-false.com/2015/fedora-nvidia-guide/

This also looks promising: https://negativo17.org/nvidia-driver/

Install CUDA (RHEL)

# Pick out your installation: https://developer.nvidia.com/cuda-downloads
$ wget http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-9.1.85-1.x86_64.rpm
$ sudo rpm -i cuda-repo-rhel7-9.1.85-1.x86_64.rpm
$ sudo yum clean all
$ sudo yum install cuda

Install CUDA (Fedora)

# Pick out your installation: https://developer.nvidia.com/cuda-downloads
$ wget http://developer.download.nvidia.com/compute/cuda/repos/fedora25/x86_64/cuda-repo-fedora25-9.1.85-1.x86_64.rpm
$ sudo rpm -i cuda-repo-fedora25-9.1.85-1.x86_64.rpm
$ sudo dnf clean all
$ sudo dnf install cuda

Install node.js & hs-miner (Both)

$ curl --silent --location https://rpm.nodesource.com/setup_9.x | sudo bash -
$ sudo yum install nodejs gcc-c++ make git python2
$ npm install hs-miner

Arch Linux

$ sudo pacman -S nodejs npm git nvidia nvidia-utils nvidia-settings cuda python2
$ npm install hs-miner

OSX

$ brew install node git coreutils perl grep gnu-sed gawk python2
$ brew tap caskroom/drivers
$ brew cask install nvidia-cuda
$ npm install hs-miner

Windows

TODO

Debugging

Pass an extra argument to the make commands to specify special behavior. Run make regtest extra=preprocess to output .cup files for the CUDA files. Or pass an environment variable EXTRA_ARG to one of the npm install-* scripts for the same behavior, such as $ EXTRA_ARG=preprocess npm run install.

Contribution and License Agreement

If you contribute code to this project, you are implicitly allowing your code to be distributed under the MIT license. You are also implicitly verifying that all code is your original work. </legalese>

License

See LICENSE for more info.