Mining - learnforcode/mypages GitHub Wiki

CPU Mining with Gabey

CPU_Mining

To mine at abeychain, you'll just need abeychain client, gabey.

NOTE: Ensure your blockchain is fully synchronised with the main chain before starting to mine, otherwise you will not be mining on the main chain.

When you start up your abeychain node with gabey it is not mining by default. To start it in mining mode, you use the --mine command line option. The -minerthreads parameter can be used to set the number parallel mining threads (defaulting to the total number of processor cores).

gabey --mine --minerthreads=4

only mine fruit

gabey --minefruit --minerthreads=4

You can also start and stop CPU mining at runtime using the console. miner.start takes an optional parameter for the number of miner threads.

> miner.start(8)
null
> miner.stop()
true

or

> miner.startFruit(8)
null
> miner.stop()
true

Note that mining for real TRUE only makes sense if you are in sync with the network (since you mine on top of the consensus block). Therefore the abeychain downloader/synchroniser will delay mining until syncing is complete, and after that mining automatically starts unless you cancel your intention with miner.stop().

In order to earn ABEY you must have your coinbase address set. This coinbase defaults to your primary account. If you don't have an coinbase address, then gabey --mine or gabey --minefruitwill not start up.

You can set your coinbase on the command line:

gabey --coinbase '0xa4d8e9cae4d04b093aac82e6cd355b6b963fb7ff' --mine 2>> gabey.log

or

gabey --coinbase '0xa4d8e9cae4d04b093aac82e6cd355b6b963fb7ff' --minefruit 2>> gabey.log

You can reset your coinbase on the console too:

miner.setCoinbase(abey.accounts[2])

Note that your coinbase does not need to be an address of a local account, just an existing one.

There is an option to add extra Data (32 bytes only) to your mined blocks. By convention this is interpreted as a unicode string, so you can set your short vanity tag.

