Skip to content
BiyunZeng edited this page May 29, 2019 · 11 revisions

CPU Mining with Getrue

CPU_Mining

To mine at truechain, you'll just need truechain client, Getrue.

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 truechain node with getrue 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).

getrue --mine --minerthreads=4

only mine fruit

getrue --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 truechain 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 TRUE you must have your coinbase address set. This coinbase defaults to your primary account. If you don't have an coinbase address, then Getrue --mine or Getrue --minefruitwill not start up.

You can set your coinbase on the command line:

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

or

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

You can reset your coinbase on the console too:

miner.setCoinbase(etrue.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("trueminer")
...
debug.printBlock(131805)
BLOCK(be465b020fdbedc4063756f0912b5a89bbb4735bd1d1df84363e05ade0195cb1): Size: 531.00 B TD: 643485290485 {
NoNonce: ee48752c3a0bfe3d85339451a5f3f411c21c8170353e450985e1faab0a9ac4cc
Header:
[
...
        Miner:           a4d8e9cae4d04b093aac82e6cd355b6b963fb7ff
        Number:             131805
        Extra:              trueminer
...
}

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 true balance of your coinbase account. Now assuming your coinbase is a local account:

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

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

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

etrue = etrue.getBlock("latest").difficulty/miner.getHashRate(); // estimated time in seconds
Math.floor(etrue / 3600.) + "h " + Math.floor((etrue % 3600)/60) + "m " +  Math.floor(etrue % 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 getrue only supports a CPU miner natively. We are working on a GPU miner, Getrue however can be used in conjunction with trueminer, using the standalone miner as workers and getrue as scheduler communicating via JSON-RPC.

Trueminer 0n Linux:

git clone https://github.com/truechain/trueminer.git

GPU mining with trueminer

To miner with getrue:

wget https://github.com/truechain/truechain-engineering-code/releases/download/v1.0.2/getrue-linux-amd64-1.0.2-758c849.tar.gz
tar -zxvf getrue-linux-amd64-1.0.2-758c849.tar.gz

the detail 'getrue' you can reference CPU_mine

To install and build GPU trueminer from source:

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

To install and build CPU trueminer from source:

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

The detail trueminer install trueminer readme.md

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

Using trueminer with getrue on solo mode

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

getrue 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 getrue.

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

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

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

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

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

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

If the default command trueminer does not work, try to specify the OpenCL device with: --opencl-device X where X is 0, 1, 2, etc. When running trueminer 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 trueminer with getrue on stratum mode

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

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

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