/ EIPs Public

# Change difficulty adjustment to target mean block time including uncles#100

Closed
opened this issue Apr 29, 2016 · 9 comments
Closed

# Change difficulty adjustment to target mean block time including uncles #100

opened this issue Apr 29, 2016 · 9 comments

### Specification

Currently, the formula to compute the difficulty of a block includes the following logic:

```adj_factor = max(1 - ((timestamp - parent.timestamp) // 10), -99)
child_diff = int(max(parent.difficulty + (parent.difficulty // BLOCK_DIFF_FACTOR) * adj_factor, min(parent.difficulty, MIN_DIFF)))
...```

If `block.number >= METROPOLIS_FORK_BLKNUM`, we change the first line to the following:

`adj_factor = max(1 + len(parent.uncles) - ((timestamp - parent.timestamp) // 9), -99)`

### Specification (1b)

`adj_factor = max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99)`

### Rationale

This new formula ensures that the difficulty adjustment algorithm targets a constant average rate of blocks produced including uncles, and so ensures a highly predictable issuance rate that cannot be manipulated upward by manipulating the uncle rate. The formula can be fairly easily seen to be (to within a tolerance of ~3/4194304) mathematically equivalent to assuming that a block with `k` uncles is equivalent to a sequence of `k+1` blocks that all appear with the exact same timestamp, and this is likely the simplest possible way to accomplish the desired effect.

Changing the denominator from 10 to 9 ensures that the block time remains roughly the same (in fact, it should decrease by ~3% given the current uncle rate of 7%).

(1b) accomplishes almost the same effect but has the benefit that it depends only on the block header (as you can check the uncle hash against the blank hash) and not the entire block.

### Update 2017.06.29

Version (1b) was chosen.

 lgtm

### SergioDemianLerner commented May 18, 2016 • edited

 lgtm. If the uncle rate decreases, the avg block rate will slightly increase, forcing an increase in the uncle rate. If the uncle rate increases, the avg block rate will slightly decrease, forcing an decrease in the uncle rate. Nice negative feedback loop. If block reward depended on the current block rate, so that reward/sec were always constant, block rate could be freely chosen by the network and the difficulty adjustment formula could allow decreasing block rate down to 5 secs if network conditions tolerated it. All dynamic.

This was referenced Jan 25, 2017
mentioned this issue Feb 1, 2017
mentioned this issue Feb 7, 2017
mentioned this issue Feb 10, 2017
This was referenced Mar 2, 2017
mentioned this issue Mar 9, 2017
mentioned this issue Mar 18, 2017
mentioned this issue Mar 21, 2017

### gumb0 commented Mar 22, 2017 • edited

 Uncle number is not the part of the header, so now to validate the header we need not only the parent header, but parent body, too. Wouldn't this cause troubles for the light clients? Update. This was the concern only for 1a specification, but now 1b seems to be the consensus and it doesn't require the parent body.

mentioned this issue Mar 27, 2017
mentioned this issue Apr 21, 2017
This was referenced Jun 29, 2017

### pirapira commented Aug 2, 2017

 The activation should be `BYZANTIUM_FORK_BLKNUM` now.

### marcogiglio commented Aug 3, 2017 • edited

 The proposed change has a negative conseguence on the effective gas throughtput of the network per second. Since uncle rates increas 0.77% per each additional 1M unit of gas consumed, after applying this change, increasing the block gas limit would result in a less than linear increase in effective throughput per second, due to the increased uncles which are now taken in consideration for blocktime calculation. The effect becomes evident already at around 20M block gas limit, where the available throughtput is around 80% of what would be with today difficulty algorithm, at least in theory. Assuming linearity of the uncle rate probability, the effective throughput per second converges then to a value equivalent to a 50M gas block limit, which becomes kinda of hardcoded since voting the gas beyond that actually decreases the throughtput because of the increasing uncle rate.

mentioned this issue Aug 9, 2017
mentioned this issue Aug 15, 2017
mentioned this issue Aug 18, 2017
mentioned this issue Aug 20, 2017
mentioned this issue Aug 25, 2017

### Souptacular commented Oct 11, 2017

 @vbuterin This needs to be a PR.

### jamesray1 commented Oct 20, 2017

 When you make a PR maybe just include the chosen option 1b.

### cdetrio commented Oct 20, 2017

 This has a PR #692

mentioned this issue Oct 20, 2017
mentioned this issue Oct 23, 2017

### nicksavers commented Jan 7, 2018

 PR has been merged and EIP is active in the main repository with status Final https://github.com/ethereum/EIPs/blob/master/EIPS/eip-100.md @vbuterin The document still references this issue for discussion, but I imagine it can be closed.

mentioned this issue Jan 17, 2018
mentioned this issue Aug 27, 2018
mentioned this issue Dec 28, 2018
mentioned this issue Mar 13, 2019
mentioned this issue Mar 19, 2019
mentioned this issue Jun 25, 2020