Author

Topic: Why does the difficulty adjust every 2016 blocks? Why not every block? (Read 1952 times)

legendary
Activity: 1246
Merit: 1016
Strength in numbers
I have a feeling that Satoshi new he might be alone for a while and didn't want to "give himself" low difficulty and very high block rewards. I mean he did get to have highest ever block rewards, but at least he gave others 4 years to get in on that. 4 years was probably his "by then or never" guess.

Or maybe he figured we could use some free media every 4 years :-)
legendary
Activity: 1246
Merit: 1016
Strength in numbers
Even if you solve the pick-your-own timestamp issue which is far from trivial, like eleuthria says, you would just get wildly fluctuating difficulty. Sometimes you'll find blocks within 1 second of each other and difficulty will go up 600x or more, then since it will take so long to find that high difficulty block (much worse than you expect because many miners will just turn off) that you'll have a very low difficulty next year when someone finds that block and difficulty will go way down, then BAM next block found and sky high difficulty again.

But even if we adjust the difficulty every block, that doesn't mean it has to be calculated solely with respect to the previous block. As someone else said upthread, you could keep a moving average of, say the last 200 blocks. That would smooth things out.

But I can see the OPs proposal being a serious pain in the arse for miners (of whom I am one). As it is, you have to keep reassessing every two weeks or so, whether it is still profitable to mine. If the difficulty (and hence, payout on a share in a pool) changes every block that would make it a bit of a nightmare to calculate profitability. The incentive to mine would be reduced, and without miners Bitcoin can't work.

Hijiack: What I *do* think would have been a good idea would be for the block rewards to have decayed more smoothly, say every month instead of every four years. Then again, the sky didn't appear to fall last December, not even with those pesky Mayans egging it on.

Ah, I overlooked continual readjusting based on a large number of blocks.

I don't think it would be that bad for miners turn-off decisions. If they really wanted to stop asap when difficulty reached a certain point that is trivial to code. As it is profitability already fluctuates in real time based on the bitcoin value.
hero member
Activity: 492
Merit: 503
Even if you solve the pick-your-own timestamp issue which is far from trivial, like eleuthria says, you would just get wildly fluctuating difficulty. Sometimes you'll find blocks within 1 second of each other and difficulty will go up 600x or more, then since it will take so long to find that high difficulty block (much worse than you expect because many miners will just turn off) that you'll have a very low difficulty next year when someone finds that block and difficulty will go way down, then BAM next block found and sky high difficulty again.

But even if we adjust the difficulty every block, that doesn't mean it has to be calculated solely with respect to the previous block. As someone else said upthread, you could keep a moving average of, say the last 200 blocks. That would smooth things out.

But I can see the OPs proposal being a serious pain in the arse for miners (of whom I am one). As it is, you have to keep reassessing every two weeks or so, whether it is still profitable to mine. If the difficulty (and hence, payout on a share in a pool) changes every block that would make it a bit of a nightmare to calculate profitability. The incentive to mine would be reduced, and without miners Bitcoin can't work.

Hijiack: What I *do* think would have been a good idea would be for the block rewards to have decayed more smoothly, say every month instead of every four years. Then again, the sky didn't appear to fall last December, not even with those pesky Mayans egging it on.
member
Activity: 85
Merit: 10
Well it was said already that the 10mins are the average time needed to find a block. But let me put it in some more understandable analogy.
Think of the difficulty as the sided of a dice. All sides are black except one which is white.
Now you roll the dice, white means you have found a block and black means you didn't.
Let's assume you can only roll the dice once per minute. If the dice has 6 sides you have a chance of 1/6 to find a block every minute. So in average you need 6 minutes to find a block.
But it's also possible that you get the white side on the first try, which means you can also find a block in one minute.

If you are able to somehow increase your speed and you can roll the dice twice a minute now then you would get a block every 3 minutes in average. But if we want the generation time to be constant we need to increase the difficulty which means we take a dice with 12 sides and the generation time is back to 6 minutes in average.

As you can see it's pretty easy to set the difficulty if the global hash rate of the network is known. The problem is that we actually can't know about the hash rate directly, but we do know the elapsed time since the last block was found. Combined with the current difficulty that's enough to calculate the hash rate. But there is a very high error rate. Let's go back to our analogy. Imagine you set the difficulty after every found block(which is what you wanted to know about), then with a dice with 6 sides it's actually pretty common to get the white side on the first try. The Network only knows that we found a block after 1 minute with a difficulty of 6. The Network wants to have a constant rate of 6 minutes per block which is why the difficulty gets adjusted to 36. As you can see the difficulty was multiplied by 6 although our hash rate didn't really change.

The solution for the problem is to average between block generations. If the number of blocks to average is too high, the difficulty will stay on the same level for too long. But if it's too low we will have huge difficulty jumps.

