Ethereum – How to Decrease Difficulty of an Ongoing Private Blockchain

difficultyminingtestnets

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.

Best Answer

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.

Related Topic