Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
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.
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
Now check the block difficulty using admin.nodeInfo console command.
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?
- EOS 101: Getting started with EOS, Part 1
- Quorum 101: Getting started with Quorum
- 13 sidechain projects every blockchain developer should know about
Clap 50 times and follow me on Twitter: @vasa_develop
How to reduce block difficulty in ethereum private testnet was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.