3

Please note that my question is in addition to following question: How do I decrease the difficulty on a private testnet?. I am sorry that, I am lost in its answers.

[Q] Is it possible to decrease difficulty of ongoing private Ethereum blockchain (for example: blockchain already mined 491,312 number of blocks)? or should I create a new private Ethereum blockchain from 0th block to alter the difficulty?

I have applied @eth's solution https://ethereum.stackexchange.com/a/7159/4575 on my enode and released that difficulty is started to decrease, but I was not able to mine any of my upcoming transactions due to following error and so on:

Bad block #491231 (0x39e86646d54ad4a83ba41abc1192fb8e64bfcbf733aa2e5e94351fd168091068)
Difficulty check failed for header 914854

In addition to that, I was not sure to apply this solution on all nodes that are connected to me private ethereum network? or only on the enode that the peers connected into?

Thank you for your valuable help and time.

2
  • 1
  • I am not asking how does the Ethereum Homestead difficulty adjustment algorithm works. My question was related if I have an ongoing private network and for example difficulty is around 4000.00 KH, is it possible to pull the diffuculty towards 1 KH ? Since difficulty keep increasing and I cant make difficulty constant, my miners with low CPU (2 GB RAM ) won't able to keep it up. But thanks anyways. @nikmac.
    – alper
    Jan 5, 2017 at 5:52

2 Answers 2

2

No, you won't be able to get past the point at which you changed the difficulty algorithm. You'll have to start from scratch, I'm afraid.


The error you're seeing is coming from the ValidateHeader() function, which, surprisingly, attempts to validate the values contained in the header of the current block being imported.

In short, the Block Header Validity section of the Yellow Paper states the following:

(51) Hd = D(H)

Which is a cryptic way of stating that the difficulty in the current block's header must match the calculated expected difficulty, given the difficulty of the block's parent, and the current block number.

expd := CalcDifficulty(config, header.Time.Uint64(), parent.Time.Uint64(), parent.Number, parent.Difficulty)
if expd.Cmp(header.Difficulty) != 0 {
    return fmt.Errorf("Difficulty check failed for header (remote: %v local: %v)", header.Difficulty, expd)
}

Your CalcDifficulty() function - which you've altered - is now returning a value which doesn't match the block header of a block which was created before you made the change.

Edit:

You could of course edit the code again to either remove or temporarily disable this check, but you'd forever have the discrepancy in your chain. It'd be up to you to decide if that matters or not.

1

You can reduce the rate of block difficulty increament by making some changes in the consensus code of go-ethereum. Open consensus.go which resides at consensus/ethash/consensus.go and search for the below line.

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

Now replace the above line with the below one.

return big.NewInt(1).

Now build the go-ethereum using make geth command.

I strongly recommend you to go through this article for much detailed implementation of the above process.

1
  • The OP had already followed those instructions (which were already outlined in the post they referenced). The question was how to do it in an ongoing chain - i.e. without starting again from scratch, and without having a discrepancy in the chain. Jun 11, 2018 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.