Page MenuHomePhabricator

Add a difficulty adjustement mechanism in case of abrupt hashrate loss
ClosedPublic

Authored by deadalnix on Jul 5 2017, 22:36.

Details

Summary

We don't want the ABC chain to be stale in case the hashrate supporting it decreases. It is unknown at this stage how much hashrate we can secure short term.

The algorithm look at the MTP of the current chain tip and the MTP of the chain tip 6 blocks in the past. The expected difference is 1h when the chain operates normally. If the difference grow bigger than 12h, the difficulty target is bumped up by 1/4 .

Because the MTP will take about 6 blocks to reflect the change in difficulty, several adjstement in a row are to be expected. Running the adjustement 6 time in a row, which is what we expect in case the chain is close to the limit.

This algorithm is compatible with the existing chain and therefore do not need an activation mechanism. Triggering it require to lose 92% of the hashrate abruptly, which never happened. It also do not allow to ressurect a dead chain. You need to be able to mine enough block to move the MTP for it to kick in. A miner will have to bet the chain will be valluable.

Test Plan
make check

Added unit test for the retargeting algorithm.

Run a full sync of both the main chain and the testnet.

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kyuupichan requested changes to this revision.Jul 6 2017, 08:35
kyuupichan added inline comments.
src/pow.cpp
78 ↗(On Diff #739)

I don't think the above logic or comment is correct.

Consider, if you double the target, you halve the difficulty.

Hence adding 1/4 to to the target only reduces the difficulty by 20%.

This revision now requires changes to proceed.Jul 6 2017, 08:35
src/pow.cpp
78 ↗(On Diff #739)

You are correct. I need to rephrase this comment.

deadalnix edited edge metadata.

Fix incorrect comment.

This revision is now accepted and ready to land.Jul 6 2017, 13:53
This revision was automatically updated to reflect the committed changes.
dgenr8 added inline comments.
src/pow.cpp
37

Moving this block of code after the % == 0 check has the effect of disabling the testnet 20-minute rule at a difficulty boundary. Was that desired / necessary?

src/pow.cpp
37

Never mind, that was already the case!