Page MenuHomePhabricator

Add a difficulty adjustement mechanism in case of abrupt hashrate loss

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



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

rABC Bitcoin ABC
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

deadalnix created this revision.Jul 5 2017, 22:36
Herald added a reviewer: Restricted Project. · View Herald TranscriptJul 5 2017, 22:36
kyuupichan requested changes to this revision.Jul 6 2017, 08:35
kyuupichan added inline comments.
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
deadalnix added inline comments.Jul 6 2017, 09:36
78 ↗(On Diff #739)

You are correct. I need to rephrase this comment.

deadalnix updated this revision to Diff 742.Jul 6 2017, 09:48
deadalnix edited edge metadata.

Fix incorrect comment.

kyuupichan accepted this revision.Jul 6 2017, 13:53
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 a subscriber: dgenr8.Jul 24 2017, 02:50
dgenr8 added inline comments.

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?

dgenr8 added inline comments.Jul 24 2017, 02:55

Never mind, that was already the case!