Skip to content
zeoio edited this page Sep 14, 2020 · 48 revisions

CPU Mining with Gccm

At Frontier, the first release of Ccmchain, you'll just need a) a GPU and b) an Ccmchain client, Gccm. CPU mining will be possible but too inefficient to hold any value.

At the moment, Gccm only includes a CPU miner, and the team is testing a GPU miner branch, but this won't be part of Frontier.

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 ccmchain node with gccm 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).

gccm --mine --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)
true
> miner.stop()
true

Note that mining for real ether only makes sense if you are in sync with the network (since you mine on top of the consensus block). Therefore the ccm blockchain 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 ether you must have your coinbase address set. This coinbase defaults to your primary account. If you don't have an coinbase address, then gccm --mine will not start up.

You can set your coinbase on the command line:

gccm --coinbase 1 --mine  2>> gccm.log // 1 is index: second account by creation order OR
gccm --coinbase '0xa4d8e9cae4d04b093aac82e6cd355b6b963fb7ff' --mine 2>> gccm.log

You can reset your coinbase on the console too:

miner.setCoinbase(ccm.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("ΞTHΞЯSPHΞЯΞ")
...
debug.printBlock(131805)
BLOCK(be465b020fdbedc4063756f0912b5a89bbb4735bd1d1df84363e05ade0195cb1): Size: 531.00 B TD: 643485290485 {
NoNonce: ee48752c3a0bfe3d85339451a5f3f411c21c8170353e450985e1faab0a9ac4cc
Header:
[
...
        Coinbase:           a4d8e9cae4d04b093aac82e6cd355b6b963fb7ff
        Number:             131805
        Extra:              ΞTHΞЯSPHΞЯΞ
...
}

See also this proposal

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

> miner.hashrate
712000

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

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

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

> personal.unlockAccount(ccm.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 = ccm.coinbase
  }
  limit = ccm.blockNumber - lastn
  for (i = ccm.blockNumber; i >= limit; i--) {
    if (ccm.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, ccm.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.

The logs show locally mined blocks confirmed after 5 blocks. At the moment you may find it easier and faster to generate the list of your mined blocks from these logs.

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 12 second 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

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

Given a difficulty of 3 billion, a typical CPU with 800KH/s is expected to find a block every ....?

GPU mining


Hardware

The algorithm is memory hard and in order to fit the DAG into memory, it needs 1-2GB of RAM on each GPU. If you get Error GPU mining. GPU memory fragmentation? you havent got enough memory.

The GPU miner is implemented in OpenCL, so AMD GPUs will be 'faster' than same-category NVIDIA GPUs.

ASICs and FPGAs are relatively inefficient and therefore discouraged.

To get openCL for your chipset and platform, try:

On Ubuntu

AMD

download: ADL_SDK8.zip and AMD-APP-SDK-v2.9-1.599.381-GA-linux64.sh

./AMD-APP-SDK-v2.9-1.599.381-GA-linux64.sh
ln -s /opt/AMDAPPSDK-2.9-1 /opt/AMDAPP
ln -s /opt/AMDAPP/include/CL /usr/include
ln -s /opt/AMDAPP/lib/x86_64/* /usr/lib/
ldconfig
reboot
apt-get install fglrx-updates
// wget, tar, opencl
sudo aticonfig --adapter=all --initial
sudo aticonfig --list-adapters
* 0. 01:00.0 AMD Radeon R9 200 Series

* - Default adapter

Nvidia

The following instructions are, for the most part, relevant to any system with Ubuntu 14.04 and a Nvidia GPU. Setting up an EC2 instance for mining

On MacOSx

wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.29_mac.pkg
sudo installer -pkg ~/Desktop/cuda_7.0.29_mac.pkg -target /
brew update
brew tap ccmchain/ccmchain
brew reinstall cpp-ccmchain --with-gpu-mining --devel --headless --build-from-source

You check your cooling status:

aticonfig --adapter=0 --od-gettemperature

Mining Software

The official Frontier release of gccm only supports a CPU miner natively. We are working on a GPU miner, but it may not be available for the Frontier release. Gccm however can be used in conjunction with ccmminer, using the standalone miner as workers and gccm as scheduler communicating via JSON-RPC.

GPU mining with miner

To mine with ccm:

ccm -m on -G -a <coinbase> -i -v 8 //

To install miner from source:

cd cpp-ccmchain
cmake -DETHASHCL=1 -DGUI=0
make -j4
make install

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

Using miner with gccm

gccm account new
gccm --rpc --rpccorsdomain localhost 2>> gccm.log &
miner -G  // -G for GPU, -M for benchmark
tail -f gccm.log

miner communicates with gccm on port 8545 (the default RPC port in gccm). You can change this by giving the --rpcport option to gccm. Miner will find get on any port. Note that you need to set the CORS header with --rpccorsdomain localhost. You can also set port on miner with -F http://127.0.0.1:3301. Setting the ports is necessary if you want several instances mining on the same computer, although this is somewhat pointless. If you are testing on a private cluster, we recommend you use CPU mining instead.

Also note that you do not need to give gccm the --mine option or start the miner in the console unless you want to do CPU mining on TOP of GPU mining.

If the default for miner does not work try to specify the OpenCL device with: --opencl-device X where X is 0, 1, 2, etc. When running miner 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 " }

To debug gccm:

gccm  --rpccorsdomain "localhost" --verbosity 6 2>> gccm.log

To debug the miner:

make -DCMAKE_BUILD_TYPE=Debug -DETHASHCL=1 -DGUI=0
gdb --args miner -G -M

Note hashrate info is not available in gccm when GPU mining. Check your hashrate with miner, miner.hashrate will always report 0.

miner and ccm

miner can be used in conjunction with ccm via rpc

ccm -i -v 8 -j // -j for rpc
miner -G -M // -G for GPU, -M for benchmark
tail -f gccm.log

or you can use ccm to GPU mine by itself:

ccm -m on -G -a <coinbase> -i -v 8 //

Further Resources:

Clone this wiki locally