create account

Steem mining: how to increase hash rate by 60% (patches included) by letc

View this thread on: hive.blogpeakd.comecency.com
· @letc · (edited)
$2.17
Steem mining: how to increase hash rate by 60% (patches included)
![picture](https://ipfs.io/ipfs/Qmbru6b6okFwQLgbAVLeu3atkQQUJorcfnQyySffy8cg7F)
([image source](https://www.pexels.com/photo/pen-technology-computer-pc-40879/))

The vanilla steemd (built as described [here](https://steemit.com/steem-help/@letc/building-steem-with-gcc-6-1-on-fedora-24)) mines at 8646 hps* on my humble double core Pentium. Let's see what can be improved, starting from the simplest things. First, recompile steemd with `-march=native` to enable optimizations specific to your CPUs architecture (Intel Haswell in my case):

    $ cmake \
        -DCMAKE_C_FLAGS="-march=native" -DCMAKE_CXX_FLAGS="-march=native" \
        -DBOOST_ROOT="$HOME/opt/boost-1.60.0" \
        -DENABLE_CONTENT_PATCHING=OFF -DLOW_MEMORY_NODE=ON \
        -DCMAKE_BUILD_TYPE=Release .

(I described the building process in [this post](https://steemit.com/steem-help/@letc/building-steem-with-gcc-6-1-on-fedora-24), just replace the cmake command used there with the variant above)

Hash rate is now 8738 hps (+1%). YMMV depending on the CPU architecture and compiler version. 

The next thing to do is to enable GMP. Install [GMP](https://gmplib.org/) and apply [this simple patch](https://ipfs.io/ipfs/QmSv8VL2y3f6umhnqoFbs8NRhVJqj4efE596Z6PqqkPKvR/steem-gmp.patch):

    $ curl https://ipfs.io/ipfs/QmVA3QACfkH33bjhTqD5268hHV7kWQSroYFGgJDxzGAXBR |\
        patch -p1

You may need to fix the path to libgmp.a in `libraries/fc/CMakeLists.txt`

After recompiling with GMP, I got 9301 hps (+8% to the initial rate).

Now we'll try something more interesting. The EC cryptography functions used in POW algorithm are implemented in the secp256k1 library that is bundled with Steem. Naturally, this implementation puts security before performance, so there is a lot of overhead added due to measures taken to protect secret key (namely, constant-time calculations and excessive memory cleaning). There is a [fast unsafe variant](https://github.com/llamasoft/secp256k1_fast_unsafe) of the library, but it is not directly compatible with the version used in Steem. So I ported back the changes from the fast unsafe version. Here is [the patch](https://ipfs.io/ipfs/QmSv8VL2y3f6umhnqoFbs8NRhVJqj4efE596Z6PqqkPKvR/steem-fast-unsafe.patch),  **use it at your own risk**. You can apply it with the following command:

    $ curl https://ipfs.io/ipfs/QmZMy6kD2rG9Fyw6sax461qu4fK811CynYECrjsyMfzXxV |\
        patch -p1

Hash rate is now 13884 (+61% to the initial rate)! Note that this patch is most efficient when GMP is enabled.

Ideally, we would need two different ECC implementations — a fast unsafe one for mining (since the POW algorithm does not use the accounts active key after HF13, key security is irrelevant there) and a secure one for signing transactions. But the patch above modifies the common ECC implementation used in Steem.

**Again: use it at your own risk!** 

Probably, it would be possible to improve the hash rate even more by creating a different separate miner-specific ECC implementation that disregards security and generality to achieve the maximum performance. BTW, that's what GPU miners probably have, so running on GPU per se is not their only advantage. CPU miners might still have a chance to compete.

I'm not hoping to profit from mining with the humble hardware I have, I was just curious to experiment. The only mining reward I can hope for is the reward for my posts about mining, so I'm sharing the patches.

(*) Hash rates are average of top 5 measurements (I exclude lower measurements that are likely influenced by other processes running on my PC) taken while mining for about 1 minute.
👍  , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorletc
permlinksteem-mining-how-to-increase-hash-rate-by-60-patches-included
categorymining
json_metadata{"tags":["mining","steem","steemit"],"image":["https://ipfs.io/ipfs/Qmbru6b6okFwQLgbAVLeu3atkQQUJorcfnQyySffy8cg7F"],"links":["https://www.pexels.com/photo/pen-technology-computer-pc-40879/","https://steemit.com/steem-help/@letc/building-steem-with-gcc-6-1-on-fedora-24","https://gmplib.org/","https://ipfs.io/ipfs/QmSv8VL2y3f6umhnqoFbs8NRhVJqj4efE596Z6PqqkPKvR/steem-gmp.patch","https://github.com/llamasoft/secp256k1_fast_unsafe","https://ipfs.io/ipfs/QmSv8VL2y3f6umhnqoFbs8NRhVJqj4efE596Z6PqqkPKvR/steem-fast-unsafe.patch"]}
created2016-08-31 18:16:54
last_update2016-08-31 22:57:36
depth0
children3
last_payout2016-10-01 19:12:27
cashout_time1969-12-31 23:59:59
total_payout_value2.134 HBD
curator_payout_value0.033 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,614
author_reputation4,908,604,636,880
root_title"Steem mining: how to increase hash rate by 60% (patches included)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,074,043
net_rshares5,779,789,610,497
author_curate_reward""
vote details (26)
@arcange ·
Nice post. I will try it. Thanks for sharing !
properties (22)
authorarcange
permlinkre-letc-steem-mining-how-to-increase-hash-rate-by-60-patches-included-20160831t215842942z
categorymining
json_metadata{"tags":["mining"]}
created2016-08-31 21:58:42
last_update2016-08-31 21:58:42
depth1
children0
last_payout2016-10-01 19:12:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length46
author_reputation1,146,633,779,972,293
root_title"Steem mining: how to increase hash rate by 60% (patches included)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,076,814
net_rshares0
@cryptohead ·
Thanks for the valuable tips!
properties (22)
authorcryptohead
permlinkre-letc-steem-mining-how-to-increase-hash-rate-by-60-patches-included-20160901t055230549z
categorymining
json_metadata{"tags":["mining"]}
created2016-09-01 05:52:33
last_update2016-09-01 05:52:33
depth1
children0
last_payout2016-10-01 19:12:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length29
author_reputation607,929,583,052
root_title"Steem mining: how to increase hash rate by 60% (patches included)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,080,849
net_rshares0
@mrosenquist ·
Nicely done optimizations.  I like the fact you explained the dangers of the insecure variant.  Informs the readers and gives them a good choice.  Well done!
👍  
properties (23)
authormrosenquist
permlinkre-letc-steem-mining-how-to-increase-hash-rate-by-60-patches-included-20160831t190719723z
categorymining
json_metadata{"tags":["mining"]}
created2016-08-31 19:07:24
last_update2016-08-31 19:07:24
depth1
children0
last_payout2016-10-01 19:12:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length157
author_reputation178,495,942,506,925
root_title"Steem mining: how to increase hash rate by 60% (patches included)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,074,756
net_rshares1,551,949,046
author_curate_reward""
vote details (1)