I have implemented private chain in ethereum but its difficulty level increases by time as a result the mining process slows down. Is it possible to make the difficulty static or disable it in testnet.
Modify the CalcDifficulty
in Geth to return a static number, then rebuild Geth. Example:
func CalcDifficulty(config *ChainConfig, time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
return big.NewInt(0x4000)
}
Source: Answer to Is it possible to change the block target time?
-
1
-
2@ThorkilVærge I usually won't answer/reply if I don't know. But I'm doing so here since I'm not ignoring the question, and would encourage if there are new answers. – eth♦ May 3 '18 at 7:41
If it is private chain you can define difficulty
in genesis block.
Something like this
{
"nonce": "0x0000000000000042",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"difficulty": "0x4000",
"alloc": {},
"coinbase": "0x0000000000000000000000000000000000000000",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "Custem Ethereum Genesis Block",
"gasLimit": "0xffffffff"
}
Here is a good read to How to Set up testnet
-
1I have used this format only. Initially the mining is fast but as the time flows the difficulty increases and mining goes very slow. – Abhishek Ranjan Jul 18 '16 at 7:19
-
1The difficulty is adjusted automatically so the average block time is within the hard-coded time in ethereum. The difficulty you specify in the genesis file is just the starting difficulty. To make difficulty static you need to modify the source code. – dragosb Jul 18 '16 at 12:42
-
1
-
1what genesis block has to do with difficulty as it is only to create inital blockchain . difficulty is measured by CalcDifficulty algo. – Himanshu sharma Dec 5 '16 at 12:18
-
1@Himanshusharma I understand that. OP is asking about creating the initial set up. – niksmac Dec 5 '16 at 16:16
Here you can see the whole explanation to do it: http://blog.coinfabrik.com/fast-smart-contracts-execution-ethereum-private-blockchain-development-environment/
-
2That tutorial doesn't add anything to the accepted answer. If it included some details on how to rebuild from source once the change was made, then fair enough, but it doesn't. – Richard Horrocks Mar 17 '17 at 14:52