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.
2 Answers
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, 2018 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. Jul 18, 2016 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.– dragosbJul 18, 2016 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. Dec 5, 2016 at 12:18
-
1@Himanshusharma I understand that. OP is asking about creating the initial set up.– niksmacDec 5, 2016 at 16:16