Zephyrnet Logo

How Often Does Bitcoin Take an Hour to Mine a New Block

Date:

Bitcoin’s proof of work consensus is built to keep block intervals, or the time between mining two consecutive blocks, at the average of 10 minutes over time. It achieves that by adjusting mining difficulty every 2016 blocks, depending on the changes to the total hash rate of the network participants. However, the actual distribution of these block intervals is very interesting and worth taking a deeper look into.

Recently I was presented with the next problem: How often does mining a new block take more than an hour? To answer that, we will take a look into the distribution of block intervals and try to make sense of it mathematically.

A perfect place to play with Bitcoin block data is a public BigQuery DB dataset provided by Google. They hold and update block and transaction datasets for most major blockchains. You can log into the BigQuery console and find the dataset called:

I will just dive right into the raw data and plot the distribution of the block intervals for the Bitcoin blockchain.

In this SQL query we first add a column block_interval_seconds to the table called with_block_interval. Column block_interval_seconds is calculated as a difference in seconds between the consecutive blocks. To achieve that we use BigQuery’s built in function TIMESTAMP_DIFF() which calculates the difference between two timestamps. And a window function called LAG() gives us a previous value in the ordered partition. So basically a timestamp value of the block before the current block.

What we want to do next is plot all these values to the chart and see the distribution. As of now, Bitcoin blockchain has around 660.000 blocks, so plotting all of these values on the single chart would be a bit too intense for my computer. This is why at the end of the SQL script we arrange block_interval_seconds values into buckets with the size of 1 minute. If we want more granular chart, we can adjust buckets size accordingly.

Histogram of block interval distribution

From the distribution plot we can see how a big portion of blocks was actually mined in just a minute or two. And how the block interval distribution follows an exponential curve. Actually, even though the average block interval is 10 minutes long, the median value is lower than that. If I calculate the median value from the given dataset, it is about 6,5 minutes. That means that the majority of blocks are mined significantly faster than the average of 10 minutes. But then the long tail of exponential distribution pushes the average block interval to 10 minutes.

Another interesting property of exponential distribution is that it is memoryless. What does that mean? It means that previous events do not impact the next block interval. And it also means, that in any moment we look into the blockchain, the average time to the next block will always be the same: 10 minutes.

Imagine this, you are trying to pay for some groceries with your Bitcoins and you are waiting for the confirmation. Now, confirmation block hasn’t been mined for 5 minutes already. And you think to yourself, it should be mined any minute now, since the average block interval is 10 minutes. Actually because exponential distribution has a characteristic of being memoryless, it doesn’t really matter for how long you have been waiting already. That doesn’t change the probability, and the fact that the next block will be mined in average 10 minutes from now.

Now that we know what is the distribution of block intervals, let’s try to solve this question mathematically.

When we have independent events happening, we can use Poisson distribution to determine the probability of events happening in a given time period. All we need to know is an average number of events that should happen in the given time period.

Poisson probability for K events
  • λ is an average amount of events
  • K is a number of events we are calculating probability for

Now that we know how to calculate probability, we can go back to the question. We are interested in the probability of 0 events happening within an hour. In average we expect 6 events to happen in an hour, since average block interval is 10 minutes. So we get:

Probability of 0 events happening in an hour

There we have it, mathematically calculated probability of 0 events happening in an hour. Now we can answer the original question: How often does mining a new block take more than an hour? We expect this to happen once every e⁶ events, or e⁶ * 10 minutes.

So every 2 days and 20 hours we can expect a block interval of more than 1 hour.

We can go back to the BigQuery dataset and see how often does Bitcoin blockchain really see this happening, and if our prediction is accurate.

At the moment of writing, if you run this query, you will get 1572 rows, which is the number of times a block interval exceeded 1 hour in the history of Bitcoin blockchain.

All together there were 666.279 blocks mined until now, with the average block interval of 10 minutes. This means that in average, this event occurred every 2 days and 22 hours.

Scatter plot of all blocks which’s block interval exceeded one hour

Seemingly a very simple blockchain property block interval, can be quite interesting to dive more deep into. We can see that with Poisson distribution we were able to very accurately predict how often block interval takes more than an hour. And that is also a testament to the Bitcoin blockchain, on how reliable and predictable it has been throughout the years.

It can be quite tricky to gather all Bitcoin blockchain data in a well organised data structure, so I’m really glad that BigQuery provides us with up to date public datasets that we can use in our own projects.

Source: https://medium.com/swlh/how-often-does-bitcoin-take-an-hour-to-mine-a-new-block-c1c89e6e45eb?source=rss——-8—————–cryptocurrency

spot_img

Latest Intelligence

spot_img