miner.setExtra("abeyminer")
...
debug.printBlock(131805)
BLOCK(be465b020fdbedc4063756f0912b5a89bbb4735bd1d1df84363e05ade0195cb1): Size: 531.00 B TD: 643485290485 {
NoNonce: ee48752c3a0bfe3d85339451a5f3f411c21c8170353e450985e1faab0a9ac4cc
Header:
[
...
        Miner:           a4d8e9cae4d04b093aac82e6cd355b6b963fb7ff
        Number:             131805
        Extra:              abeyminer
...
}

You can check your hashrate with miner.getHashRate(), the result is in H/s (Hash operations per second).

> miner.getHashRate()
30

After you successfully mined some blocks, you can check the abey balance of your coinbase account. Now assuming your coinbase is a local account:

> abey.getBalance(abey.coinbase).toNumber();
'34698870000000' 

In order to spend your earnings you will need to have this account unlocked.

> personal.unlockAccount(abey.coinbase)
Password
true

You can check which blocks are mined by a particular miner (address) with the following code snippet on the console:

function minedBlocks(lastn, addr) {
  addrs = [];
  if (!addr) {
    addr = abey.coinbase
  }
  limit = abey.blockNumber - lastn
  for (i = abey.blockNumber; i >= limit; i--) {
    if (abey.getBlock(i).miner == addr) {
      addrs.push(i)
    }
  }
  return addrs
}
// scans the last 1000 blocks and returns the blocknumbers of blocks mined by your coinbase 
// (more precisely blocks the mining reward for which is sent to your coinbase).   
minedBlocks(1000, abey.coinbase);
//[352708, 352655, 352559]

Note that it will happen often that you find a block yet it never makes it to the canonical chain. This means when you locally include your mined block, the current state will show the mining reward credited to your account, however, after a while, the better chain is discovered and we switch to a chain in which your block is not included and therefore no mining reward is credited. Therefore it is quite possible that as a miner monitoring their coinbase balance will find that it may fluctuate quite a bit.

Mining success depends on the set block difficulty. Block difficulty dynamically adjusts each block in order to regulate the network hashing power to produce a 10 minute blocktime. Your chances of finding a block therefore follows from your hashrate relative to difficulty. The time you need to wait you are expected to find a block can be estimated with the following code:

INCORRECT...CHECKING

abey = abey.getBlock("latest").difficulty/miner.getHashRate(); // estimated time in seconds
Math.floor(abey / 3600.) + "h " + Math.floor((abey % 3600)/60) + "m " +  Math.floor(abey % 60) + "s";
// 1h 3m 30s

GPU mining


Hardware

The GPU miner is implemented in OpenCL,to get openCL for your chipset and platform, try:

On Ubuntu

NVIDIA

add-apt-repository ppa:graphics-drivers/ppa
apt-get install nvidia-418 nvidia-418-dev nvidia-opencl-dev nvidia-opencl-icd-418

Mining Software

The official release of gabey only supports a CPU miner natively. We are working on a GPU miner, gabey however can be used in conjunction with abeyminer, using the standalone miner as workers and gabey as scheduler communicating via JSON-RPC.

abeyminer 0n Linux:

git clone https://github.com/abeychain/abeyminer.git

GPU mining with abeyminer

To miner with gabey:

wget https://github.com/abeychain/go-abey/releases/download/v1.0.2/gabey-linux-amd64-1.0.2-758c849.tar.gz
tar -zxvf gabey-linux-amd64-1.0.2-758c849.tar.gz

the detail 'gabey' you can reference CPU_mine

To install and build GPU abeyminer from source:

cd abeyminer
mkdir build
cd build
cmake ..
cmake -budid .
make install

To install and build CPU abeyminer from source:

cd abeyminer
mkdir build
cd build
cmake .. -DETHASHCL=OFF -DBINKERN=OFF -DETHASHCUDA=OFF -DAPICORE=ON -DETHASHCPU=ON
cmake -budid .
make install

The detail abeyminer install abeyminer readme.md

To set up GPU mining you need a coinbase account. It can be an account created locally or remotely.

Using abeyminer with gabey on solo mode

  • start gabey to support remote mining
./gabey  --datadir ./data --config ./data/config  --rpc --rpcaddr 0.0.0.0 --rpcapi "abey,:net,web3,miner" --mine --remote --coinbase <coinbase> console

gabey will listen all ip address when giving --rpcaddr 0.0.0.0, you can give the exact ip address that want miner to connect, or --rpcaddr 127.0.01 only allow the miner running on the host to connect gabey.

abeyminer communicates with gabey on port 8545 . You also can change port by giving the rpcport option to gabey.

abeyminer will find gabey on any port. Note that you need to set the param with hostname:port to connect the gabey .

Also note that you do have need to give gabey the --mine option to start the miner , and also need use --remote to support remote getwork .

  • abeyminer solo mode using CPU
abeyminer --cpu -P http://hostname:port

  • abeyminer solo mode using GPU
abeyminer -G -P http://hostname:port

Use abeyminer -H get abeyminer a full list of available commands.

If the default command abeyminer does not work, try to specify the OpenCL device with: --opencl-device X where X is 0, 1, 2, etc. When running abeyminer with -M (benchmark), you should see something like:

Benchmarking on platform: { "platform": "NVIDIA CUDA", "device": "GeForce GTX 750 Ti", "version": "OpenCL 1.1 CUDA" }


Benchmarking on platform: { "platform": "Apple", "device": "Intel(R) Xeon(R) CPU E5-1620 v2 @ 3.70GHz", "version": "OpenCL 1.2 " }

Using abeyminer with gabey on stratum mode

  • abeyminer stratum mode using CPU
abeyminer --cpu -P stratum+tcp://WALLET.WORKER@hostname:port
  • abeyminer stratum mode using GPU
abeyminer -G -P stratum+tcp://WALLET.WORKER@hostname:port

abeyminer use stratum protocl to connect the mining pool , the hostname:port is pool hostname and port

Note hashrate info is not available in gabey ,you have use abeyminerneed add params -R.

⚠️ **GitHub.com Fallback** ⚠️