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

in #mining8 years ago (edited)

picture
(image source)

The vanilla steemd (built as described here) 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, 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 and apply this simple 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 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, 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.

Sort:  

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!

Thanks for the valuable tips!

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 62555.95
ETH 2435.55
USDT 1.00
SBD 2.64