32

The timestamps starting at block 145044 are:

145044: 2011-09-12 15:46:39     
145045: 2011-09-12 16:05:07 
145046: 2011-09-12 16:00:05 // ~5 minutes before prior block
145047: 2011-09-12 15:53:36 // ~7 & ~12 minutes before 2 prior blocks
145048: 2011-09-12 16:04:06 // after 2 prior blocks but still before 145045

How does this occur?

2
  • is the notion of time in btc still this fuzzy in 2016? has there been any BIP to make this more strictly ordered? Sep 22, 2016 at 21:13
  • @smatthewenglish: If you have a new question, please create another topic: How to Ask
    – Murch
    Nov 5, 2020 at 14:41

9 Answers 9

26

From the wiki:

A timestamp is accepted as valid if it is greater than the median timestamp of previous 11 blocks, and less than the network-adjusted time + 2 hours. "Network-adjusted time" is the median of the timestamps returned by all nodes connected to you.

Whenever a node connects to another node, it gets a UTC timestamp from it, and stores its offset from node-local UTC. The network-adjusted time is then the node-local UTC plus the median offset from all connected nodes. Network time is never adjusted more than 70 minutes from local system time, however.

It's not obvious that there aren't any problems with this way of timestamping. See the blog post Timejacking & Bitcoin and the discussion about it here.

4
  • 1
    So block producers out of sync by up to an hour or 2 cause no real problems so long as they remain in the minority.
    – Mocky
    Sep 12, 2011 at 17:54
  • 1
    I added some info on potential problems to the answer.
    – D.H.
    Sep 12, 2011 at 19:59
  • so then the blockchain is more about ordering, and timestampedness only in a more abstract sense is it? Sep 14, 2016 at 14:32
  • What do you mean by ****greater than the median timestamp of previous 11 blocks**** ? Apr 18, 2017 at 12:42
19

The root cause of this is that without a central authority, it's impossible to know for sure what the current time is.

The protocol rejects blocks with a timestamp earlier than the median of the timestamps from the previous 11 blocks or later than 2 hours after the current network time. Any other timestamp is acceptable. Note that 'network time' may differ from the actual time, since the bitcoin network attempts to correct for incorrect clock settings by taking the median of the time reported by all connected peers as the network time.

You can read about an attack that this makes possible here:

By announcing inaccurate timestamps when connecting to a node, an attacker can alter a node's network time counter and deceive it into accepting an alternate block chain. This could significantly increase the chances of a successful double-spend, drain a node's computational resources, or simply slow down the transaction confirmation rate.

4
15

To add a bit to the other answers: Imagine if the protocol required that timestamps increase. Now imagine somebody mines a block with a timestamp a minute in the future as far as you can tell. What do you do? If you try to mine blocks with the timestamp you currently believe is correct, your blocks will get rejected (since they'd have a timestamp earlier than the last accepted block).

Due to the requirement that the network easily agree on whether a block is valid or not, the protocol can't require highly-accurate timestamps as a condition of accepting a block as valid. As a result, requiring monotonic timestamps would likely make things worse rather than better.

11

There is no requirement that blocks have a timestamp after the previous block. The only requirement is that the timestamp is greater than the median timestamp of the last 11 blocks. So this means that a block can have a lower timestamp than its parent, within a certain bound.

This happens because miners do not have perfectly in sync clocks. There can be slight differences in their internal clocks that make them off by a few seconds. If a miner gets really lucky and finds a block soon after another one, because of the clock differences, it is possible that his clock is still behind the timestamp of the parent block. That is probably what happened here.

7

I believe the timestamp is based off of the machine hosting the bitcoin client that submitted the block, and variance is allowed as not everyone has their computer time synched properly.

1
  • Do you know where is the code that performs this function? Sep 22, 2016 at 16:47
7

At least one mining pool deliberately sets timestamps 6 minutes in the future and Block 145045 appears to be from Eligius (the generation transaction is split into multiple addresses).

1
  • why do they do that? do they still do it? Sep 22, 2016 at 21:14
4

Block timestamps are not very accurate and are allowed to be up to several hours off. It is difficult for a decentralized network to come to an agreement on an official time.

Reasons that it might be inaccurate are different system times, lag, and also miners often change the time by small amounts once they have tried all possible nonces. This allows them to get new hashes using the old nonces.

Here are the rules of what timestamps are allowed.

4

There is a fair amount of leeway in the block timestamp. The timestamp for block N must be greater than the median network time, which is calculated as the median of the past 11 blocks, and also less than the network time + 2 hours, where network time is calculated based on the node's system time, as well as the median time reported by the node's peers.

1

A block's timestamp should only be treated as an approximate time that the block was mined. There is no way to enforce a miner to include 'the actual time', because it is impossible for the network to ascertain the truth of this. So instead, the network imposes a rule that the timestamp must adhere the following rules in order to be considered valid:

(The info below is copy/pasted from the Bitcoin.org developer reference)

The block time is a Unix epoch time when the miner started hashing the header (according to the miner). Must be strictly greater than the median time of the previous 11 blocks. Full nodes will not accept blocks with headers more than two hours in the future according to their clock.

Thus, it is possible for a block at height N to have a timestamp that comes after the the timestamp of the block at height N+1, as long as it follows these rules otherwise.

1
  • 1
    "Full nodes will not accept blocks with headers more than two hours in the future according to their clock." that is not entirely correct AFAIK. It should not be more than two hours from the 'network adjusted time'. When you connect to a node, the node sends a time stamp and you store the difference between the time returned to you by the node and your current local clock. Then after connecting to all nodes you calculate the median deviation between your clock and the network clock. At any point you calculate 'network adjusted time' by adding your local time to the median dev noted earlier
    – Ugam Kamat
    May 21, 2019 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.