How to reduce block difficulty in ethereum private testnet

Written by vasa | Published 2018/06/08
Tech Story Tags: ethereum | ethereum-private-testnet | ethereum-testnet | block-difficulty | reduce-block-difficulty

TLDRvia the TL;DR App

bait for ethereum lovers

One of the greatest problems when it comes to development on ethereum private testnet is it’s slow consensus. Thanks to POW(Proof of Work). This problem also increases with time as the block difficulty increases. So, our testnet becomes slower and slower, block by block.

dog: How it feels like to use POW (source)

One obvious solution to this problem is to use a bigger machine as your miner. But eventually, after some time it will also get slow when it hits some big difficulty rate. But there is another easy solution to this problem, that is to reduce the rate at which blockchain difficulty increases to as low as 1/block.(i.e. your block difficulty rate will increase by only 1 per block)

Let’s see how it’s done.

Step 1: Clone go-ethereum

git clone https://github.com/ethereum/go-ethereum

Step 2: Create your own mutant ethereum

Open consensus.go which resides at consensus/ethash/consensus.go . Now search for the line given below.

return CalcDifficulty(chain.Config(), time, parent)

And replace it with

return big.NewInt(1)

Step 3: Build your mutant ethereum

Head out to the root folder(go-ethereum) and run following command.

make geth

And after you are done, you will see this line at the end.

Now, you can run this command to make your mutant geth globally available.

sudo mv build/bin/geth /usr/bin

Step 4: Let’s test it out

Create a custom genesis file like one given below.

Now, run the following command to start your private testnet using your mutant geth.

geth --datadir ./DataDir init ./genesis.jsongeth --datadir ./DataDir --networkid 1212 --mine --minerthreads=1 --etherbase="0x30f28686aef33adbfbc13797b1d9f5a2f2759f56" console

starting up private testnet

Now check the block difficulty using admin.nodeInfo console command.

at block: 9, difficulty: 9

Voila, you are done. You have just created your own version of ethereum. That deserves some celebration.

Learned something? Click the 👏 to say “thanks!” and help others find this article.

Hold down the clap button if you liked the content! It helps me gain exposure .

Want to learn more? Check out my previous articles…

Quantum Computing: Is it the end of blockchain?_Experts are suggesting quantum computing may render blockchain obsolete. As the tech giants such as Google and IBM are…_hackernoon.com

EOS 101: Getting started with EOS, Part 1_The only blockchain which has blocktime of less than a second: 0.5 sec!_hackernoon.com

Quorum 101: Getting started with Quorum_This post marks the first in a new Quorum series I am starting in an effort to provide some easy to read instructions…_hackernoon.com

13 sidechain projects every blockchain developer should know about_The whole world is going through the blockchain revolution. But wait…is this really what we dreamed of? Present…_medium.com

Clap 50 times and follow me on Twitter: @vasa_develop


Written by vasa | Entrepreneur | Co-founder @tbc_inc, an MIT CIC incubated startup | Speaker |https://vaibhavsaini.com
Published by HackerNoon on 2018/06/08