So changing the difficulty after every block would work, but it would be a mess because of the jumping difficulty. However as already said "running averaging" would also be an option. But I think we can agree on that the current system works just fine.
legendary
Activity: 1246
Merit: 1016
Strength in numbers
Even if you solve the pick-your-own timestamp issue which is far from trivial, like eleuthria says, you would just get wildly fluctuating difficulty. Sometimes you'll find blocks within 1 second of each other and difficulty will go up 600x or more, then since it will take so long to find that high difficulty block (much worse than you expect because many miners will just turn off) that you'll have a very low difficulty next year when someone finds that block and difficulty will go way down, then BAM next block found and sky high difficulty again.

Adjusting every block is not workable, but I wonder how fast it could be and still be mostly ok. Intuitively daily doesn't seem like it would be a problem, but you would have more fluctuations than now and I don't see the benefit. Anywhere from 1 week to 2 months seems ok, except if you pick something like 2 months and there is a big slowdown it could take a multiple of that to get to the next adjustment, that seems bad.
legendary
Activity: 1750
Merit: 1007
As the rules are now people can enter their own timestamp on a block up to some distance from other nearby blocks. Over 2016 blocks inaccuracies of an hour or so don't matter, but it would be severe if we changed the difficulty every block. There are even blocks with timestamps before the blocks that they come after, what would difficulty be then?
Let's change the valid timestamp. Every timestamp has to be greater than the previous block's time and less than the network-adjusted time + 10 minutes. What happens then?

Thank you all for your help.

Your solution is impossible, since there is no guarantee of blocks being generated within 10 minutes, and forcing timestamps to show up as if they were 10 minutes apart would just be putting purposely bad information into the block headers.

As for the main question, there is still the massive problem of luck.  Creating a block is a purely random process.  If you've never looked yourself, you should leave blockchain.info up on your screen one day and take note of the varying time between blocks.  Some blocks are generated within seconds of each other, while other blocks have an hour gap between them.  This isn't the result of network hash rate growing/shrinking, just the standard variance associated with mining, spread across the entire network.

The only way to "guarantee" a block is made within 10 minutes would be to set the difficulty so absurdly low that blocks average LESS than 30 seconds.  It is not impossible for a block to take more than 20x the expected amount of work to be completed.
newbie
Activity: 56
Merit: 0
As the rules are now people can enter their own timestamp on a block up to some distance from other nearby blocks. Over 2016 blocks inaccuracies of an hour or so don't matter, but it would be severe if we changed the difficulty every block. There are even blocks with timestamps before the blocks that they come after, what would difficulty be then?
Let's change the valid timestamp. Every timestamp has to be greater than the previous block's time and less than the network-adjusted time + 10 minutes. What happens then?

Thank you all for your help.
legendary
Activity: 1246
Merit: 1016
Strength in numbers
As the rules are now people can enter their own timestamp on a block up to some distance from other nearby blocks. Over 2016 blocks inaccuracies of an hour or so don't matter, but it would be severe if we changed the difficulty every block. There are even blocks with timestamps before the blocks that they come after, what would difficulty be then?
newbie
Activity: 56
Merit: 0
The difficulty determines the expected amount of time. The actual amount of time to produce a block is random. So, even if it were feasible, adjusting the difficulty every block would not ensure that the blocks are produced exactly every 10 minutes.
So, if bitcoin were to check every block would it break? Would it be usable at all?
It checks every block, but adjusts only every 2 weeks. Good averaging requires a significant sampling size (>1000).

However, it could also be a running averaging. See the difficulty adjustment for ppcoin.
Thank you. However, my question is this: What would happen if it adjusted with every block? Would bitcoin break?
donator
Activity: 994
Merit: 1000
The difficulty determines the expected amount of time. The actual amount of time to produce a block is random. So, even if it were feasible, adjusting the difficulty every block would not ensure that the blocks are produced exactly every 10 minutes.
So, if bitcoin were to check every block would it break? Would it be usable at all?
It checks every block, but adjusts only every 2 weeks. Good averaging requires a significant sampling size (>1000).

However, it could also be a running averaging. See the difficulty adjustment for ppcoin.
newbie
Activity: 56
Merit: 0
The difficulty determines the expected amount of time. The actual amount of time to produce a block is random. So, even if it were feasible, adjusting the difficulty every block would not ensure that the blocks are produced exactly every 10 minutes.
So, if bitcoin were to check every block would it break? Would it be usable at all?
legendary
Activity: 4522
Merit: 3426
The difficulty determines the expected amount of time. The actual amount of time to produce a block is random. So, even if it were feasible, adjusting the difficulty every block would not ensure that the blocks are produced exactly every 10 minutes.
newbie
Activity: 56
Merit: 0
What would happen if difficulty readjusted every block to make sure every block was resolved in 10 minutes time?
Jump to: